@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
package/src/php/Utils/Env.php
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
<?php
|
|
2
|
-
|
|
3
|
-
declare(strict_types=1);
|
|
4
|
-
|
|
5
|
-
namespace Anonympins\Fingerprint\Utils;
|
|
6
|
-
|
|
7
|
-
class Env
|
|
8
|
-
{
|
|
9
|
-
/** @var array<string, mixed> */
|
|
10
|
-
private static array $localCache = [];
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* @param string $key
|
|
14
|
-
* @param mixed $default
|
|
15
|
-
* @return mixed
|
|
16
|
-
*/
|
|
17
|
-
public static function get(string $key, $default = null)
|
|
18
|
-
{
|
|
19
|
-
if (array_key_exists($key, self::$localCache)) {
|
|
20
|
-
return self::$localCache[$key];
|
|
21
|
-
}
|
|
22
|
-
if (isset($_ENV[$key]) && $_ENV[$key] !== '') {
|
|
23
|
-
return $_ENV[$key];
|
|
24
|
-
}
|
|
25
|
-
if (isset($_SERVER[$key]) && $_SERVER[$key] !== '') {
|
|
26
|
-
return $_SERVER[$key];
|
|
27
|
-
}
|
|
28
|
-
$val = getenv($key);
|
|
29
|
-
if ($val !== false && $val !== '') {
|
|
30
|
-
return $val;
|
|
31
|
-
}
|
|
32
|
-
return $default;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
public static function set(string $key, $value): void
|
|
36
|
-
{
|
|
37
|
-
self::$localCache[$key] = $value;
|
|
38
|
-
$_ENV[$key] = $value;
|
|
39
|
-
$_SERVER[$key] = $value;
|
|
40
|
-
@putenv("{$key}={$value}");
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
public static function clear(string $key): void
|
|
44
|
-
{
|
|
45
|
-
unset(self::$localCache[$key]);
|
|
46
|
-
unset($_ENV[$key]);
|
|
47
|
-
unset($_SERVER[$key]);
|
|
48
|
-
@putenv($key);
|
|
49
|
-
}
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
declare(strict_types=1);
|
|
4
|
+
|
|
5
|
+
namespace Anonympins\Fingerprint\Utils;
|
|
6
|
+
|
|
7
|
+
class Env
|
|
8
|
+
{
|
|
9
|
+
/** @var array<string, mixed> */
|
|
10
|
+
private static array $localCache = [];
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @param string $key
|
|
14
|
+
* @param mixed $default
|
|
15
|
+
* @return mixed
|
|
16
|
+
*/
|
|
17
|
+
public static function get(string $key, $default = null)
|
|
18
|
+
{
|
|
19
|
+
if (array_key_exists($key, self::$localCache)) {
|
|
20
|
+
return self::$localCache[$key];
|
|
21
|
+
}
|
|
22
|
+
if (isset($_ENV[$key]) && $_ENV[$key] !== '') {
|
|
23
|
+
return $_ENV[$key];
|
|
24
|
+
}
|
|
25
|
+
if (isset($_SERVER[$key]) && $_SERVER[$key] !== '') {
|
|
26
|
+
return $_SERVER[$key];
|
|
27
|
+
}
|
|
28
|
+
$val = getenv($key);
|
|
29
|
+
if ($val !== false && $val !== '') {
|
|
30
|
+
return $val;
|
|
31
|
+
}
|
|
32
|
+
return $default;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public static function set(string $key, $value): void
|
|
36
|
+
{
|
|
37
|
+
self::$localCache[$key] = $value;
|
|
38
|
+
$_ENV[$key] = $value;
|
|
39
|
+
$_SERVER[$key] = $value;
|
|
40
|
+
@putenv("{$key}={$value}");
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public static function clear(string $key): void
|
|
44
|
+
{
|
|
45
|
+
unset(self::$localCache[$key]);
|
|
46
|
+
unset($_ENV[$key]);
|
|
47
|
+
unset($_SERVER[$key]);
|
|
48
|
+
@putenv($key);
|
|
49
|
+
}
|
|
50
50
|
}
|
|
@@ -1,75 +1,75 @@
|
|
|
1
|
-
<?php
|
|
2
|
-
|
|
3
|
-
declare(strict_types=1);
|
|
4
|
-
|
|
5
|
-
namespace Anonympins\Fingerprint\Utils;
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Fournit des fonctions pour détecter les patterns d'injection malveillants.
|
|
9
|
-
*/
|
|
10
|
-
class MaliciousPatterns
|
|
11
|
-
{
|
|
12
|
-
/**
|
|
13
|
-
* @var array<string, string> Map des patterns malveillants regroupés par type.
|
|
14
|
-
*/
|
|
15
|
-
private const INJECTION_PATTERNS = [
|
|
16
|
-
// SQL/NoSQL injections, including time-based attacks
|
|
17
|
-
'sql' => '/(\$ne|\' *OR *\'1\'=\'1|[\'";]\s*--|; ?(DROP|TRUNCATE|DELETE)|UNION SELECT|(?:SLEEP|BENCHMARK)\s*\(|WAITFOR DELAY)/i',
|
|
18
|
-
// Log4Shell (JNDI injection)
|
|
19
|
-
'log4shell' => '/\$\{jndi:(ldap|rmi|dns):/i',
|
|
20
|
-
// Server-Side Template Injection (SSTI) for engines like Jinja2, Twig, etc.
|
|
21
|
-
'ssti' => '/\{\{.*\}\}|\{%.*%\}/',
|
|
22
|
-
// XML External Entity (XXE) injection
|
|
23
|
-
'xxe' => '/<!ENTITY\s+.*SYSTEM/i',
|
|
24
|
-
// Path Traversal
|
|
25
|
-
'traversal' => '/(\.\.\/|\.\.)/',
|
|
26
|
-
// Remote Command Execution (RCE)
|
|
27
|
-
// The original regex had an issue with `|cmd` being interpreted as a modifier in some PCRE versions.
|
|
28
|
-
// Using a non-capturing group (?:...) makes it more robust and fixes the compilation error.
|
|
29
|
-
'rce' => '/`.*`|(?:^|[\n;&|]\s*)(?:ping|ls|whoami|cat|rm|ncat|nc|bash|sh|powershell|cmd)\b/i',
|
|
30
|
-
// Server-Side Request Forgery (SSRF)
|
|
31
|
-
'ssrf' => '/(?:https?:\/\/)?(?:127\.\d+\.\d+\.\d+|169\.254\.169\.254|10\.\d+\.\d+\.\d+|172\.(?:1[6-9]|2\d|3[01])\.\d+\.\d+|192\.168\.\d+\.\d+|localhost|0\.0\.0\.0|\[[0:]+1\])\b/i',
|
|
32
|
-
// Carriage Return Line Feed (CRLF) Injection
|
|
33
|
-
'crlf' => '/[\r\n]|%0[ad]/i',
|
|
34
|
-
// Cross-Site Scripting (XSS)
|
|
35
|
-
'xss' => '/(<script|javascript:|on\w+\s*=|alert\s*\(|confirm\s*\(|prompt\s*\(|<img\s+src[^>]+onerror|<iframe)/i',
|
|
36
|
-
// Open Redirect
|
|
37
|
-
'openRedirect' => '/^(https?:)?\/\/(?![^\/]*?(localhost|127\.0\.0\.1))[^\s\/]+/i',
|
|
38
|
-
// Local/Remote File Inclusion (LFI/RFI)
|
|
39
|
-
'lfi' => '/(?:etc\/passwd|win\.ini|boot\.ini|php:\/\/filter|data:\/\/|zip:\/\/)/i',
|
|
40
|
-
// Shellshock (CVE-2014-6271)
|
|
41
|
-
'shellshock' => '/\(\)\s*\{\s*:\s*;\s*\}\s*/i',
|
|
42
|
-
// NoSQL Injection (MongoDB query operators)
|
|
43
|
-
'nosql' => '/\$(?:eq|ne|gt|gte|lt|lte|in|nin|and|or|nor|not|expr|jsonSchema|mod|regex|text|where|elemMatch)/i',
|
|
44
|
-
];
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Vérifie si une chaîne de caractères contient des patterns d'injection connus.
|
|
48
|
-
* @param string $str La chaîne à vérifier.
|
|
49
|
-
* @param array<string> $typesToDetect Les types d'injections à détecter (par défaut, tous).
|
|
50
|
-
* @return bool True si un pattern malveillant est détecté, false sinon.
|
|
51
|
-
*/
|
|
52
|
-
public static function isMalicious(string $str, array $typesToDetect = []): bool
|
|
53
|
-
{
|
|
54
|
-
if (empty($typesToDetect)) {
|
|
55
|
-
$typesToDetect = array_filter(array_keys(self::INJECTION_PATTERNS), function ($key) {
|
|
56
|
-
return $key !== 'openRedirect';
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
foreach ($typesToDetect as $type) {
|
|
61
|
-
if (isset(self::INJECTION_PATTERNS[$type])) {
|
|
62
|
-
try {
|
|
63
|
-
if (preg_match(self::INJECTION_PATTERNS[$type], $str)) {
|
|
64
|
-
return true;
|
|
65
|
-
}
|
|
66
|
-
}catch (\Exception $e){
|
|
67
|
-
error_log($type);
|
|
68
|
-
error_log($e->getMessage());
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
declare(strict_types=1);
|
|
4
|
+
|
|
5
|
+
namespace Anonympins\Fingerprint\Utils;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Fournit des fonctions pour détecter les patterns d'injection malveillants.
|
|
9
|
+
*/
|
|
10
|
+
class MaliciousPatterns
|
|
11
|
+
{
|
|
12
|
+
/**
|
|
13
|
+
* @var array<string, string> Map des patterns malveillants regroupés par type.
|
|
14
|
+
*/
|
|
15
|
+
private const INJECTION_PATTERNS = [
|
|
16
|
+
// SQL/NoSQL injections, including time-based attacks
|
|
17
|
+
'sql' => '/(\$ne|\' *OR *\'1\'=\'1|[\'";]\s*--|; ?(DROP|TRUNCATE|DELETE)|UNION SELECT|(?:SLEEP|BENCHMARK)\s*\(|WAITFOR DELAY)/i',
|
|
18
|
+
// Log4Shell (JNDI injection)
|
|
19
|
+
'log4shell' => '/\$\{jndi:(ldap|rmi|dns):/i',
|
|
20
|
+
// Server-Side Template Injection (SSTI) for engines like Jinja2, Twig, etc.
|
|
21
|
+
'ssti' => '/\{\{.*\}\}|\{%.*%\}/',
|
|
22
|
+
// XML External Entity (XXE) injection
|
|
23
|
+
'xxe' => '/<!ENTITY\s+.*SYSTEM/i',
|
|
24
|
+
// Path Traversal
|
|
25
|
+
'traversal' => '/(\.\.\/|\.\.)/',
|
|
26
|
+
// Remote Command Execution (RCE)
|
|
27
|
+
// The original regex had an issue with `|cmd` being interpreted as a modifier in some PCRE versions.
|
|
28
|
+
// Using a non-capturing group (?:...) makes it more robust and fixes the compilation error.
|
|
29
|
+
'rce' => '/`.*`|(?:^|[\n;&|]\s*)(?:ping|ls|whoami|cat|rm|ncat|nc|bash|sh|powershell|cmd)\b/i',
|
|
30
|
+
// Server-Side Request Forgery (SSRF)
|
|
31
|
+
'ssrf' => '/(?:https?:\/\/)?(?:127\.\d+\.\d+\.\d+|169\.254\.169\.254|10\.\d+\.\d+\.\d+|172\.(?:1[6-9]|2\d|3[01])\.\d+\.\d+|192\.168\.\d+\.\d+|localhost|0\.0\.0\.0|\[[0:]+1\])\b/i',
|
|
32
|
+
// Carriage Return Line Feed (CRLF) Injection
|
|
33
|
+
'crlf' => '/[\r\n]|%0[ad]/i',
|
|
34
|
+
// Cross-Site Scripting (XSS)
|
|
35
|
+
'xss' => '/(<script|javascript:|on\w+\s*=|alert\s*\(|confirm\s*\(|prompt\s*\(|<img\s+src[^>]+onerror|<iframe)/i',
|
|
36
|
+
// Open Redirect
|
|
37
|
+
'openRedirect' => '/^(https?:)?\/\/(?![^\/]*?(localhost|127\.0\.0\.1))[^\s\/]+/i',
|
|
38
|
+
// Local/Remote File Inclusion (LFI/RFI)
|
|
39
|
+
'lfi' => '/(?:etc\/passwd|win\.ini|boot\.ini|php:\/\/filter|data:\/\/|zip:\/\/)/i',
|
|
40
|
+
// Shellshock (CVE-2014-6271)
|
|
41
|
+
'shellshock' => '/\(\)\s*\{\s*:\s*;\s*\}\s*/i',
|
|
42
|
+
// NoSQL Injection (MongoDB query operators)
|
|
43
|
+
'nosql' => '/\$(?:eq|ne|gt|gte|lt|lte|in|nin|and|or|nor|not|expr|jsonSchema|mod|regex|text|where|elemMatch)/i',
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Vérifie si une chaîne de caractères contient des patterns d'injection connus.
|
|
48
|
+
* @param string $str La chaîne à vérifier.
|
|
49
|
+
* @param array<string> $typesToDetect Les types d'injections à détecter (par défaut, tous).
|
|
50
|
+
* @return bool True si un pattern malveillant est détecté, false sinon.
|
|
51
|
+
*/
|
|
52
|
+
public static function isMalicious(string $str, array $typesToDetect = []): bool
|
|
53
|
+
{
|
|
54
|
+
if (empty($typesToDetect)) {
|
|
55
|
+
$typesToDetect = array_filter(array_keys(self::INJECTION_PATTERNS), function ($key) {
|
|
56
|
+
return $key !== 'openRedirect';
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
foreach ($typesToDetect as $type) {
|
|
61
|
+
if (isset(self::INJECTION_PATTERNS[$type])) {
|
|
62
|
+
try {
|
|
63
|
+
if (preg_match(self::INJECTION_PATTERNS[$type], $str)) {
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
}catch (\Exception $e){
|
|
67
|
+
error_log($type);
|
|
68
|
+
error_log($e->getMessage());
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
75
|
}
|