一、問題描述
- 最近項目系統處於安全防護階段;相關維護人員會通過工具掃描指定項目系統所使用的軟件,判斷其是否存在某些不安全的漏洞。藉此機會修復漏洞以至於使系統變的更加的安全,防止對系統用戶以及系統方造成相關的損失。
- 一般來說,軟件的漏洞都與版本信息有關,隱藏版本號或者修改web服務器所用的軟件名稱是爲了防止惡意用戶利用軟件漏洞進行攻擊。
- 今天,我們就來說一下頭信息泄漏nginx版本信息以及如何進行修復。
二、修復步驟
- 修復方法分爲兩種:
(1)直接隱藏掉nginx的版本信息
(2)修改web服務器所使用的nginx的名稱和版本信息 - 直接隱藏掉nginx的版本信息
[root@VM_0_12_centos conf]# vim nginx.conf
#添加內容
server_tokens off;
瀏覽器控制檯抓包可以看到:
**Response Headers**
Accept-Ranges: bytes
Content-Length: 739
Content-Type: text/html
Date: Tue, 30 Jun 2020 07:53:36 GMT
ETag: "5e9bc167-2e3"
Last-Modified: Sun, 19 Apr 2020 03:11:35 GMT
Server: nginx
-
修改web服務器所使用的nginx的名稱和版本信息
(1)一共需要修改三個文件。包括: ·src/core目錄下的nginx.h文件 ·src/http目錄下的ngx_http_header_filter_module.c文件 ·src/http目錄下的ngx_http_special_response.c文件 (2)修改內容如下: [root@VM_0_12_centos core]# vim nginx.h #define NGINX_VERSION "" #define NGINX_VER "CSDN" NGINX_VERSION [root@VM_0_12_centos http]# vim ngx_http_header_filter_module.c static u_char ngx_http_server_string[] = "Server: CSDN" CRLF; [root@VM_0_12_centos http]# vim ngx_http_special_response.c static u_char ngx_http_error_tail[] = "<hr><center>CSDN</center>" CRLF "</body>" CRLF "</html>" CRLF (3) 重新編譯nginx並啓動 [root@VM_0_12_centos nginx]# ./configure --prefix=/usr/local/nginx [root@VM_0_12_centos nginx]# make && make install [root@VM_0_12_centos sbin]# kill -9 PID [root@VM_0_12_centos sbin]# ./nginx -c /usr/local/nginx/conf/nginx.conf #重新加載配置文件並啓動 (4)瀏覽器控制檯抓包可以看到: **Response Headers** Accept-Ranges: bytes Content-Length: 739 Content-Type: text/html Date: Tue, 30 Jun 2020 07:53:36 GMT ETag: "5e9bc167-2e3" Last-Modified: Sun, 19 Apr 2020 03:11:35 GMT Server: CSDN
三、總結
- 建議大家選擇第二種方式,雖然修改的文件以及操作可能多了點,但是第二種相對於第一種更安全一些。
- 本人選擇第二種:因爲二者存在的差異在於按照第一種方式修改完成之後,在一些靜態文件(html/css/js/png/…)的請求頭中還會存在nginx相應的版本信息;大家可以都嘗試一下,然後找找問題。大家有啥問題,都可以給我留言~