@anonympins/fingerprint 0.3.2 → 0.3.4
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 +193 -0
- package/README.md +1080 -834
- package/composer.json +39 -0
- package/index.js +5 -0
- package/package.json +31 -23
- package/phpunit.xml +21 -0
- package/public/fp.js +2 -0
- package/src/js/build-client.js +69 -0
- package/{fingerprint.builder.js → src/js/fingerprint.builder.js} +168 -175
- package/{fingerprint.client.js → src/js/fingerprint.client.js} +634 -538
- package/src/js/fingerprint.client.obfuscated.js +1 -0
- package/{fingerprint.js → src/js/fingerprint.js} +3733 -3294
- package/{library.js → src/js/library.js} +1729 -1729
- package/{problem-manager.js → src/js/problem-manager.js} +539 -522
- package/src/php/AutoTuner.php +155 -0
- package/src/php/Challenge/ChallengeUtils.php +306 -0
- package/src/php/Config/SecurityProfiles.php +267 -0
- package/src/php/DirectFingerprint.php +81 -0
- package/src/php/FingerprintBuilder.php +186 -0
- package/src/php/FingerprintClient.php +132 -0
- package/src/php/FingerprintEngine.php +863 -0
- package/src/php/Optimization/FunctionRegistry.php +63 -0
- package/src/php/Optimization/Optimization.php +256 -0
- package/src/php/Optimization/OptimizationOperators.php +305 -0
- package/src/php/Optimization/ProblemInitializers.php +53 -0
- package/src/php/ProblemManager.php +255 -0
- package/src/php/RequestContext.php +91 -0
- package/src/php/Store/IStore.php +42 -0
- package/src/php/Store/InMemoryStore.php +67 -0
- package/src/php/Store/StoreManager.php +36 -0
- package/src/php/Tests/ChallengeUtilsTest.php +82 -0
- package/src/php/Tests/FingerprintBuilderTest.php +58 -0
- package/src/php/Tests/FingerprintEngineTest.php +300 -0
- package/src/php/Tests/IpReputationTest.php +157 -0
- package/src/php/Tests/PowTest.php +40 -0
- package/src/php/Tests/ProblemManagerTest.php +295 -0
- package/src/php/Tests/RequestUtilsTest.php +81 -0
- package/src/php/Tests/problems.config.json +9 -0
- package/src/php/Utils/BigInt.php +145 -0
- package/src/php/Utils/BlockList.php +100 -0
- package/src/php/Utils/Logger.php +30 -0
- package/src/php/Utils/MaliciousPatterns.php +59 -0
- package/src/php/Utils/RequestUtils.php +962 -0
- package/fingerprint.client.obfuscated.js +0 -1
- /package/{mongodb-store.js → src/js/mongodb-store.js} +0 -0
- /package/{optimization.worker.js → src/js/optimization.worker.js} +0 -0
- /package/{pow.solver.inline.js → src/js/pow.solver.inline.js} +0 -0
- /package/{pow.solver.js → src/js/pow.solver.js} +0 -0
- /package/{pow.worker.js → src/js/pow.worker.js} +0 -0
- /package/{redis-store.js → src/js/redis-store.js} +0 -0
- /package/{sql-store.js → src/js/sql-store.js} +0 -0
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
];
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Vérifie si une chaîne de caractères contient des patterns d'injection connus.
|
|
34
|
+
* @param string $str La chaîne à vérifier.
|
|
35
|
+
* @param array<string> $typesToDetect Les types d'injections à détecter (par défaut, tous).
|
|
36
|
+
* @return bool True si un pattern malveillant est détecté, false sinon.
|
|
37
|
+
*/
|
|
38
|
+
public static function isMalicious(string $str, array $typesToDetect = []): bool
|
|
39
|
+
{
|
|
40
|
+
if (empty($typesToDetect)) {
|
|
41
|
+
$typesToDetect = array_keys(self::INJECTION_PATTERNS);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
foreach ($typesToDetect as $type) {
|
|
45
|
+
if (isset(self::INJECTION_PATTERNS[$type])) {
|
|
46
|
+
try {
|
|
47
|
+
if (preg_match(self::INJECTION_PATTERNS[$type], $str)) {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
}catch (\Exception $e){
|
|
51
|
+
error_log($type);
|
|
52
|
+
error_log($e->getMessage());
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
}
|