1、描述

一般在配置Nginx访问静态资源时,需要指定文件服务器上的路径,一般是在location配置alias设置文件目录。如果alias路径后配置了/而location路径后未配置/就会出现目录穿越的漏洞,访问通过调整url格式可以看到alias配置路径的目录的上层目录文件情况,造成信息泄露

2、解决方案

配置alias目录路径时,location后面的目录路径也要加上/,如:location /files/

3、配置示例

配置

location配置的路径是/cc1

server {

  listen 8081;

  server_name localhost;

     location /cc1 {

        autoindex on;

        alias /test/;

        autoindex_exact_size off;

        autoindex_localtime on;

        charset utf-8;

        index index.html index.htm;

     }

 }

访问http://localhost:8081/cc1/

这时调整urlhttp://localhost:8081/cc1../

发现/test上层目录的情况,也就是根分区下的目录、文件情况也显示了出来,这时我们可以进入到根分区任意的目录,服务器上的所有文件全部暴露

配置后:

这时的location后面的路径是/cc1/

server {

  listen 8081;

  server_name localhost;

     location /cc1/ {

        autoindex on;

        alias /test/;

        autoindex_exact_size off;

        autoindex_localtime on;

        charset utf-8;

        index index.html index.htm;

     }

}

继续访问http://localhost:8081/cc1../

访问失败,目录穿越漏洞已修复

但是需要注意,如果将alias配置成root的话,需要设置location配置到/,如果location后配置到其他路径的话,那么会报404错误

例:

配置location后的路径为/cc1

现在访问http://192.168.88.138:8081/cc1/1.html,发现报404错误

这是将location改成到/后再次访问,成功

个人技术文档分享网站,更多有关于linux运维相关学习资料

点击右侧网站分类查看相关模块资料

https://opszzfwordpress.club/

 

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注