TryHack3M: Sch3Ma D3Mon

A guided challenge to learn about SQL injection exploits. -by strategos, MaxRobertson and arebel

The following post by 0xb0b is licensed under CC BY 4.0


Some Wireshark

We download the task files and find a ssl_key.log file in there as well as a pcapng. Inspecting the pcapng with Wireshark, we see we are dealing with a lot of encrypted HTTPS traffic. Since we have a ssl_key.log file, we can decrypt that traffic following the guide below:

Edit → Preferences → Protocols → TLS → (Pre)-Master-Secret log filename [ssl-key.log]

After adding the ssl.key.log file, we should be able to see the clear text content of the HTTPS traffic.

To answer the first two questions, we follow packet no. 78.

right click → Follow → HTTP Stream

Here we find the credentials to access the products search page for the following tasks.

Manual and Non-Manual SQLI

We start a Nmap scan and find three open ports, on port 8000 we find the page in question.

After logging in with the found credentials from the Wireshark pcapng file...

...we are redirected to /searchproducts.php.

Manually

We have to guess or enumerate the database, since we have some column names like Product Name, Product Type, etc. on the page, we deduce that the actual column names in the table are like product_name. Since the challenge heading is about unlisted stuff, and we are facing the products page, we try the table name unlisted_products. With that, we are able to retrieve the hidden path.

We could also enumerate the database by querying the information_schema.tables.

See this article as referene:

With the following query we can retrieve all tables from the database:

Get the columns of the table:

Retrieve the data from the table:

Easter Egg

Go check it out :)

SQLMap

We can capture the request of searching an arbitrary product and use that in SQLMap to dump the entire database and finding some neat easter eggs and all the info we need for the upcoming questions.

OS Command SQLI

We head to /os_sqli.php and edit the provided payload with 3 additional null values, and get the user in context running the OS commands.

Running pwd to answer the question of Task 4.

To find the needle in the malwarestack we are asked to decrypt the .txt.gpg files with the keys hidden in the database. Let's first try to retrieve the receipts. We can find the receipts at /home/receipts.

But we can't actually retrieve its full content since it is cut.

A workaround is to spawn a reverse shell. We see that we have python3 available. Let's craft a python3 reverse shell using revshells.com and save the file to our machine. Next, we create an HTTP server via python on our machine to make the script available to the target machine. We use curl via the sqli OS command page to download the reverse shell script and then execute that afterwards.

Download the reverse shell to /tmp:

Execute reverse shell:

We have now an interactive shell which can be upgraded using:

With the upgraded shell we can move arround freely.

Now we are able to extract the contents fully of 300000.txt.pgp via cat and copy its content. Next, we save that.

Next, we can use the dump of SQLMap to retrieve the bitcoin_sender_address to decrypt the receipt and get the location of the malware.

You can also retrieve it manually. Head back to /searchproducts.php.

First, checkout the tables we have:

Transactions seems promising:

Get the contents of transactions table:

After decrypting the receipt we get the path to the malware. In line 59 we can see which file extension gets added to the file after encryption.

By reading the readme.txt, we are able to determine how to set the program in debug mode. After running the program in that mode, we are able to retrieve the final flag.

Last updated

Was this helpful?