隐藏nginx 版本等信息



[root@LNMP ~]# curl -I 127.0.0.1

HTTP/1.1 200 OK

Server: nginx/1.6.2

Date: Thu, 24 Sep 2015 00:59:17 GMT

Content-Type: text/html

Content-Length: 612

Last-Modified: Tue, 22 Sep 2015 07:55:24 GMT

Connection: keep-alive

ETag: "5601096c-264"

Accept-Ranges: bytes


[root@LNMP ~]#

 

修改在http模块增加下面内容

http {

########################start

   server_tokens off;

########################end

}

#######重启nginx服务

 /application/nginx/sbin/nginx -s reload

[root@LNMP conf]# ../sbin/nginx -s reload

[root@LNMP conf]# curl -I 127.0.0.1          

HTTP/1.1 200 OK

Server: nginx

Date: Thu, 24 Sep 2015 01:01:05 GMT

Content-Type: text/html

Content-Length: 612

Last-Modified: Tue, 22 Sep 2015 07:55:24 GMT

Connection: keep-alive

ETag: "5601096c-264"

Accept-Ranges: bytes

[root@LNMP conf]#

 

[root@LNMP conf]# curl -I -s 10.0.0.4 | grep Server

Server: nginx


##########################

隐藏软件名称

cd /home/lvnian/tools/nginx-1.6.2

curl -I 127.0.0.1

curl -I -s 10.0.0.4 | grep Server

cd /home/lvnian/tools/nginx-1.6.2

grep 1.6.2 src/core/nginx.h 

sed -i 's#1.6.2#2.2.22#g' src/core/nginx.h 

grep 2.2.22 src/core/nginx.h 

grep nginx/ src/core/nginx.h

sed -i 's#nginx/#lvnian/#g' src/core/nginx.h  

grep lvnian/ src/core/nginx.h


###########################具体过程

[root@LNMP conf]# curl -I -s 10.0.0.4 | grep Server

Server: nginx

[root@LNMP conf]# cd /home/lvnian/tools/nginx-1.6.2

[root@LNMP nginx-1.6.2]# grep 1.6.2 src/core/nginx.h 

#define NGINX_VERSION      "1.6.2"

[root@LNMP nginx-1.6.2]# sed -i 's#1.6.2#2.2.22#g' src/core/nginx.h 

[root@LNMP nginx-1.6.2]# grep 2.2.22 src/core/nginx.h                     

#define NGINX_VERSION      "2.2.22"

[root@LNMP nginx-1.6.2]# grep nginx/ src/core/nginx.h

#define NGINX_VER          "nginx/" NGINX_VERSION

[root@LNMP nginx-1.6.2]# sed -i 's#nginx/#lvnian/#g' src/core/nginx.h            

[root@LNMP nginx-1.6.2]# grep lvnian/ src/core/nginx.h                       

#define NGINX_VER          "lvnian/" NGINX_VERSION

[root@LNMP nginx-1.6.2]# 

########################修改ngx_http_header_filter_module.c

cd /home/lvnian/tools/nginx-1.6.2/src/http/


vim ngx_http_header_filter_module.c ##修改49/50行成下面内容

 49 static char ngx_http_server_string[] = "Server: lvnian" CRLF;

 50 static char ngx_http_server_full_string[] = "Server:lvnian" NGINX_VER CRLF;


##########################

或者用sed 修改

grep '"Server:' ngx_http_header_filter_module.c 

cp ngx_http_header_filter_module.c ngx_http_header_filter_module.c.ori

sed -i 's/"Server:/"Server:lvnian/g' ngx_http_header_filter_module.c

grep '"Server:' ngx_http_header_filter_module.c 

sed -i 's/"Server:lvnian nginx/"Server:lvnian/g' ngx_http_header_filter_module.c

grep '"Server:' ngx_http_header_filter_module.c 

####################sed 修改过程

[root@LNMP http]# grep '"Server:' ngx_http_header_filter_module.c 

static char ngx_http_server_string[] = "Server: nginx" CRLF;

static char ngx_http_server_full_string[] = "Server: " NGINX_VER CRLF;

[root@LNMP http]# cp ngx_http_header_filter_module.c ngx_http_header_filter_module.c.ori

[root@LNMP http]# sed -i 's/"Server:/"Server:lvnian/g' ngx_http_header_filter_module.c

[root@LNMP http]# grep '"Server:' ngx_http_header_filter_module.c                       

static char ngx_http_server_string[] = "Server:lvnian nginx" CRLF;

static char ngx_http_server_full_string[] = "Server:lvnian " NGINX_VER CRLF;

[root@LNMP http]# sed -i 's/"Server:lvnian nginx/"Server:lvnian/g' ngx_http_header_filter_module.c

[root@LNMP http]# grep '"Server:' ngx_http_header_filter_module.c                               static char ngx_http_server_string[] = "Server:lvnian" CRLF;

static char ngx_http_server_full_string[] = "Server:lvnian " NGINX_VER CRLF;



########################修改 vim ngx_http_special_response.c

vim ngx_http_special_response.c  ##修改成下面内容

29:"<hr><center>lvnian</center>" CRLF

####或者sed 修改,命令如下:

grep 'nginx' ngx_http_special_response.c

sed -i 's/>nginx</>lvnian</' ngx_http_special_response.c 

grep 'nginx' ngx_http_special_response.c

grep 'lvnian' ngx_http_special_response.c

#####sed 修改过程

[root@LNMP http]# grep 'nginx' ngx_http_special_response.c

#include <nginx.h>

"<hr><center>nginx</center>" CRLF

[root@LNMP http]# sed -i 's/>nginx</>lvnian</' ngx_http_special_response.c      

[root@LNMP http]# grep 'nginx' ngx_http_special_response.c                 

#include <nginx.h>

[root@LNMP http]# grep 'lvnian' ngx_http_special_response.c     

"<hr><center>lvnian</center>" CRLF


#############################重新编译

cd /home/lvnian/tools/nginx-1.6.2

cp /application/nginx/conf /tmp/ -rp

rm -rf /application/ngin*

./configure --user=nginx --group=nginx --prefix=/application/nginx-1.6.2 --with-http_stub_status_module --with-http_ssl_module

make && make install

pkill nginx

curl -I 127.0.0.1

/application/nginx-1.6.2/sbin/nginx 


#################

[root@LNMP nginx-1.6.2]# curl -I 127.0.0.1                   

HTTP/1.1 200 OK

Server:lvnian lvnian/2.2.22

Date: Thu, 24 Sep 2015 01:38:03 GMT

Content-Type: text/html

Content-Length: 612

Last-Modified: Thu, 24 Sep 2015 01:36:48 GMT

Connection: keep-alive

ETag: "560353b0-264"

Accept-Ranges: bytes


打开该站点不存在的一个网页,显示如下

wKioL1YDXATwVjU1AABShYW_csw952.jpg