Detection
1
Fuzz the Template
Inject a sequence of special characters:
${{<%[%'"}}%\Observe server responses for errors or unexpected evaluation.2
Distinguish from XSS
Test mathematical expressions:
{{7*7}}→49(template evaluated)${7*7}→49or${7*7}(depends on engine)<%= 7*7 %>→49(Ruby/ASP style)
3
Identify the Engine
Different engines use different syntax. Use this flowchart approach:
{{7*7}}→ 49: Twig or Jinja2{{7*'7'}}→7777777: Jinja2${7*7}→ 49: FreeMarker or Spring EL<%= 7*7 %>→ 49: ERB (Ruby)@(2+2)→ 4: Razor (.NET)
Automated Tools
Exploitation by Engine
- Jinja2 (Python)
- Twig (PHP)
- FreeMarker (Java)
- ERB (Ruby)
- Smarty (PHP)
- Mako (Python)
- Tornado (Python)
- Razor (.NET)