note 110139 added to security.filesystem

From: Date: Sun, 23 Sep 2012 10:49:49 +0000
Subject: note 110139 added to security.filesystem
Groups: php.notes 
Request: Send a blank email to php-notes+get-190973@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/110139 Del: integrated -- https://master.php.net/note/delete/110139/integrated Del: useless -- https://master.php.net/note/delete/110139/useless Del: bad code -- https://master.php.net/note/delete/110139/bad+code Del: spam -- https://master.php.net/note/delete/110139/spam Del: non-english -- https://master.php.net/note/delete/110139/non-english Del: in docs -- https://master.php.net/note/delete/110139/in+docs Del: other reasons-- https://master.php.net/note/delete/110139 Reject -- https://master.php.net/note/reject/110139 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#190973) next »