Hack The Box - Cap
Cap is an easy Linux challenge on HTB. The name of the machine is a nice hint guiding the way to solve this challenge. First, it leads to an IDOR or insecure direct object reference that gives access to a PCAP. This PCAP contains unencrypted traffic from another user connecting and logging in over FTP. These credentials then give access FTP but also allow logging in as this user. Once on the box, a setuid capability is granted to the Python binary, making it easy to spawn a new shell as the root user.
Recon
An nmap
scan reveals the following open ports FTP (21), SSH (22) and HTTP (80):
It doesn’t seem that anonymous access is available on FTP. Besides that nmap
shows that gunicorn is running behind port 80, hinting that this is most likely a python application. Opening the website in Firefox reveals a dashboard of some sorts:
At this point I kick of a gobuster scan gobuster dir -u http://10.10.10.245 -w /opt/SecLists/Discovery/Web-Content/raft-small-words.txt -o ./gobuster.txt
to see if there are any hidden paths to exploit. While that is running in the background I start doing some manual discovery. The navigation on the left gives access to a couple of pages
The Security Snapshot menu goes to /capture
but eventually redirects to /data/3
. It seems to be a network capturing tool showing the amount of TCP, IP and UDP for some networks. Clicking the download link goes to /download/3
and will download a pcap file. Opening up the pcap file in Wireshark shows that the file all contains network traffic from my IP and the target machine. It’s the plain http traffic that the gobuster created. This reveals that this tool is capturing all network traffic from the public networking interface of the target machine.
Opening the IP Config /ip
page seems to be returning the result from the ipconfig
command. Thinking about this for a second, it’s probably safe to assume that the previous link is executing tcpdump
on the eth0
interface.
The last page Network Status goes to /netstat
and just returns the output of executing netstat
.
The result of the gobuster
scan doesn’t reveal anything new or hidden. All paths uncovered via the scan we already found doing manual recon:
Getting a shell as user
As far as the enumeration goes, we didn’t discover all that much. We got a couple of pages that mostly return some static information. But the /capture
page is a rather interesting one. Reloading the page a few times it starts redirecting to different pages over time. Initially, it redirected to /data/3
, but after a few more gobuster scans and that id started going. All gobuster information start from id 3, this makes me wonder what pcap files are available before id 3. This is what they call an IDOR insecure direct object reference. It is a vulnerability that allows an attacker to manipulate a URL or a parameter to a request to access objects they aren’t supposed to access.
With curl
it’s possible to quickly download all available pcap files:
Digging through the first pcap file 0.pcap
reveals credentials for a user nathan in a plain text FTP session:
Using the username nathan
and password Buck3tH4TF0RM3!
gives access to the FTP server and contains the user.txt
file:
The same username and password also gives access to login via SSH:
Escalating to root
The home directory is rather empty, but as it turns out it was also possible to just access the user.txt just by logging in via SSH:
A tool like linPEAS will give a better insight into what vulnerabilities are available on the system. I personally prefer download the script to my local machine and make it available via a python webserver:
Downloading and immediately piping into bash make sure we are not leaving a trace on the system while running recon. The result reveals that python has the set_uid capability set. Capabilities are a Linux feature introduced a while back to break down the permissions of the root user. So instead giving program full root privileges you can give it a few capabilites.
The capabilites set on Python binary are cap_setuid
and cap_net_bind_service+eip
. Opening up the man page for these capabilites with man capabilities
reveals what extra features it gives to the Python binary:
We can see that the cap_net_bind_service
can be used to allow a process to bind to privileged ports, which ports less than 1024. This is a pretty useful on but also we can’t really exploit. The cap_setuid
on the other hand allows changing the UID when forking of into a new process. We can easily abuse this capability by having python start bash as the root user;
Running that command gives access the root
user and the root.txt
flag.