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

本文主要是介绍隐藏nginx响应头中的server信息(HTTP服务器版本信息泄漏),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

安全审计中有时会有

漏洞名称 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# 隐藏Servermore_clear_headers 'Server';# 伪装Servermore_set_headers 'Server: my-server';# set and clear output headerslocation /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 headerslocation /type {more_set_headers 'Content-Type: text/plain';# ...}# set input headerslocation /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 existsmore_set_input_headers -r 'X-Foo: howdy';

这篇关于隐藏nginx响应头中的server信息(HTTP服务器版本信息泄漏)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1032324

相关文章

Nginx部署HTTP/3的实现步骤

《Nginx部署HTTP/3的实现步骤》本文介绍了在Nginx中部署HTTP/3的详细步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学... 目录前提条件第一步:安装必要的依赖库第二步:获取并构建 BoringSSL第三步:获取 Nginx

HTTP 与 SpringBoot 参数提交与接收协议方式

《HTTP与SpringBoot参数提交与接收协议方式》HTTP参数提交方式包括URL查询、表单、JSON/XML、路径变量、头部、Cookie、GraphQL、WebSocket和SSE,依据... 目录HTTP 协议支持多种参数提交方式,主要取决于请求方法(Method)和内容类型(Content-Ty

Web服务器-Nginx-高并发问题

《Web服务器-Nginx-高并发问题》Nginx通过事件驱动、I/O多路复用和异步非阻塞技术高效处理高并发,结合动静分离和限流策略,提升性能与稳定性... 目录前言一、架构1. 原生多进程架构2. 事件驱动模型3. IO多路复用4. 异步非阻塞 I/O5. Nginx高并发配置实战二、动静分离1. 职责2

Python 基于http.server模块实现简单http服务的代码举例

《Python基于http.server模块实现简单http服务的代码举例》Pythonhttp.server模块通过继承BaseHTTPRequestHandler处理HTTP请求,使用Threa... 目录测试环境代码实现相关介绍模块简介类及相关函数简介参考链接测试环境win11专业版python

Linux搭建ftp服务器的步骤

《Linux搭建ftp服务器的步骤》本文给大家分享Linux搭建ftp服务器的步骤,本文通过图文并茂的形式给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录ftp搭建1:下载vsftpd工具2:下载客户端工具3:进入配置文件目录vsftpd.conf配置文件4:

使用Python的requests库来发送HTTP请求的操作指南

《使用Python的requests库来发送HTTP请求的操作指南》使用Python的requests库发送HTTP请求是非常简单和直观的,requests库提供了丰富的API,可以发送各种类型的HT... 目录前言1. 安装 requests 库2. 发送 GET 请求3. 发送 POST 请求4. 发送

Nginx中配置使用非默认80端口进行服务的完整指南

《Nginx中配置使用非默认80端口进行服务的完整指南》在实际生产环境中,我们经常需要将Nginx配置在其他端口上运行,本文将详细介绍如何在Nginx中配置使用非默认端口进行服务,希望对大家有所帮助... 目录一、为什么需要使用非默认端口二、配置Nginx使用非默认端口的基本方法2.1 修改listen指令

解决Nginx启动报错Job for nginx.service failed because the control process exited with error code问题

《解决Nginx启动报错Jobfornginx.servicefailedbecausethecontrolprocessexitedwitherrorcode问题》Nginx启... 目录一、报错如下二、解决原因三、解决方式总结一、报错如下Job for nginx.service failed bec

SQL Server 查询数据库及数据文件大小的方法

《SQLServer查询数据库及数据文件大小的方法》文章介绍了查询数据库大小的SQL方法及存储过程实现,涵盖当前数据库、所有数据库的总大小及文件明细,本文结合实例代码给大家介绍的非常详细,感兴趣的... 目录1. 直接使用SQL1.1 查询当前数据库大小1.2 查询所有数据库的大小1.3 查询每个数据库的详

Spring Boot 整合 SSE(Server-Sent Events)实战案例(全网最全)

《SpringBoot整合SSE(Server-SentEvents)实战案例(全网最全)》本文通过实战案例讲解SpringBoot整合SSE技术,涵盖实现原理、代码配置、异常处理及前端交互,... 目录Spring Boot 整合 SSE(Server-Sent Events)1、简述SSE与其他技术的对