如何应对及修复 Nginx (CVE-2022-3638)安全漏洞:第二部分 - 漏洞修补方法
最编程
2024-07-24 08:20:35
...
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版本重新编译
#查看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 ]; 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
重新编译后:
验证:
下一篇: 重现 Nginx 的解析漏洞细节