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

# Internal

## 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 21,80 -sS -Pn -sCV`&#x20;

<figure><img src="https://438683079-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIbHEScEP34huXd5EXNdb%2Fuploads%2FI1wL5UDvZbRZHJtJeVer%2Fimage.png?alt=media&amp;token=34f935bb-cccf-4df0-a2cf-975364842cb8" alt=""><figcaption></figcaption></figure>

As we can see, it tries to redirect to `http://internal.dl` so we will add this domain to our `/etc/hosts:`

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

```
ffuf-vhost () {
	ffuf -H "Host: FUZZ.$1" -u http://$1 -w /usr/share/wordlists/seclists/Discovery/DNS/subdomains-top1million-20000.txt ${@: 2}
}
```

we did `ffuf-dir internal.dl` and we found the following subdomains, so we add it also to `/etc/hosts`:

<figure><img src="https://438683079-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIbHEScEP34huXd5EXNdb%2Fuploads%2FG5tqAtPO3aPjHinNjUnq%2Fimage.png?alt=media&amp;token=cc69b3a6-7368-4fb5-a070-4a4b28917d5f" alt=""><figcaption></figcaption></figure>

<figure><img src="https://438683079-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIbHEScEP34huXd5EXNdb%2Fuploads%2FcNJwMtofAiUL7HwULT8O%2Fimage.png?alt=media&amp;token=dddea7c2-8fcb-432b-8999-c181998fff0b" alt=""><figcaption></figcaption></figure>

Browsing `internal.dl` gives us little to no information, but `backup.internal.dl` give us a potential attack vector:

<figure><img src="https://438683079-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIbHEScEP34huXd5EXNdb%2Fuploads%2Fdev1fTFCKzS1FGCPuqgT%2Fimage.png?alt=media&amp;token=e88638d4-b76a-434c-be01-925331899e62" alt=""><figcaption></figcaption></figure>

<figure><img src="https://438683079-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIbHEScEP34huXd5EXNdb%2Fuploads%2FFcM8847y7UHH9ghVspss%2Fimage.png?alt=media&amp;token=1d3f1233-f1d6-4cf8-8bbd-bc8fea6479a3" alt=""><figcaption></figcaption></figure>

As we can see, there is a field where we input a path, and the server is executing a `ls -lah:`

<figure><img src="https://438683079-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIbHEScEP34huXd5EXNdb%2Fuploads%2FhyU3nIawP79Zdf5TXkKx%2Fimage.png?alt=media&amp;token=85d1aa46-8305-4365-9c35-7a7e94db4c3d" alt=""><figcaption></figcaption></figure>

## 3 - Exploitation

Trying to do `/etc/passwd | echo "test"` and many other operators get blacklisted, so we start trying all the potential ways to bypass the WAF. Finally, we found that with `$()` we can bypass the operator blacklist, but many commands like `echo` or `cat` are blacklisted too.

This is a minor problem, as usually we can bypass it via `c '' a '' t`, and this is a example of that situation.

<figure><img src="https://438683079-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIbHEScEP34huXd5EXNdb%2Fuploads%2FEuhVDEmLQPo9nzEMk6ib%2Fimage.png?alt=media&amp;token=ce32f90b-9705-46ae-b2f7-4d9a995973bc" alt=""><figcaption></figcaption></figure>

Knowing this, we could craft a reverse shell to catch it with `penelope` . For this, we need to create it on our attacking host, and download it from the victim via wget.

<figure><img src="https://438683079-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIbHEScEP34huXd5EXNdb%2Fuploads%2FJdCPZAlIFNed7Nq9ZQgJ%2Fimage.png?alt=media&amp;token=ec270ef0-f846-4103-97e9-ae2147f3cb3b" alt=""><figcaption></figcaption></figure>

<figure><img src="https://438683079-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIbHEScEP34huXd5EXNdb%2Fuploads%2Fl6zf0e26mfo7qARzmA2e%2Fimage.png?alt=media&amp;token=fd2a88c2-6dbe-4225-904d-710853bd582f" alt=""><figcaption></figcaption></figure>

After setting up our listener with `penelope -p 3110` we will activate it via `$(b''a''s''h /opt/revshell)`.

<figure><img src="https://438683079-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIbHEScEP34huXd5EXNdb%2Fuploads%2Ft9BowMmxW6Eh3z2KPJON%2Fimage.png?alt=media&amp;token=3f828d03-2c7f-4fc4-b841-931d62f6509c" alt=""><figcaption></figcaption></figure>

## 4 - Privilege Escalation

Doing `/find -type f -name "*.txt" 2>/dev/null` we will try to find any .txt file storing credentials or any useful data, and we found the following one:

<figure><img src="https://438683079-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIbHEScEP34huXd5EXNdb%2Fuploads%2FzAFISxCf2MjF316MOW5l%2Fimage.png?alt=media&amp;token=1050bd34-fd52-4ebd-8416-a42e6ff0a641" alt=""><figcaption></figcaption></figure>

<figure><img src="https://438683079-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIbHEScEP34huXd5EXNdb%2Fuploads%2FD1wWFXDaI33jQKV92dRd%2Fimage.png?alt=media&amp;token=36414f25-2e7e-4c95-9722-00d30c4cff4e" alt=""><figcaption></figcaption></figure>

We can see reading `/etc/passwd` that `vault` is a system user, so we'll try to perform an `hydra` attack on him using that set of passwords:

<figure><img src="https://438683079-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIbHEScEP34huXd5EXNdb%2Fuploads%2Fb1x2eQDPNwSrdrkncYI5%2Fimage.png?alt=media&amp;token=420055a0-9ed0-4a21-9048-3f7e585951bb" alt=""><figcaption></figcaption></figure>

We found `vault:Yk8$pZ5@cN4!` , so we will access via SSH.

Running the following commands trying to find useful information, we got this files:

<figure><img src="https://438683079-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIbHEScEP34huXd5EXNdb%2Fuploads%2F2wKRR3oAfqNOi3HWri44%2Fimage.png?alt=media&amp;token=ce5e4db3-a03f-43ed-b6ba-0d7f196f4310" alt=""><figcaption></figcaption></figure>

<figure><img src="https://438683079-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIbHEScEP34huXd5EXNdb%2Fuploads%2FiDMGkYrg8OwFBwBonqot%2Fimage.png?alt=media&amp;token=f95d52c0-73fe-4417-be2f-472a64e41ac6" alt=""><figcaption></figcaption></figure>

<figure><img src="https://438683079-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIbHEScEP34huXd5EXNdb%2Fuploads%2Fb08W1eedmKuY0yc0HWnC%2Fimage.png?alt=media&amp;token=268a7dfd-5fb3-4e1e-816d-bb777a28bd59" alt=""><figcaption></figcaption></figure>

As we saw on the SUID listing, we have `/usr/local/bin/vaultctl` with SUID bit activated, and after researching a bit, just by executing it we'll spawn a root shell:

<figure><img src="https://438683079-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIbHEScEP34huXd5EXNdb%2Fuploads%2FeM8P8m4CEpsG7iTGZygP%2Fimage.png?alt=media&amp;token=8a15e032-1235-4966-974d-8f7340d9ecc4" alt=""><figcaption></figcaption></figure>
