0


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

在这里插入图片描述

参考链接:1,2

二、漏洞处理

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

在这里插入图片描述

--- a/src/core/ngx_resolver.c    Tue Jul 1221:44:022022+0400+++ b/src/core/ngx_resolver.c    Thu Jul 1421:26:542022+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版本重新编译

#查看openssl库文件位置
ldconfig -p|grep libssl*   #或者openssl version -a,ldconfig -v

./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 ];thenmake 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 &&makecp ./lib*.a /usr/lib/
#重新make后,如下图3#之后,替代现有的nginx二进制文件即可#web验证##查看web信息
openssl s_client -connect 域名地址:446 -tls1_2
openssl s_client -connect 域名地址:446 -tls1_3

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

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

四、附录:报错处理

4.1 报错:Nginx make编译报错No such file or directory Error 127

/bin/sh: line 2: ./config: No such file or directory
make[1]: *** [/usr/local/ssl/.openssl/include/openssl/ssl.h] Error 127
make[1]: Leaving directory `/usr/local/src/nginx-1.14.0’
make: *** [build] Error 2

如上所示,报错提示Nginx在编译时不能在/usr/local/.openssl/ 这个目录找到对应的文件,现在实际路径并非为.openssl隐藏文件,因此我们去修改Nginx编译时正确openssl的路径,修改Nginx的编译库配置文件:./nginx-1.20.1/auto/lib/openssl/conf,修改需要的目录,去除openssl前面的点就行,如下所示。
在这里插入图片描述

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

4.2 Nginx 编译报错:pcre error 127

/bin/sh: line 2: ./configure: No such file or directory
make[1]: *** [/usr/local/pcre/Makefile] Error 127
make[1]: Leaving directory `/usr/local/src/nginx-0.8.54′
make: *** [build] Error 2

如上报错找不到prce目录,我们需手动指定,追加参数:–with-pcre=/usr/local/pcre-8.35;可执行find / -name “libpcre.so.1” /查找“libpcre.so.1”所存在的位置,验证pcregrep -V;


本文转载自: https://blog.csdn.net/ximenjianxue/article/details/128081798
版权归原作者 羌俊恩 所有, 如有侵权,请联系我们删除。

“Nginx 安全漏洞(CVE-2022-3638)处理”的评论:

还没有评论