Hack the Box (HTB) machines walkthrough series — Magic
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 Magic.
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 Magic, is retired.
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 “Magic” machine IP is 10.10.10.185.
- We will adopt our usual methodology of performing penetration testing. Let’s start with enumeration in order to learn as much information about the machine as possible.
- As usual, let’s start with the Nmap scan to gather more information about the services running on this machine.
<<nmap -sC -sV -oA Magic 10.10.10.185>>
- As we can see that we can only access two ports: 22 and 80. Let’s start the enumeration from them.
- Below is the home page in port 80.
- There is a login page, which is susceptible to SQL injection with a simple payload such as ‘ or ‘1’=’1 .
- After that, we get an image upload box. I tried uploading a direct PHP shell and PHP shell embedded with other image formats but it worked with the .png format.
- Browsing that uploaded shell, we got a reverse shell back as www-data.
- Enumerating the system, we got a DB file named db.php5, which revealed a surname and password for user “theseus”. Trying to sudo that user with the password failed.
- Using mysqldump to dump the DB revealed another password, as shown below.
- Using this password to sudo to user “theseus” was a success. Before that, we need to upgrade our current shell also, as shown below.
- Grabbing the user.txt file.
- Now, let’s start the escalation process. Seems like a SUID binary on the machine.
- Checking its normal usage, it looks like there must be lot of system-level commands in use to gather such information from the machine.
- Running strings on the binary reveals multiple commands in use such as fdisk, free and so on.
- Since their explicit location is not used, we can exploit any such commands by hijacking the control flow through our malicious binary. Below is the malicious “free” binary:
- Once uploaded, we make the binary executable:
- Append that to the system path so that malicious free is executed first and we get a reverse shell back.
- We ran the binary again and as expected, it hangs while executing free binary because it is busy in giving us the shell back.
- We got a shell back as root. Enumerating to grab the root.txt file:
This was a good machine where the initial foothold was somewhat challenging. After that, escalation to root was straightforward.
We will continue this series with more examples of interesting HTB machines.
We've encountered a new and totally unexpected error.
Get instant boot camp pricing
A new tab for your requested boot camp pricing will open in 5 seconds. If it doesn't open, click here.