Overpass

Overpass

Room link: https://tryhackme.com/room/overpass

Scanning

I ran an nmap aggressive scan on the box using nmap -A [Remote IP].

PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 37:96:85:98:d1:00:9c:14:63:d9:b0:34:75:b1:f9:57 (RSA)
|   256 53:75:fa:c0:65:da:dd:b1:e8:dd:40:b8:f6:82:39:24 (ECDSA)
|_  256 1c:4a:da:1f:36:54:6d:a6:c6:17:00:27:2e:67:75:9c (ED25519)
80/tcp open  http    Golang net/http server (Go-IPFS json-rpc or InfluxDB API)
|_http-title: Overpass
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 18.61 seconds

Just to cover all my bases, I also ran a full port scan on the box to see if there were any random open ports using nmap -p- [Remote IP].

PORT   STATE SERVICE
22/tcp open  ssh
80/tcp open  http

Nmap done: 1 IP address (1 host up) scanned in 47.09 seconds

So, it appears that we are only working with ssh and http for services.

Enumeration

Let's use Nikto and gobuster to enumerate the website. I like using Nikto with the -h option and gobuster with the directory-list-1.0.txt file produced by SecLists (https://github.com/danielmiessler/SecLists). Depending on your computing capability, it may take a while to complete directory enumeration

The output of Nikto shows interesting locations like /admin, /downloads, and /img.

Gobuster produced some of the same information.

Initial Access

The /admin page asks for a username and password. Using the Network section in Developer Tools on the browser, I can see that when the login button is pressed a login.js script runs. I took a look at the login.js file.

The most important section is the login() function, specifically the Cookies.set("SessionToken",statusOrCookie). With this information, I can set the Cookie to be blank, which bypasses the if statement (if (statusOrCookie === "Incorrect credentials")) and authenticates. I will set the Cookie in the Developer Tools console with:

After setting the Cookie, I simply reload the /admin page and I will authenticate and login.

Exploitation

After authenticating, I am presented with an RSA private key on the /admin page:

I attempted to authenticate with the rsa private key (make sure to set the correct permissions with chmod 400 ssh_james) as ssh -i ssh_james james@[THM IP]. However, it requested a passphrase:

Therefore, I needed to use John the Ripper to crack the passphrase for me. ssh2john is a great python script within john that helps me to format the private key for use with john.

Now that it is properly formatted, I can attempt to crack the passphrase with John the Ripper. I used rockyou as the wordlist.

The passphrase returned:

With the passphrase, I am able to login as user james and find flag at user.txt.

Privilege Escalation

After logging in as james, there is a txt file with a possible hint for privilege escalation:

The note gave hints to a possible "automated build script" which makes me think about crontab. Looking at /etc/crontab:

The last line (* * * * * root curl overpass.thm/downloads/src/buildscript.sh | bash) looks interesting and should be investigated since it is run by root. To check out the build script, I used curl to grab it from http://[RemoteIP]/downloads/src/buildscript.sh.

Basically, the job runs and updates builds from latest code using go. If I can change the buildscript to execute a reverse shell, it will be executed by root and I will have escalated privileges. In order to do so, I noticed the overpass.thm in crontab, meaning it references the /etc/hosts file to obtain the correct IP address. Therefore, if I can change the /etc/hosts file to point at my remote machine when it calls the buildscript, the job will call my attack box IP address and run the buildscript on my machine. To ensure I can update /etc/hosts file I checked the permissions.

Right now, the /etc/hosts file looks like the below.

It needs to be changed to reflect my local/attack box IP.

Let me create a reverse shell in bash and place it within my local machine at /downloads/src/buildscript.sh.

After creating the buildscript, I need to start up a python3 http server on port 80 in the parent directory of /downloads/src/buildscript.shfor the remote machine to call with the crontab.

Now, in a different terminal, I start a netcat listener on port 5555 to receive the reverse shell.

After a certain period of time, the job calls the build script, creates a reverse shell and escalates privilege!

I can see the HTTP GET request by the Overpass machine to my local machine.

In the terminal where my netcat listener is set up, I am dropped into a root shell.

Last updated