note 110138 added to security.filesystem
| From: | lehal2 at hotmail dot com | Date: | Sun, 23 Sep 2012 10:49:47 +0000 |
| Subject: | note 110138 added to security.filesystem | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-190972@lists.php.net to get a copy of this message | ||
function WhitePage($page) {
$info2 = apache_lookup_uri('src/index.php?p=' . $page);
list($arg, $val) = explode("=", $info2->args);
$myrequest = basename(htmlspecialchars_decode($val));
return $myrequest;
}
function Read_Dir($dir, $array = array()) {
$dh = opendir($dir);
$files = array();
while (($file = readdir($dh)) !== false) {
$flag = false;
if ($file !== '.' && $file !== '..' && !in_array($file,
$array)) {
$files[] = trim($file);
}
}
return $files;
}
function WhiteList($page = null) {
$info2 = apache_lookup_uri('src/index.php?p=' . $page);
list($arg, $val) = explode("=", $info2->args);
// basename from the std class
$myrequest = basename(htmlspecialchars_decode($val));
$myrequest = trim($myrequest . '.php');
//pathinfo from the std class
$path = pathinfo($info2->filename);
// get the files array
$whitefiles = Read_Dir($path['dirname']);
if (in_array($myrequest, $whitefiles, true)) {
$res = 1;
} else {
$res = 0;
}
return $res;
}
// this is solution of this kind of the problems
//$p='index.php?p=../../../../../../../../etc/passwd%00index.html';
$p = '../../../../../../../../etc/passwd%00index.html';
$p = WhitePage($p);
$result = WhiteList($p);
if ($result) {
echo 'ok';
} else {
echo 'hack attempt';
}
----
Server IP: 87.124.126.49
Probable Submitter: 2.122.145.189
----
Manual Page -- http://www.php.net/manual/en/security.filesystem.php
Edit -- https://master.php.net/note/edit/110138
Del: integrated -- https://master.php.net/note/delete/110138/integrated
Del: useless -- https://master.php.net/note/delete/110138/useless
Del: bad code -- https://master.php.net/note/delete/110138/bad+code
Del: spam -- https://master.php.net/note/delete/110138/spam
Del: non-english -- https://master.php.net/note/delete/110138/non-english
Del: in docs -- https://master.php.net/note/delete/110138/in+docs
Del: other reasons-- https://master.php.net/note/delete/110138
Reject -- https://master.php.net/note/reject/110138
Search -- https://master.php.net/manage/user-notes.php