隐藏Nginx软件名及版本号
2016-05-21 19:54
525 查看
软件的漏洞都和版本有关,这个很像汽车的缺陷,同一批次的有问题,就都有问题,别的批次可能就都是好的,因此应尽量隐藏或消除Web服务对访问用户显示的各类敏感信息(例如web sevrer名或版本号),这样恶意用户难以猜到他攻击的服务器是否为有特定漏洞的软件版本,从而加强安全性。
如何查看nginx版本?
linux:
$ curl -I 127.0.01
HTTP/1.1 200 OK
Server: nginx/1.9.15 #这里清晰的显示了web软件名和版本号
Date: Sat, 21 May 2016 11:09:11 GMT
Content-Type: text/html
Content-Length: 10381
Last-Modified: Sat, 14 May 2016 11:25:10 GMT
Connection: keep-alive
Vary: Accept-Encoding
ETag: "57370b16-288d"
Accept-Ranges: bytes
我们试图curl一下百度,看看百度使用的是web server
$ curl -I baidu.com
HTTP/1.1 200 OK
Date: Sat, 21 May 2016 11:10:34 GMT
Server: Apache #返回的是apache, 且不存在版本号,百度可能是将真实的web server名更改为appache
Last-Modified: Tue, 12 Jan 2010 13:48:00 GMT
ETag: "51-47cf7e6ee8400"
Accept-Ranges: bytes
Content-Length: 81
Cache-Control: max-age=86400
Expires: Sun, 22 May 2016 11:10:34 GMT
Connection: Keep-Alive
Content-Type: text/html
隐藏版本号:
nginx 中的servers_tokens选项,作用是控制http响应头中web服务器版本号的显示以及错误信息中web服务版本信息的显示,http标签段内加入servers_tokens off即可隐藏版本号
http
{
'''
server_tokens off;
'''
}
reload nginx后,再查看
# curl -I 127.0.0.1
HTTP/1.1 200 OK
Server: nginx #版本号已消失,但还存在web server名称
Date: Sat, 21 May 2016 11:18:50 GMT
Content-Type: text/html
Content-Length: 10381
Last-Modified: Sat, 14 May 2016 11:25:10 GMT
Connection: keep-alive
Vary: Accept-Encoding
ETag: "57370b16-288d"
Accept-Ranges: bytes
隐藏了nginx版本号后,最好也把Web server的名称隐藏或更改以迷惑黑客,遗憾的是,nginx并不支持通过配置来指定web server名,可能也是出于开源和推广的原因。因此更改nginx名需更改nginx源码并重新编译。下面以nginx-1.9.5为例(其他版本nginx大同小异,核心代码并不改动).
1.修改nginx-1.9.15/src/core/nginx.h文件
找到NGINX_VERSION,NGINX_VER, NGINX_VAR这几个宏定义,修改后如下
#define NGINX_VERSION "1.9.15" #修改为要显示的版本号
#define NGINX_VER "nginx/" NGINX_VERSION #修改掉"nginx"
#define NGINX_VAR "NGINX" #修改为其他软件名称
修改后如下:
#define NGINX_VERSION "2.2.15"
#define NGINX_VER "apache/" NGINX_VERSION
#define NGINX_VAR "apache"
2.修改nginx-1.9.15/src/http/ngx_http_header_filter_module.c
修改第49行中的nginx字符串,修改后
static char ngx_http_server_string[] = "Server: apache" CRLF;
3.修改nginx-1.9.15/src/http/ngx_http_special_response.c,对外页面报错时,它会控制是否显示敏感信息,将该文件中字符串包含"nginx"修改为"apache"
重新编译,并安装nginx,启动nginx服务,查看
# curl -I 127.0.0.1
HTTP/1.1 200 OK
Server: apache/2.2.15 #这里已经变成了用来欺骗恶意用户的apache和2.2.15版本
Date: Sat, 21 May 2016 11:44:51 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Sat, 21 May 2016 11:44:28 GMT
Connection: keep-alive
ETag: "57404a1c-264"
Accept-Ranges: bytes
打开一个不存在的页面查看,查看错误信息,
如何查看nginx版本?
linux:
$ curl -I 127.0.01
HTTP/1.1 200 OK
Server: nginx/1.9.15 #这里清晰的显示了web软件名和版本号
Date: Sat, 21 May 2016 11:09:11 GMT
Content-Type: text/html
Content-Length: 10381
Last-Modified: Sat, 14 May 2016 11:25:10 GMT
Connection: keep-alive
Vary: Accept-Encoding
ETag: "57370b16-288d"
Accept-Ranges: bytes
我们试图curl一下百度,看看百度使用的是web server
$ curl -I baidu.com
HTTP/1.1 200 OK
Date: Sat, 21 May 2016 11:10:34 GMT
Server: Apache #返回的是apache, 且不存在版本号,百度可能是将真实的web server名更改为appache
Last-Modified: Tue, 12 Jan 2010 13:48:00 GMT
ETag: "51-47cf7e6ee8400"
Accept-Ranges: bytes
Content-Length: 81
Cache-Control: max-age=86400
Expires: Sun, 22 May 2016 11:10:34 GMT
Connection: Keep-Alive
Content-Type: text/html
隐藏版本号:
nginx 中的servers_tokens选项,作用是控制http响应头中web服务器版本号的显示以及错误信息中web服务版本信息的显示,http标签段内加入servers_tokens off即可隐藏版本号
http
{
'''
server_tokens off;
'''
}
reload nginx后,再查看
# curl -I 127.0.0.1
HTTP/1.1 200 OK
Server: nginx #版本号已消失,但还存在web server名称
Date: Sat, 21 May 2016 11:18:50 GMT
Content-Type: text/html
Content-Length: 10381
Last-Modified: Sat, 14 May 2016 11:25:10 GMT
Connection: keep-alive
Vary: Accept-Encoding
ETag: "57370b16-288d"
Accept-Ranges: bytes
隐藏了nginx版本号后,最好也把Web server的名称隐藏或更改以迷惑黑客,遗憾的是,nginx并不支持通过配置来指定web server名,可能也是出于开源和推广的原因。因此更改nginx名需更改nginx源码并重新编译。下面以nginx-1.9.5为例(其他版本nginx大同小异,核心代码并不改动).
1.修改nginx-1.9.15/src/core/nginx.h文件
找到NGINX_VERSION,NGINX_VER, NGINX_VAR这几个宏定义,修改后如下
#define NGINX_VERSION "1.9.15" #修改为要显示的版本号
#define NGINX_VER "nginx/" NGINX_VERSION #修改掉"nginx"
#define NGINX_VAR "NGINX" #修改为其他软件名称
修改后如下:
#define NGINX_VERSION "2.2.15"
#define NGINX_VER "apache/" NGINX_VERSION
#define NGINX_VAR "apache"
2.修改nginx-1.9.15/src/http/ngx_http_header_filter_module.c
修改第49行中的nginx字符串,修改后
static char ngx_http_server_string[] = "Server: apache" CRLF;
3.修改nginx-1.9.15/src/http/ngx_http_special_response.c,对外页面报错时,它会控制是否显示敏感信息,将该文件中字符串包含"nginx"修改为"apache"
重新编译,并安装nginx,启动nginx服务,查看
# curl -I 127.0.0.1
HTTP/1.1 200 OK
Server: apache/2.2.15 #这里已经变成了用来欺骗恶意用户的apache和2.2.15版本
Date: Sat, 21 May 2016 11:44:51 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Sat, 21 May 2016 11:44:28 GMT
Connection: keep-alive
ETag: "57404a1c-264"
Accept-Ranges: bytes
打开一个不存在的页面查看,查看错误信息,
相关文章推荐
- CentOS下NGINX的安装与配置
- nginx基本架构详解
- nginx url遇到的问题
- nginx 入门
- 配置nginx.conf将URL从目录形式转为参数形式
- nginx 正则表达式
- Linux 系列(一)——Nginx 安装手册
- CentOS系统搭建Nginx负载均衡
- @安装Nginx创建错误
- Linux下Nginx源码安装
- nginx/tengine限制流量如何配置
- nginx、fastCGI、php-fpm关系梳理
- 安装nginx
- nginx做负载均衡器以及proxy缓存配置
- Mac OS安装nginx with nginx-stick-module-ng
- nginx学习笔记六(Nginx事件框架处理流程)
- 【架构】Nginx如何设置X-Request-ID请求头,记录请求时间:毫秒?
- Linux下安装Nginx
- Nginx防盗链详细设置
- 基于keepalived 实现VIP转移,lvs,nginx的高可用