root@thehacksparrow:~/writeups$ SYSTEM ONLINE
root@sparrow:~/writeups$ cat crypto-failures.md
// Offensive

Crypto Failures

3 Jan 2024 · 12 min read · root access
Executive summary — Crypto Failures is a Medium cryptography and web-exploitation room on TryHackMe. The server builds a secure_cookie by applying PHP's crypt() (DES variant) to 8-byte chunks of the string user:USER_AGENT:ENC_SECRET_KEY and concatenating the outputs. Because DES crypt() encrypts each 8-byte block independently with a mere 2-character salt, controlling the User-Agent length lets us isolate a single unknown byte of ENC_SECRET_KEY in its own block and brute-force it by comparing crypt() outputs. Once the key is recovered, we forge a secure_cookie for user=admin and read the web flag. A block oracle → recover key → forge cookie → flag journey.
PlatformTryHackMe
Operating systemLinux (PHP web application)
DifficultyMedium
RoomCrypto Failures
Target IP10.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 to guest on the target.
  • secure_cookie — a concatenation of crypt() 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, and urldecode before comparing blocks.
🔒 Clearance required

This content is Root Access only. Everything else on the site — the free tier, the whole public library — stays open.

See Root Access plans

No account? Create one free then upgrade from your console.