Hack the Box (HTB) machines walkthrough series — Sneaky
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 Sneaky.
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?
Note: Only write-ups of retired HTB machines are allowed. The machine in this article, named Sneaky, 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 Sneaky machine IP is 10.10.10.20.
- We will adopt the same methodology of performing penetration testing as we’ve used previously. Let’s start with enumeration in order to gain as much information about 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 Sneaky 10.10.10.20>>
- As we can see, we only have port 80 listed from the normal ones available.
- Let’s enumerate on port 80. We can see this in the page below.
- Let’s try to brute-force this to enumerate other directories as well.
<<gobuster -u 10.10.10.20 -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt>>
- We got a hit on /dev directory, which gives us the page below:
- Some initial testing showed that SQL injection is possible. So a trivial SQL injection got us in.
- We got two names and a link to the key.
- Below is the key we have in the portal. Let’s save it locally. Despite saving it locally, we do not have a port to log into.
- Back we go to full port enumeration. We got the below ports.
- We got snmp open, so we can do a snmp walk
<<snmpwalk -v2c -c public 10.10.10.20 > snmp.txt>>
- The result indicates that there are IPv6 interfaces available. We’ll use ENVX to grab all the interfaces and we get the below interfaces. We’ll use the correct one below to log in.
- As shown below, we can log in using the saved key and the discovered IPv6 interface.
- We enumerate to grab the user.txt flag.
- Further enumerating for escalating privilege, we can see that the suid bit is set on following files.
<<find / -perm 4000 2>/dev/null >>
- Looking into the chal file, it seems like it is a candidate for buffer overflow.
- Generating a pattern of 400 using pattern_create.
<<pattern_create.rb -l 400>>
- We pass the pattern to the binary using GDB.
- We now collect the location from above and pass it to the pattern_offset file.
<<pattern_offset.rb -q {location}>>
- Now we have the offset, we need to find the EIP location. Let’s do that with random As with GDB, as shown below.
- As we can see, all the As are in the location range below.
- After some trial and error, we see that below is the EIP and whole script that can be used to overflow the buffer and execute the shell code to spawn /bin/sh.
- Running that, we can see that we got a shell with an effective ID of root.
<<chal ${python exp.py}>>
- We enumerate to grab the root flag.
This is a straightforward machine with lot of enumeration involved to grab the IPv6 interfaces, which then requires trivial buffer overflow to grab the root flag and shell.
What should you learn next?
We will continue this series soon with more such interesting HTB machines.