mirror of
https://github.com/scr34m/php-malware-scanner.git
synced 2026-06-16 12:30:35 +00:00
Whitespace and Comment handling for pattern files
The pattern files are large and complex enough to justify some whitespace and comments to explain what each entry is. Added logic to check if the line is empty or if the first character is equal to '#' before using it as a pattern. Simply skips over empty and commented lines.
This commit is contained in:
12
scan.php
12
scan.php
@@ -167,6 +167,12 @@ class MalwareScanner
|
||||
array_push($patterns, "googleBot", "htaccess");
|
||||
}
|
||||
foreach ($patterns as $toSearch) {
|
||||
if (!$toSearch) {
|
||||
continue;
|
||||
}
|
||||
if ($toSearch[0] === '#') {
|
||||
continue;
|
||||
}
|
||||
$substrCount = substr_count($fileContent, $toSearch);
|
||||
if ($substrCount > 0) {
|
||||
$found = true;
|
||||
@@ -176,6 +182,12 @@ class MalwareScanner
|
||||
|
||||
if (!$found) {
|
||||
$patterns = $this->loadPatterns(dirname(__FILE__) . '/patterns_re.txt');
|
||||
if (!$toSearch) {
|
||||
continue;
|
||||
}
|
||||
if ($toSearch[0] === '#') {
|
||||
continue;
|
||||
}
|
||||
foreach ($patterns as $toSearch) {
|
||||
if (preg_match('/' . $toSearch . '/is', $fileContent)) {
|
||||
$found = true;
|
||||
|
||||
Reference in New Issue
Block a user