Created
July 7, 2013 09:48
-
-
Save gsouf/5942960 to your computer and use it in GitHub Desktop.
Script that allows to check unix file system's security issues
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
echo "<pre>\n"; | |
if (ini_get('safe_mode')) { | |
echo "[safe_mode enabled]\n\n"; | |
} else { | |
echo "[safe_mode disabled]\n\n"; | |
} | |
if (isset($_GET['dir'])) { | |
ls($_GET['dir']); | |
} elseif (isset($_GET['file'])) { | |
cat($_GET['file']); | |
} else { | |
ls('/'); | |
} | |
echo "</pre>\n"; | |
function ls($dir) | |
{ | |
$handle = dir($dir); | |
while ($filename = $handle->read()) { | |
$size = filesize("$dir$filename"); | |
if (is_dir("$dir$filename")) { | |
if (is_readable("$dir$filename")) { | |
$line = str_pad($size, 15); | |
$line .= "<a href="{$_SERVER['PHP_SELF']}?dir=$dir$filename/">$filename/</a>"; | |
} else { | |
$line = str_pad($size, 15); | |
$line .= "$filename/"; | |
} | |
} else { | |
if (is_readable("$dir$filename")) { | |
$line = str_pad($size, 15); | |
$line .= "<a href="{$_SERVER['PHP_SELF']}?file=$dir$filename">$filename</a>"; | |
} else { | |
$line = str_pad($size, 15); | |
$line .= $filename; | |
} | |
} | |
echo "$line\n"; | |
} | |
$handle->close(); | |
} | |
function cat($file) | |
{ | |
$contents = file_get_content($file); | |
echo htmlentities($content, ENT_QUOTES, 'UTF-8'); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment