隐藏nginx响应头中的server信息(HTTP服务器版本信息泄漏)

2 篇文章 0 订阅

安全审计中有时会有

漏洞名称 HTTP服务器版本信息泄漏
漏洞描述 目标服务器返回的信息头中包含了Web Server的软件或者版本信息。

可以安装 nginx的headers-more-nginx-module模块修改或隐藏响应头信息

一、安装

1.下载 headers-more-nginx-module

下载地址
https://github.com/openresty/headers-more-nginx-module/tags

[root@localhost /]# cd /www/tools
[root@localhost tools]# wget https://github.com/openresty/headers-more-nginx-module/archive/refs/tags/v0.37.tar.gz

2.解压
解压后会多出一个headers-more-nginx-module-0.37文件夹

[root@localhost tools]# tar -zxvf v0.37.tar.gz

# 进入
[root@localhost tools]# cd headers-more-nginx-module-0.37/

# 查看当前完整路径
[root@localhost headers-more-nginx-module-0.37]# pwd

# 复制装盘备用
/www/tools/headers-more-nginx-module-0.37

[root@localhost headers-more-nginx-module-0.37]# cd ..

3.查看当前系统nginx信息

// 查看当前nginx加载的模块
[root@localhost tools]# /www/server/nginx/sbin/nginx -V 
nginx version: nginx/1.22.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
built with OpenSSL 1.1.1q  5 Jul 2022
TLS SNI support enabled
# 复制装盘备用
configure arguments: --user=www --group=www --prefix=/www/server/nginx --add-module=/www/server/nginx/src/ngx_devel_kit --add-module=/www/server/nginx/src/lua_nginx_module --add-module=/www/server/nginx/src/ngx_cache_purge --add-module=/www/server/nginx/src/nginx-sticky-module --with-openssl=/www/server/nginx/src/openssl --with-pcre=/www/server/nginx/src/pcre-8.43 --with-http_v2_module --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_stub_status_module --with-http_ssl_module --with-http_image_filter_module --with-http_gzip_static_module --with-http_gunzip_module --with-ipv6 --with-http_sub_module --with-http_flv_module --with-http_addition_module --with-http_realip_module --with-http_mp4_module --add-module=/www/server/nginx/src/ngx_http_substitutions_filter_module-master --with-ld-opt=-Wl,-E --with-cc-opt=-Wno-error --with-ld-opt=-ljemalloc --with-http_dav_module --add-module=/www/server/nginx/src/nginx-dav-ext-module

4.下载对应版本的nginx

下载对应版本的nginx

# 下载
[root@localhost tools]# wget http://nginx.org/download/nginx-1.22.1.tar.gz 

# 解压
[root@localhost tools]# tar -zxvf nginx-1.22.1.tar.gz

5.编译

在末尾添加 --add-module=/www/tools/headers-more-nginx-module-0.37
注意路径【/www/tools/headers-more-nginx-module-0.37】要换成你自己的

# 进入 nginx-1.22.1目录
[root@localhost tools]# cd nginx-1.22.1

# 先备份
[root@localhost nginx-1.12.1]# cp /www/server/nginx/sbin/nginx /www/server/nginx/sbin/nginx_old

# 编译
[root@localhost nginx-1.12.1]# ./configure --user=www --group=www --prefix=/www/server/nginx --add-module=/www/server/nginx/src/ngx_devel_kit --add-module=/www/server/nginx/src/lua_nginx_module --add-module=/www/server/nginx/src/ngx_cache_purge --add-module=/www/server/nginx/src/nginx-sticky-module --with-openssl=/www/server/nginx/src/openssl --with-pcre=/www/server/nginx/src/pcre-8.43 --with-http_v2_module --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_stub_status_module --with-http_ssl_module --with-http_image_filter_module --with-http_gzip_static_module --with-http_gunzip_module --with-ipv6 --with-http_sub_module --with-http_flv_module --with-http_addition_module --with-http_realip_module --with-http_mp4_module --add-module=/www/server/nginx/src/ngx_http_substitutions_filter_module-master --with-ld-opt=-Wl,-E --with-cc-opt=-Wno-error --with-ld-opt=-ljemalloc --with-http_dav_module --add-module=/www/server/nginx/src/nginx-dav-ext-module --add-module=/www/tools/headers-more-nginx-module-0.37

# configure完成后进行make(如原本无nginx,make后还需make install)
[root@localhost nginx-1.12.1]# make 

6.复制新的nginx到目录

[root@localhost nginx-1.12.1]# mv /www/server/nginx/sbin/nginx /www/server/nginx/sbin/nginx_bak
[root@localhost nginx-1.12.1]# cp objs/nginx /www/server/nginx/sbin/nginx

7.重新nginx生效

二、食用

修改nginx配置文件,增加代码块


 # set the Server output header
 # 隐藏Server
 more_clear_headers 'Server';
 
 # 伪装Server
 more_set_headers 'Server: my-server';

 # set and clear output headers
 location /bar {
     more_set_headers 'X-MyHeader: blah' 'X-MyHeader2: foo';
     more_set_headers -t 'text/plain text/css' 'Content-Type: text/foo';
     more_set_headers -s '400 404 500 503' -s 413 'Foo: Bar';
     more_clear_headers 'Content-Type';

     # your proxy_pass/memcached_pass/or any other config goes here...
 }

 # set output headers
 location /type {
     more_set_headers 'Content-Type: text/plain';
     # ...
 }

 # set input headers
 location /foo {
     set $my_host 'my dog';
     more_set_input_headers 'Host: $my_host';
     more_set_input_headers -t 'text/plain' 'X-Foo: bah';

     # now $host and $http_host have their new values...
     # ...
 }

 # replace input header X-Foo *only* if it already exists
 more_set_input_headers -r 'X-Foo: howdy';
  • 8
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值