Skip to content

Commit 0f0da63

Browse files
committed
HTB: Cap walkthrough
1 parent 4f96e80 commit 0f0da63

3 files changed

Lines changed: 132 additions & 0 deletions

File tree

_posts/2026-05-13-HTB-Cap.md

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
---
2+
published: true
3+
layout: post
4+
title: "HTB: Cap"
5+
categories: [hackthebox,htb]
6+
tags: [htb,hackthebox,easy,retired]
7+
---
8+
9+
![Cap HTB Logo](../assets/images/caplogo.png)
10+
11+
# Introduction
12+
13+
Cap is an easy-rated Linux machine on Hack The Box that serves as a great introduction to analyzing packet captures and understanding Linux capabilities. The attack path involves discovering an IDOR vulnerability on a security dashboard web application, extracting credentials from a PCAP file, and then abusing a Python capability misconfiguration to escalate to root.
14+
15+
# Enumeration
16+
17+
## Nmap
18+
19+
Starting with a full port scan to identify running services:
20+
21+
```bash
22+
nmap -sC -sV -p- -v cap.htb
23+
```
24+
> Note: Added cap.htb to my `/etc/hosts`
25+
26+
Three ports came back open:
27+
28+
```
29+
PORT STATE SERVICE VERSION
30+
21/tcp open ftp vsftpd 3.0.3
31+
22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.2
32+
80/tcp open http Gunicorn
33+
```
34+
35+
FTP (vsftpd 3.0.3), SSH (OpenSSH 8.2p1), and an HTTP server running Gunicorn. Anonymous FTP login was not allowed, and searchsploit didn't return anything useful for this version of vsftpd, so the web application became the primary focus.
36+
37+
## Web Application
38+
39+
Navigating to port 80 revealed a "Security Dashboard" application. The dashboard had several pages including network stats and a page at `/data/<id>` that appeared to provide downloadable PCAP captures. The page at `/data/1` showed the current session's capture, but the ID parameter in the URL stood out as a potential IDOR (Insecure Direct Object Reference).
40+
41+
## IDOR - Enumerating PCAP Files
42+
43+
Using `ffuf` to fuzz the ID parameter confirmed that multiple PCAP files existed:
44+
45+
```bash
46+
ffuf -w id.txt -u http://cap.htb/data/FUZZ -mc 200
47+
```
48+
49+
IDs 0 through 7 all returned valid responses. Each one could be downloaded via `/download/<id>`. All of the PCAP files were downloaded in bulk:
50+
51+
```bash
52+
for i in {0..7}; do
53+
wget "http://cap.htb/download/$i"
54+
done
55+
```
56+
57+
## Analyzing the PCAPs
58+
59+
Opening the downloaded captures in Wireshark revealed that PCAP `0` was the most interesting -- it was significantly larger than the others and contained FTP traffic. Following the TCP stream for the FTP session exposed plaintext credentials:
60+
61+
- **User:** `nathan`
62+
- **Password:** `Buck3tH4TF0RM3!`
63+
64+
![FTP Packets](../assets/images/capftp.png)
65+
66+
# Foothold
67+
68+
## SSH Access via Password Reuse
69+
70+
With the credentials recovered from the FTP capture, the next step was to test for password reuse. Since SSH was open, a direct login attempt was made:
71+
72+
```bash
73+
ssh nathan@cap.htb
74+
```
75+
76+
The FTP credentials worked for SSH -- password reuse gave us a shell as `nathan`.
77+
78+
## User Flag
79+
80+
The user flag was sitting in nathan's home directory:
81+
82+
```
83+
nathan@cap:~$ cat ~/user.txt
84+
c6278..........98a5d5
85+
```
86+
87+
# Privilege Escalation
88+
89+
## Enumeration with LinPEAS
90+
91+
After running `linpeas.sh` on the target, one finding immediately jumped out -- a Linux capability set on the Python binary:
92+
93+
```
94+
/usr/bin/python3.8 = cap_setuid,cap_net_bind_service+eip
95+
```
96+
97+
The `cap_setuid` capability allows a process to set its user ID to any value, including `0` (root). When this capability is assigned to an interpreter like Python, it becomes trivial to escalate privileges.
98+
99+
## Exploiting Python Capabilities
100+
101+
A quick check on [GTFOBins](https://gtfobins.github.io/gtfobins/python/#capabilities) confirmed the exploitation path. With `cap_setuid` set on Python, a one-liner is all it takes:
102+
103+
```bash
104+
python3 -c 'import os; os.setuid(0); os.execl("/bin/sh", "sh")'
105+
```
106+
107+
This sets the UID to 0 (root) and spawns a shell:
108+
109+
```
110+
# id; whoami
111+
uid=0(root) gid=1001(nathan) groups=1001(nathan)
112+
root
113+
```
114+
115+
## Root Flag
116+
117+
```
118+
# cat /root/root.txt
119+
d5e7667.............a8a6
120+
```
121+
122+
# Summary
123+
124+
| Stage | Technique |
125+
| --- | --- |
126+
| Enumeration | Nmap full port scan, web application enumeration |
127+
| IDOR | Fuzzing `/data/<id>` to find other users' PCAP files |
128+
| Credential Discovery | Extracting FTP credentials from PCAP 0 via Wireshark |
129+
| Foothold | SSH login using reused FTP credentials |
130+
| Privilege Escalation | Abusing `cap_setuid` capability on `/usr/bin/python3.8` |
131+
132+
Cap is a straightforward machine but it reinforces some important fundamentals: always check for IDOR vulnerabilities when you see sequential IDs in URLs, always inspect PCAP files for cleartext credentials, and always enumerate Linux capabilities during privilege escalation. The name "Cap" is a hint in itself -- both the packet **cap**tures and the Linux **cap**abilities are central to solving this box.

assets/images/capftp.png

306 KB
Loading

assets/images/caplogo.png

93.3 KB
Loading

0 commit comments

Comments
 (0)