Nginx 安全漏洞(CVE-2022-3638)处理

一、漏洞描述

在这里插入图片描述
近日,在一起安全扫描中,发现系统存在Nginx 安全漏洞(CVE-2022-3638)。漏洞描述如下:nginx中发现的该漏洞会影响涉及IPv4连接断开的ngx_resolver.c文件某些未知处理过程,攻击者利用该漏洞在发起远程攻击,导致这个过程中触发内存泄漏。nginx 1.23.2之前版本存在安全漏洞。

背景:该主机上Nginx为从其他主机整体打包后拷贝过来,启动运行的,后来升级时发现很多依赖项并未安装;

处理建议:目前厂商已发布升级补丁以修复漏洞,补丁获取链接:
https://github.com/nginx/nginx/commit/14341ce2377d38a268261e0fec65b6915ae6e95e

在这里插入图片描述

参考链接:12

二、漏洞处理

1)下载Nginx 1.23.2 版本或者下载上文对应的ngx_resolver.c补丁文件

在这里插入图片描述

--- a/src/core/ngx_resolver.c	Tue Jul 12 21:44:02 2022 +0400
+++ b/src/core/ngx_resolver.c	Thu Jul 14 21:26:54 2022 +0400
@@ -3684,10 +3684,7 @@
     }
 
     rn->qlen = (u_short) len;
-
-    if (r->ipv4) {
    
    
-        rn->query = p;
-    }   //上面4行删除
+    rn->query = p;  //新增让你干
 
 #if (NGX_HAVE_INET6)
     if (r->ipv6) {
    
    

补丁下载:nginx-1.23.2软件下载:;从发布的版本看,1.23.2版本并没有标明修复CVE-2022-3638漏洞,但看文件已经删除了下列代码,最好使用补丁编译。

在这里插入图片描述

2)下载后,将补丁覆盖源码包,重新编译或直接用1.23.2版本重新编译

ldconfig -p|grep libssl*

./configure --prefix=/usr/local/nginx-1.20.1 --user=nginx --group=nginx --with-http_ssl_module --with-http_gzip_static_module --with-http_realip_module --with-http_stub_status_module --with-http_flv_module --with-http_mp4_module --with-http_sub_module --with-http_v2_module --with-pcre-jit --with-pcre --with-http_dav_module --with-http_addition_module --add-module=nginx-module-vts-master --with-openssl=/usr

yum install openssl openssl-devel zlib zlib-devel pcre pcre-devel gcc gcc-c++ -y

#报错1:
make -f objs/Makefile
make[1]: Entering directory `/usr/local/src/nginx-1.13.6'
cd /usr/bin/openssl \
&& if [ -f Makefile ]; then make clean; fi \
&& ./config --prefix=/usr/bin/openssl/.openssl no-shared  \
&& make \
&& make install_sw LIBDIR=lib
/bin/sh: line 0: cd: /usr/bin/openssl: Not a directory
make[1]: *** [/usr/bin/openssl/.openssl/include/openssl/ssl.h] Error 1
make[1]: Leaving directory `/usr/local/src/nginx-1.13.6':
make: *** [build] Error 2

#报错2:
make -f objs/Makefile
make[1]: Entering directory `/usr/local/src/nginx-1.13.6'
make[1]: *** No rule to make target `/usr/include/openssl/ssl.h', needed by `objs/src/core/nginx.o'.  Stop.
make[1]: Leaving directory `/usr/local/src/nginx-1.23.2'
make: *** [build] Error 2
#处理
vim  ./auto/lib/openssl/conf //ssh.h前保留openssl,其他删除openssl
……
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"
CORE_LIBS="$CORE_LIBS $NGX_LIBDL"
#重新编译make,报错:
    ... ...
cc: error: /usr/lib/libssl.a: No such file or directory
cc: error: /usr/lib/libcrypto.a: No such file or directory
#上述报错为缺少文件所致,下载
wget https://www.openssl.org/source/old/1.0.2/openssl-1.0.2k.tar.gz
#解压后编译,生成libssl.a和libcrypto.a
./configre && make
cp ./lib*.a /usr/lib/
#重新make后,如下图3
#之后,替代现有的nginx二进制文件即可

#web验证
##查看web信息
openssl s_client -connect 域名地址:446 -tls1_2
openssl s_client -connect 域名地址:446 -tls1_3

在这里插入图片描述
在这里插入图片描述

重新编译后:
在这里插入图片描述
验证:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/ximenjianxue/article/details/128081798