> For the complete documentation index, see [llms.txt](https://eslam3kl.gitbook.io/blog/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://eslam3kl.gitbook.io/blog/hack-the-box-machines/friendzone-walkthrough.md).

# FriendZone Walkthrough

Hey Everyone! We have one of HackTheBox machines which is considered VM like OSCP, so let’s take a look at its info

<figure><img src="https://cdn-images-1.medium.com/max/800/1*fajkMFqq9FDjx8VMxCA6dw.png" alt=""><figcaption></figcaption></figure>

<figure><img src="https://cdn-images-1.medium.com/max/800/1*sOl6qM6nNtu6uxXGAH-chQ.png" alt=""><figcaption></figcaption></figure>

## **Nmap Scan**

Weof  will start our scan with knowing the open ports, services running on them, OS version, etc

`nmap -A -T4 -oG friend.gnmap 10.10.10.123`

<figure><img src="https://cdn-images-1.medium.com/max/800/1*43EUmfRsuq1jGj26AIdc_w.png" alt=""><figcaption></figcaption></figure>

As you can see, I’ve a bunch of interesting open ports, but note that in `https/443` you will find that we have subdomain `friendzone.red` and the end of the scan in `script scan results`

<figure><img src="https://cdn-images-1.medium.com/max/800/1*3_DzJBMf0Y-QlFtZX7IK7A.png" alt=""><figcaption></figcaption></figure>

`Message sigining enabled but not required` This mean that you can login to the `ftp` server with any random username and password

From here I’ve put my methodology which I’ll follow through this machine:

1. HTTP/HTTPS Enumeration
2. FTP Enumeration

Because we don’t have any more options

## **HTTPS/HTTP/FTP Enumeration**

By accessing `http://10.10.10.123`

<figure><img src="https://cdn-images-1.medium.com/max/800/1*s00pr2otTttDL3Z3MMVxvw.png" alt=""><figcaption></figcaption></figure>

Nothing here, just keep note of this mail, it may be internal mail, and this domain `friendzoneportal.red`

I’ve checked the source code and nothing appears, so let’s try to brute-force the directories by using `gobuster`

<figure><img src="https://cdn-images-1.medium.com/max/800/1*rguw4IwLZ0s6xX1_CSrbVA.png" alt=""><figcaption></figcaption></figure>

Nothing useful directory here, `robots.txt` doesn’t have information, let’s check [`https://10.10.10.123`](https://10.10.10.123/)

<figure><img src="https://cdn-images-1.medium.com/max/800/1*gqgVof0OdS26uURsq1LZ7Q.png" alt=""><figcaption></figcaption></figure>

Not found!! Ok, let’s try to add the subdomain which we found before from `nmap` scan to `/etc/hosts` and try again

<figure><img src="https://cdn-images-1.medium.com/max/800/1*xQiDFsouZ2ejf_rC_qkM3Q.png" alt=""><figcaption></figcaption></figure>

Access it again

<figure><img src="https://cdn-images-1.medium.com/max/800/1*fnhg5KM9AdrCINEcYBCa-A.png" alt=""><figcaption></figcaption></figure>

Good we have page here, let’s check the directories

<figure><img src="https://cdn-images-1.medium.com/max/800/1*lnVuUJrG0gAxLoyu8yghrA.png" alt=""><figcaption></figcaption></figure>

we have 2 directories, I’ve checked `/admin` and it doesn’t have any useful info, but the `/js` have

<figure><img src="https://cdn-images-1.medium.com/max/800/1*84mMAFKR04kIssWClAp6cw.png" alt=""><figcaption></figcaption></figure>

It seems that `base64 encoded`, let’s check the source code

<figure><img src="https://cdn-images-1.medium.com/max/800/1*6RbBa9OtNTP8HbX7gKgrDw.png" alt=""><figcaption></figcaption></figure>

I’ve guessed that word `zone` may be referring to `zone transfer` an attack. I’ve tried to search for `how to attack port 53 “DNS”`

<figure><img src="https://cdn-images-1.medium.com/max/800/1*F5pYcN9o2nbBvQSN1q6E5A.png" alt=""><figcaption></figcaption></figure>

From the first result, I’ve found it performs `Zone transfer` the attack, so I’ve tried to do the same by using `dig`

`dig axfr zonetransfer @10.10.10.123`

<figure><img src="https://cdn-images-1.medium.com/max/800/1*MtHW1b-lnA7Q38k1tVt1JA.png" alt=""><figcaption></figcaption></figure>

Good, we have more subdomains, let’s add them into `/etc/hosts`

<figure><img src="https://cdn-images-1.medium.com/max/800/1*L3K0Jd8cf2qnwgTBTSJgWQ.png" alt=""><figcaption></figcaption></figure>

Let’s try to open `uploads.friendzone.red`

<figure><img src="https://cdn-images-1.medium.com/max/800/1*yLt8avVe0n2Pi9eMf96fLA.png" alt=""><figcaption></figcaption></figure>

And after trying to upload `shell`

<figure><img src="https://cdn-images-1.medium.com/max/800/1*ZSY9YNDvkKh5GgJm11EImw.png" alt=""><figcaption></figcaption></figure>

It works and get back a number that I couldn’t know what it used for, it may be upload id ! May be.

After uploading this I’ve tried to access `/uploads/shell.php` but it fails, let’s see the other subdomains.

I’ve tried to open `administrator.friendzone.red` but it required creds, so I tried to list all content from `FTP` server by using `smbmap`

`smbmap -H 10.10.10.123 -u 'radfad' -p 'dfadfaf' -R -A creds.txt`

<figure><img src="https://cdn-images-1.medium.com/max/800/1*VQG3ZCq0gsUroSkXtYmZZg.png" alt=""><figcaption></figcaption></figure>

I’ve found username and password for admin account, and I’m sure that we will fail if we try to user them with `ssh` so I used them with the admin login portal

<figure><img src="https://cdn-images-1.medium.com/max/800/1*9BvUbOwozscNZD-t4ABdzA.png" alt=""><figcaption></figcaption></figure>

and It works

<figure><img src="https://cdn-images-1.medium.com/max/800/1*hs5DSoBgOcSgta27neI2ow.png" alt=""><figcaption></figcaption></figure>

<figure><img src="https://cdn-images-1.medium.com/max/800/1*sua082P9dXZSmkFJ1P7zuw.png" alt=""><figcaption></figcaption></figure>

It tells us to access these parameters so let’s try

<figure><img src="https://cdn-images-1.medium.com/max/800/1*4NW8JqxNTgzSu7QsMl7_9w.png" alt=""><figcaption></figcaption></figure>

The last parameter deals with the Database so what if it was vulnerable by `LFI or SQLi` let’s try `LFI`

I’ve tried to get `../../../../../etc/passwd` but it fails, so I’ve tried to get the source code for `dashboard`

<figure><img src="https://cdn-images-1.medium.com/max/800/1*orpUkhIjFLV1v3nZbutg4g.png" alt=""><figcaption></figcaption></figure>

It’s in base64 form, let’s decode it

<figure><img src="https://cdn-images-1.medium.com/max/800/1*Zbqltj3LxnvKOZKBdVWzmg.png" alt=""><figcaption></figcaption></figure>

As you can see it take the name of the page and then add `.php` at the end of.

I’ve to upload `shell.php` and access the page as `shell` from the upload page but also it fails, so I tried to upload the shell using the `FTP` server because I’ve permission to `write` in a share directory

<figure><img src="https://cdn-images-1.medium.com/max/800/1*RivZkwdk9c068ZdLmAvi4A.png" alt=""><figcaption></figcaption></figure>

After that the shell will be in `/etc/Development/shell.php` directory

Let’s try to access it through the webpage and also open `nc`

<figure><img src="https://cdn-images-1.medium.com/max/800/1*wl7t_HJGOIgEMHftpGDe_g.png" alt=""><figcaption></figcaption></figure>

<figure><img src="https://cdn-images-1.medium.com/max/800/1*PY-fyFk4crSmK9NkxxC4vA.png" alt=""><figcaption></figcaption></figure>

It works, and we have a shell now, let’s try to open `user.txt`

<figure><img src="https://cdn-images-1.medium.com/max/800/1*V6VdLnSHAYN6Z_Zg8HWgpA.png" alt=""><figcaption></figcaption></figure>

Okay, let’s search enumerate the box.

After a few minuter I’ve found this file which contain database information in `/var/www`

<figure><img src="https://cdn-images-1.medium.com/max/800/1*nfxyoI8IhTFDNxEjAS61Gw.png" alt=""><figcaption></figcaption></figure>

Use them to login with `ssh`

<figure><img src="https://cdn-images-1.medium.com/max/800/1*ahkMzddQih9WBBdva1P_dw.png" alt=""><figcaption></figcaption></figure>

Okay we have more priv. Now but we need to be as root

After using `LinPEAS` I’ve not found anything interesting, so I’ve used `PSPY` to see what happens in the box and what happen when `friend` user login to the server

After executing it,I’ve found that `reporter.py` executed every 2 minutes

<figure><img src="https://cdn-images-1.medium.com/max/800/1*LIYP580yZ00qT6WPYNVlig.png" alt=""><figcaption></figcaption></figure>

Let’s check it

<figure><img src="https://cdn-images-1.medium.com/max/800/1*pC92hlB8NCe223jS-jByMQ.png" alt=""><figcaption></figcaption></figure>

It contains `os.system(command)` which I tried to put `/bin/bash` instead of `commnd`, but I don’t have permissions to edit it, but it imports `os` library, and I think I’ve permission to edit it, I noticed that from `LinPEAS` results, let’s check

<figure><img src="https://cdn-images-1.medium.com/max/800/1*8tcu70LBDx2Q0Y00SWSttg.png" alt=""><figcaption></figcaption></figure>

That’s right, we can edit it, so I searched for `python reverse shell` and found this code

<figure><img src="https://cdn-images-1.medium.com/max/800/1*As572-yNNy2IxY8FlJfr4w.png" alt=""><figcaption></figcaption></figure>

> The last line in the code contain the command which open escaping interactive shell *and **subprocess*** library used for executing `bash` commands into `python` code

and after added it to the `os.py` and open `nc` to listen over `443` port

<figure><img src="https://cdn-images-1.medium.com/max/800/1*buzI0ZhXB2C4pl3crALkJw.png" alt=""><figcaption></figcaption></figure>

It works and we’ve the `root` flag ❤
