Heim  >  Artikel  >  Backend-Entwicklung  >  php substr_replace替换指定位置字符与内存破坏漏洞_PHP教程

php substr_replace替换指定位置字符与内存破坏漏洞_PHP教程

WBOY
WBOYOriginal
2016-07-20 11:02:251321Durchsuche

 

php教程 substr_replace替换指定位置字符与内存破坏漏洞

提示和注释
注释:如果 start 是负数且 length 小于等于 start,则 length 为 0。

$username = "zongzi"; 
echo substr_replace($username,'**','1','2');

定义和用法
substr_replace() 函数把字符串的一部分替换为另一个字符串。

语法
substr_replace(string,replacement,start,length)参数 描述
string 必需。规定要检查的字符串。
replacement 必需。规定要插入的字符串。
start 必需。规定在字符串的何处开始替换。

正数 - 在第 start 个偏移量开始替换
负数 - 在从字符串结尾的第 start 个偏移量开始替换
0 - 在字符串中的第一个字符处开始替换
 
charlist 可选。规定要替换多少个字符。

正数 - 被替换的字符串长度
负数 - 从字符串末端开始的被替换字符数
0 - 插入而非替换
 
功能同 php的substr_replace()

'参数:被替换的内容,替换内容,起始位,替换长度

function substr_replace(sourcecon,repcon,startx,lenx)
   dim reped
   reped = mid(sourcecon,startx,lenx) '取出原内容同样长度
   dim scleftx,scleft
   scleftx = startx-1
   if scleftx     scleft = ""
   else
    scleft = left(sourcecon,scleftx)
   end if
   substr_replace = replace(sourcecon,reped,repcon,startx,1)
   substr_replace = scleft&substr_replace
end function

()中断内存破坏漏洞
bugraq id:
cve id:cve-2010-2190
cncve id:cncve-20102190
 
漏洞发布时间:2010-05-31
漏洞更新时间:2010-06-28
 
漏洞起因
设计错误
危险等级

 
影响系统
php 5.2 php 5.3  
不受影响系统
 
危害
远程攻击者可以利用漏洞泄漏敏感信息。
 
攻击所需条件
攻击者必须访问使用substr_replace()函数的应用程序。
 
漏洞信息
php是一款流行的网络编程语言。
php的substr_replace()函数存在信息泄漏问题:

php_function(substr_replace)
{
    ...
    if (zend_parse_parameters(zend_num_args() tsrmls_cc, "zzz|z", &str, &repl, &from, &len) == failure) {
        return;
    }
   
    if (z_type_pp(str) != is_array) {
        convert_to_string_ex(str);
    }
    if (z_type_pp(repl) != is_array) {
        convert_to_string_ex(repl);
    }
    if (z_type_pp(from) != is_array) {
        convert_to_long_ex(from);
    }
    if (argc > 3) {
        separate_zval(len);
        if (z_type_pp(len) != is_array) {
            convert_to_long_ex(len);
            l = z_lval_pp(len);
        }
    } else {
        if (z_type_pp(str) != is_array) {
            l = z_strlen_pp(str);
        }
    }
    if (z_type_pp(str) == is_string) {
        if (
            (argc == 3 && z_type_pp(from) == is_array) ||
            (argc == 4 && z_type_pp(from) != z_type_pp(len))
        ) {
            php_error_docref(null tsrmls_cc, e_warning, "'from' and 'len' should be of same type - numerical or array ");
            return_stringl(z_strval_pp(str), z_strlen_pp(str), 1);     
        }

使用不同类型的‘from’和'len'参数调用substr_replace()函数,会触发e_warning错误。如果php没有删除调用时通过引用传递功能,用户空间错误处理器会使用这个中断更改'str'参数类型。如果'str'类型更改为整数类型可导致泄漏任意内存,如果'str'更改为数组,允许泄漏使用重要内存偏移的哈希表。


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/445368.htmlTechArticlephp教程 substr_replace替换指定位置字符与内存破坏漏洞 提示和注释 注释:如果 start 是负数且 length 小于等于 start,则 length 为 0。 $username =...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn