#49670 [NEW]: prefix bypass in file_get_contents

From: Date: Fri, 25 Sep 2009 18:42:08 +0000
Subject: #49670 [NEW]: prefix bypass in file_get_contents
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-142889@lists.php.net to get a copy of this message
From: david at majorsecurity dot info Operating system: Unix PHP version: 5.3.0 PHP Bug Type: *Directory/Filesystem functions Bug description: prefix bypass in file_get_contents Description: ------------ If you use a prefix (i.e myownprefix_ ) in your source code to make sure that only files containing this prefix can be opened, this can be bypassed within file_get_contents(). Let's say that you have placed 2 files in your htdocs folder: 1. /htdocs/david/myownprefix_home.php 2. /htdocs/david/home.php 3. /htdocs/bug.php Reproduce code: --------------- --- From manual page: function.file-get-contents --- Example code (bug.php): <?php if(isset($_GET['seite'])) { $seite = $_GET['seite']; $datei = nl2br(file_get_contents("./david/myownprefix_$seite.php")); echo $datei; } ?> Proof of concept: http://localhost/bug.php?seite=/../home Expected result: ---------------- Now this would open the file /htdocs/home.php and our defined prefix will be bypassed. -- Edit bug report at http://bugs.php.net/?id=49670&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=49670&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=49670&r=trysnapshot53 Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=49670&r=trysnapshot60 Fixed in SVN: http://bugs.php.net/fix.php?id=49670&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=49670&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=49670&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=49670&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=49670&r=needscript Try newer version: http://bugs.php.net/fix.php?id=49670&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=49670&r=support Expected behavior: http://bugs.php.net/fix.php?id=49670&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=49670&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=49670&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=49670&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=49670&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=49670&r=dst IIS Stability: http://bugs.php.net/fix.php?id=49670&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=49670&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=49670&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=49670&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=49670&r=mysqlcfg

« previous php.bugs (#142889) next »