mirror of
https://github.com/scr34m/php-malware-scanner.git
synced 2026-06-16 12:30:35 +00:00
Verbose Bug fix and pattern loading optimization
Verbose flag was not proceeding with the next scan due to !found being set. Added a check to see if it is verbose when it decides to do the next scan. Patterns should be loaded once and only once. The files aren't large so not a problem with memory, however it might impact performance if we are loading the same 3 files ever time we scan a file.
This commit is contained in:
23
scan.php
23
scan.php
@@ -38,6 +38,10 @@ class MalwareScanner
|
||||
);
|
||||
private $followSymlink = false;
|
||||
|
||||
private $patterns_raw = array();
|
||||
private $patterns_iraw = array();
|
||||
private $patterns_re = array();
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$options = getopt('he:i:kwxd:lv', array('help', 'extension:', 'ignore:', 'hide-ok', 'hide-whitelist', 'extra-check', 'directory:', 'follow-symlink', 'verbose'));
|
||||
@@ -170,11 +174,14 @@ class MalwareScanner
|
||||
$found = false;
|
||||
$hash = '';
|
||||
$toSearch = '';
|
||||
$patterns = $this->loadPatterns(dirname(__FILE__) . '/patterns_raw.txt');
|
||||
$this->patterns_raw = $this->loadPatterns(dirname(__FILE__) . '/patterns_raw.txt');
|
||||
$this->patterns_iraw = $this->loadPatterns(dirname(__FILE__) . '/patterns_iraw.txt');
|
||||
$this->patterns_re = $this->loadPatterns(dirname(__FILE__) . '/patterns_re.txt');
|
||||
|
||||
if ($this->extraCheck) {
|
||||
array_push($patterns, "googleBot", "htaccess");
|
||||
array_push($this->patterns_raw, "googleBot", "htaccess");
|
||||
}
|
||||
foreach ($patterns as $toSearch) {
|
||||
foreach ($this->patterns_raw as $toSearch) {
|
||||
if (!$toSearch) {
|
||||
continue;
|
||||
}
|
||||
@@ -193,9 +200,8 @@ class MalwareScanner
|
||||
}
|
||||
}
|
||||
|
||||
if (!$found) {
|
||||
$patterns = $this->loadPatterns(dirname(__FILE__) . '/patterns_iraw.txt');
|
||||
foreach ($patterns as $toSearch) {
|
||||
if (!$found || $this->verbose) {
|
||||
foreach ($this->patterns_iraw as $toSearch) {
|
||||
if (!$toSearch) {
|
||||
continue;
|
||||
}
|
||||
@@ -215,9 +221,8 @@ class MalwareScanner
|
||||
}
|
||||
}
|
||||
|
||||
if (!$found) {
|
||||
$patterns = $this->loadPatterns(dirname(__FILE__) . '/patterns_re.txt');
|
||||
foreach ($patterns as $toSearch) {
|
||||
if (!$found || $this->verbose) {
|
||||
foreach ($this->patterns_re as $toSearch) {
|
||||
if (!$toSearch) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user