382-Validation HTB Official Writeup Tamarisk
382-Validation HTB Official Writeup Tamarisk
Validation
9th September 2021
Difficulty: Easy
Classification: Official
Synopsis:
Validation is an easy machine created for the September Qualifiers of UHC (Ultimate Hacking
Championship). There is a web page that lets users register and specify their country. Once
signed in, the website displays other users within your Country and the query it does this is
Vulnerable to SQL Injection. The registration function utilizes Prepared Statements and is not SQL
Injectable, however the developer trusted that all data from the database was safe and did not
use Prepared Statements when viewing others users in the country making this a Second Order
SQL Injection. It is possible to write a webshell and then escalate to root via a re-used database
password.
Skills Required
Web Enumeration
SQL Injection
Enumeration
Nmap
nmap -p- 10.10.11.116
Nmap reveals that 22 (SSH), 80 (HTTP), and 8080 (HTTP) are open. Only Port 80 gives us a page,
so we will start there.
The easiest way to exploit this is to open two Repear Tabs, one for registering accounts and the
other for viewing the account.php page. The workflow is:
By sending the country of Country' Union Select 1-- - , we see the page no longer displays an
error which tells us the SQL Query is returning 1 variable.
Dropping a File
Knowing that there is Union Injection and that this is an PHP Applicaiton, we can attempt to use
the "INTO OUTFILE" statement of SQL to drop a webshell. Sending the payload
It will create a PHP WebShell on the server which was can use to get code execution. The weird
thing about this is the /account.php , will display an SQL Error which may lead you to believe it
did not work. This is because the SQL Syntax we used does not return any fields when creating
the file, it is expecting it to return the country name but since it doesn't it errors. If you navigate
to 10.10.11.116/shell.php you can confirm the file now exists.
Getting a Reverse Shell is as simple as just sending the normal bash URL Encoded payload:
Note: You may not always get a visible prompt back after you enter the password. If you enter a
command you will see it did provide you a shell.