root@sparrow:~/writeups$ cat crypto-failures.md
// Offensive
Crypto Failures
3 Jan 2024
· 6 min read
· root access
Executive summary — Crypto Failures is a Medium cryptography and web-exploitation room on TryHackMe. The server builds asecure_cookieby applying PHP'scrypt()(DES variant) to 8-byte chunks of the stringuser:USER_AGENT:ENC_SECRET_KEYand concatenating the outputs. Because DEScrypt()encrypts each 8-byte block independently with a mere 2-character salt, controlling theUser-Agentlength lets us isolate a single unknown byte ofENC_SECRET_KEYin its own block and brute-force it by comparingcrypt()outputs. Once the key is recovered, we forge asecure_cookieforuser=adminand read the web flag. A block oracle → recover key → forge cookie → flag journey.
| Platform | TryHackMe |
| Operating system | Linux (PHP web application) |
| Difficulty | Medium |
| Room | Crypto Failures |
| Target IP | 10.10.122.185 |
Attack map
[80/HTTP] secure_cookie = concat( crypt(8B_block, salt) ) over
user:USER_AGENT:ENC_SECRET_KEY
| DES crypt() -> independent 8-byte blocks + 2-char salt
v
[ORACLE] tune the User-Agent length to isolate
1 unknown key byte in its own block
| brute-force printable ASCII, compare the crypt() block
v
[KEY] recover ENC_SECRET_KEY byte by byte (THM{...} encryption key)
| forge secure_cookie for user=admin (same salt + same UA)
v
[FLAG] request as admin -> web flag THM{...}1. Reconnaissance — inspect the cookies
First, request the web root and inspect the Set-Cookie headers. We pin a known User-Agent because, as we will see, it is part of the encrypted plaintext:
curl -s -D - -A 'testUA' http://10.10.122.185/ -o /dev/null | grep -i '^Set-Cookie'At least two cookies show up:
user— defaults togueston the target.secure_cookie— a concatenation ofcrypt()outputs; its first two characters are the 2-char salt.
We extract the secure_cookie string and the salt (first two characters):
SEC=$(curl -s -D - -A 'testUA' http://10.10.122.185/ -o /dev/null \
| awk -F'Set-Cookie: ' '/secure_cookie/ {print $2}' \
| sed 's/;.*//' | tr -d '\r\n')
echo "secure_cookie from server: $SEC"
# first two chars are the salt
SALT=${SEC:0:2}
echo "detected salt: $SALT"Note: some servers URL-encode the cookie value in the header (you may see%2F, etc.). Work with the raw string returned above to extract the salt, andurldecodebefore comparing blocks.
🔒 Clearance required
Root Access unlocks the content you can't see — everything else on the site is already open.
See Root Access plansNo account? Create one free then upgrade from your console.