Nginx HTTP/2和mp4模块拒绝服务预警

栏目: 服务器 · Nginx · 发布时间: 5年前

内容简介:报告编号:B6-2018-110901报告来源:360-CERT

Nginx HTTP/2和mp4模块拒绝服务预警

报告编号:B6-2018-110901

报告来源:360-CERT

报告作者:360-CERT

更新日期:2018-11-09

0x00 事件背景

Nginx 11月6日的安全更新中,修复了三个可导致拒绝服务的漏洞:CVE-2018-16843,CVE-2018-16844和CVE-2018-16845。位于nginx HTTP/2 模块和流媒体MP4模块。

CVE-2018-16843,CVE-2018-16844漏洞存在于ngx_http_v2模块之中,当用户添加http2支持时(默认不开启),攻击者可以发送特制的HTTP/2请求,消耗CPU和内存资源,最终导致DoS。

CVE-2018-16845漏洞存在于ngx_http_mp4_module模块中,当用户对Nginx添加MP4流媒体支持,恶意的MP4文件会导致处理进程无限循环、崩溃或者内存泄露。

0x01 影响范围

CVE-2018-16843,CVE-2018-16844影响版本:

  • Mainline version :1.9.5 - 1.15.5

CVE-2018-16845 影响版本:

  • Mainline version :1.1.3+, 1.0.7+

0x02 补丁分析

file:src/http/v2/ngx_http_v2.c src/http/v2/ngx_http_v2.h

--- a/src/http/v2/ngx_http_v2.c    Tue Nov 06 16:29:35 2018 +0300

+++ b/src/http/v2/ngx_http_v2.c    Tue Nov 06 16:29:49 2018 +0300

@@ -4481,12 +4481,19 @@

#endif

+    h2scf = ngx_http_get_module_srv_conf(h2c->http_connection->conf_ctx,

+                                         ngx_http_v2_module);

+

+    if (h2c->idle++ > 10 * h2scf->max_requests) {

+        ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,

+                      "http2 flood detected");

+        ngx_http_v2_finalize_connection(h2c, NGX_HTTP_V2_NO_ERROR);

+        return;

+    }

+

c->destroyed = 0;

ngx_reusable_connection(c, 0);

-    h2scf = ngx_http_get_module_srv_conf(h2c->http_connection->conf_ctx,

-                                         ngx_http_v2_module);

-

h2c->pool = ngx_create_pool(h2scf->pool_size, h2c->connection->log);

if (h2c->pool == NULL) {

ngx_http_v2_finalize_connection(h2c, NGX_HTTP_V2_INTERNAL_ERROR);

--- a/src/http/v2/ngx_http_v2.c    Tue Nov 06 16:29:18 2018 +0300
+++ b/src/http/v2/ngx_http_v2.c    Tue Nov 06 16:29:35 2018 +0300
@@ -664,6 +664,7 @@
     h2c->pool = NULL;
     h2c->free_frames = NULL;
+    h2c->frames = 0;
     h2c->free_fake_connections = NULL;
 #if (NGX_HTTP_SSL)
@@ -2895,7 +2896,7 @@
         frame->blocked = 0;
-    } else {
+    } else if (h2c->frames < 10000) {
         pool = h2c->pool ? h2c->pool : h2c->connection->pool;
         frame = ngx_pcalloc(pool, sizeof(ngx_http_v2_out_frame_t));
@@ -2919,6 +2920,15 @@
         frame->last = frame->first;
         frame->handler = ngx_http_v2_frame_handler;
+
+        h2c->frames++;
+
+    } else {
+        ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
+                      "http2 flood detected");
+
+        h2c->connection->error = 1;
+        return NULL;
     }
 #if (NGX_DEBUG)

为了修补CVE-2018-16843,CVE-2018-16844漏洞,新增了idle和frames变量统计请求数,每个子进程处理的请求数远大于配置的max_requests或者超出10000,将不进行处理。

CVE-2018-16845:

file:src/http/modules/ngx_http_mp4_module.c

--- src/http/modules/ngx_http_mp4_module.c

+++ src/http/modules/ngx_http_mp4_module.c

@@ -942,6 +942,13 @@ ngx_http_mp4_read_atom(ngx_http_mp4_file

atom_size = ngx_mp4_get_64value(atom_header + 8);

atom_header_size = sizeof(ngx_mp4_atom_header64_t);

+                if (atom_size < sizeof(ngx_mp4_atom_header64_t)) {

+                    ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,

+                                  "\"%s\" mp4 atom is too small:%uL",

+                                  mp4->file.name.data, atom_size);

+                    return NGX_ERROR;

+                }

+

} else {

ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,

"\"%s\" mp4 atom is too small:%uL",

MP4文件由若干称为Atom(或称为box)的数据对象组成,每个Atom的头部为四个字节的数据长度(Big Endian)和四个字节的类型标识,数据长度和类型标志都可以扩展。Atom可以嵌套,即其数据域可以由若干其它Atom组成,从而实现结构化的数据。为了修补CVE-2018-16845,在MP4模块中对文件的Atom头部结构进行检查,过滤掉恶意的MP4文件。

0x03 修复建议

关闭http/2请求处理和MP4流媒体支持,强烈建议将Nginx 升级至1.15.6,或1.14.1 stable 最新版本。

0x04 时间线

2018-11-06 Nginx 发布版本更新

2018-11-09 360CERT 发布预警公告

0x05 参考链接

  1. nginx security advisory (CVE-2018-16845)
  2. nginx security advisory (CVE-2018-16843, CVE-2018-16844)

声明:本文来自360CERT,版权归作者所有。文章内容仅代表作者独立观点,不代表安全内参立场,转载目的在于传递更多信息。如需转载,请联系原作者获取授权。


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

云经济学

云经济学

乔·韦曼 (Joe Weinman) / 人民邮电出版社 / 2014-7-1 / CNY 75.00

在云计算日益成熟的今天,“接入而非拥有”的理念不断为人们所理解和接受。 《云经济学》阐述了“云经济学”不是经济理论中深奥的数学模型,而是技术革命的生动概括。“灵活的云计算能够有效提升企业的商业价值”则是本书的核心理念。 《云经济学——企业云计算战略与布局》从商业、金融及经济的视角解释了云经济的潜在原理,并通过易于理解的案例阐述了云计算是如何创造出综合价值的。无论你是供应商、零售商、服务......一起来看看 《云经济学》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具