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

来源:互联网 发布:linux usleep 精度 编辑:程序博客网 时间:2024/05/20 18:53

平滑升级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 enabledconfigure 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/nginxfind: ‘/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_64checking 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 ... foundchecking for -Wl,-E switch ... foundchecking for gcc builtin atomic operations ... foundchecking for C99 variadic macros ... foundchecking for gcc variadic macros ... foundchecking for gcc builtin 64 bit byteswap ... foundchecking for unistd.h ... foundchecking for inttypes.h ... foundchecking for limits.h ... foundchecking for sys/filio.h ... not 

3.4 只编译make ,不执行make install

# make make -f objs/Makefilemake[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.ccc -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.ccc -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 -tnginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successfulkill -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 enabledconfigure 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 -tnginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful
# nginx -s reload
# ps -ef |grep nginxavahi      741     1  0 328 ?       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 processroot     18425 15358  0 10:40 pts/0    00:00:00 grep --color=auto nginxroot     21249     1  0 525 ?       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回源,视频加载播放,断点续传功能的服务有影响,在设置之前,请先确认业务是否有相关功能再进行部署。

原创粉丝点击