Sitemap
Krang2K

Krang2K

Penetration Testing write-ups, discussions, and all other things considering. When all else fails, RTFM!

TryHackMe: Root Me

6 min readJul 20, 2022

Room: https://tryhackme.com/room/rrootme
THM Level: Easy
Actual Level: Very Easy, Beginner

Summary:
The TryHackMe room ‘Root Me’ is a guided beginner question room. The below walk-through is intended to assist all beginners at a very basic level. I will show you how to start from nothing and create an attack surface that will lead to compromising the host with a root shell. Let’s begin Enumerating :-)

Walk-through

Task 2: Reconnaissance
Add the IP address to your /etc/hosts file by running the following command in the terminal. Replace the IP address (10.10.212.49) with the IP address THM gives you after you start the machine.

After adding the IP address to the/etc/hosts and giving the box enough time to boot up I start with a basic TCP port scan using Rustscan that will also run basic Nmap scripts.

Press enter or click to view image in full size
Simple TCP port scan using Rustscan: rustscan -a rootme.thm -u 5000

Command Breakdown:
The -a defines the address to scan which is rootme.thm. The -u is short for ulimit and allows us to increase the number of packets sent to the address. The output gives us the answer to the first question.

  1. How many ports are open? 2

Next, Let’s use Nmap to detect the version.

Press enter or click to view image in full size
Nmap command to detect version: nmap -p 22,80 -sV --version-all rootme.thm

Command Breakdown:
The -p specifies which ports to scan. We know from the Rustcan output that port 22 and 80 are open. -sV is the flag we need to detect the service Version. You can detect most common versions with the -sV flag alone but I decided to add the argument --version-all which will try every single probe. Now we can answer question 2 and 3.

2. What version of Apache is running? 2.4.29

3. What service is running on port 22? SSH

Press enter or click to view image in full size
Nmap -sV Output

Let’s visit rootme.thm/index.php in a browser!

Press enter or click to view image in full size
http://rootme.thm/index.php

We are returned a Linux prompt animation that just says root@rootme:~# and asks the question “Can you root me?”.

Let’s check the source code by pressing the Ctrl + U key on the keyboard.

Press enter or click to view image in full size
Ctrl + u

We want to check for possible comments in the html code that may help expand the attack surface further. Comments will stand out with a green color font to you. In the above screenshot, you can see there are no comments but rather just the html comment tags that are empty. An actual comment example is shown below and could possibly contain URL’s, passwords, usernames, or other information that developer’s will leave behind.

HTML Comment Example

Let’s continue with some directory busting/fuzzing to find additional directories that are not linked to the home page. There are many tools that can be used to find hidden directories such as dirb, dirsearch, dirbuster, gobuster, feroxbuster, ffuf, wfuzz just to name a few. All of these tools have pro’s and con’s and can pretty much use use the same wordlists that you so choose. My recommendation is to start with a basic fast scan and follow up with more thorough scans later. Finding a good hidden directory is dependent on you choosing a good wordlist. I will start with a basic dirsearch scan just to show the simple syntax.

Press enter or click to view image in full size
dirsearch -u http://rootme.thm -x 403

Command Breakdown:
The -u specifies the URL we want to directory bust while the -x excludes any returned HTTP 403 codes. The 403’s can pill up and this is a basic first scan. If I was working on a harder attack surface I may include the 403’s in later scans to potentially bypass the forbidden areas.

Get Krang2K’s stories in your inbox

Join Medium for free to get updates from this writer.

Two directories stand and look very juicy! /panel/ and /uploads/

I’ll scan with Gobuster as well since the room asked for that tool just so you can compare the two tools.

Press enter or click to view image in full size
gobuster dir --url http://rootme.thm -w /usr/share/wordlists/dirb/common.txt -b 404,403

Command Breakdown:
When using gobuster you must specify which mode you are going to use first. In this case, I am using dir which means the directory / file enumeration mode. Other options that can be used are dns, fuzz, s3,or vhost but are not needed for our purposes right now. The --url flag is to specify the URL you are targeting. The -w flag is needed along with a file path to the wordlist you are going to use. Tools such as dirb and dirsearch have a wordlist that will be used if you don’t specify one. Gobuster on the other hand needs a list. The -b will exclude all HTTP 403 and 404 responses.

We can see that /panel and /uploads was returned with HTTP 301 redirects. Both of these HTTP 301 redirects to HTTP 200 of /panel/ and /uploads/.

Let’s visit those directories to determine next steps using a browser.

http://rootme.thm/panel/

Question 5 is ready to be answered since /panel/ isn’t hidden to us anymore.

5. What is the hidden directory? /panel/

Task 3: Getting A Shell
Earlier, we saw the site is using .php so we’ll try and upload a reverse shell that uses the .php file extension in the panel upload area but first we need to bypass the panel upload application since a .php file extension is not allowed to be uploaded.

Somewhere in the code it could specify file types that are allowed or not allowed so I’ll look at the view-source. No such luck, the filtering must be happening in the back.

The primary strategy for identifying a file upload vulnerability is to manipulate the file extension. There is a good list at hacktricks https://book.hacktricks.xyz/pentesting-web/file-upload.

I used the following list:
php
php2
php3
php4
php5
php6
php7
phps
phps
pht
phtm
phtml
pgif
shtml
htaccess
phar
inc
hphp
ctp
module

I used Burp Suite to automate the attack by replaying the list of file types using Intruder. Start Burp and proxy the browser web traffic through it (you can use FoxyProxy if you’re on the AttackBox and browsing with FireFox).

You need to capture the HTTP PUT request and replay the attempt.

Send this over to Intruder:

I’ll use PHP PentestMonkey reverse shell and download it from www.revshells.com, which is a great website to bookmark for future engagements if you haven’t done so already. Pentestmonkey has their website and you can also find this php reverse shell on Github.com page. Input your tun0 ip address and port number you wish to use in order to catch the reverse shell. (Note: You can run the command `ip a` to get your ip address from the command line.)

Press enter or click to view image in full size
Copy A PHP Reverse Shell

TO BE CONTINUED…

--

--

Krang2K
Krang2K

Written by Krang2K

Penetration Testing write-ups, discussions, and all other things considering. When all else fails, RTFM!