# Hack The Box - Chaos

## Quick Summary

Hey guys today Chaos retired and here’s my write-up about it. Chaos was a CTF-style machine, I can’t say that it simulated a real life situation. I had fun solving this box, some steps were straightforward others were very tricky. About main steps, To get an initial shell as www-data we will exploit a web application that used LaTeX. After that we will escalate privileges to another user and escape rbash. For root privilege escalation we will extract root credentials from a firefox profile and get a root shell. It’s a Linux box and its ip is 10.10.10.120, I added it to /etc/hosts as chaos.htb. Let’s jump right in.

## Nmap

As always we will start with nmap to scan for open ports and services :
nmap -sV -sT -sC chaos.htb

We got some ports. http on port 80 and 10000, email related services (imap, pop3) running on ports 110, 143, 993 and 995. Let’s check http.

## HTTP Initial Enumeration

Port 10000 gave me this error :

So I switched to https and got a login form :

We don’t have any credentials and I ran gobuster and got nothing interesting so we will ignore this and look at port 80.

It’s just a normal website, rest of it :

I checked that contact form and it’s doing nothing. I ran gobuster on chaos.htb and got these results :

And now this part is tricky. Because going to the ip of the box 10.10.10.120 instead of chaos.htb will give us a different thing (virtual hosting).

It’s saying Direct IP not allowed. I ran another gobuster scan on the ip and got different results :

On chaos.htb the thing the caught my attention was /source so I checked that and it didn’t have anything :

I checked http://10.10.10.120/wp and found a wordpress website :

I looked at the posts, there was only one post and it was password protected :

I clicked on the post link and saw that the author of the post is called human :

Before trying to bruteforce the password I tried some basic stuff first and the username:username type of credentials worked. The password was human :

And we got some credentials for mail : ayush:jiujitsu

## Accessing the e-mail Service, Decrypting Secret Message

We saw earlier some email services running on the machine. Now we have credentials to access these services. To do that we will use an email client, I used claws-mail (can be installed with apt) and configured it like this :

Inbox was empty but drafts had something :

After the message he attached two files : enim_msg.txt and en.py. He said you are the password, so first guess … password most likely will be sahay.
enim_msg.txt is the encrypted message :

And en.py is the script used to encrypt the message :

By looking at the encryption script we will know that the message is AES encrypted. I used this tool to decrypt the message :

Password sahay worked. The decrypted message was saved in a file called t. It was base64 encoded so I had to decode it :

Let’s check that.

## Exploiting LaTeX, Reverse Shell as www-data

It’s a web application that creates pdfs, There’s a field for input and 3 templates to choose from (test1, test2, test3) before trying to create a pdf I ran gobuster and got these results :

/doc :

Nothing important, just some documentation pdfs. There was a directory called latex, this reveals that the web app is using LaTeX.
/pdf :

This is where the created pdfs are saved, I looked at some of them and they were just tests. Like this one for example :

I tried to create a pdf and intercepted the request with burp :

The response showed a full log which revealed type and version of the backend software used to create the pdfs.

However the first template failed :

test2 worked fine :

test3 as well. LaTeX can be injectable and can cause some vulnerabilities if there wasn’t a good filter. I tried some payloads from Payloads All The Things and most of them got filtered. But this injection payload worked : \immediate\write18{command}. So I got a reverse shell like this :

Url Encoded :

We got a reverse shell as www-data, There are two users on the box : sahay and ayush. We need to be one of them :

## Privilege Escalation to ayush, Bypassing rbash, User Flag

We got earlier ayush credentials for mail : ayush:jiujitsu let’s try that password :

It worked but we are in a restricted bash shell now.
This guide is useful for bypassing restricted shells. I tried some commands to know what can I do from that shell and I could run tar. So I went back to www-data and went to /tmp.
I created a file and called it rick : touch rick
Then I added that file to a tar archive and called it rick.tar : tar -cvf rick.tar rick
I went back to ayush and used tar to bypass the shell : tar cf /dev/null rick.tar --checkpoint=1 --checkpoint-action=exec=/bin/bash
After that I just had to fix my path and I had a functioning bash shell :

Now we can read the user flag :

We owned user.

## Extracting Credentials from Firefox Profile, Privilege Escalation and Root Flag

By looking at the /home directory for ayush I saw something strange :

There was a .mozilla data directory there. I went there and there was a directory for Firefox and it had a profile :

We can use a tool called firefox decrypt and pass that profile to it. This tool extracts credentials from Firefox profiles.
I had to get the firefox directory on my box first, I ran a python simple http server on port 1919 in /home/ayush/.mozilla/firefox then on my box I created a directory called firefox and downloaded the contents of the original firefox directory from the simple http server : wget http://chaos.htb:1919/ --recursive.
Server Log :

Downloaded files were saved in a directory called chaos.htb:1919.
After that I used firefox_decrypt.py and gave it the profile which was called bzo7sjt1.default :

It asked for a password, I gave ayush‘s password (jiujitsu) and it worked. We got credentials for the application that was running on port 10000 and the username was root : root:Thiv8wrej~.
I didn’t go to port 10000 again, I tried su root first with this password and it worked :

We owned root !

That’s it , Feedback is appreciated !