#35960 [Bgs->Opn]: preg_replace exploit using 'e' (executor)
| From: | djmaze at cpgnuke dot com | Date: | Tue, 10 Jan 2006 11:31:15 +0000 |
| Subject: | #35960 [Bgs->Opn]: preg_replace exploit using 'e' (executor) | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-91727@lists.php.net to get a copy of this message | ||
ID: 35960
User updated by: djmaze at cpgnuke dot com
Reported By: djmaze at cpgnuke dot com
-Status: Bogus
+Status: Open
Bug Type: *Regular Expressions
Operating System: Windows
PHP Version: 5.1.1
New Comment:
If you preg_replace() submitted data thru $_GET or $_POST i can for
example put in $_GET something like: $_GET['input'] = '$foobar';
This means either update the documentation with an note stating that
using the 'e' modifier the function doesn't backslash $ or force it to
do so.
Because "echo $_GET['input'];" outputs $foobar
and the preg_replace() outputs the content of $foobar
Previous Comments:
------------------------------------------------------------------------
[2006-01-10 12:20:31] tony2001@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
echo $exploited; is much more easier way to output a variable.
------------------------------------------------------------------------
[2006-01-10 12:14:58] djmaze at cpgnuke dot com
Description:
------------
When using preg_replace() with the 'e' modifier you can exploit
variables since the $ sign doesn't get backslashed.
Tested on several PHP versions both 4.x and 5.x
Reproduce code:
---------------
<?php
error_reporting(E_ALL);
$exploited = 'my password';
$exploit = '[php]$exploited[/php]';
function highlight_php($txt)
{
return "<pre>$txt</pre>";
}
echo preg_replace('#\[PHP\](.*?)\[/PHP\]#sie', 'highlight_php("\\1")',
$exploit); # exploited
echo preg_replace('#\[PHP\](.*?)\[/PHP\]#sie',
'highlight_php(\'\\1\')', $exploit); # no exploit
?>
Expected result:
----------------
<pre>$exploited</pre>
Actual result:
--------------
<pre>my password</pre>
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=35960&edit=1