1. 程式人生 > >nginx漏洞分析與升級修復

nginx漏洞分析與升級修復

一 、此次漏洞分析

1 nginx HTTP/2漏洞

[nginx-announce] nginx安全公告(CVE-2018-16843,CVE-2018-16844)
在nginx HTTP / 2實現中發現了兩個安全問題,
漏洞對伺服器的影響:
可能會導致過多的記憶體消耗(CVE-2018-16843)和CPU使用率(CVE-2018-16844)。
影響範圍:
這些問題會影響使用ngx_http_v2_module編譯的nginx(不是預設情況下編譯)如果“listen”指令的“http2”選項是用於配置檔案。
影響版本:
這些問題會影響nginx 1.9.5 - 1.15.5。
解決方法:
問題在nginx 1.15.6,1.14.1中得到修復。建議升級到最新穩定版

以上內容參考:
 http://mailman.nginx.org/pipermail/nginx-announce/2018/000220.html

2 ngx_http_mp4_module漏洞

[nginx-announce] nginx安全公告(CVE-2018-16845)
漏洞對伺服器的影響:
在ngx_http_mp4_module中發現了一個安全問題,可能是這個問題允許攻擊者在工作程序中導致無限迴圈,導致攻擊工作程序崩潰,或者可能導致工作程序記憶體使用特製的mp4檔案(CVE-2018-16845)進行披露。
影響範圍:
如果使用ngx_http_mp4_module構建,則該問題僅影響nginx(預設情況下不構建模組)並使用“mp4”指令配置檔案。此外,只有在攻擊時才能進行攻擊,攻擊者能夠觸發特製的mp4檔案的處理使用ngx_http_mp4_module。
影響版本:


該問題影響nginx 1.1.3 +,1.0.7 +。
解決方法:
該問題在1.15.6,1.14.4中得到修復。建議升級到最新穩定版

該問題的補丁可以在這裡找到:
http://nginx.org/download/patch.2018.mp4.txt
以上內容參考:
http://mailman.nginx.org/pipermail/nginx-announce/2018/000221.html

3 模組ngx_http_mp4_module介紹

作用:為H.264(一種視訊編碼格式)/AAC(一種音訊編碼格式)檔案,主要是以 .mp4、.m4v、和.m4a為副檔名的檔案, 提供偽流媒體服務端支援。

二、nginx升級

1 備份原有檔案

cp -a /usr/local/nginx /tmp/nginx_back

2 解壓nginx-1.14.1.tar.gz檔案

tar -xf nginx-1.14.1

3 進入nginx-1.14.1目錄

cd nginx-1.14.1

4 編譯配置

(1)請先使用nginx -V 命令檢視原有nginx編譯的選項,

# nginx -V

nginx version: nginx/1.0.15
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-http_flv_module --add-module=/usr/local/src/nginx-auth-ldap --with-http_realip_module

(2)故保持和原有一樣的編譯配置,根據自己情況具體而定

./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module 
--with-http_ssl_module --with-http_gzip_static_module --with-http_flv_module --with-http_realip_module
--with-http_auth_request_module --with-http_auth_request_module --add-module=/usr/local/src/nginx-auth-ldap
--add-module=/usr/local/src/headers-more-nginx-module-master --with-cc-opt=-Wno-error

5 編譯

make

6 備份原來sbin/nginx

cd /usr/local/nginx/sbin/
mv nginx nginx.back

7 複製nginx-1.14.1/objs/nginx到/usr/local/nginx/sbin/

cp nginx-1.14.1/objs/nginx /usr/local/nginx/sbin/

8 升級

cd nginx-1.14.1
make upgrade

輸出如下:

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
sleep 1
test -f /usr/local/nginx/logs/nginx.pid.oldbin
kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`

或者輸出為以下內容: 

/usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
sleep 1
test -f /usr/local/nginx/logs/nginx.pid.oldbin
make: *** [upgrade] Error 1    

看到 Error 1也不用太在意,已經升級成功

如果nginx是關閉的請情況輸出如下:

/usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]
make: *** [upgrade] Error 1

9 檢視升級是否成功

# /usr/local/nginx/sbin/nginx -v

nginx version: nginx/1.14.1