打開題目及其對應(yīng)鏈接
http://111.200.241.244:54518/file?filename=/flag.txt&filehash=56c3edef87e35138fd9a79ff81bb0253
得到如下三個文件及其內(nèi)容
/flag.txt
flag in /fllllllllllllag
/welcome.txt
render
/hints.txt
md5(cookie_secret+md5(filename))
由題目標題可知,該網(wǎng)站用的時tornado框架
有提示1可知,flag在/fllllllllllllag文件下
將鏈接中/flag.txt替換為/fllllllllllllag后得到如下頁面
改變msg后文字,頁面內(nèi)容也有所改變秩冈,證明存在模板注入漏洞并且能夠回顯
由提示2得知render存在漏洞新啼,查看render函數(shù)的說明
render時模板渲染函數(shù)佩研,可以將對應(yīng)參數(shù)渲染入模板內(nèi)
Tornado模板支持控制語句和表達式柒竞。控制語句被{%和%}包圍趟紊,例如{%如果len(items)>2%}。表達式被{{和}包圍碰酝,例如{{items[0]}霎匈。
表達式可以是任何Python表達式,包括函數(shù)調(diào)用送爸。模板代碼在包含以下對象和函數(shù)的命名空間中執(zhí)行铛嘱。(請注意,此列表適用于使用RequestHandler.render和render_字符串呈現(xiàn)的模板袭厂。如果您直接在RequestHandler外部使用tornado.template模塊墨吓,則其中許多條目不存在)。
escape: alias for tornado.escape.xhtml_escape
xhtml_escape: alias for tornado.escape.xhtml_escape
url_escape: alias for tornado.escape.url_escape
json_encode: alias for tornado.escape.json_encode
squeeze: alias for tornado.escape.squeeze
linkify: alias for tornado.escape.linkify
datetime: the Python datetime module
handler: the current RequestHandler object
request: alias for handler.request
current_user: alias for handler.current_user
locale: alias for handler.locale
_: alias for handler.locale.translate
static_url: alias for handler.static_url
xsrf_form_html: alias for handler.xsrf_form_html
reverse_url: alias for Application.reverse_url
All entries from the ui_methods and ui_modules Application settings
Any keyword arguments passed to render or render_string
最有可能包含cookie_secret時在hander
問題時如何獲取cookie_secret參數(shù)嵌器,通過用戶手冊可以查詢到settings中有cookie_secret參數(shù)
通過查閱文檔發(fā)現(xiàn)cookie_secret在Application對象settings屬性中肛真,還發(fā)現(xiàn)self.application.settings有一個別名
RequestHandler.settings An alias for self.application.settings.
handler指向的處理當前這個頁面的RequestHandler對象, RequestHandler.settings指向self.application.settings爽航, 因此handler.settings指向RequestHandler.application.settings蚓让。
構(gòu)造payload獲取cookie_secret
/error?msg={{handler.settings}}
setting中由cookie_secret參數(shù),通過{{handler.settings}}可以獲得cookie_secret參數(shù)
通過md5(cookie_secret+md5(filename))可以計算出filehash值
在python3的標準庫中讥珍,已經(jīng)移除了md5历极,而關(guān)于hash加密算法都放在hashlib這個標準庫中,如SHA1衷佃、SHA224趟卸、SHA256、SHA384氏义、SHA512和MD5算法等锄列。
md5()方法使用
update(arg)傳入arg對象來更新hash的對象。必須注意的是惯悠,該方法只接受byte類型邻邮,否則會報錯。這就是要在參數(shù)前添加b來轉(zhuǎn)換類型的原因克婶。? 同時要注意筒严,重復(fù)調(diào)用update(arg)方法丹泉,是會將傳入的arg參數(shù)進行拼接,而不是覆蓋鸭蛙。也就是說摹恨,m.update(a); m.update(b) 等價于m.update(a+b)。? hexdigest()在英語中hex有十六進制的意思娶视,因此該方法是將hash中的數(shù)據(jù)轉(zhuǎn)換成數(shù)據(jù)晒哄,其中只包含十六進制的數(shù)字。
import hashlib
m = hashlib.md5()
m.update(b'/fllllllllllllag')
f = m.hexdigest()
m = hashlib.md5()
m.update(b'2ab80280-7bdd-402a-b0c7-cabdb3a4715a'+f.encode(encoding='utf-8'))
f = m.hexdigest()
得到最終的payload
filename=/fllllllllllllag&filehash=07949418d71869acb05f173716f4d19c