Sitemap
MeetCyber

hack the present, secure the future

Hack The Box: Cap Writeup

3 min read6 days ago

--

Press enter or click to view image in full size

Machine Name: Cap

Difficulty: Easy

OS: Linux

Machine Overview

Cap is an easy difficulty Linux machine running an HTTP server that performs administrative functions including performing network captures. Improper controls result in Insecure Direct Object Reference (IDOR) giving access to another user’s capture. The capture contains plaintext credentials and can be used to gain foothold. A Linux capability is then leveraged to escalate to root.

1. Reconnaissance & Enumeration

Start by scanning the target host with nmap to discover open ports and running services:

Press enter or click to view image in full size

The scan reveals three active services:

  • Port 21: FTP (vsftpd 3.0.3)
  • Port 22: SSH (OpenSSH 8.2p1)
  • Port 80: HTTP (Gunicorn / Python web application)

2. Web Exploration & IDOR Vulnerability

Navigating to the web interface on port 80 reveals an administrative dashboard featuring network diagnostics and a “Security Snapshot” feature.

Press enter or click to view image in full size

Inspecting the URL structure suggests potential Insecure Direct Object Reference (IDOR) vulnerability.

Testing sequential IDs by modifying the path to /data/0 grants access to the earliest capture log recorded by the system.

Press enter or click to view image in full size

3. Traffic Analysis with Wireshark

Open the downloaded capture file in Wireshark:

Press enter or click to view image in full size

Inspect overall traffic via Statistics → Protocol Hierarchy.

  • A notable amount of unencrypted FTP traffic is present.
Press enter or click to view image in full size

Apply an FTP display filter:

Press enter or click to view image in full size

Follow the TCP stream or inspect the USER and PASS packets directly.

Get CyberExplorer’s stories in your inbox

Join Medium for free to get updates from this writer.

Plaintext credentials leaked in the stream:

  • Username: nathan
  • Password: Buck3tH4TF0RM3!

4. Initial Access (User Flag)

With these credentials, authenticate via FTP to inspect accessible files:

Listing directory contents confirms the presence of user.txt. Retrieve it to the local machine:

ftp> ls -la
ftp> get user.txt
ftp> exit

the flag is downloaded, we can use cat command to see it

Alternatively, establish an interactive SSH session as nathan:

Press enter or click to view image in full size

5. Privilege Escalation (Root Flag)

Once authenticated via SSH, enumerate system binaries and permissions. Inspecting Linux capabilities assigned to executables reveals an insecure permission:

Press enter or click to view image in full size

input: getcap -r / 2>/dev/null

Output : /usr/bin/python3.8 = cap_setuid,cap_net_admin+eip

The cap_setuid capability allows the binary to change its effective User ID (UID) without requiring full root/sudo privileges.

Exploit this by executing Python to set the process UID to 0 (root) and spawn a privileged shell:

python3 -c ‘import os; os.setuid(0); os.system(“/bin/bash”)’

Press enter or click to view image in full size

we can find our next flag here in the root/root.txt file

Press enter or click to view image in full size

--

--