隐藏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

相关文章

在Spring Boot中浅尝内存泄漏的实战记录

《在SpringBoot中浅尝内存泄漏的实战记录》本文给大家分享在SpringBoot中浅尝内存泄漏的实战记录,结合实例代码给大家介绍的非常详细,感兴趣的朋友一起看看吧... 目录使用静态集合持有对象引用,阻止GC回收关键点:可执行代码:验证:1,运行程序(启动时添加JVM参数限制堆大小):2,访问 htt

SQL server配置管理器找不到如何打开它

《SQLserver配置管理器找不到如何打开它》最近遇到了SQLserver配置管理器打不开的问题,尝试在开始菜单栏搜SQLServerManager无果,于是将自己找到的方法总结分享给大家,对SQ... 目录方法一:桌面图标进入方法二:运行窗口进入方法三:查找文件路径方法四:检查 SQL Server 安

python连接本地SQL server详细图文教程

《python连接本地SQLserver详细图文教程》在数据分析领域,经常需要从数据库中获取数据进行分析和处理,下面:本文主要介绍python连接本地SQLserver的相关资料,文中通过代码... 目录一.设置本地账号1.新建用户2.开启双重验证3,开启TCP/IP本地服务二js.python连接实例1.

springboot filter实现请求响应全链路拦截

《springbootfilter实现请求响应全链路拦截》这篇文章主要为大家详细介绍了SpringBoot如何结合Filter同时拦截请求和响应,从而实现​​日志采集自动化,感兴趣的小伙伴可以跟随小... 目录一、为什么你需要这个过滤器?​​​二、核心实现:一个Filter搞定双向数据流​​​​三、完整代码

Nginx中配置HTTP/2协议的详细指南

《Nginx中配置HTTP/2协议的详细指南》HTTP/2是HTTP协议的下一代版本,旨在提高性能、减少延迟并优化现代网络环境中的通信效率,本文将为大家介绍Nginx配置HTTP/2协议想详细步骤,需... 目录一、HTTP/2 协议概述1.HTTP/22. HTTP/2 的核心特性3. HTTP/2 的优

使用Python自建轻量级的HTTP调试工具

《使用Python自建轻量级的HTTP调试工具》这篇文章主要为大家详细介绍了如何使用Python自建一个轻量级的HTTP调试工具,文中的示例代码讲解详细,感兴趣的小伙伴可以参考一下... 目录一、为什么需要自建工具二、核心功能设计三、技术选型四、分步实现五、进阶优化技巧六、使用示例七、性能对比八、扩展方向建

基于Python打造一个可视化FTP服务器

《基于Python打造一个可视化FTP服务器》在日常办公和团队协作中,文件共享是一个不可或缺的需求,所以本文将使用Python+Tkinter+pyftpdlib开发一款可视化FTP服务器,有需要的小... 目录1. 概述2. 功能介绍3. 如何使用4. 代码解析5. 运行效果6.相关源码7. 总结与展望1

详解nginx 中location和 proxy_pass的匹配规则

《详解nginx中location和proxy_pass的匹配规则》location是Nginx中用来匹配客户端请求URI的指令,决定如何处理特定路径的请求,它定义了请求的路由规则,后续的配置(如... 目录location 的作用语法示例:location /www.chinasem.cntestproxy

使用Python实现一键隐藏屏幕并锁定输入

《使用Python实现一键隐藏屏幕并锁定输入》本文主要介绍了使用Python编写一个一键隐藏屏幕并锁定输入的黑科技程序,能够在指定热键触发后立即遮挡屏幕,并禁止一切键盘鼠标输入,这样就再也不用担心自己... 目录1. 概述2. 功能亮点3.代码实现4.使用方法5. 展示效果6. 代码优化与拓展7. 总结1.

使用Python开发一个简单的本地图片服务器

《使用Python开发一个简单的本地图片服务器》本文介绍了如何结合wxPython构建的图形用户界面GUI和Python内建的Web服务器功能,在本地网络中搭建一个私人的,即开即用的网页相册,文中的示... 目录项目目标核心技术栈代码深度解析完整代码工作流程主要功能与优势潜在改进与思考运行结果总结你是否曾经