nginx 隐藏版本号与WEB服务器信息(yum)
安全审计中有时会有
漏洞名称 HTTP服务器版本信息泄漏
漏洞描述 目标服务器返回的信息头中包含了Web Server的软件或者版本信息。
可以安装 nginx的headers-more-nginx-module模块修改或隐藏响应头信息
一、安装
1.下载 headers-more-nginx-module
下载地址
https://github.com/openresty/headers-more-nginx-module/tags
wget https://github.com/openresty/headers-more-nginx-module/archive/refs/tags/v0.37.tar.gz
2.解压
tar -zxvf v0.37.tar.gz
解压后会多出一个headers-more-nginx-module-0.37文件夹
3.查看当前系统nginx信息
// 查看当前nginx加载的模块,这里使用的是yum安装的
nginx -V
接下来操作的是yum安装的,如何编译第三方模块
4.下载对应版本的nginx,这里的版本必须和之前yum安装的NGINX版本一致
# 下载
wget http://nginx.org/download/nginx-1.26.1.tar.gz
# 解压
[root@localhost tools]# tar -zxvf nginx-1.26.1.tar.gz
5.编译
# 先备份
cp /usr/sbin/nginx /usr/sbin/nginx_old
yum install gcc pcre-devel zlib-devel make unzip openssl-devel -y
cd nginx-1.26.1
这里的编译模块是复制之前yum安装的编译模块,nginx -V
./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' --add-module=/headers-more-nginx-module-0.37/
在末尾添加 --add-module=/headers-more-nginx-module-0.37
注意路径【/headers-more-nginx-module-0.37】要换成你自己的
configure完成后进行make(如原本无nginx,make后还需make install)
6.复制新的nginx到目录
cp objs/nginx /usr/sbin/nginx
7.重启nginx生效
二、测试
修改nginx配置文件,增加代码块
1、隐藏版本
加入参数:server_tokens off;
效果(版本已经看不到了):
2、隐藏Server
加入参数 : more_clear_headers 'Server';
效果(已经看不到server了)
3、伪装Server
加入参数: more_set_headers 'Server: my-server';
效果(server已经变成我们自定义的)