Skip to content

Instantly share code, notes, and snippets.

@CaptainFreak
Created February 17, 2018 05:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CaptainFreak/bf8fb57f5029d29569f76bc7f67c5389 to your computer and use it in GitHub Desktop.
Save CaptainFreak/bf8fb57f5029d29569f76bc7f67c5389 to your computer and use it in GitHub Desktop.
XSLT Injection Demo
<?xml version="1.0" ?>
<fruits>
<fruit>
<name>Lemon</name>
<description>Yellow and sour</description>
</fruit>
<fruit>
<name>Watermelon</name>
<description>Round, green outside, red inside</description>
</fruit>
</fruits>
<html>
<body>
<form action="xslt.php" method="get">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>
<?php
//ini_set('display_errors', 1);
//ini_set('display_startup_errors', 1);
//error_reporting(E_ALL);
echo $_GET["name"];
echo $_GET["email"]."\n";
$xml=new DOMDocument;
$xml->load('c.xml');
$myfile = fopen("xslt.xsl", "w");
$txt = "<?xml version=\"1.0\" encoding=\"utf-8\"?>
<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">
<xsl:template match=\"/fruits\">".
$_GET["name"]."
Fruits:
<!-- Loop for each fruit -->
<xsl:for-each select=\"fruit\">
<!-- Print name: description -->
- <xsl:value-of select=\"name\"/>: <xsl:value-of select=\"description\"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>";
fwrite($myfile, $txt);
fclose($myfile);
$xsl=new DOMDocument;
$xsl->load("xslt.xsl");
$proc=new XSLTProcessor;
$proc->registerPHPFunctions();
$proc->importStyleSheet($xsl);
echo $proc->transformToXML($xml);
?>
@kingthorin
Copy link

If you're testing under xampp on windows you might need to edit \xampp\php\php.ini and uncomment extension=php_xsl.dll

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment