Skip to content

Commit da86b22

Browse files
committed
Add filterFile() method
1 parent d3f7ec3 commit da86b22

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/AntiScanScanClub.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ class AntiScanScanClub
1313
*/
1414
private $filterRules = "filter_rules.json";
1515

16+
/**
17+
* @var string $filterFiles
18+
*/
19+
private $filterFiles = "filter_files.txt";
20+
1621
/**
1722
* @var string $defaultBlacklists
1823
*/
@@ -114,6 +119,39 @@ public function filterInput($data = [], $blocker = FALSE, $clientIp) {
114119
return FALSE;
115120
}
116121

122+
123+
/**
124+
* Prevention of access to credentials and/ important files/path
125+
* e.g: wp-admin.php, .git/, backups.tar.gz, www.sql (see many more at filter_files.txt)
126+
*
127+
* @param array $data the request data
128+
* @param bool $blocker add client IP to blacklists if trying to credentials and/ important files/path
129+
* @param $clientIp the visitor client IP
130+
* @return void/bool
131+
*
132+
* @throws \Symfony\Component\HttpKernel\Exception\HttpException
133+
*/
134+
public function filterFile($url = NULL, $blocker = FALSE, $clientIp) {
135+
$filterFiles = __DIR__ . "/" . $this->filterFiles;
136+
$getFile = @file_get_contents($filterFiles);
137+
138+
if ($getFile === FALSE) {
139+
throw new \Exception("Error Processing filter Files File!", TRUE);
140+
}
141+
142+
$objectFiles = file($filterFiles);
143+
144+
foreach ($objectFiles as $key => $value) {
145+
$file = trim($value);
146+
if (strpos($url, trim($file)) !== FALSE) {
147+
if ($blocker === TRUE) $this->addToBlacklisted($clientIp, "Trying to access " . $file);
148+
return abort($this->abort);
149+
}
150+
}
151+
152+
return FALSE;
153+
}
154+
117155
/**
118156
* Add client IP to blacklists rule
119157
*

0 commit comments

Comments
 (0)