From 44aafb09726cc358a591e4d23033ff931eb81168 Mon Sep 17 00:00:00 2001 From: nichogenius Date: Fri, 18 Aug 2017 07:31:33 -0600 Subject: [PATCH] Cleaned up pattern whitespace and comment handling checking for comments and whitespace lines in pattern files should only be done once when the patterns are loaded. Added this code to the loadPatterns() function and removed it from the 3 scan loops. --- scan.php | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/scan.php b/scan.php index d54dbc4..044880a 100644 --- a/scan.php +++ b/scan.php @@ -164,6 +164,14 @@ class MalwareScanner $list = array(); if (is_readable($file)) { foreach (file($file) as $pattern) { + //Check if the line is only whitespace and skips. + if (strlen(trim($pattern)) == 0) { + continue; + } + //Check if first char in pattern is a '#' which indicates a comment and skips. + if ($pattern[0] === '#') { + continue; + } $list[] = trim($pattern); } } @@ -183,12 +191,6 @@ class MalwareScanner array_push($this->patterns_raw, "googleBot", "htaccess"); } foreach ($this->patterns_raw as $toSearch) { - if (!$toSearch) { - continue; - } - if ($toSearch[0] === '#') { - continue; - } if (strpos($fileContent, $toSearch) !== FALSE){ $found = true; if ($hash === ''){ @@ -203,12 +205,6 @@ class MalwareScanner if (!$found || $this->verbose) { foreach ($this->patterns_iraw as $toSearch) { - if (!$toSearch) { - continue; - } - if ($toSearch[0] === '#') { - continue; - } if (stripos($fileContent, $toSearch) !== FALSE){ $found = true; if ($hash === ''){ @@ -224,12 +220,6 @@ class MalwareScanner if (!$found || $this->verbose) { foreach ($this->patterns_re as $toSearch) { - if (!$toSearch) { - continue; - } - if ($toSearch[0] === '#') { - continue; - } if (preg_match('/' . $toSearch . '/im', $fileContent)) { $found = true; if ($hash === ''){