说明
2018 年 11 月 9 日,阿里云云盾应急响应中心监测到 Nginx 近日发布安全更新,披露了三个可能导致服务器拒绝服务的漏洞:CVE-2018-16843、CVE-2018-16844 和 CVE-2018-16845。位于 Nginx HTTP/2 模块和流媒体 MP4 模块中。攻击者通过构造特定的恶意 HTTP 请求,可远程 DoS 服务器。
详情
CVE-2018-16843、CVE-2018-16844 漏洞存在于 ngx_http_v2_module 模块之中(默认情况下不编译,编译时需要开启–with-http_v2_module,同时将 listen http2 添加到配置文件中),当用户添加 http2 支持时,攻击者可以发送特制的 HTTP/2 请求,消耗 CPU 和内存资源,最终导致服务器 DoS。CVE-2018-16845 漏洞存在于 ngx_http_mp4_module 模块中,当 Nginx 处理恶意的 MP4 文件时会导致处理进程无限循环、崩溃或者内存泄露,造成服务器 DoS。
影响范围
主线版本:< 1.15.6
稳定版本:< 1.14.1
风险评级
CVE-2018-16843:高危
CVE-2018-16844:高危
CVE-2018-16845:高危
升级 nginx
下载
###最新版本nginx(当前最新稳定版为1.16.1也修复了以上漏洞)
wget http://nginx.org/download/nginx-1.16.1.tar.gz
wget https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz
wget https://www.openssl.org/source/openssl-1.1.1d.tar.gz
查看原来服务器 nginx 的扩展
nginx -V
##获取内容(以下以我服务器为例)
./configure --prefix=/usr/local/nginx --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.pid --lock-path=/var/run/nginx.lock --user=www --group=www --with-http_stub_status_module --with-http_v2_module --with-http_ssl_module --with-http_gzip_static_module --with-http_realip_module --with-http_flv_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_gunzip_module --with-openssl=../openssl-1.1.1t --with-pcre=../pcre-8.42 --with-pcre-jit
将其复制出来并修改个别需要升级或者添加扩展的地方
./configure --prefix=/usr/local/nginx --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.pid --lock-path=/var/run/nginx.lock --user=www --group=www --with-http_stub_status_module --with-http_v2_module --with-http_ssl_module --with-http_gzip_static_module --with-http_realip_module --with-http_flv_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_gunzip_module --with-http_random_index_module --with-http_secure_link_module --with-http_auth_request_module --with-http_mp4_module --with-openssl=../openssl-1.1.1d --with-pcre=../pcre-8.43 --with-pcre-jit
编译
tar xzf pcre-8.43.tar.gz
tar xzf nginx-1.16.1.tar.gz
tar xzf openssl-1.1.1d.tar.gz
pushd nginx-1.16.1
./configure --prefix=/usr/local/nginx --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.pid --lock-path=/var/run/nginx.lock --user=www --group=www --with-http_stub_status_module --with-http_v2_module --with-http_ssl_module --with-http_gzip_static_module --with-http_realip_module --with-http_flv_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_gunzip_module --with-http_random_index_module --with-http_secure_link_module --with-http_auth_request_module --with-http_mp4_module --with-openssl=../openssl-1.1.1d --with-pcre=../pcre-8.43 --with-pcre-jit
##注意只需make无需make install
make
升级
##查看原来nginx二进制文件的位置
##我的位置在/usr/sbin/nginx中
whereis nginx
##备份原来的nginx二进制文件
mv /usr/sbin/nginx /usr/sbin/nginx.old
##make编译后的nginx二进制在objs目录下
cp objs/nginx /usr/sbin/nginx
##查看nginx是否成功替换
nginx -V
##查看nginx配置是否正确(如果不正确,请按照提示修改)
nginx -t
迁移
##找到nginx的master进程,发送USR2信号
###向主进程(master)发送USR2信号,Nginx会启动一个新版本的master进程和对应工作进程,和旧版一起处理请求
ps aux | grep nginx | grep master| grep -v grep
###以下为输出进程
root 994 0.0 0.0 59620 3748 ? Ss 7月06 0:00 nginx: master process /usr/sbin/nginx
###发送USR2
kill -USR2 994
##向nginx的master进程发送WINCH信号
###向旧的Nginx主进程(master)发送WINCH信号,它会逐步关闭自己的工作进程(主进程不退出),这时所有请求都会由新版Nginx处理
kill -WINCH 994
验证 nginx 版本号,并访问测试
curl -I http://127.0.0.1
HTTP/1.1 301 Moved Permanently
Server: nginx/1.16.1
Date: Tue, 22 Oct 2019 04:13:19 GMT
Content-Type: text/html
Content-Length: 169
Connection: keep-alive
Location: https://127.0.0.1/