Dixit Wikipedia : "PHP is a general-purpose server-side scripting language originally designed for web development to produce dynamic web pages. It is among one of the first developed server-side scripting languages that is embedded into a HTML source document, rather than calling an external file to process data. Ultimately, the code is interpreted by a web server with a PHP processor module which generates the resulting web page."

Creating files

Version 5 of the PHP language uses the libxslt engine to transform XML documents using XSLT. Prior to version 5.3.9, calls to libxslt were not restricted via xsltSetSecurityPrefs(). It was then possible to create or overwrite files on the engine side, typically for dropping a PHP Web Shell. This vulnerability (Bug #54446 / CVE-2012-0057) was patched in version 5.3.9 (ChangeLog).

Simple PoC

The attached create-file-via-libxslt.php PoC will drop a basic PHP script in /tmp/.

PoC with crypto

A better script was later posted on OSS-Security at RedHat request. This PHP script (php539-xslt.php) will by default display a pre-filled HTML form including XML data, XSLT code and RC4-encrypted malicious PHP code. When the form is submitted, the user-controlled XML data is transformed using the user-controlled XSLT code. Then, the output of this transformation is displayed in the browser. Meanwhile, the malicious PHP code is decrypted using a static key ("simple_demo") and saved to "/var/www/xxx/backdoor.php".

Executing PHP code

A call to registerPHPFunctions() allows to execute standard PHP functions directly from the XSLT stylesheet. I never came across this pattern in real-life engagements but Google Code search references several instances of it (dork: "registerPHPFunctions lang:^php$"). This isn't a bug and will not be patched.

Namespace Extension function PoC Note Any PHP functionexecute-code-via-libxslt.php A call to registerPHPFunctions() is needed

The attached execute-code-via-libxslt.php PoC will use the passthru() PHP function to execute "uname -a".

Reading binary files via PHP filters

Untested : could we read binary files too ?

<!DOCTYPE scan [<!ENTITY test SYSTEM "php://filter/read=convert.base64-encode/resource=/etc/passwd">]>
Source :

Anti XEE



Welcome on the XSLT Hacking Encyclopedia !

You may be interested by the Engines and Applications pages.

Link to the blog
Twitter: @Agarri_FR

Tag Cloud

Unknown macro: tagcloud. Click on this message for details.

Content by Nicolas Grégoire / Agarri
Blog - Follow me @Agarri_FR