[HTB | Hard] Pollution

HackTheBox Link

Port Scanning

We start with a simple nmap scan:

We can see that we have 3 open ports:

  • Port 22: simple ssh

  • Port 80 Apache web server

  • Port 6379 Redis database

Web Scanning

Website Enumeration

As we can deduct from the server is that we have a domain (collect.htb) that we can add to our "/etc/hosts" and for the login/register input there is nothing we can do for now.

Scanning for vhosts we found out that we have 2 of them:

  • forum.collect.htb

  • developers.collect.htb

As the "developers" endpoint is protected by a htpasswd login we check for the forum.

Proxy History and First Escalation

After browsing the forum the only suspicius thing we could observe is a proxy history posted by one of the user:

Inside this file we can see some http request encoded in base64 but one is more useful than all the others:

We can actually try this post request on the main website to get the administrator page (you need to be logged with a normal user and to replace the PHPSESSID cookie)!

XXE

It seems there is nothing useful in the admin page apart for the form which let you subscribe to the API. Intercepting the request with BurpSuite we can notice that is a API that accept xml input:

After some tries we got arbitrary file read through XXE by hosting a dtd file in our machine and adding an external entity in the API request. XXE portswigger exercise that helped me + a php wrapper

For achieve the local file read we need to setup a few but simple things:

  1. Host a python server

  1. Create a local .dtd file (mine is called exploit.dtd) (insert in <FILETOREAD> the path of the file you want to read, you cannot read all files) (insert in <IP> your machine ip)

  1. Make a request including the entity in the xml api request

  1. decode from base64 the files recieved in the python server log

Local File Enumeration, Further Escalation and RevShell

As soon we got Local file enumeration we read the index.php:

Nothing useful here, but we can surely check the required ../bootstrap.php:

Nice, we now have credentials fo the redis server. But we are not done with local files because we remembered that there is an htpasswd-protected "developers" endpoint so we need to read /var/www/developers/.htpasswd: developers_group:apr1$MzKA5yXY$DwEz.jxW9USWo8.goD7jY1

We simply crack the password with hashcat (hashcat -a 0 -m 1600 hash.txt rockyou.txt) and get the combo: developers_group:r0cket

We can now login to developers.collect.htb We now got another login page (uff) We once again ask for our previous local file reading to read /var/www/developers/index.php:

Ok, we need "auth" set in our session.

After a bit of research we found out that we can actually see and modify our PHPSESSID thanks to the Redis database credentials we found earlier HackTricks Redis Pentesting

Now we can just authenticate by setting auth|s:4:\"True\"; with: set PHPREDIS_SESSION:r7f65lnphhgddoosgngf4gou1i "username|s:4:\"test\";role|s:5:\"admin\";auth|s:4:\"True\";"

The website actually don't seem to have nothing interesting, only the parameter in the url catch the eye.

After a lot of tries we finally got RCE thanks to php filer chains: python php_filter_chain_generator.py --chain '<?= print_r(system($_GET["cmd"]));?>' and then make a request like this on burpsuite: GET /?cmd=<command>&page=<php_chain>

RevShell to User

The thing that caught the attention was that the only user of the machine, victor, was running a strange process: "php-fpm" and searching for it we found FastCGI Pentesting which run on port 9000 (which is open on localhost). We can easily escalate to the user victor with this bash script:

We run it with: bash excalate.sh localhost And then: /tmp/victorbash -p

User 2 Root

In the user directory we found the folder "pollution_api" which was runned by root (root 1381 0.0 1.8 1679760 74312 ? Sl Mar28 0:01 /usr/bin/node /root/pollution_api/index.js): reversing the api we found out:

  • A mysql user and password

  • A prototype pollution vulnerability on the /messages/send endpoint

The first thing to do is to set up a user for our user in the database by updating the role from user to admin in the users table. We then now retrieve the x-access-token form the api sending a request like this from the previous admin panel in "collect.htb":

Then we make a request with the crafted Prototype Pollution Injection due to the non sanitized "merge" function:

We run the python script with python3 exploit.py

We've done it! Now we just need to /tmp/rootbash -p to get root privilege! uid=0(root) gid=0(root) groups=0(root)

That's was a really cool box and thanks for the reading.

Hope to see you soon!

Pedio Zaki

Last updated

Was this helpful?