Nginx range filter模块数字错误漏洞修复 (Nginx平滑升级)
对线上生产环境服务器进行漏洞扫描, 发现有两台前置机器存在Nginx range filter模块数字错误漏洞, 当使用nginx标准模块时,攻击者可以通过发送包含恶意构造range域的header 请求,来获取响应中的缓存文件头部信息。该漏洞存在于Nginx 1.13.3以下版本中, 只要Ningx开启了缓存功能, 攻击者即可发送恶意请求进行远程攻击造成信息泄露。也就是说当Nginx服务器使用代理缓存的情况下, 缓存文件头可能包含后端服务器的真实IP地址或其它敏感信息,攻击者就可以利用该漏洞拿到这些敏感信息,从而导致信息泄露。故此漏洞存在安全隐患, 需要尽快修复.
该漏洞修复方案一:
找到nginx的源码解压包, 在nginx的源码包中找到ngx_http_range_filter_module.c
[root@dtin ~]# cd /data/software/nginx-1.12.2
[root@dtin nginx-1.12.2]# vim ./src/http/modules/ngx_http_range_filter_module.c
.......
if (suffix) {
start = content_length - end;
end = content_length - 1;
}
....... 将上面ngx_http_range_filter_module.c源码文件中的"start = content_length - end;"改为“start = (end < content_length) ? content_length - end : 0;"
即改为:
[root@dtin nginx-1.12.2]# vim ./src/http/modules/ngx_http_range_filter_module.c
.......
if (suffix) {
start = (end < content_length) ? content_length - end : 0;
end = content_length - 1;
}
....... 接着重新编译nginx,并进行替换即可。
该漏洞修复方案一 (推荐这一种)
由于是生产环境, 线上业务不能停, 故需要进行Nginx平滑升级, 升级过程中服务不能中断. Nginx平滑升级原理如下介绍:
多进程模式下的请求分配方式
Nginx默认工作在多进程模式下,即主进程(master process)启动后完成配置加载和端口绑定等动作,fork出指定数量的工作进程(worker process),这些子进程会持有监听端口的文件描述符(fd),并通过在该描述符上添加监听事件来接受连接(accept)。
信号的接收和处理
Nginx主进程在启动完成后会进入等待状态,负责响应各类系统消息,如SIGCHLD、SIGHUP、SIGUSR2等。
Nginx信号
主进程支持的信号
- TERM, INT: 立刻退出
- QUIT: 等待工作进程结束后再退出
- KILL: 强制终止进程
- HUP: 重新加载配置文件,使用新的配置启动工作进程,并逐步关闭旧进程。
- USR1: 重新打开日志文件
- USR2: 启动新的主进程,实现热升级
- WINCH: 逐步关闭工作进程
工作进程支持的信号
- TERM, INT: 立刻退出
- QUIT: 等待请求处理结束后再退出
- USR1: 重新打开日志文件
=================nginx平滑升级操作记录====================
[app@web-node01 ~]# /data/nginx/sbin/nginx -v
nginx version: nginx/1.12.2 备份之前安装的nginx (其实主要备份的是sbin/nginx 和 conf配置目录, 这里我全部备份)
[app@web-node01 ~]# cp -r /data/nginx /data/nginx.old
[app@web-node01 ~]# ll /data/
total 0
drwxr-xr-x 10 app app 133 Sep 15 22:31 nginx
drwxr-xr-x 10 app app 133 Nov 15 15:21 nginx.old 下载nginx1.14.1的安装包, 解压并进行编译安装. 安装路径需与旧版一致
[app@web-node01 software]# ll nginx-1.14.1.tar.gz
-rw-rw-r-- 1 app app 1014040 Nov 15 11:04 nginx-1.14.1.tar.gz
[app@web-node01 software]# tar -zvxf nginx-1.14.1.tar.gz
[app@web-node01 software]# cd nginx-1.14.1/
[app@web-node01 nginx-1.14.1]# ./configure --prefix=/data/nginx --user=app --group=app --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream
[app@web-node01 nginx-1.14.1]# make && make install 发送USR2信号
向主进程发送USR2信号,Nginx会启动一个新版本的master进程和工作进程,和旧版一起处理请求
[app@web-node01 nginx-1.14.1]# ps -ef|grep nginx
app 1899 30168 0 15:25 pts/0 00:00:00 grep --color=auto nginx
app 19233 22333 0 Sep21 ? 00:00:00 nginx: worker process
app 19234 22333 0 Sep21 ? 00:00:00 nginx: worker process
app 19235 22333 0 Sep21 ? 00:00:00 nginx: worker process
app 19236 22333 0 Sep21 ? 00:00:01 nginx: worker process
app 19237 22333 0 Sep21 ? 00:00:00 nginx: worker process
app 19238 22333 0 Sep21 ? 00:00:01 nginx: worker process
app 19239 22333 0 Sep21 ? 00:00:05 nginx: worker process
app 19240 22333 0 Sep21 ? 00:00:01 nginx: worker process
app 19241 22333 0 Sep21 ? 00:00:27 nginx: cache manager process
root 22333 1 0 Sep15 ? 00:00:00 nginx: master process /data/nginx/sbin/nginx [app@web-node01 nginx-1.14.1]# kill -USR2 22333 [app@web-node01 nginx-1.14.1]# ps -ef|grep nginx
root 1911 22333 0 15:26 ? 00:00:00 nginx: master process /data/nginx/sbin/nginx
app 1912 1911 0 15:26 ? 00:00:00 nginx: worker process
app 1913 1911 0 15:26 ? 00:00:00 nginx: worker process
app 1914 1911 0 15:26 ? 00:00:00 nginx: worker process
app 1915 1911 0 15:26 ? 00:00:00 nginx: worker process
app 1916 1911 0 15:26 ? 00:00:00 nginx: worker process
app 1917 1911 0 15:26 ? 00:00:00 nginx: worker process
app 1918 1911 0 15:26 ? 00:00:00 nginx: worker process
app 1919 1911 0 15:26 ? 00:00:00 nginx: worker process
app 1920 1911 0 15:26 ? 00:00:00 nginx: cache manager process
app 1921 1911 0 15:26 ? 00:00:00 nginx: cache loader process
app 1923 30168 0 15:26 pts/0 00:00:00 grep --color=auto nginx
app 19233 22333 0 Sep21 ? 00:00:00 nginx: worker process
app 19234 22333 0 Sep21 ? 00:00:00 nginx: worker process
app 19235 22333 0 Sep21 ? 00:00:00 nginx: worker process
app 19236 22333 0 Sep21 ? 00:00:01 nginx: worker process
app 19237 22333 0 Sep21 ? 00:00:00 nginx: worker process
app 19238 22333 0 Sep21 ? 00:00:01 nginx: worker process
app 19239 22333 0 Sep21 ? 00:00:05 nginx: worker process
app 19240 22333 0 Sep21 ? 00:00:01 nginx: worker process
app 19241 22333 0 Sep21 ? 00:00:27 nginx: cache manager process
root 22333 1 0 Sep15 ? 00:00:00 nginx: master process /data/nginx/sbin/nginx 发送WITCH信号
向原Nginx主进程发送WINCH信号,它会逐步关闭其下的工作进程(主进程不退出),这时所有请求都会由新版Nginx处理.
[app@web-node01 nginx-1.14.1]# kill -WITCH 22333 //如果这个命令报错,则可以忽略, 在最后一步直接kill掉原来Nginx主进程的pid即可. 发送HUP信号 (特别注意: 这一步是回退, 如果不回退, 则直接忽略这一步即可)
如果这时需要回退,可向原Nginx主进程发送HUP信号,它会重新启动工作进程, 仍使用旧版配置文件 。
然后可以将新版Nginx进程杀死(使用QUIT、TERM、或者KILL)
[app@web-node01 nginx-1.14.1]# kill -HUP 22333 升级完毕
如果不需要回滚,可以将原Nginx主进程杀死(使用QUIT、TERM、或者KILL),至此完成热升级。 [app@web-node01 nginx-1.14.1]# ps -ef|grep nginx
root 1911 22333 0 15:26 ? 00:00:00 nginx: master process /data/nginx/sbin/nginx
app 1912 1911 0 15:26 ? 00:00:00 nginx: worker process
app 1913 1911 0 15:26 ? 00:00:00 nginx: worker process
app 1914 1911 0 15:26 ? 00:00:00 nginx: worker process
app 1915 1911 0 15:26 ? 00:00:00 nginx: worker process
app 1916 1911 0 15:26 ? 00:00:00 nginx: worker process
app 1917 1911 0 15:26 ? 00:00:00 nginx: worker process
app 1918 1911 0 15:26 ? 00:00:00 nginx: worker process
app 1919 1911 0 15:26 ? 00:00:00 nginx: worker process
app 1920 1911 0 15:26 ? 00:00:00 nginx: cache manager process
app 2394 30168 0 15:33 pts/0 00:00:00 grep --color=auto nginx
app 19233 22333 0 Sep21 ? 00:00:00 nginx: worker process
app 19234 22333 0 Sep21 ? 00:00:00 nginx: worker process
app 19235 22333 0 Sep21 ? 00:00:00 nginx: worker process
app 19236 22333 0 Sep21 ? 00:00:01 nginx: worker process
app 19237 22333 0 Sep21 ? 00:00:00 nginx: worker process
app 19238 22333 0 Sep21 ? 00:00:01 nginx: worker process
app 19239 22333 0 Sep21 ? 00:00:05 nginx: worker process
app 19240 22333 0 Sep21 ? 00:00:01 nginx: worker process
app 19241 22333 0 Sep21 ? 00:00:27 nginx: cache manager process
root 22333 1 0 Sep15 ? 00:00:00 nginx: master process /data/nginx/sbin/nginx [app@web-node01 nginx-1.14.1]# sudo kill -9 19233 19234 19235 19236 19237 19238 19239 19240 19241 22333 [app@web-node01 nginx-1.14.1]# ps -ef|grep nginx
root 1911 1 0 15:26 ? 00:00:00 nginx: master process /data/nginx/sbin/nginx
app 1912 1911 0 15:26 ? 00:00:00 nginx: worker process
app 1913 1911 0 15:26 ? 00:00:00 nginx: worker process
app 1914 1911 0 15:26 ? 00:00:00 nginx: worker process
app 1915 1911 0 15:26 ? 00:00:00 nginx: worker process
app 1916 1911 0 15:26 ? 00:00:00 nginx: worker process
app 1917 1911 0 15:26 ? 00:00:00 nginx: worker process
app 1918 1911 0 15:26 ? 00:00:00 nginx: worker process
app 1919 1911 0 15:26 ? 00:00:00 nginx: worker process
app 1920 1911 0 15:26 ? 00:00:00 nginx: cache manager process
app 2496 30168 0 15:35 pts/0 00:00:00 grep --color=auto nginx [app@web-node01 ~]# /data/nginx/sbin/nginx -v
nginx version: nginx/1.14.1
Nginx range filter模块数字错误漏洞修复 (Nginx平滑升级)的更多相关文章
- Nginx range filter模块数字错误漏洞修复 (Nginx平滑升级) 【转】
对线上生产环境服务器进行漏洞扫描, 发现有两台前置机器存在Nginx range filter模块数字错误漏洞, 当使用nginx标准模块时,攻击者可以通过发送包含恶意构造range域的header ...
- Linux kernel ‘lbs_debugfs_write’函数数字错误漏洞
漏洞名称: Linux kernel ‘lbs_debugfs_write’函数数字错误漏洞 CNNVD编号: CNNVD-201311-421 发布时间: 2013-11-29 更新时间: 2013 ...
- Linux kernel get_prng_bytes函数数字错误漏洞
漏洞名称: Linux kernel get_prng_bytes函数数字错误漏洞 CNNVD编号: CNNVD-201310-142 发布时间: 2013-10-11 更新时间: 2013-10-1 ...
- 高性能Web服务器Nginx的配置与部署研究(14)平滑升级你的Nginx
1.概述(可以直接跳过看第2部分) Nginx方便地帮助我们实现了平滑升级.其原理简单概括,就是: (1)在不停掉老进程的情况下,启动新进程. (2)老进程负责处理仍然没有处理完的请求,但不再接受处理 ...
- CVE-2013-2729 Adobe Reader和Acrobat 数字错误漏洞
这个洞是在论坛里看到的,感觉很有意思,来学习一下.个人感觉IE或者说是浏览器的洞和Adobe洞都是比较难调的,主要是有大量的类难以摸清之间的关系. 这个洞是一个整数溢出的洞,这个不是重点.重点是利用的 ...
- nginx gzip filter模块分析
API:http://refspecs.linuxbase.org/LSB_3.1.1/LSB-Core-generic/LSB-Core-generic/zlib-deflateinit2.html ...
- Web安全常见漏洞修复建议
转载地址:https://security.pingan.com/blog/17.html SQL注入 在服务器端要对所有的输入数据验证有效性. 在处理输入之前,验证所有客户端提供的数据,包括所有的参 ...
- nginx 增加 lua模块
Nginx中的stub_status模块主要用于查看Nginx的一些状态信息. 本模块默认是不会编译进Nginx的,如果你要使用该模块,则要在编译安装Nginx时指定: ./configure –wi ...
- PrestaShop 网站漏洞修复如何修复
PrestaShop网站的漏洞越来越多,该网站系统是很多外贸网站在使用的一个开源系统,从之前的1.0初始版本到现在的1.7版本,经历了多次的升级,系统使用的人也越来越多,国内使用该系统的外贸公司也很多 ...
随机推荐
- dropzone 上传插件
dropzone dropzone.js是一个可预览的上传文件工具,不依赖任何框架(如jQuery),且具有可定制化.实现文件拖拽上传,提供AJAX异步上传功能. 1. html文件 dropzone ...
- 17、文件IO详解及实例
上篇文章已经讲过了文件系统的一些基本的概念,这里首先对文件IO进行详细的学习,文件IO也称为系统调用IO,是操作系统为"用户态"运行的进程和硬件交互提供的一组接口,即操作系统内核留 ...
- js反选
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...
- Python自动化开发 - 流程控制
一.拾遗主题 1.变量 理解变量在计算机内存中的表示 >>> a = "ABC" Python解释器干了两件事情: 在内存中创建了一个'ABC'的字符串: 在内存 ...
- XML语法随记
1.特殊字符的转义 & ---- & < ---- < > ---- > " ---- " ' ----- &ap ...
- ECCV 2016 paper list
摘录ECCV2016部分文章,主要有Human pose esimation, Human activiity / actions, Face alignment, Face detection & ...
- Sql Server Report 导出到EXCEL 指定行高
在SQL SERVER REPORT 2005做报表的时候,发现在report中指定的行高没有用.google了一下,找到了解决方法. Make both CanGrow and CanShrink ...
- hangfire的使用
1.安装: hangfire包.StackExchange.Redis(abp下的hangfire则安装abp.hangfire) 2.配置 startup文件configuration方法添加以下代 ...
- kali linux 安装sublime text3完全教程
点击进入官网 下载页面 将鼠标放在64 bit(64位系统)上右击复制链接 打开终端: #wget 路径(粘贴刚复制的) #tar -xvvf 刚刚下载的文件文件名(解压) #mv 解压出来的文件名 ...
- Code Chef December Challenge 2018题解
传送门 \(MAXEP\) 二分,不过二分的时候要注意把\(mid\)设成\(\left\lfloor{9l+r\over 10}\right\rfloor\),这样往右的次数不会超过\(6\)次 / ...