> 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/ja/writeups-ctf/hackthebox/linux-easy/cap-hackthebox-writeup.md).

# Cap HackTheBox攻略記事

安全でないディレクトリオブジェクト参照（IDOR）、情報漏えい、Capabilitiesの悪用（Python3.8）（権限昇格）を扱うCap HackTheBox Easy Linuxマシンの攻略記事。実践的な列挙、

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

{% hint style="warning" %}
スキル:

* 安全でないディレクトリオブジェクト参照（IDOR）
* 情報漏えい
* Capabilities の悪用（Python3.8）（権限昇格）
  {% endhint %}

## 偵察

**作業環境の設定:**

重要なコンテンツ、エクスプロイト、Nmap の偵察結果を保存するために、3つのフォルダを作成して作業環境を整えます。

<figure><img src="https://2001299964-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://2001299964-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://2001299964-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://2001299964-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://2001299964-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://2001299964-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 サービスにアクセスすると、というセクションを発見します **Security Snapshot**。このセクションでは、 **pcap** システムログを含むファイルを作成してダウンロードできます。

<figure><img src="https://2001299964-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://2001299964-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://2001299964-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 パラメータを手動で変更して snapshot 0 にアクセスすると、機密情報を含むファイルを取得できます。

### **Wireshark による解析**

のフレームを調べることで、 **pcap** ファイル内にあるユーザーの認証情報を特定します:

* ユーザー名: `nathan`
* パスワード: `Buck3tH4TF0RM3!`

<figure><img src="https://2001299964-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://2001299964-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://2001299964-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**:

capabilities でフィルタすると、Python 3.8 が表示されます:

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

<figure><img src="https://2001299964-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://2001299964-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://2001299964-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://2001299964-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/ja/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.
