@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.
Files changed (51) hide show
  1. package/CHANGELOG.md +193 -0
  2. package/README.md +1080 -834
  3. package/composer.json +39 -0
  4. package/index.js +5 -0
  5. package/package.json +31 -23
  6. package/phpunit.xml +21 -0
  7. package/public/fp.js +2 -0
  8. package/src/js/build-client.js +69 -0
  9. package/{fingerprint.builder.js → src/js/fingerprint.builder.js} +168 -175
  10. package/{fingerprint.client.js → src/js/fingerprint.client.js} +634 -538
  11. package/src/js/fingerprint.client.obfuscated.js +1 -0
  12. package/{fingerprint.js → src/js/fingerprint.js} +3733 -3294
  13. package/{library.js → src/js/library.js} +1729 -1729
  14. package/{problem-manager.js → src/js/problem-manager.js} +539 -522
  15. package/src/php/AutoTuner.php +155 -0
  16. package/src/php/Challenge/ChallengeUtils.php +306 -0
  17. package/src/php/Config/SecurityProfiles.php +267 -0
  18. package/src/php/DirectFingerprint.php +81 -0
  19. package/src/php/FingerprintBuilder.php +186 -0
  20. package/src/php/FingerprintClient.php +132 -0
  21. package/src/php/FingerprintEngine.php +863 -0
  22. package/src/php/Optimization/FunctionRegistry.php +63 -0
  23. package/src/php/Optimization/Optimization.php +256 -0
  24. package/src/php/Optimization/OptimizationOperators.php +305 -0
  25. package/src/php/Optimization/ProblemInitializers.php +53 -0
  26. package/src/php/ProblemManager.php +255 -0
  27. package/src/php/RequestContext.php +91 -0
  28. package/src/php/Store/IStore.php +42 -0
  29. package/src/php/Store/InMemoryStore.php +67 -0
  30. package/src/php/Store/StoreManager.php +36 -0
  31. package/src/php/Tests/ChallengeUtilsTest.php +82 -0
  32. package/src/php/Tests/FingerprintBuilderTest.php +58 -0
  33. package/src/php/Tests/FingerprintEngineTest.php +300 -0
  34. package/src/php/Tests/IpReputationTest.php +157 -0
  35. package/src/php/Tests/PowTest.php +40 -0
  36. package/src/php/Tests/ProblemManagerTest.php +295 -0
  37. package/src/php/Tests/RequestUtilsTest.php +81 -0
  38. package/src/php/Tests/problems.config.json +9 -0
  39. package/src/php/Utils/BigInt.php +145 -0
  40. package/src/php/Utils/BlockList.php +100 -0
  41. package/src/php/Utils/Logger.php +30 -0
  42. package/src/php/Utils/MaliciousPatterns.php +59 -0
  43. package/src/php/Utils/RequestUtils.php +962 -0
  44. package/fingerprint.client.obfuscated.js +0 -1
  45. /package/{mongodb-store.js → src/js/mongodb-store.js} +0 -0
  46. /package/{optimization.worker.js → src/js/optimization.worker.js} +0 -0
  47. /package/{pow.solver.inline.js → src/js/pow.solver.inline.js} +0 -0
  48. /package/{pow.solver.js → src/js/pow.solver.js} +0 -0
  49. /package/{pow.worker.js → src/js/pow.worker.js} +0 -0
  50. /package/{redis-store.js → src/js/redis-store.js} +0 -0
  51. /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
+ }