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 $dir = '';
private $extension = '.php';
private $extension = array ('.php');
private $flagBase64 = false;
private $flagChecksum = false;
private $flagComments = false;
@@ -188,7 +188,7 @@ class MalwareScanner
)
);
//Help Option should be first
//Help Option should be first
if (isset($options['help']) || isset($options['h'])) {
$this->showHelp();
exit;
@@ -199,11 +199,17 @@ class MalwareScanner
$this->dir = isset($options['directory']) ? $options['directory'] : $options['d'];
}
if (isset($options['extension']) || isset($options['e'])) {
$ext = isset($options['extension']) ? $options['extension'] : $options['e'];
if ($ext[0] != '.') {
$ext = '.' . $ext;
$a = isset($options['extension']) ? $options['extension'] : $options['e'];
if (!is_array($a)) {
$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'])) {
$tmp = isset($options['ignore']) ? $options['ignore'] : $options['i'];
@@ -371,7 +377,7 @@ class MalwareScanner
$this->process($dir . $file . '/');
} elseif (is_file($dir . $file)) {
$ext = strtolower(substr($file, strrpos($file, '.')));
if ($ext == $this->extension) {
if (in_array($ext, $this->extension)) {
$this->scan($dir . $file);
}
}
@@ -507,7 +513,7 @@ class MalwareScanner
echo 'Usage: php scan.php -d <directory>' . PHP_EOL;
echo ' -h --help Show this help message' . 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 ' -a --all-output Enables --checksum,--comment,--pattern,--time' . PHP_EOL;
echo ' -b --base64 Scan for base64 encoded PHP keywords' . PHP_EOL;