漏洞修复记录

检测到目标X-Content-Type-Options响应头缺失

解决方式

nginx 增加响应头配置:

add_header X-Content-Type-Options "nosniff"  always; 

检测到目标X-XSS-Protection响应头缺失

解决方式

add_header X-XSS-Protection "1; mode=block"  always;

Web服务器未能正确处理异常请求导致Web服务器版本信息泄露,攻击者收集到服务器信息后可进行进一步针对性攻击。

针对错误页面做调整优化

检测到目标Content-Security-Policy响应头缺失

解决方式

add_header Content-Security-Policy "script-src 'self' 'unsafe-inline' 'unsafe-eval'"     always; 

检测到目标服务器启用了OPTIONS方法

检测到目标Referrer-Policy响应头缺失

解决方式

add_header Referrer-Policy "origin" always;

检测到目标Strict-Transport-Security响应头缺失

解决方式

add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload" always;

检测到目标X-Permitted-Cross-Domain-Policies响应头缺失

解决方式

add_header X-Permitted-Cross-Domain-Policies  "master-only" always;

检测到目标X-Download-Options响应头缺失

解决方式

add_header X-Download-Options "noopen" always;

点击劫持:X-Frame-Options未配置

解决方式

add_header X-Frame-Options "sameorigin" always;

内链补充

Nginx漏扫响应头缺失问题处理

ICMPtimestamp请求响应漏洞处理(CVE-1999-0524)

允许Traceroute探测漏洞处理

Nginx安全配置样例

http {
autoindex off;
server_tokens off;
client_max_body_size 64m;

## -----------------------------------------
## 1、此处省略其他 http 节点配置
## 2、下面的配置也可以写在 server {} 中
## -----------------------------------------

#解决 [ 检测到目标Content-Security-Policy响应头缺失 ]
add_header Content-Security-Policy "script-src 'self' 'unsafe-inline' 'unsafe-eval'" always;
#解决 [ 检测到目标Referrer-Policy响应头缺失 ]
add_header Referrer-Policy "same-origin" always;
#解决 [ 检测到目标Strict-Transport-Security响应头缺失 ]
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload" always;
#解决 [ 检测到目标X-Content-Type-Options响应头缺失 ]
add_header X-Content-Type-Options "nosniff" always;
#解决 [ 检测到目标X-Download-Options响应头缺失 ]
add_header X-Download-Options "noopen" always;
#解决 [ 点击劫持:X-Frame-Options未配置 ]
add_header X-Frame-Options "sameorigin" always;
#解决 [ 检测到目标X-Permitted-Cross-Domain-Policies响应头缺失 ]
add_header X-Permitted-Cross-Domain-Policies "none" always;
#解决 [ 检测到目标X-XSS-Protection响应头缺失 ]
add_header X-XSS-Protection "1; mode=block" always;

# 告诉搜索引擎爬虫不要索引或跟踪网站上的页面
add_header X-Robots-Tag "none" always;
#隐藏HTTP响应头中的"X-Powered-By"字段。这个字段通常包含有关服务器所使用的技术和版本的信息。
proxy_hide_header X-Powered-By;
#这个字段通常包含有关服务器上运行的后端应用程序或应用程序框架的信息,与之前提到的proxy_hide_header类似,但针对FastCGI服务器。
fastcgi_hide_header X-Powered-By;
}

nginx/tomcat-修复:可通过HTTP获取远端WWW服务信息

参考博客

插件:headers-more-nginx-module

进入nginx的安装目录(执行make install后安装的目录,例:/usr/local/nginx

cd /home/env/nginx/sbin/

查询nginx版本信息

./nginx  -V

复制configure arguments后的配置命令,并在nginx-1.26.3原始解压目录下执行

./configure --prefix=/home/env/nginx --with-http_stub_status_module --with-http_ssl_module --add-module=/home/env/nginx/nginx-1.26.3/src/headers-more-nginx-module-0.37

若引用新版ssl需追加配置命令:--with-openssl=/usr/local/openssl_3.3

报错注意:解决Nginx添加openssl模块编译时报错

修改当前nginx解压目录下配置文件

vim usr/local/nginx-x.x.x/auto/lib/openssl/conf

移除.openssl目录信息后,重新进行Nginx的编译安装即可

#CORE_INCS="$CORE_INCS $OPENSSL/.openssl/include"
#CORE_DEPS="$CORE_DEPS $OPENSSL/.openssl/include/openssl/ssl.h"
#CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libssl.a"
#CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libcrypto.a"
#修改成以下代码:
CORE_INCS="$CORE_INCS $OPENSSL/include"
CORE_DEPS="$CORE_DEPS $OPENSSL/include/openssl/ssl.h"
CORE_LIBS="$CORE_LIBS $OPENSSL/lib/libssl.a"
CORE_LIBS="$CORE_LIBS $OPENSSL/lib/libcrypto.a"

若重新./configure后在执行make命令报错

建立软链接

ln -snf /usr/local/openssl_3.3/lib64/libssl.a /usr/local/openssl_3.3/lib/libssl.a
ln -snf /usr/local/openssl_3.3/lib64/libcrypto.a /usr/local/openssl_3.3/lib/libcrypto.a

建立软连接报错,提示目录不存在,则手动创建目录即可

重新执行make

注意:不要执行make install覆盖安装

备份原已安装nginx

cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak

将编译好的nginx复制过去

编译后的nginx在源码/home/env/nginx/nginx-1.26.3/objs路径下

cp nginx /home/env/nginx/sbin/

查看Nginx版本信息

修改配置文件/usr/local/nginx/conf/nginx.conf

http 中添加 下面一行

more_clear_headers 'Server';

相关参考博客

参考博客01

参考博客02

参考博客03