mirror of
https://github.com/scr34m/php-malware-scanner.git
synced 2026-06-16 12:30:35 +00:00
New flag to specify custom white list file
This commit is contained in:
@@ -36,6 +36,7 @@ Usage: php scan.php -d <directory>
|
||||
-o --output-format Custom defined output format
|
||||
-j --wordpress-version Version of wordpress to get md5 signatures
|
||||
--combined-whitelist Combined whitelist
|
||||
--custom-whitelist Loads whitelist from specified file and merge with existing
|
||||
--disable-stats Disable statistics output
|
||||
```
|
||||
|
||||
|
||||
39
scan.php
39
scan.php
@@ -42,6 +42,7 @@ class MalwareScanner
|
||||
private $flagScanEverything = false;
|
||||
private $flagCombinedWhitelist = false;
|
||||
private $flagDisableStats = false;
|
||||
private $customWhitelist = array();
|
||||
private $outputFormat = '';
|
||||
private $whitelist = array();
|
||||
private $ignore = array();
|
||||
@@ -191,16 +192,21 @@ class MalwareScanner
|
||||
return $list;
|
||||
}
|
||||
|
||||
//Loads the whitelist file
|
||||
public function loadWhitelist()
|
||||
/**
|
||||
* Loads the whitelist files
|
||||
*/
|
||||
public function loadWhitelists()
|
||||
{
|
||||
if (!is_file(__DIR__ . '/whitelist.txt')) {
|
||||
return;
|
||||
}
|
||||
$fp = fopen(__DIR__ . '/whitelist.txt', 'r');
|
||||
while (!feof($fp)) {
|
||||
$line = fgets($fp);
|
||||
$this->whitelist[] = substr($line, 0, 32);
|
||||
$a = array_merge([__DIR__ . '/whitelist.txt'], $this->customWhitelist);
|
||||
foreach ($a as $file) {
|
||||
if (is_file($file)) {
|
||||
$fp = fopen($file, 'r');
|
||||
while (!feof($fp)) {
|
||||
$line = fgets($fp);
|
||||
$this->whitelist[] = substr($line, 0, 32);
|
||||
}
|
||||
fclose($fp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -248,6 +254,7 @@ class MalwareScanner
|
||||
'wordpress-version:',
|
||||
'scan-everything',
|
||||
'combined-whitelist',
|
||||
'custom-whitelist:',
|
||||
'disable-stats'
|
||||
)
|
||||
);
|
||||
@@ -334,6 +341,13 @@ class MalwareScanner
|
||||
if (isset($options['combined-whitelist'])) {
|
||||
$this->setFlagCombinedWhitelist(true);
|
||||
}
|
||||
if (isset($options['custom-whitelist'])) {
|
||||
$a = $options['custom-whitelist'];
|
||||
if (!is_array($a)) {
|
||||
$a = array($a);
|
||||
}
|
||||
$this->setCustomWhitelist(array_unique($a));
|
||||
}
|
||||
if (isset($options['disable-stats'])) {
|
||||
$this->setFlagDisableStats(true);
|
||||
}
|
||||
@@ -435,6 +449,11 @@ class MalwareScanner
|
||||
$this->flagDisableStats = $b;
|
||||
}
|
||||
|
||||
public function setCustomWhitelist($a)
|
||||
{
|
||||
$this->customWhitelist = $a;
|
||||
}
|
||||
|
||||
// @see http://stackoverflow.com/a/13914119
|
||||
private function pathMatches($path, $pattern, $ignoreCase = false)
|
||||
{
|
||||
@@ -626,7 +645,7 @@ class MalwareScanner
|
||||
{
|
||||
$this->initializePatterns();
|
||||
|
||||
$this->loadWhitelist();
|
||||
$this->loadWhitelists();
|
||||
|
||||
if ($this->flagCombinedWhitelist && !$this->updateCombinedWhitelist()) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user