平滑升級Nginx到新版本v1.12.1修復Nginx最新漏洞CVE-2017-7529

平滑升級Nginx到新版本v1.12.1修復Nginx最新漏洞CVE-2017-7529

來源自己博客地址:http://www.51geeks.com/?p=1526

升級實施步驟

一 查看版本及配置

# nginx -Vnginx version: nginx/1.8.1built by gcc 4.8.5 20150623 (Red Hat 4.8.5-4) (GCC) 
built with OpenSSL 1.0.1e-fips 11 Feb 2013TLS SNI support enabled
configure arguments: --prefix=/usr --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-pcre

二 查看nginx所在目錄,並備份下

# find / -name nginx/run/nginx
find: ‘/run/user/42/gvfs’: 權限不夠
/etc/nginx
/var/log/nginx
/var/spool/mail/nginx
/var/tmp/nginx
/var/software/nginx-1.8.1/objs/nginx
/usr/sbin/nginx
/usr/local/nginx
/home/nginx

三 編譯安裝

3.1解壓 nginx-1.12.1

# tar xf nginx-1.12.1.tar.gz

3.2進入nginx-1.12.1/ 目錄

#cd nginx-1.12.1/

3.3編譯配置

# ./configure --prefix=/usr --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-pcrechecking for OS
 + Linux 3.10.0-327.el7.x86_64 x86_64
checking for C compiler ... found
 + using GNU C compiler
 + gcc version: 4.8.5 20150623 (Red Hat 4.8.5-4) (GCC) 
checking for gcc -pipe switch ... found
checking for -Wl,-E switch ... found
checking for gcc builtin atomic operations ... found
checking for C99 variadic macros ... found
checking for gcc variadic macros ... found
checking for gcc builtin 64 bit byteswap ... found
checking for unistd.h ... found
checking for inttypes.h ... found
checking for limits.h ... found
checking for sys/filio.h ... not

3.4 只編譯make ,不執行make install

# make 
make -f objs/Makefile
make[1]: 進入目錄“/usr/local/src/nginx-1.12.1”
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
    -o objs/src/core/nginx.o \
    src/core/nginx.c
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
    -o objs/src/core/ngx_log.o \
    src/core/ngx_log.c
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
    -o objs/src/core/ngx_palloc.o \

3.5 備份sbin目錄下的nginx文件(提前備份)

# cp -a /usr/sbin/nginx /usr/sbin/nginx20170715.bak

3.6 執行完後,這裏不用在make install了,接下來重命名/sbin/nginx爲nginx.old

#mv /usr/sbin/nginx /usr/sbin/nginx.old

3.7 複製/usr/local/src/nginx-1.12.1/objs 
下的nginx文件到 /sbin/目錄下的nginx文件

# cp -a nginx /usr/sbin/

3.8 升級nginx:

# make upgrade/usr/sbin/nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
kill -USR2 `cat /var/run/nginx/nginx.pid`
kill: 用法:kill [-s 信號聲明 | -n 信號編號 | -信號聲明] 進程號 | 任務聲明 ... 或 kill -l [信號聲明]
make: *** [upgrade] 錯誤 1

3.9 查看版本升級是否成功:

# nginx -Vnginx version: nginx/1.12.1built by gcc 4.8.5 20150623 (Red Hat 4.8.5-4) (GCC) 
built with OpenSSL 1.0.1e-fips 11 Feb 2013TLS SNI support enabled
configure arguments: --prefix=/usr --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-pcre

四 測試配置

# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
# nginx -s reload
# ps -ef |grep nginxavahi      741     1  0 3月28 ?       00:00:20 avahi-daemon: running [pv-ecmnginx02.local]
nginx    18418 21249  0 10:40 ?        00:00:00 nginx: worker processnginx    18419 21249  0 10:40 ?        00:00:00 nginx: worker processnginx    18420 21249  0 10:40 ?        00:00:00 nginx: worker processnginx    18421 21249  0 10:40 ?        00:00:00 nginx: worker processnginx    18422 21249  0 10:40 ?        00:00:00 nginx: worker processnginx    18423 21249  0 10:40 ?        00:00:00 nginx: worker proce***oot     18425 15358  0 10:40 pts/0    00:00:00 grep --color=auto nginxroot     21249     1  0 5月25 ?       00:00:00 nginx: master process nginx

五 關於漏洞描述:

2017年7月11日,Nginx官方發佈了一個新的安全漏洞公告(漏洞編號:CVE-2017-7529),該漏洞系nginx的range過濾器的整數溢出漏洞,遠程***者通過構造特定請求可利用該漏洞導致信息泄露,目前官方評級爲中級。

(當使用Nginx標準模塊時,如果文件頭從緩存返回響應,允許***者獲取緩存文件頭。在某些配置中,緩存文件頭可能包含後端服務器IP地址或其他敏感信息。此外,如果使用第三方模塊有潛在的可能導致拒絕服務。)

爲避免您的業務受影響,建議您及時進行安全自查,並開展安全修復工作,詳細操作參見如下指引說明:

【漏洞概述】 
***者可構造惡意請求來觸發Nginx Web Server 0.5.6-1.13.2版本的一個整數溢出漏洞,進而獲取服務器緩存返回的、包括後端服務器的真實IP等在內的敏感信息。此外,部分Nginx第三方模塊(影響範圍暫未知)受此漏洞影響,將使服務器面臨可能無法提供web服務(拒絕服務)、Worker進程內存內容泄漏等風險。

【漏洞細節】 
漏洞代碼位於src/http/modules/ngx_http_range_filter_module.c。該模塊是header filter,負責處理含有Ranges的請求頭。由於max_ranges默認不限制大小,同時又因爲相關代碼處理邏輯限制不嚴,進而導致一個整數溢出漏洞,***者可構造惡意請求觸發整數溢出漏洞,進而獲取服務器緩存中的敏感信息。其修復細節技術如下:

@@ -377,6 +377,10 @@ ngx_http_range_parse(ngx_http_request_t 
range->start = start; 
range->end = end;

  • if (size > NGX_MAX_OFF_T_VALUE – (end – start)) {

  • return NGX_HTTP_RANGE_NOT_SATISFIABLE;



  • size += end – start;

if (ranges– == 0) {

【風險等級】 
中風險

【漏洞風險】 
信息泄露

【影響版本】 
Nginx Web Server 0.5.6-1.13.2 版本

【安全版本】 
Nginx Web Server 1.13.3+, 1.12.1+版本

【修復建議】 
目前Ubuntu官方已發佈專門針對該漏洞的補丁更新。 
方案一: 根據Ubuntu系統版本,升級到指定版本即可。運行“sudo apt-get update && sudo apt-get install nginx”命令,升級到如下版本:

Ubuntu 16.04 LTS: 
nginx-extras 1.10.3-0ubuntu0.16.04.2 
nginx-full 1.10.3-0ubuntu0.16.04.2 
nginx-common 1.10.3-0ubuntu0.16.04.2 
nginx-light 1.10.3-0ubuntu0.16.04.2 
nginx-core 1.10.3-0ubuntu0.16.04.2

Ubuntu 14.04 LTS: 
nginx-extras 1.4.6-1ubuntu3.8 
nginx-full 1.4.6-1ubuntu3.8 
nginx-common 1.4.6-1ubuntu3.8 
nginx-light 1.4.6-1ubuntu3.8 
nginx-core 1.4.6-1ubuntu3.8

方案二: 如果您Nginx服務爲官方源碼方式安裝,建議您參照上述【安全版本】升級到官方提供的Nginx Web Server1.12.1(Stable version)或1.13.3(Mainline version)最新版本。 
下載鏈接: 
[1.12.1] http://nginx.org/download/nginx-1.12.1.tar.gz 
[1.13.3] http://nginx.org/download/nginx-1.13.3.tar.gz

方案三: 如果您的Nginx服務受某些因素限制,暫時無法升級到上述最新版本。建議您採取以下漏洞臨時緩解措施進行防禦: 
即,在Nginx的配置文件nginx.conf中,將max_ranges設置爲1。形如:max_ranges 1; 
注:將max_ranges設置爲1,可能對部分大文件的下載,CDN回源,視頻加載播放,斷點續傳功能的服務有影響,在設置之前,請先確認業務是否有相關功能再進行部署。



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章