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

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<1 then 
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

不受影响系统,危害,远程攻击者可以利用漏洞泄漏敏感信息.

攻击所需条件,攻击者必须访问使用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, "&#39;from&#39; and &#39;len&#39; 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'更改为数组,允许泄漏使用重要内存偏移的哈希表.

文章网址:

随意转载^^但请附上教程地址。

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor