一、漏洞描述
近日,在一起安全掃描中,發(fā)現(xiàn)系統(tǒng)存在Nginx 安全漏洞(CVE-2022-3638)。漏洞描述如下:nginx中發(fā)現(xiàn)的該漏洞會(huì)影響涉及IPv4連接斷開(kāi)的ngx_resolver.c文件某些未知處理過(guò)程,攻擊者利用該漏洞在發(fā)起遠(yuǎn)程攻擊,導(dǎo)致這個(gè)過(guò)程中觸發(fā)內(nèi)存泄漏。nginx 1.23.2之前版本存在安全漏洞。
背景:該主機(jī)上Nginx為從其他主機(jī)整體打包后拷貝過(guò)來(lái),啟動(dòng)運(yùn)行的,后來(lái)升級(jí)時(shí)發(fā)現(xiàn)很多依賴項(xiàng)并未安裝;
處理建議:目前廠商已發(fā)布升級(jí)補(bǔ)丁以修復(fù)漏洞,補(bǔ)丁獲取鏈接:
https://github.com/nginx/nginx/commit/14341ce2377d38a268261e0fec65b6915ae6e95e
參考鏈接:1,2
二、漏洞處理
1)下載Nginx 1.23.2 版本或者下載上文對(duì)應(yīng)的ngx_resolver.c補(bǔ)丁文件
--- 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) {
補(bǔ)丁下載:;nginx-1.23.2軟件下載:;從發(fā)布的版本看,1.23.2版本并沒(méi)有標(biāo)明修復(fù)CVE-2022-3638漏洞,但看文件已經(jīng)刪除了下列代碼,最好使用補(bǔ)丁編譯。
2)下載后,將補(bǔ)丁覆蓋源碼包,重新編譯或直接用1.23.2版本重新編譯
#查看openssl庫(kù)文件位置
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
#報(bào)錯(cuò)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
#報(bào)錯(cuò)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,報(bào)錯(cuò):
... ...
cc: error: /usr/lib/libssl.a: No such file or directory
cc: error: /usr/lib/libcrypto.a: No such file or directory
#上述報(bào)錯(cuò)為缺少文件所致,下載
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
#之后,替代現(xiàn)有的nginx二進(jìn)制文件即可
#web驗(yàn)證
##查看web信息
openssl s_client -connect 域名地址:446 -tls1_2
openssl s_client -connect 域名地址:446 -tls1_3
重新編譯后:
驗(yàn)證:
四、附錄:報(bào)錯(cuò)處理
4.1 報(bào)錯(cuò):Nginx make編譯報(bào)錯(cuò)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
如上所示,報(bào)錯(cuò)提示Nginx在編譯時(shí)不能在/usr/local/.openssl/ 這個(gè)目錄找到對(duì)應(yīng)的文件,現(xiàn)在實(shí)際路徑并非為.openssl隱藏文件,因此我們?nèi)バ薷腘ginx編譯時(shí)正確openssl的路徑,修改Nginx的編譯庫(kù)配置文件:./nginx-1.20.1/auto/lib/openssl/conf,修改需要的目錄,去除openssl前面的點(diǎn)就行,如下所示。
4.2 Nginx 編譯報(bào)錯(cuò):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文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-412021.html
如上報(bào)錯(cuò)找不到prce目錄,我們需手動(dòng)指定,追加參數(shù):–with-pcre=/usr/local/pcre-8.35;可執(zhí)行find / -name “l(fā)ibpcre.so.1” /查找“l(fā)ibpcre.so.1”所存在的位置,驗(yàn)證pcregrep -V;文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-412021.html
到了這里,關(guān)于Nginx 安全漏洞(CVE-2022-3638)處理的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!