--- title: "XSLT Server-Side Injection (Extensible Stylesheet Language Transformations)" section: "Web Pentesting" sectionSlug: "pentesting-web" sourcePath: "src/pentesting-web/xslt-server-side-injection-extensible-stylesheet-language-transformations.md" sourceUrl: "https://github.com/HackTricks-wiki/hacktricks/blob/188de82beb54e70956b2952367a0af91d26758b8/src/pentesting-web/xslt-server-side-injection-extensible-stylesheet-language-transformations.md" sha: "188de82beb54e70956b2952367a0af91d26758b8" isIndex: false modified: true license: "CC-BY-NC-4.0" --- # XSLT Server-Side Injection (Extensible Stylesheet Language Transformations) ## Basic Information XSLT is a technology employed for transforming XML documents into different formats. It comes in three versions: 1, 2, and 3, with version 1 being the most commonly utilized. The transformation process can be executed either on the server or within the browser.[[2]](#references) The frameworks that are most frequently used include:[[3]](#references) - **Libxslt** from Gnome, - **Xalan** from Apache, - **Saxon** from Saxonica. For the exploitation of vulnerabilities associated with XSLT, it is necessary for xsl tags to be stored on the server side, followed by accessing that content. An illustration of such a vulnerability is documented in the following source: [https://www.gosecure.net/blog/2019/05/02/esi-injection-part-2-abusing-specific-implementations/](https://www.gosecure.net/blog/2019/05/02/esi-injection-part-2-abusing-specific-implementations/).[[10]](#references) ## Example - Tutorial ```bash sudo apt-get install default-jdk sudo apt-get install libsaxonb-java libsaxon-java ``` ```xml CD Title The artist Da Company 10000 1760 ``` ```xml

The Super title

Title artist
``` Execute: ```xml saxonb-xslt -xsl:xsl.xsl xml.xml Warning: at xsl:stylesheet on line 2 column 80 of xsl.xsl: Running an XSLT 1.0 stylesheet with an XSLT 2.0 processor

The Super title

Title artist
CD Title The artist
``` ### Fingerprint ```xml Version:
Vendor:
Vendor URL:
Product Name:
Product Version:
Is Schema Aware ?:
Supports Serialization:
Supports Backwards Compatibility:
``` And execute ```xml $saxonb-xslt -xsl:detection.xsl xml.xml Warning: at xsl:stylesheet on line 2 column 80 of detection.xsl: Running an XSLT 1.0 stylesheet with an XSLT 2.0 processor

XSLT identification

Version:2.0
Vendor:SAXON 9.1.0.8 from Saxonica
Vendor URL:http://www.saxonica.com/
``` ### Post-fingerprint attack map Once you have the vendor string, switch quickly to the processor-specific primitives instead of retrying generic XXE payloads: - **libxslt / lxml / GNOME**: test `document()`, `exsl:document`, and in PHP environments `php:function()`. - **Saxon / Saxonica**: test `unparsed-text()`, `xsl:result-document`, and Java/C# extension functions if external functions are enabled. - **Xalan / Apache**: test Java extension namespaces such as `http://xml.apache.org/xalan/java` and `xalan://...`; blind RCE or file-write payloads are often easier than capturing stdout. - **Microsoft / .NET**: test `document()` plus `msxsl:script`; on modern .NET (Core / 5+) embedded script is unsupported, so a failed script payload does **not** rule out `document()`-based SSRF/LFI. ### Read Local File ```xml ``` ```xml $ saxonb-xslt -xsl:read.xsl xml.xml Warning: at xsl:stylesheet on line 1 column 111 of read.xsl: Running an XSLT 1.0 stylesheet with an XSLT 2.0 processor root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin sys:x:3:3:sys:/dev:/usr/sbin/nologin sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/usr/sbin/nologin man:x:6:12:man:/var/cache/man:/usr/sbin/nologin lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin ``` ### SSRF ```xml ``` ### Versions There might be more or less functions depending on the XSLT version used: - [https://www.w3.org/TR/xslt-10/](https://www.w3.org/TR/xslt-10/) - [https://www.w3.org/TR/xslt20/](https://www.w3.org/TR/xslt20/) - [https://www.w3.org/TR/xslt-30/](https://www.w3.org/TR/xslt-30/) ## Fingerprint Upload this and take information ```xml Version:
Vendor:
Vendor URL:
Product Name:
Product Version:
Is Schema Aware ?:
Supports Serialization:
Supports Backwards Compatibility:
``` ## SSRF ```xml ``` ## Javascript Injection ```xml ``` ## Directory listing (PHP) ### **Opendir + readdir** ```xml - - - - - - - - - ``` ### **Assert (var_dump + scandir + false)** ```xml
``` ## Read files ### **Internal - PHP** ```xml ``` ### **Internal - XXE** ```xml ]> &ext_file; ``` ### **Through HTTP** ```xml ``` ```xml ]> &passwd; ``` ### **`document()` usually expects XML** On **libxslt**, `document()` is useful for SSRF and for reading **other XML documents**, but trying to read arbitrary local text files such as `/etc/passwd` will often fail because the referenced resource is parsed as XML. - `document('/path/to/file.xml')` may work if the target file is valid XML. - `document('/etc/passwd')` commonly errors because the file is not XML. This is useful when triaging a target: a failed `document('/etc/passwd')` does **not** necessarily mean the XSLT processor is hardened.[[4]](#references) ### Parser asymmetry: XML hardened, XSLT still dangerous Some applications harden the **input XML** parser but not the **stylesheet** parser. With lxml, options such as `resolve_entities=False`, `no_network=True`, `dtd_validation=False`, and `load_dtd=False` can block classic XXE in the uploaded XML while the XSLT still gets parsed with default settings or extension features enabled. That pattern usually means: - XXE in the XML document may fail. - XSLT-specific features such as `system-property()`, `document()`, extension functions, and EXSLT elements may still be reachable. So if XXE payloads fail, fingerprint the processor first and then switch to processor-specific XSLT payloads instead of stopping at the XML parser result. With **lxml** specifically, remember that `XSLTAccessControl` defaults to allowing file and network access, and it only mediates transformation-time I/O. `xsl:import` / `xsl:include` are parsed before that access-control hook, so a target can still fetch attacker-controlled stylesheets even when later `document()` calls are restricted.[[7]](#references) ### **Internal (PHP-function)** ```xml ``` ```xml
``` ### Port scan ```xml ``` ## Write to a file ### XSLT 2.0 ```xml Write Local File ``` ### **Xalan-J extension** ```xml Write Local File ``` ### **libxslt / EXSLT `exsl:document`** If the target fingerprints as **libxslt** (`system-property('xsl:vendor')`) and the application lets you upload or store attacker-controlled XSLT, test **EXSLT secondary output**. `exsl:document` can write a new document to an arbitrary path writable by the XSLT process.[[4]](#references)[[6]](#references) ```xml 0xdf was here! ``` Practical workflow: - First write a marker into a **web-served path** to confirm the primitive. - Then write into an **execution sink** already present on the host, such as a cron-polled script directory, a parser auto-reload path, or another scheduled task input. If you are generating shell payloads through XML, remember that this is **XML encoding**, not URL encoding. For example, use `&` to generate a literal `&` inside the written file. Writing `%26` will usually persist `%26` literally and break shell redirections.[[4]](#references) Other ways to write files in the PDF ## Include external XSL ```xml ``` ```xml ``` ## Execute code ### **php:function** ```xml ``` ```xml
``` Execute code using other frameworks in the PDF[[1]](#references) ### **Java / .NET specific execution primitives** #### **Xalan-Java (blind command execution)** ```xml ``` If you only get a boolean or a Java object reference back, treat it as **blind RCE** and pivot to DNS/HTTP callbacks, file writes, or time delays instead of trying to capture stdout directly. #### **Saxon (reflexive Java extension functions)** ```xml ``` This needs **SaxonJ-PE/EE** reflexive extension functions to be available. If `ALLOW_EXTERNAL_FUNCTIONS` is disabled you may still keep `doc()` / `unparsed-text()` primitives, so a failed Java call does not mean the stylesheet is fully sandboxed.[[8]](#references) #### **.NET `msxsl:script`** ```xml ``` This only works when the application loads the stylesheet with script enabled (`XsltSettings.EnableScript=true` / `TrustedXslt`). On **.NET Framework** this is still a valid execution primitive; on **.NET Core / .NET 5+** `msxsl:script` is unsupported, so test `document()` separately.[[9]](#references) ### **More Languages** This page contains RCE examples for other languages and runtimes: [**Fortify XSLT injection examples**](https://vulncat.fortify.com/en/detail?id=desc.dataflow.java.xslt_injection#C%23%2FVB.NET%2FASP.NET) **(C#, Java, PHP)**. ## **Access PHP static functions from classes** The following function will call the static method `stringToUrl` of the class XSL: ```xml ``` (Example from [http://laurent.bientz.com/Blog/Entry/Item/using_php_functions_in_xsl-7.sls](http://laurent.bientz.com/Blog/Entry/Item/using_php_functions_in_xsl-7.sls)) ### GeoNetwork formatter upload chain [Geonetwork](/hacktricks/network-services-pentesting/pentesting-web/geonetwork) ## More Payloads - Check [https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/XSLT%20Injection](https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/XSLT%20Injection) for additional processor-specific discovery and exploitation payloads.[[5]](#references) - Check [https://vulncat.fortify.com/en/detail?id=desc.dataflow.java.xslt_injection](https://vulncat.fortify.com/en/detail?id=desc.dataflow.java.xslt_injection) ## **Brute-Force Detection List** [Xslt.Txt](https://raw.githubusercontent.com/HackTricks-wiki/hacktricks/188de82beb54e70956b2952367a0af91d26758b8/src/pentesting-web/https%3A/github.com/carlospolop/Auto_Wordlists/blob/main/wordlists/xslt.txt) ## References - [1] [XSLT_SSRF](https://feelsec.info/wp-content/uploads/2018/11/XSLT_SSRF.pdf) - [2] [Abusing XSLT for practical attacks - Arnaboldi - IOActive](http://repository.root-me.org/Exploitation%20-%20Web/EN%20-%20Abusing%20XSLT%20for%20practical%20attacks%20-%20Arnaboldi%20-%20IO%20Active.pdf) - [3] [Abusing XSLT for practical attacks - Arnaboldi - Blackhat 2015](http://repository.root-me.org/Exploitation%20-%20Web/EN%20-%20Abusing%20XSLT%20for%20practical%20attacks%20-%20Arnaboldi%20-%20Blackhat%202015.pdf) - [4] [0xdf - HTB Conversor](https://0xdf.gitlab.io/2026/03/21/htb-conversor.html) - [5] [PayloadsAllTheThings - XSLT Injection](https://swisskyrepo.github.io/PayloadsAllTheThings/XSLT%20Injection/) - [6] [EXSLT - exsl:document](https://exslt.github.io/exsl/elements/document/index.html) - [7] [lxml API - XMLParser](https://lxml.de/api/lxml.etree.XMLParser-class.html) - [8] [Saxon - Writing reflexive extension functions in Java](https://www.saxonica.com/html/documentation11/extensibility/extension-functions-J/reflexive-functions/index.html) - [9] [.NET - Script Blocks Using msxsl:script](https://learn.microsoft.com/en-us/dotnet/standard/data/xml/script-blocks-using-msxsl-script) - [10] [gosecure.net - Esi Injection Part 2 Abusing Specific Implementations](https://www.gosecure.net/blog/2019/05/02/esi-injection-part-2-abusing-specific-implementations)