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