> 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/very-easy/hedgehog.md).

# Hedgehog

Themed username brute-forced with Hydra, pivoted from tails to sonic via sudo, and gained root through unrestricted sudo permissions.

## 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`

**Result:**

<figure><img src="https://438683079-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIbHEScEP34huXd5EXNdb%2Fuploads%2FSvkB3N2ymuwomkhgJEzb%2F(Hedgehog)%20Targeted%20Port%20Scan.png?alt=media&amp;token=3d6423e4-d87a-49a0-81e6-020f546d93a6" alt=""><figcaption><p>(Hedgehog) Targeted Port Scan</p></figcaption></figure>

We tried to find exploits or shellcodes using `searchsploit OpenSSH 9.6p1` and `searchsploit Apache httpd 2.4.58` but there wasn't any. Our next step will be directory enumeration.

With the command `ffuf -w /path/to/wordlist/directory-list-2.3-medium.txt:FUZZ -u http://10.129.129.108/FUZZ` we didn't find anything useful, so we will browse the website.

<figure><img src="https://438683079-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIbHEScEP34huXd5EXNdb%2Fuploads%2F3SrhX8AlUl50OhhnglaM%2F(Hedgehog)%20Web%20Content.png?alt=media&amp;token=d2c0c2bd-e376-45db-9335-b715567284db" alt=""><figcaption><p>(Hedgehog) Web Content</p></figcaption></figure>

There wasn't anything useful on the source code, and since the machine name is "Hedgehog" and Tails is a character from the game series, we will try to brute-force SSH with Hydra using that username.

## 3 - Exploitation

Running:

```
hydra -l tails -P /usr/share/wordlists/rockyou.txt ssh://172.17.0.2
```

we found the next credentials: `tails:3117548331`.

## 4 - Privilege Escalation

Running `sudo -l` we can see that user `tails` has the next permissions:&#x20;

<figure><img src="https://438683079-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIbHEScEP34huXd5EXNdb%2Fuploads%2FDh4yJ5MsAVbpNIQ6D8BN%2F(Hedgehog)%20Tails%20Sudo%20Permissions.png?alt=media&amp;token=3d2f7af9-2052-49a9-a933-eba32349ce48" alt=""><figcaption><p>(Hedgehog) Tails Sudo Permissions</p></figcaption></figure>

Knowing that, we ran `sudo -u sonic sudo -l` and found this:

<figure><img src="https://438683079-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIbHEScEP34huXd5EXNdb%2Fuploads%2FXaTgGBnzzoYUGwyn5oJo%2F(Hedgehog)%20Sonic%20Sudo%20Permissions.png?alt=media&amp;token=3270aa65-c3ff-4949-917c-4665d18f4891" alt=""><figcaption><p>(Hedgehog) Sonic Sudo Permissions</p></figcaption></figure>

Finally, we can run `sudo -u sonic sudo su` and we spawn a root shell.

## 5 - Summary

**Initial Access:** Obtained valid credentials by discovering an username on the website. The password was cracked using `hydra`.

**Execution:** Pivoted to user `sonic` using `sudo` permissions on all commands as `sonic`.

**Privilege Escalation:** Elevated privileges to root using `sudo` permissions on all commands as `root`, as it was allowed for the `sonic` user.
