From 5675fb8e79d1e6d6f35194e9a96f83b1debff979 Mon Sep 17 00:00:00 2001 From: Gabor Gyorvari Date: Tue, 27 Dec 2016 17:51:39 +0100 Subject: [PATCH] New arguments to follow symlinked directories, default is not to follow --- README.md | 3 ++- scan.php | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 7d1aef1..d8ff30d 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,8 @@ Usage scan.php -d [-e=.php] [--hide-ok] [--hide-whitelist] -e=.php Extension --hide-ok Hide OK aka not infected messages --hide-whitelist Hide whitelisted messages - --extra-check Adds GoogleBot and htaccess to Scan List. + --extra-check Adds GoogleBot and htaccess to Scan List + --follow-symlink Follow symlinked directories ``` Whitelisting diff --git a/scan.php b/scan.php index 8caee62..354fede 100644 --- a/scan.php +++ b/scan.php @@ -26,17 +26,18 @@ class MalwareScanner private $extension = '.php'; private $flagHideOk = false; private $flagHideWhitelist = false; - private $ExtraCheck = false; + private $extraCheck = false; private $whitelist = array(); private $stat = array( 'directories' => 0, 'files_scanned' => 0, 'files_infected' => 0, ); + private $followSymlink = false; public function __construct() { - $options = getopt('hd:e::', array('hide-ok', 'hide-whitelist', 'extra-check')); + $options = getopt('hd:e::', array('hide-ok', 'hide-whitelist', 'extra-check', 'follow-symlink')); if (isset($options['h'])) { $this->showHelp(); } else { @@ -54,7 +55,10 @@ class MalwareScanner $this->flagHideWhitelist = true; } if (isset($options['extra-check'])) { - $this->ExtraCheck = true; + $this->extraCheck = true; + } + if (isset($options['follow-symlink'])) { + $this->followSymlink = true; } if (isset($options['d'])) { $this->run($options['d']); @@ -106,6 +110,9 @@ class MalwareScanner if ($file == '.' || $file == '..') { continue; } + if (!$this->followSymlink && is_link($dir . $file)) { + continue; + } if (is_dir($dir . $file)) { $this->process($dir . $file . '/'); } elseif (is_file($dir . $file)) { @@ -300,7 +307,7 @@ class MalwareScanner 'C0derz.com', 'Mr.HiTman', ); - if ($this->ExtraCheck) { + if ($this->extraCheck) { array_push($patterns, "googleBot", "htaccess"); } foreach ($patterns as $toSearch) { @@ -389,7 +396,8 @@ class MalwareScanner echo ' -e=.php Extension' . PHP_EOL; echo ' --hide-ok Hide OK aka not infected messages' . PHP_EOL; echo ' --hide-whitelist Hide whitelisted messages' . PHP_EOL; - echo ' --extra-check Adds GoogleBot and htaccess to Scan List.' . PHP_EOL; + echo ' --extra-check Adds GoogleBot and htaccess to Scan List' . PHP_EOL; + echo ' --follow-symlink Follow symlinked directories' . PHP_EOL; } }