> For the complete documentation index, see [llms.txt](https://itszaiden.gitbook.io/pentesting/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://itszaiden.gitbook.io/pentesting/writeups/dockerlabs/easy/vulnvault.md).

# VulnVault

## 1 - Reconnaissance

We begin with a fast Nmap scan to identify open ports:

`nmap 172.17.0.2 -p- --open -sS -Pn --min-rate 5000 -T5`

**Result: ports 22 and 80 are open.**

## 2 - Enumeration

Now we run a service/version detection scan, targeting only the open ports we found on the previous scan:

`nmap 172.17.0.2 -p 22,80 -sS -Pn -sCV`

<figure><img src="https://438683079-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIbHEScEP34huXd5EXNdb%2Fuploads%2Fz2Y4BU1SzUz2a7ELMcGN%2Fimage.png?alt=media&amp;token=d3d00a4e-910d-43fd-b128-641fd6c19e51" alt=""><figcaption></figcaption></figure>

We tried to find exploits or shellcodes but there wasn't any. Our next step will be directory enumeration. Using our tool **ffuf-dir:**

```
ffuf-dir () {
	ffuf -u $1 -w /usr/share/wordlists/dirb/big.txt ${@: 2} -e .html,.php,.txt
}
```

we did `ffuf-dir http://172.17.0.2/FUZZ` we found the following routes:

<figure><img src="https://438683079-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIbHEScEP34huXd5EXNdb%2Fuploads%2FT0xeHQvmEiJreO0tKiUo%2Fimage.png?alt=media&amp;token=7a0179ab-96c7-4f4b-9ac3-0c43da896f8b" alt=""><figcaption></figcaption></figure>

Browsing the website we saw some potential to upload a reverse shell hidden on a txt, but that wasn't a viable path on this machine. Therefore, we started trying with `/index.php`.

<figure><img src="https://438683079-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIbHEScEP34huXd5EXNdb%2Fuploads%2FwgatlYNDuEMyT0ojjaNE%2Fimage.png?alt=media&amp;token=340aa134-eb80-4aa5-8aee-f5961dc94786" alt=""><figcaption></figcaption></figure>

## 3 - Exploitation

We decided to try command injection, as it was making a `touch /var/www/html/reportes/ USERINPUT`. After inputting `; cat /etc/passwd` we found this:

<figure><img src="https://438683079-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIbHEScEP34huXd5EXNdb%2Fuploads%2FL7C3hMceL5V5gRQyBv8o%2Fimage.png?alt=media&amp;token=822a7762-bf68-452b-a0d3-b1ca866757ab" alt=""><figcaption></figcaption></figure>

As we can see, the only user with a `/home` is `/samara` so we'll try to find relevant data using this.

<figure><img src="https://438683079-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIbHEScEP34huXd5EXNdb%2Fuploads%2Fqx1cLzOqwOFEddUllwmd%2Fimage.png?alt=media&amp;token=2d25b397-2261-4710-8bff-4baf0a25d973" alt=""><figcaption></figcaption></figure>

<figure><img src="https://438683079-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIbHEScEP34huXd5EXNdb%2Fuploads%2F3IRiX89pXjo9I9vEavvI%2Fimage.png?alt=media&amp;token=47a5b290-2409-4854-81d6-32fc2ac2c2dd" alt=""><figcaption></figcaption></figure>

After checking, `message.txt` and `user.txt` are not useful, but we found a `.ssh` folder.

<figure><img src="https://438683079-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIbHEScEP34huXd5EXNdb%2Fuploads%2FptqaC70nwdmDV2aAHLZA%2Fimage.png?alt=media&amp;token=11a29c93-603d-4435-9644-2ab8592bc173" alt=""><figcaption></figcaption></figure>

After copying `id_rsa` we can login as `samara` on the system via private key.

<figure><img src="https://438683079-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIbHEScEP34huXd5EXNdb%2Fuploads%2FkAo1sBnT95edYyBsmZa5%2Fimage.png?alt=media&amp;token=b530946e-da13-40d1-a209-8eed40a6929e" alt=""><figcaption></figcaption></figure>

## 4 - Privilege Escalation

We didn't find any sudo rights on any binary nor SUID bit active on useful binaries.

<figure><img src="https://438683079-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIbHEScEP34huXd5EXNdb%2Fuploads%2FGWk7NmqlZ6rBisNng3ST%2Fimage.png?alt=media&amp;token=f624f006-2be0-47ac-8621-10900a34a4b6" alt=""><figcaption></figcaption></figure>

Listing the running processes we find this:

<figure><img src="https://438683079-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIbHEScEP34huXd5EXNdb%2Fuploads%2FmPFXxZT4WBPuApUJmAKj%2Fimage.png?alt=media&amp;token=0314b359-c06c-4350-9dbe-ae9a0f5234fa" alt=""><figcaption></figcaption></figure>

As we can see, `/usr/local/bin/echo.sh` is running as root constantly, and we have write permissions over that file, so changing its content to `chmod +s /bin/bash` will activate SUID bit on bash.

After running `/bin/bash -p` we obtain a root shell:

<figure><img src="https://438683079-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIbHEScEP34huXd5EXNdb%2Fuploads%2FtljhR2tr4L2nayov66OQ%2Fimage.png?alt=media&amp;token=5164eb48-1762-4bd4-8b71-8f246030bd5c" alt=""><figcaption></figcaption></figure>
