Skip to content

Instantly share code, notes, and snippets.

@gsouf
Created July 7, 2013 09:48
Show Gist options
  • Save gsouf/5942960 to your computer and use it in GitHub Desktop.
Save gsouf/5942960 to your computer and use it in GitHub Desktop.
Script that allows to check unix file system's security issues
<?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