General definition

Homoiconicity is the property of a programming language that the code and the data are stored in the same format. For example, the following languages are homoiconics :

  • Lisp : using lists and theirs sub-types
  • ASM : using bytes stored in memory
  • XSLT : using the XML format

In some memory corruption exploits, shellcode is transmitted as data and later executed when the execution flow is altered. This is possible because of homoiconicity. Executing code transmitted as data is sometimes possible with XSLT too. 

Triggering embedded code

In some contexts (like browsers), XSLT code execution can be triggered while a XML document is parsed, via a xsl:stylesheet tag. The executed XSLT code can be stored on the Internet or in the XML document itself (homoiconicity + self-reference trick). A  blog post  by Chris Evans describes a pseudo SVG file triggering a simple RAM DoS . But we can do better ;-)

Exploiting via dynamic SVG images

We can create XML files which will be interpreted by browsers like perfectly valid self-contained dynamic SVG images. The SVG image is generated on the fly by the (Turing complete) XSLT engine of the browser and rendered.

In the following example, the XSLT code will :

  • fingerprint the underlying XSLT engine
  • draw a circle (red if Webkit, green otherwise)
  • try to exploit CVE-2011-1774 if Webkit is detected

Screenshot of Opera :

Screenshot of Epiphany :

Created by Nicolas Gregoire on 2012/01/04 22:18


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.
Content by Nicolas Grégoire / Agarri
Blog - Follow me @Agarri_FR