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

Cap HackTheBox 简单 Linux 机器复盘，涵盖不安全的目录对象引用（IDOR）、信息泄露、滥用 Capabilities（Python3.8）（提权），并包含实用的枚举、

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

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

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

## 侦察

**工作区设置：**

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a81481797c9cbfb49c64290bc93ab8fedf2eceb1%2Fimage%20(2635).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-30fc5efd2317beac0cfc470d6e18975a3d27f37c%2Fimage%20(2636).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.245 -oG allPorts
```

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

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

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

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

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

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

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

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

### 端口 80 - HTTP

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

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

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

## IDOR 漏洞

**初步观察**

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

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

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

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

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

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

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

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

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

#### 凭据的使用

**FTP 访问**

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

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

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

**SSH 访问**

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

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

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

## 权限提升

### 漏洞 Capabilities Python3.8

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

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

```bash
getcap -r / 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-bad265b20ed751399b0407a02b119c26920f019a%2Fimage%20(890).png?alt=media" 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="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-634dcad12e29296cc5b5e81aa1a1c440ce70709e%2Fimage%20(891).png?alt=media" alt=""><figcaption></figcaption></figure>

### root.txt 标志 :)

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-aa4e8bc4f48dc5657804fd3bbeeb59fe60e7526d%2Fimage%20(892).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-ecc4d94682f76c14c22c6861e1e64a264a784df7%2Fimage%20(893).png?alt=media" 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 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/cap-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.
