# XXE

## <mark style="color:yellow;">Basics of XML</mark>

Extensible Markup Language (XML) is a language designed to store and transport data similar to JSON.

<figure><img src="https://1674729424-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyzdFWSUijzVYOP1hAsit%2Fuploads%2F1NgRU7inX4XRcWUQcEmS%2Fimage.png?alt=media&#x26;token=9356cb6c-b76f-4147-9ad3-bbf64955f774" alt=""><figcaption><p>The basic structure of XML</p></figcaption></figure>

If you ever see this line in burp you should test for XXE:

* \<?xml version="1.0" encoding="UTF-8"?>

Document Type Definition (DTD) defines the structure and the legal elements and attributes of an XML document:

* Here an ENTITY acts as a variable called “user” and holds the text “Ghostlulz”.

<figure><img src="https://1674729424-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyzdFWSUijzVYOP1hAsit%2Fuploads%2F3vveBA02aiaX2qTQxEQM%2Fimage.png?alt=media&#x26;token=a812ae2b-491c-468f-b74d-ba7ba101b099" alt=""><figcaption><p>Document Type Definition</p></figcaption></figure>

Note that an external entity loads its data from an external source, for example:

* \<!DOCTYPE foo \[\<!ENTITY ext SYSTEM "[http://example.com">\]>](https://yasmeen-rezk.gitbook.io/my-notes/bug-bounty-playbook-1/section-3-exploitation-phase/chapter-11-exploitation-owasp/http:/example.com">]>)
* \<!DOCTYPE foo \[\<!ENTITY ext SYSTEM "file:///path/to/file">]>

## <mark style="color:yellow;">XXE</mark>

Whenever you see XML you should test for XXE.

<figure><img src="https://1674729424-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyzdFWSUijzVYOP1hAsit%2Fuploads%2F7sNEQrVR6VPdcQqy0Ryk%2Fimage.png?alt=media&#x26;token=043ef17d-e7df-4c23-ab5a-c1ade9bc7cec" alt=""><figcaption></figcaption></figure>

In order to read the data the entity must be returned in the response, So:

* &#x20;if we can use external entities to grab data from a file on disk and store it in a variable, we can try to read data from the “/etc/passwd” file and store it in a variable.

#### Testing for XXE

1. put in your malicious external entity and replace each node value with it, like:

* Here we created an external entity to grab the data in the “/etc/passwd” file and stored it in the entity XXE then placed the variable in the "\<productID>" node.

<figure><img src="https://1674729424-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyzdFWSUijzVYOP1hAsit%2Fuploads%2Fp3U8FB892d5Tix1Dajyb%2Fimage.png?alt=media&#x26;token=72ecfd9a-c6b8-454b-a628-a2a2d6a2382d" alt=""><figcaption><p>XXE payload</p></figcaption></figure>

2. If the server doesn’t block external entities the response will be reflected to you, like:

<figure><img src="https://1674729424-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyzdFWSUijzVYOP1hAsit%2Fuploads%2F5TwQTQCPy4Qfgfoy6HI3%2Fimage.png?alt=media&#x26;token=130b29e4-93da-4a9b-9d5d-f57939210930" alt=""><figcaption><p>Use XXE to read /etc/passwd file</p></figcaption></figure>

The vulnerable application used can be found at [**https://portswigger.net/web-security**](https://portswigger.net/web-security)
