Skip to content

Instantly share code, notes, and snippets.

@MattSandy
Created February 9, 2019 19:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MattSandy/c58a55a007f3a33bc9212335ecf430d3 to your computer and use it in GitHub Desktop.
Save MattSandy/c58a55a007f3a33bc9212335ecf430d3 to your computer and use it in GitHub Desktop.
Scans the current directory and subdirectories for files which contain eval(), base64_decode(), or exec() references.
<?php
error_reporting(0);
if(isset($_GET['file'])) {
highlight_file(urldecode($_GET['file']));
die();
} else if(isset($_GET['del'])) {
unlink(urldecode($_GET['del']));
echo "file deleted";
die();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Potentially Bad File Scanner</title>
<style type="text/css">
body { font-size:12pt;background-color:#f6f6f6; }
span { color:red; }
a {color:#333;margin-bottom:4px;text-decoration: none;}
em {font-size:10pt; color:green; }
</style>
</head>
<body>
<?php
$directories = expandDirectories(dirname(__FILE__));
function expandDirectories($base_dir) {
$directories = array();
foreach(scandir($base_dir) as $file) {
if($file == '.' || $file == '..') continue;
$dir = $base_dir.DIRECTORY_SEPARATOR.$file;
if(is_dir($dir)) {
$directories []= $dir;
$directories = array_merge($directories, expandDirectories($dir));
}
}
return $directories;
}
//print_r($directories);
foreach($directories as $dir) {
$files = scandir($dir);
foreach($files as $file) {
if(substr($file,-4)==".php") {
$loc = $dir . '/' . $file;
if(strpos(file_get_contents($loc),"eval(") !== false) {
echo '<a href="scan.php?file=' .$loc . '">' . $loc . '</a>';
echo ' <em>' . intval((filesize($loc)/1024)) . 'kb</em> ';
echo ' <a href="scan.php?del=' .$loc . '"><span>[del]</span></a><br />';
} else if(strpos(file_get_contents($loc),"base64_decode(") !== false) {
echo '<a href="scan.php?file=' .$loc . '">' . $loc . '</a>';
echo ' <em>' . intval((filesize($loc)/1024)) . 'kb</em> ';
echo ' <a href="scan.php?del=' .$loc . '"><span>[del]</span></a><br />';
} else if(strpos(file_get_contents($dir . '/' . $file),"exec(") !== false) {
echo '<a href="scan.php?del=' . $dir . '/' . $file . '">' . $dir . '/' . $file . "</a><br>";
}
}
}
}?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment