nginx安全最佳化之隱藏版本

來源:互聯網
上載者:User

標籤:安全   nginx   

安全一直是互連網不可忽視的問題,今天介紹下nginx隱藏版本,別人不清楚你的版本,就無法使用針對nginx的漏洞進行攻擊。nginx軟體是開源的但是源碼中也攜帶版本資訊,可以修改原始碼進行隱藏版本資訊。


版本顯示

[[email protected] ~]# curl -I 192.168.1.7|grep Server             

Server: nginx/1.8.1 #nginx的軟體版本資訊


51CTO的web容器版本

[[email protected] nginx-1.8.1]# curl -I www.51cto.com|grep Server

Server: Tengine   #隱藏了版本資訊

隱藏了版本,讓版本漏洞無法使用


修改nginx原始碼來隱藏nginx版本資訊

檔案1 "nginx-1.8.1/src/core/nginx.h" 12行-23行

原設定檔

[[email protected] tools]# sed -n ‘12,23p‘ nginx-1.8.1/src/core/nginx.h  

#define nginx_version      1008001

#define NGINX_VERSION      "1.8.1"  #修改想要顯示的版本如:2.2.23

#define NGINX_VER          "nginx/" NGINX_VERSION 

                          #將nginx修改成想要顯示的軟體名稱

#ifdef NGX_BUILD

#define NGINX_VER_BUILD    NGINX_VER " (" NGX_BUILD ")"

#else

#define NGINX_VER_BUILD    NGINX_VER

#endif


#define NGINX_VAR          "NGINX" #將nginx修改成想要顯示的軟體名稱(Evan Web Server)

#define NGX_OLDPID_EXT     ".oldbin"

修改後

[[email protected] tools]# sed -n ‘12,23p‘ nginx-1.8.1/src/core/nginx.h

#define nginx_version      1008001

#define NGINX_VERSION      "2.2.23" #版本修改為2.2.23

#define NGINX_VER          "EWS/" NGINX_VERSION

#nginx修改為EWS

#ifdef NGX_BUILD

#define NGINX_VER_BUILD    NGINX_VER " (" NGX_BUILD ")"

#else

#define NGINX_VER_BUILD    NGINX_VER

#endif


#define NGINX_VAR          "EWS" #nginx修改為EWS

#define NGX_OLDPID_EXT     ".oldbin" 


檔案2 "nginx-1.8.1/src/http/ngx_http_header_filter_module.c" 49行

源檔案

[[email protected] tools]# sed -n ‘49p‘ nginx-1.8.1/src/http/ngx_http_header_filter_module.c 

static char ngx_http_server_string[] = "Server: nginx" CRLF;  #將nginx修改為想要的版本

修改後

[[email protected] tools]# sed -n ‘49p‘ nginx-1.8.1/src/http/ngx_http_header_filter_module.c 

static char ngx_http_server_string[] = "Server: EWS" CRLF;   #將nginx修改為了EWS


修改連結錯誤的版本顯示

錯誤連結網站顯示

650) this.width=650;" src="http://s4.51cto.com/wyfs02/M02/7F/6E/wKiom1ceKV-yqSpUAABgE_igSGE414.jpg" title="nginx錯誤版本修複.jpg" width="400" height="113" border="0" hspace="0" vspace="0" style="width:400px;height:113px;" alt="wKiom1ceKV-yqSpUAABgE_igSGE414.jpg" />

訪問錯誤的連結也有暴露版本資訊的危險


檔案3 "nginx-1.8.1/src/http/ngx_http_special_response.c" 29行

源檔案

[[email protected] tools]# sed -n ‘21,31p‘ nginx-1.8.1/src/http/ngx_http_special_response.c

"<hr><center>nginx</center>" CRLF  #將nginx修改為想要的版本資訊

修改後

[[email protected] tools]# sed -n ‘29p‘ nginx-1.8.1/src/http/ngx_http_special_response.c    

"<hr><center>EWS</center>" CRLF


重新編譯安裝,可以看到如下效果

編譯安裝方法:http://iywdd.blog.51cto.com/11177578/1767529


版本資訊

[[email protected] nginx-1.8.1]# curl -I 192.168.1.7

HTTP/1.1 200 OK

Server: EWS/2.2.23   #更改為EWS/2.2.23 

Date: Thu, 07 Apr 2016 11:51:41 GMT

Content-Type: text/html

Content-Length: 612

Last-Modified: Thu, 07 Apr 2016 11:50:40 GMT

Connection: keep-alive

ETag: "57064990-264"

Accept-Ranges: bytes


錯誤連結修改後結果


650) this.width=650;" src="http://s5.51cto.com/wyfs02/M00/7F/6E/wKiom1ceKfqQwiT0AABlydcgghA186.jpg" title="錯誤連結修改.jpg" width="400" height="110" border="0" hspace="0" vspace="0" style="width:400px;height:110px;" alt="wKiom1ceKfqQwiT0AABlydcgghA186.jpg" />

訪問錯誤的連結更改了版本資訊

本文出自 “營運地帶” 部落格,請務必保留此出處http://iywdd.blog.51cto.com/11177578/1767686

nginx安全最佳化之隱藏版本

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.