<menu id="guoca"></menu>
<nav id="guoca"></nav><xmp id="guoca">
  • <xmp id="guoca">
  • <nav id="guoca"><code id="guoca"></code></nav>
  • <nav id="guoca"><code id="guoca"></code></nav>

    Nginx 配置錯誤導致漏洞

    Path nginx/insecure-configuration

    運行測試環境

    docker-compose up -d

    運行成功后,Nginx將會監聽8080/8081/8082三個端口,分別對應三種漏洞。

    Mistake 1. CRLF注入漏洞

    Nginx會將$uri進行解碼,導致傳入%0a%0d即可引入換行符,造成CRLF注入漏洞。

    錯誤的配置文件示例(原本的目的是為了讓http的請求跳轉到https上):

    location / {
        return 302 https://$host$uri;
    }

    Payload: http://your-ip:8080/%0a%0dSet-Cookie:%20a=1,可注入Set-Cookie頭。

    利用《Bottle HTTP 頭注入漏洞探究》中的技巧,即可構造一個XSS漏洞:

    Mistake 2. 目錄穿越漏洞

    Nginx在配置別名(Alias)的時候,如果忘記加/,將造成一個目錄穿越漏洞。

    錯誤的配置文件示例(原本的目的是為了讓用戶訪問到/home/目錄下的文件):

    location /files {
        alias /home/;
    }

    Payload: http://your-ip:8081/files../ ,成功穿越到根目錄:

    Mistake 3. add_header被覆蓋

    Nginx配置文件子塊(server、location、if)中的add_header,將會覆蓋父塊中的add_header添加的HTTP頭,造成一些安全隱患。

    如下列代碼,整站(父塊中)添加了CSP頭:

    add_header Content-Security-Policy "default-src 'self'";
    add_header X-Frame-Options DENY;
    
    location = /test1 {
        rewrite ^(.*)$ /xss.html break;
    }
    
    location = /test2 {
        add_header X-Content-Type-Options nosniff;
        rewrite ^(.*)$ /xss.html break;
    }

    /test2的location中又添加了X-Content-Type-Options頭,導致父塊中的add_header全部失效:

    XSS可被觸發:

    本文章首發在 網安wangan.com 網站上。

    上一篇 下一篇
    討論數量: 0
    只看當前版本


    暫無話題~
    亚洲 欧美 自拍 唯美 另类