RSS订阅
PHP程序员站--WWW.PHPERZ.COM  
网站地图
高级搜索
收藏本站

 当前位置:主页 >> PHP基础 >> 基础文章 >> 文章内容
PHP wordwrap()缓冲区溢出漏洞
[收藏此页[打印本页]   
来源:  作者:  发布时间:2007-12-10


 
 

 


受影响系统:
PHP PHP 5.1.2
PHP PHP 4.4.2
描述:
--------------------------------------------------------------------------------
CVE(CAN) ID: CVE-2006-1990,CVE-2006-1991 phperz.com

PHP是广泛使用的通用目的脚本语言,特别适合于Web开发,可嵌入到HTML中。

php程序员站

PHP的wordwrap()函数实现上存在漏洞,远程攻击者可能利用此漏洞对PHP执行堆溢出攻击,可能导致拒绝服务或执行任意指令。 phperz.com

由于错误的整数计算,如果向PHP的wordwrap()函数发送了超长字符串的话,就会触发堆溢出漏洞。在下文的[1]或[2]中,整数“alloced”是从用户输入字符串的长度计算出来的。如果设置了长字符串(大约1MB)的话在乘法操作时就会溢出产生小正整数,在[3]中使用进行内存分配。在[4]中用户输入拷贝到新分配的缓冲区“newtext”,而这个缓冲区过小,在memcpy()中会溢出。拷贝大小“current”会包含用户提供字符串“text”的长度。 phperz~com

php-4.4.2/ext/standard/string.c中的有漏洞代码:

phperz.com

--------------------------------------------------------
PHP_FUNCTION(wordwrap)
{
const char *text, *breakchar = "\n";
char *newtext;
int textlen, breakcharlen = 1, newtextlen, alloced, chk;
long current = 0, laststart = 0, lastspace = 0;
long linelength = 75;
zend_bool docut = 0;
...
if (linelength > 0) {
chk = (int)(textlen/linelength + 1);
[1] alloced = textlen + chk * breakcharlen + 1;
} else {
chk = textlen;
[2] alloced = textlen * (breakcharlen + 1) + 1;
}
if (alloced <= 0) {
RETURN_FALSE;
}
[3] newtext = emalloc(alloced); php程序员之家

...
if (laststart != current) {
[4] memcpy(newtext+newtextlen, text+laststart, current-laststart);
newtextlen += current - laststart;
}
...
}
--------------------------------------------------------

php程序员站

如果memory_limit的值过高,还可能导致内存拒绝服务。

php程序员站

<*来源:Leon Juranic (ljuranic@LSS.hr) phperz~com

链接:http://secunia.com/advisories/19803/print/
http://www.infigo.hr/hr/in_focus/advisories/INFIGO-2006-04-02
http://docs.info.apple.com/article.html?artnum=304829
http://secunia.com/advisories/23155/
http://www.us-cert.gov/cas/techalerts/TA06-333A.html
http://security.gentoo.org/glsa/glsa-200605-08.xml
http://lwn.net/Alerts/184910
http://lwn.net/Alerts/191259/
ftp://patches.sgi.com/support/free/security/advisories/20060701-01-U.asc
*> www.phperz.com

测试方法:
-------------------------------------------------------------------------------- phperz.com

警 告 php程序员站

以下程序(方法)可能带有攻击性,仅供安全研究与教学之用。使用者风险自负!

www.phperz.com

$a = str_repeat ("A",438013);
$b = str_repeat ("B",951140);
wordwrap ($a,0,$b,0);
?> php程序员站

建议:
--------------------------------------------------------------------------------
厂商补丁: php程序员之家

PHP
---
目前厂商已经发布了升级补丁以修复这个安全问题,请到厂商的主页下载: phperz.com

http://www.php.net/downloads.php

www~phperz~com

RedHat
------
RedHat已经为此发布了安全公告(RHSA-2006:0501-02,RHSA-2006:0568-01)以及相应补丁:
RHSA-2006:0501-02:Moderate: php security update
链接:http://lwn.net/Alerts/184910

php程序员站

RHSA-2006:0568-01:Moderate: php security update
链接:http://lwn.net/Alerts/191259/ php程序员之家

SGI
---
SGI已经为此发布了一个安全公告(20060701-01-U)以及相应补丁:
20060701-01-U:SGI Advanced Linux Environment 3 Security Update #60
链接:ftp://patches.sgi.com/support/free/security/advisories/20060701-01-U.asc php程序员之家

Gentoo
------
Gentoo已经为此发布了一个安全公告(GLSA-200605-08)以及相应补丁:
GLSA-200605-08:PHP: Multiple vulnerabilities
链接:http://security.gentoo.org/glsa/glsa-200605-08.xml www~phperz~com

所有PHP用户都应升级到最新版本: php程序员站

# emerge --sync
# emerge --ask --oneshot --verbose dev-lang/php

php程序员站


 
 相关文章
 
发表评论
全部评论(0条)
 
 站内搜索
 热门搜索 基础  mysql  url  adodb
高级搜索 网站地图 站长工具 IP查询 收藏本站
 热点文章
 随机推荐
网站首页 | 网站地图 | 高级搜索 | RSS订阅
PHP程序员站 Copyright © 2007,PHPERZ.COM All Rights Reserved 粤ICP备07503606号 联系站长