This is a medium difficulty Linux machine from HackTheBox created by Frey and thek. In this scenario, my IP is 10.10.14.103 and the target’s IP is 10.129.11.47
Gathering Information
This step is always the same, you must ping the machine to see if is alive, and then use Nmap to scan all the ports to avoid surprises.
Looks like http-robot.txt is open, if there is nothing relevant at the website, we can check some urls by /http-robot.txt.
Browser: http://10.129.11.47/
There is no registration panel
To explore the website, try to login with simple credentials, like admin@admin, or admin@admin1234, etc (Nothing Happens). And then try to recover your password.
With this kind of answer, we can't enumerate.
Now we return to our finding.
Browser: http://10.129.11.47/robots.txt
Looks like we need to be logged in to get more information from these paths. But after exploring many of them, /help have interesting information.
Browser: http://10.129.11.47/help
Click in bookmarks.html
As you can see, in view:source at bookmarks.html, there is a Java Script command written in hexadecimal, copy it and use echo to translate.
The output it is still dirty, we need to replace every " by using | sed "s/"/'/g" at the end of the previous command.
And here, we can find some important information, like {user_login : clave} and {user_password : 11des0081x}, let's try at user login.
Browser: http://10.129.11.47/users/sign_in
Login with clave@11des0081x
We are in, it's time to explore the whole site.
At Snippets there is something interesting.
We can save this information for the future, a good practice is to copy this file and save it in your local device. After doing this, return to Projects > Your Projects > Administrator/Profile.
Here, we have to find where is project is launched, is a profile page, so it must be at http://10.129.11.47/profile/, and if you go to http://10.129.11.47/profile/developer.jpg, you can see that is directly connected, for us this is an advantage, because we are connected as developer "clave" and we can upload or create files here.
Create a new file called reverseShell.php and add the below code, after that, commit and merge the new file.
Here, we need to be the user "clave" to see the content of the first flag. Previously, we found a postgresql file in the machine. First you must test with which psql if the system has the application, if not, you can simulate something similar with php, and it's already tested that the target have PHP.
If we follow the process by using the example from PHP: PDO, we can login to PSQL.
And we found a password, open a new terminal and translate the password with: echo "c3NoLXN0cjBuZy1wQHNz" | base64 -d; echo. The output is {ssh-str0ng-p@ss}, with this in hand, open a new terminal, translate, and then login thorough ssh.
Privileges Escalation
So first we want to gather information from the current account.
And the only interesting thing here is only the file "RemoteConnection.exe", we will download that file and then try to figure out what's going on.
From the target, encrypt the whole file in base64, copy the content and create a file at your local terminal, with the same name.
If you use md5sum in both files, and the result is the same (same hash), is the same .exe file and you did the process well.
Now from our local terminal, we will analyze the executable.
To continue the scanning of the executable file, we are going to use GHidra
Move to file to the dragon.
Here, the best option to analyze the file, is seeing every function inside the folder F.
Here there is something about Putty.exe, a ssh remote connection software. And something about "ipParameters," is probably that the credentials are here. To extract it we are going to use a debugger like x32dbg.
- x32dbg: Load the file
- x32dbg: Right Click > Search for > All Modules > String References
- x32dbg: Search for "Clave", because of what we found at the code. And double click at the remoteconnection row.
- x32dbg: Press F2 in the row 00C01647 to stop the executable file until that point.
printf "var _0x4b18=["\x76\x61\x6C\x75\x65","\x75\x73\x65\x72\x5F\x6C\x6F\x67\x69\x6E","\x67\x65\x74\x45\x6C\x65\x6D\x65\x6E\x74\x42\x79\x49\x64","\x63\x6C\x61\x76\x65","\x75\x73\x65\x72\x5F\x70\x61\x73\x73\x77\x6F\x72\x64","\x31\x31\x64\x65\x73\x30\x30\x38\x31\x78"];document[_0x4b18[2]](_0x4b18[1])[_0x4b18[0]]= _0x4b18[3];document[_0x4b18[2]](_0x4b18[4])[_0x4b18[0]]= _0x4b18[5];" | sed "s/"/'/g"
var _0x4b18=[';value';,';user_login';,';getElementById';,';clave';,';user_password';,';11des0081x';];document[_0x4b18[2]](_0x4b18[1])[_0x4b18[0]]= _0x4b18[3];document[_0x4b18[2]](_0x4b18[4])[_0x4b18[0]]= _0x4b18[5];
Connection received on 10.129.11.47 60386
bash: cannot set terminal process group (1415): Inappropriate ioctl for device
bash: no job control in this shell
www-data@bitlab:/var/www/html/profile$ whoami
whoami
www-data
Target Terminal [www-data]
which psql # Nothing happens
php --interactive
php example
<?php
/* Connect to a MySQL database using driver invocation */
$dsn = 'mysql:dbname=testdb;host=127.0.0.1';
$user = 'dbuser';
$password = 'dbpass';
$dbh = new PDO($dsn, $user, $password);
?>
php --interactive
$connection = new PDO('pgsql:dbname=profiles;host=localhost', 'profiles', 'profiles');
$connect = $connection->query("select * from profiles");
$result = $connect->fetchAll();
print_r($result);
echo "c3NoLXN0cjBuZy1wQHNz" | base64 -d; echo
ssh-str0ng-p@ss
ssh clave@10.129.11.47 # ssh-str0ng-p@ss
# It fails? Maybe is now necessary to decrypt the password...
ssh clave@10.129.11.47 # c3NoLXN0cjBuZy1wQHNz==
# It works