Allow multiple extension argument to be used

This commit is contained in:
Gabor Gyorvari
2018-03-02 18:44:51 +01:00
parent 99801506e7
commit ceb278bf6c

View File

@@ -26,7 +26,7 @@ class MalwareScanner
private $ANSI_OFF = "\033[0m"; private $ANSI_OFF = "\033[0m";
private $dir = ''; private $dir = '';
private $extension = '.php'; private $extension = array ('.php');
private $flagBase64 = false; private $flagBase64 = false;
private $flagChecksum = false; private $flagChecksum = false;
private $flagComments = false; private $flagComments = false;
@@ -199,11 +199,17 @@ class MalwareScanner
$this->dir = isset($options['directory']) ? $options['directory'] : $options['d']; $this->dir = isset($options['directory']) ? $options['directory'] : $options['d'];
} }
if (isset($options['extension']) || isset($options['e'])) { if (isset($options['extension']) || isset($options['e'])) {
$ext = isset($options['extension']) ? $options['extension'] : $options['e']; $a = isset($options['extension']) ? $options['extension'] : $options['e'];
if ($ext[0] != '.') { if (!is_array($a)) {
$ext = '.' . $ext; $a = array($a);
}
$this->extension = array();
foreach ($a as $ext) {
if ($ext[0] != '.') {
$ext = '.' . $ext;
}
$this->extension[] = strtolower($ext);
} }
$this->extension = strtolower($ext);
} }
if (isset($options['ignore']) || isset($options['i'])) { if (isset($options['ignore']) || isset($options['i'])) {
$tmp = isset($options['ignore']) ? $options['ignore'] : $options['i']; $tmp = isset($options['ignore']) ? $options['ignore'] : $options['i'];
@@ -371,7 +377,7 @@ class MalwareScanner
$this->process($dir . $file . '/'); $this->process($dir . $file . '/');
} elseif (is_file($dir . $file)) { } elseif (is_file($dir . $file)) {
$ext = strtolower(substr($file, strrpos($file, '.'))); $ext = strtolower(substr($file, strrpos($file, '.')));
if ($ext == $this->extension) { if (in_array($ext, $this->extension)) {
$this->scan($dir . $file); $this->scan($dir . $file);
} }
} }
@@ -507,7 +513,7 @@ class MalwareScanner
echo 'Usage: php scan.php -d <directory>' . PHP_EOL; echo 'Usage: php scan.php -d <directory>' . PHP_EOL;
echo ' -h --help Show this help message' . PHP_EOL; echo ' -h --help Show this help message' . PHP_EOL;
echo ' -d <directory> --directory Directory for searching' . PHP_EOL; echo ' -d <directory> --directory Directory for searching' . PHP_EOL;
echo ' -e <file extension> --extension File Extension to Scan' . PHP_EOL; echo ' -e <file extension> --extension File Extension to Scan, can be used multiple times' . PHP_EOL;
echo ' -i <directory|file> --ignore Directory of file to ignore' . PHP_EOL; echo ' -i <directory|file> --ignore Directory of file to ignore' . PHP_EOL;
echo ' -a --all-output Enables --checksum,--comment,--pattern,--time' . PHP_EOL; echo ' -a --all-output Enables --checksum,--comment,--pattern,--time' . PHP_EOL;
echo ' -b --base64 Scan for base64 encoded PHP keywords' . PHP_EOL; echo ' -b --base64 Scan for base64 encoded PHP keywords' . PHP_EOL;