配置漏洞是指用户配置不当导致的漏洞,在Nginx中存在众多的配置漏洞
CLRF头部注入攻击
CLRF是Carriage-Return Line-Feed的缩写,即回车换行,用字节来表示的话是\r\n,字节码表示就是0x0d0x0a。在HTTP请求头部中,头部参数之间通过CRLF来分割,头部参数与消息体通过两个CRLF来分割:
Post / HTTP/1.1[\r\n]
Host: 127.0.0.1:8080[\r\n]
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0[\r\n]
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8[\r\n]
Accept-Language: en-US,en;q=0.5[\r\n]
Accept-Encoding: gzip, deflate[\r\n]
Connection: close[\r\n]
Upgrade-Insecure-Requests: 1[\r\n]
[\r\n]
[\r\n]
***********************body**************************
CRLF头部注入指的是向请求头部参数注入回车换行符,如果服务器接收后没有能够正确对其进行处理则可能把我们注入的CRLF识别为头部参数分割符相应的把CRLF后面的数据识别为头部参数。
http://127.0.0.1/abc.php[\r\n]Set-Cookie:abc=1232
我们知道头部中有Referer参数用来指示发起此请求的页面是谁,如果我们通过上述链接访问另一个页面admin.php时这是头部参数则可能如下:
GET / HTTP/1.1[\r\n]
Host: 127.0.0.1:8080[\r\n]
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0[\r\n]
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8[\r\n]
Accept-Language: en-US,en;q=0.5[\r\n]
Accept-Encoding: gzip, deflate[\r\n]
Referer:http://127.0.0.1/abc.php[\r\n]Set-Cookie:abc=1232[\r\n]
Connection: close[\r\n]
Upgrade-Insecure-Requests: 1[\r\n]
后台服务器接收到这个请求后如果没有正确处理头部值中的CRLF则可能出现如下情况:
GET / HTTP/1.1[\r\n]
Host: 127.0.0.1:8080[\r\n]
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0[\r\n]
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8[\r\n]
Accept-Language: en-US,en;q=0.5[\r\n]
Accept-Encoding: gzip, deflate[\r\n]
Referer:http://127.0.0.1/abc.php[\r\n]
Set-Cookie:abc=1232[\r\n]
Connection: close[\r\n]
Upgrade-Insecure-Requests: 1[\r\n]
这时我们就向头部中注入了Set-Cookie这个头部参数。当然上面的演示也只是为了演示,向服务器注入头部参数没有任何意义,接下来我们看实际的例子。
这里我们以Vulhub提供的Nginx配置漏洞环境进行演示。此环境中导致漏洞的配置如下,此配置实现了强制跳转的功能,当用户访问nginx服务器时由于此配置的存在我们会被强制跳转到以https协议访问我们之前访问的链接:
#nginx.conf
location / {
return 302 https://$host$uri;
}