c++ - Nginx 有符号整数,CVE-2013-2028

标签 c++ security nginx

几年前,我刚刚看到这篇关于安全漏洞的分析文章,CVE-2013-2028,作者 vnsecurity .

但是,我对第一点很感兴趣,说这个错误本质上是由整数符号不匹配引起的。

It simply parses the chunked size input as hex and convert it to base of 10. And since ctx->size is defined with size_t, an unsigned type, the value of the variable can be misinterpreted as negative number when casting to signed type, as we will see later.

因为我对此很好奇,所以我去搜索“ctx”的struct,我遇到了这个:

struct ngx_http_chunked_s {
ngx_uint_t           state;
off_t                size;
off_t                length;
};

据我所知,ctx->size不是size_t而是off_t,它是一个有符号整数。那么,请问我是不是理解错了,还是措辞有误。

可以在这个 repo 中找到较旧的 nginx 版本.

提前致谢!

最佳答案

通过快速阅读,我认为作者对 ngx_http_read_discarded_request_body 有点困惑。的本地sizectx->size .

输入的路径是:

  1. ngx_http_parse_chunked:2011 : ctx->size是一个带符号的输入。
  2. ngx_http_parse_chunked:2183 : 签名ctx->length根据 ctx->size 设置.
  3. ngx_http_discard_request_body_filter:735 : 签名r->headers_in.content_length_n设置为 ctx->length .
  4. ngx_http_read_discarded_request_body:649 : r->headers_in.content_length_n将转换为 size_t并分配给size (如果 content_length_n < NGX_HTTP_DISCARD_BUFFER_SIZE ,如果 0 > content_length_n 则始终为真)。
  5. ngx_http_read_discarded_request_body:652 : r->connection->recv被称为 size作为要读取的字节数。
  6. ngx_http_read_discarded_request_body : size > sizeof (buffer) (NGX_HTTP_DISCARD_BUFFER_SIZE)。因此,会出现栈溢出。

我希望这是可以理解的。

关于c++ - Nginx 有符号整数,CVE-2013-2028,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39342233/

相关文章:

windows - 您会推荐哪些资源来学习操作系统安全性?

docker - 无法通过 docker-letsencrypt-nginx-proxy-companion 启用 ssl

linux - nginx 中是否有某种解压缩模块?

ubuntu - init.d 脚本不会在重新启动时启动,但可以从命令行运行

c++ - 哪个库用于体素数据结构?

c++ - 将通用堆栈容器实现为适配器类模板

c++ - 使用静态库编译错误可执行文件

javascript - Javascript 中的随机函数被认为是不安全的。真的有关系吗?

c++ - 使用 -D_GLIBCXX_USE_CXX11_ABI=0 构建 boost

c# - 页面方法和安全