http://cyberspark.net/webmasters
This is a standalone, not to be confused with the Cloudkick 'agent' plugin
version, which has some similar functionality.
/help
Describes what options are available.
/path
Reports the filesystem path to this script. Does nothing else.
/report
/report=n
Spiders the site and builds a baseline set of hashes or lengths. Does nothing active.
If "n" (a number) is present the site is spidered only to this maximum depth.
It's best to start with 1 or 2 so as not to overburden your server.
/report=n&base=xxxxxxx
Prepares a report using "xxxxxxx" as the base subdirectory and a depth of "n"
REPAIR CAPABILITIES ARE NOT PRESENT IN THIS SCRIPT.
Create a directory /cyberspark within the docroot of the web server
Make this directory world-writeable (chmod 777 or chmod a+rwx )
Within your Apache (or other) web server configuration, add:
\r\n";
$wrap = 1;
}
echo ".";
// try {
$depth++;
$dirContents = dir($baseDirectory);
// Run through this directory
while (($entry = $dirContents->read()) !== false) {
// Next entry in the directory
$thisEntry = $baseDirectory.$entry;
if ((strcmp('.',$entry)<>0) && (strcmp('..',$entry)<>0) && is_dir($thisEntry)) {
// Next entry is a directory, dive into it
spiderThis($thisEntry."/", $maxDepth);
}
else if (is_link($thisEntry)) {
// Skip 'link' (not directory, not file) avoids recursion
}
else if (is_file($thisEntry)) {
$stat = stat($thisEntry);
$totalFiles++;
// MD5: use this to record md5 hashes of files rather than lengths
// but this will be much more time-consuming than just looking at lengths.
// $filemd5s[] = md5_file($thisentry);
// Record file lengths
$fileSize = $stat['size'];
$results[$thisEntry] = $fileSize;
if ($status[$thisEntry] <> $fileSize) {
if ($status[$thisEntry] == 0) {
echo "
\nNew file: ".$status[$thisEntry]." -> [".$fileSize."] $thisEntry ";
$newFiles++;
}
else {
$len = strlen($thisEntry);
if(($len > 3) and !(strpos(strtolower($thisEntry), "log", $len-3) == ($len-3))) {
echo "
\nNew size: ".$status[$thisEntry]." -> [".$fileSize."] $thisEntry ";
$newSizes++;
}
}
}
// And scan PHP files for eval and gzinflate and base64
// try {
$len = strlen($thisEntry);
if(($len > 4) and (strpos(strtolower($thisEntry), ".php", $len-4) == ($len-4))) {
$thisFile = fopen($thisEntry,"r");
$thisContents = fread($thisFile, $maxFileSize);
fclose($thisFile);
$phpFiles++;
if (strlen($thisContents) > 0) {
if (strpos(strtolower($thisContents), "eval(") !== false) {
echo "
\nFound eval(): -> $thisEntry";
$newSuspect++;
}
else if (strpos(strtolower($thisContents), "gzinflate(") !== false) {
echo "
\nFound gzinflate(): -> $thisEntry ";
$newSuspect++;
}
else if (strpos(strtolower($thisContents), "base64_decode(") !== false) {
echo "
\nFound base64_decode(): -> $thisEntry ";
$newSuspect++;
}
}
}
// }
// catch (Exception $egbx) {
// }
// Remove from 'previous status' array. When we finish, anything left in
// this array will be a file that has disappeared.
unset($status[$thisEntry]);
}
// Otherwise ignore ("." and ".." for instance)
}
$depth--;
// }
// catch (Exception $x) {
// echo "
\r\nException: $x->getMessage()
\r\n";
// }
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// MAIN script - this is executed when the file is invoked by HTTP GET or HTTP PUT
// Get the filesystem path to this file (only the PATH) including an ending "/"
$path = substr(__FILE__,0,strrpos(__FILE__,'/')+1); // including the last "/"
// '/help' - - - - - - - - - - - -
if (isset($_GET['help'])) {
// /help
echo "\n
Produces a report on status of all PHP files. If 'n' (a number) is present the site is spidered only to this maximum depth. (Start by using 1 or 2 for the depth until you know how quickly your server can perform this task.)
Run several times to establish a baseline, then in the future you can watch for any significant changes.
If base=xxxxxxx is specified then the report starts at directory /xxxxxxx with respect to where the CyberSpark PHP is located
\n\n"; return; } // '/path' - - - - - - - - - - - - - if (isset($_GET['path'])) { // /path echo "\r\n\r\n
CyberSpark local agent report
Base directory is $fullPath
Spidering depth will be $maxDepth
Any changes reported below are 'since the last time this script was run.'
Do not stop this script or leave this page until it finishes.