|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-01-31 13:22 UTC] ludovit at scholtz dot sk
Description:
------------
There is a serious bug in all versions of php.
When webmaster use input variables in directories functions, like is_file, include, ... , hacker could include his own file in system.
For example.
Someone do logs in files. Hacker is able to put in logs something like <? phpinfo();?>. He know the path.
let say /data/log.txt
Then there is /index.php file, which contains
<?
// if magic quotes are on
foreach($_REQUEST as $k=>$v) $_REQUEST[$k] = stripslashes($v);
if(is_file("my_lang_dir/".$_REQUEST["x"].".txt")
include "my_lang_dir/".$_REQUEST["x"].".txt";
?>
...
Problem is when attacker use ?x=../data/log.txt%00&
function stripslashes makes from %00 chr(0)
then in is_file() fc goes my_lang_dir/../data/log.txt\0.txt
and most probably functions in os sees only my_lang_dir/../data/log.txt and zero, as terminating char.
i think this should return false, but it return true, and continue.....
I found this error while i was testing one server, and with this i have gained access to remote server.
Reproduce code:
---------------
?x=../data/log.txt%00&
<?
// if magic quotes are on
foreach($_REQUEST as $k=>$v) $_REQUEST[$k] = stripslashes($v);
if(is_file("my_lang_dir/".$_REQUEST["x"].".txt")
include "my_lang_dir/".$_REQUEST["x"].".txt";
?>
Expected result:
----------------
it should not include anything
Actual result:
--------------
it includes log file
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Dec 14 08:00:01 2025 UTC |
if this isnt bug, then i dont know what else should be. if someone can gain full access to server because of error in php, i dont know.. i messed () in line if(is_file("my_lang_dir/".$_REQUEST["x"].".txt") it should look like if(is_file("my_lang_dir/".$_REQUEST["x"].".txt"))maybe it should be better example.. ?x=../data/log.txt%00& <? // if magic quotes are on foreach($_REQUEST as $k=>$v) $_REQUEST[$k] = stripslashes($v); if(is_file("my_lang_dir/".$_REQUEST["x"].".template")) include "my_lang_dir/".$_REQUEST["x"].".template"; ?>I think this is bug. if some programmer would write this code: <? foreach($_REQUEST as $k=>$v) $_REQUEST[$k] = stripslashes($v); echo $file = "my_lang_dir/".$_REQUEST["x"].".template"; if(is_file($file)){ echo file_get_contents($file); } ?> ok. lets say we have this code. proggramer want to read .template file. he think that there is NO chance to open any other file than .template. This is mistake of php, that it allows attacker to read forexample .php file. if you save your mysql conf in file conf.php, and attacker would run ?x=../conf.php%00, then he would read configuration for mysql, reveal password, and it is not good. if someone dont use file_get_contents, but include, it will execute php code in that file. if attacker can write into any file on accesible path, he can corrupt whole system. I think this is critical bug. Solutions to patch this bugs are> to strip zero chars from string (before processiong to c), or throw some error.. or to do something, but definitly no to include file "mydir/file.php" instead of "mydir/file.php\0.template" I used this bug while i tested one serious server. It is not fault of programmer of system, but bug in php!!! Ludovit Scholtz