@anonympins/fingerprint 0.6.7 → 0.7.1
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 +33 -0
- package/README.md +3 -7
- package/composer.json +8 -1
- package/package.json +1 -1
- package/public/fingerprint-wordpress.zip +0 -0
- package/public/fp.wasm +0 -0
- package/src/js/build-client.js +9 -11
- package/src/js/dynamic-wasm.js +7 -7
- package/src/js/fingerprint.builder.js +37 -38
- package/src/js/fingerprint.client.js +236 -152
- package/src/js/fingerprint.client.obfuscated.js +1 -1
- package/src/js/fingerprint.js +517 -101
- package/src/js/fingerprint.utils.js +213 -213
- package/src/js/library.js +355 -384
- package/src/js/mongodb-store.js +1 -1
- package/src/js/optimization.worker.js +27 -27
- package/src/js/pow.solver.inline.js +206 -62
- package/src/js/pow.solver.js +235 -101
- package/src/js/pow.worker.js +48 -26
- 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 +101 -40
- 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 +204 -32
- package/src/php/Config/SecurityProfiles.php +21 -0
- package/src/php/DirectFingerprint.php +190 -145
- package/src/php/FingerprintBuilder.php +29 -30
- package/src/php/FingerprintClient.php +24 -25
- package/src/php/FingerprintEngine.php +1836 -1880
- package/src/php/Ja3AnomalyDetector.php +258 -227
- package/src/php/Optimization/FunctionRegistry.php +7 -7
- package/src/php/Optimization/Optimization.php +24 -24
- package/src/php/Optimization/OptimizationOperators.php +28 -27
- 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 +662 -693
- 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/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 +236 -19
- package/src/php/Utils/TLSClientHelloParser.php +369 -212
- package/src/php/WordPress/WpDbStore.php +155 -0
- package/src/php/WordPress/fingerprint-wordpress.php +217 -0
- package/src/php/WordPress/package.php +123 -0
- package/src/php/bin/auto-tune.php +118 -118
|
@@ -1,118 +1,118 @@
|
|
|
1
|
-
<?php
|
|
2
|
-
|
|
3
|
-
declare(strict_types=1);
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
$autoloaderPaths = [
|
|
12
|
-
__DIR__ . '/../../vendor/autoload.php',
|
|
13
|
-
__DIR__ . '/../vendor/autoload.php',
|
|
14
|
-
__DIR__ . '/../../../autoload.php',
|
|
15
|
-
];
|
|
16
|
-
|
|
17
|
-
$autoloaded = false;
|
|
18
|
-
foreach ($autoloaderPaths as $path) {
|
|
19
|
-
if (file_exists($path)) {
|
|
20
|
-
require_once $path;
|
|
21
|
-
$autoloaded = true;
|
|
22
|
-
break;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (!$autoloaded) {
|
|
27
|
-
fwrite(STDERR, "
|
|
28
|
-
exit(1);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
use Anonympins\Fingerprint\Optimization\Optimization;
|
|
32
|
-
use Anonympins\Fingerprint\Store\StoreManager;
|
|
33
|
-
use Anonympins\Fingerprint\Utils\RequestUtils;
|
|
34
|
-
|
|
35
|
-
// 1. Récupération des arguments CLI
|
|
36
|
-
$configPath = $argv[1] ?? null;
|
|
37
|
-
if (!$configPath) {
|
|
38
|
-
echo "Usage: php auto-tune.php [
|
|
39
|
-
exit(1);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (!file_exists($configPath)) {
|
|
43
|
-
fwrite(STDERR, "
|
|
44
|
-
exit(1);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
$config = json_decode(file_get_contents($configPath), true);
|
|
48
|
-
if (json_last_error() !== JSON_ERROR_NONE) {
|
|
49
|
-
fwrite(STDERR, "
|
|
50
|
-
exit(1);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// 2.
|
|
54
|
-
$store = StoreManager::getStore();
|
|
55
|
-
if (!$store) {
|
|
56
|
-
fwrite(STDERR, "
|
|
57
|
-
exit(1);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
$rawTrafficLogs = $store->get('traffic_logs') ?? [];
|
|
61
|
-
if (empty($rawTrafficLogs)) {
|
|
62
|
-
echo "[AutoTuning]
|
|
63
|
-
exit(0);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// 3.
|
|
67
|
-
$sanitizedLogs = RequestUtils::sanitizeTrafficData($rawTrafficLogs);
|
|
68
|
-
|
|
69
|
-
$minDataPoints = $config['autotuning']['minDataPoints'] ?? 200;
|
|
70
|
-
if (count($sanitizedLogs) < $minDataPoints) {
|
|
71
|
-
echo "[AutoTuning]
|
|
72
|
-
exit(0);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
echo "[AutoTuning]
|
|
76
|
-
|
|
77
|
-
// 4.
|
|
78
|
-
$paretoFront = Optimization::solveFullSecurityTuning(['trafficData' => $sanitizedLogs]);
|
|
79
|
-
if (empty($paretoFront)) {
|
|
80
|
-
fwrite(STDERR, "[AutoTuning]
|
|
81
|
-
exit(1);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// 5.
|
|
85
|
-
$bestSolution = $paretoFront[0];
|
|
86
|
-
$minDistance = sqrt(pow($bestSolution['objectives'][0], 2) + pow($bestSolution['objectives'][1], 2));
|
|
87
|
-
foreach ($paretoFront as $candidate) {
|
|
88
|
-
$distance = sqrt(pow($candidate['objectives'][0], 2) + pow($candidate['objectives'][1], 2));
|
|
89
|
-
if ($distance < $minDistance) {
|
|
90
|
-
$minDistance = $distance;
|
|
91
|
-
$bestSolution = $candidate;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
$newConfig = $bestSolution['solution'];
|
|
96
|
-
$maxChangeVelocity = 0.15; //
|
|
97
|
-
|
|
98
|
-
$applyInertialUpdate = function (array &$current, array $target) use ($maxChangeVelocity) {
|
|
99
|
-
$sumCurrent = array_sum($current);
|
|
100
|
-
if ($sumCurrent === 0) return;
|
|
101
|
-
$sumTarget = 0;
|
|
102
|
-
foreach ($current as $k => $v) {
|
|
103
|
-
if (isset($target[$k])) $sumTarget += $target[$k];
|
|
104
|
-
}
|
|
105
|
-
$ratio = ($sumTarget - $sumCurrent) / $sumCurrent;
|
|
106
|
-
$factor = 1 + max(-$maxChangeVelocity, min($maxChangeVelocity, $ratio));
|
|
107
|
-
foreach ($current as $k => &$v) {
|
|
108
|
-
if (isset($target[$k])) $v *= $factor;
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
$applyInertialUpdate($config['thresholds'], $newConfig['thresholds']);
|
|
113
|
-
$applyInertialUpdate($config['weights'], $newConfig['weights']);
|
|
114
|
-
$applyInertialUpdate($config['patterns'], $newConfig['patterns']);
|
|
115
|
-
|
|
116
|
-
// 6.
|
|
117
|
-
file_put_contents($configPath, json_encode($config, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
|
118
|
-
echo "[AutoTuning]
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
declare(strict_types=1);
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Periodic security configuration auto-tuning CLI script.
|
|
7
|
+
* Reads current configuration, prunes and sanitizes traffic logs,
|
|
8
|
+
* executes the genetic optimizer, and writes back the optimized profile.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
$autoloaderPaths = [
|
|
12
|
+
__DIR__ . '/../../vendor/autoload.php',
|
|
13
|
+
__DIR__ . '/../vendor/autoload.php',
|
|
14
|
+
__DIR__ . '/../../../autoload.php',
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
$autoloaded = false;
|
|
18
|
+
foreach ($autoloaderPaths as $path) {
|
|
19
|
+
if (file_exists($path)) {
|
|
20
|
+
require_once $path;
|
|
21
|
+
$autoloaded = true;
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (!$autoloaded) {
|
|
27
|
+
fwrite(STDERR, "Error: Unable to load autoloader. Run 'composer install'.\n");
|
|
28
|
+
exit(1);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
use Anonympins\Fingerprint\Optimization\Optimization;
|
|
32
|
+
use Anonympins\Fingerprint\Store\StoreManager;
|
|
33
|
+
use Anonympins\Fingerprint\Utils\RequestUtils;
|
|
34
|
+
|
|
35
|
+
// 1. Récupération des arguments CLI
|
|
36
|
+
$configPath = $argv[1] ?? null;
|
|
37
|
+
if (!$configPath) {
|
|
38
|
+
echo "Usage: php auto-tune.php [path_to_security-config.json]\n";
|
|
39
|
+
exit(1);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (!file_exists($configPath)) {
|
|
43
|
+
fwrite(STDERR, "Error: Configuration file not found: {$configPath}\n");
|
|
44
|
+
exit(1);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
$config = json_decode(file_get_contents($configPath), true);
|
|
48
|
+
if (json_last_error() !== JSON_ERROR_NONE) {
|
|
49
|
+
fwrite(STDERR, "Error: Invalid JSON configuration file.\n");
|
|
50
|
+
exit(1);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// 2. Connect to datastore to retrieve accumulated traffic logs
|
|
54
|
+
$store = StoreManager::getStore();
|
|
55
|
+
if (!$store) {
|
|
56
|
+
fwrite(STDERR, "Error: No active persistent datastore available.\n");
|
|
57
|
+
exit(1);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
$rawTrafficLogs = $store->get('traffic_logs') ?? [];
|
|
61
|
+
if (empty($rawTrafficLogs)) {
|
|
62
|
+
echo "[AutoTuning] No traffic logs available for optimization.\n";
|
|
63
|
+
exit(0);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// 3. Sanitize data to prevent poisoning / Sybil attacks
|
|
67
|
+
$sanitizedLogs = RequestUtils::sanitizeTrafficData($rawTrafficLogs);
|
|
68
|
+
|
|
69
|
+
$minDataPoints = $config['autotuning']['minDataPoints'] ?? 200;
|
|
70
|
+
if (count($sanitizedLogs) < $minDataPoints) {
|
|
71
|
+
echo "[AutoTuning] Postponed: Insufficient sanitized logs (" . count($sanitizedLogs) . "/{$minDataPoints}).\n";
|
|
72
|
+
exit(0);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
echo "[AutoTuning] Starting optimization pass on " . count($sanitizedLogs) . " traffic data points...\n";
|
|
76
|
+
|
|
77
|
+
// 4. Compute Pareto front
|
|
78
|
+
$paretoFront = Optimization::solveFullSecurityTuning(['trafficData' => $sanitizedLogs]);
|
|
79
|
+
if (empty($paretoFront)) {
|
|
80
|
+
fwrite(STDERR, "[AutoTuning] Optimization returned no solutions.\n");
|
|
81
|
+
exit(1);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// 5. Select the most balanced solution (closest to origin)
|
|
85
|
+
$bestSolution = $paretoFront[0];
|
|
86
|
+
$minDistance = sqrt(pow($bestSolution['objectives'][0], 2) + pow($bestSolution['objectives'][1], 2));
|
|
87
|
+
foreach ($paretoFront as $candidate) {
|
|
88
|
+
$distance = sqrt(pow($candidate['objectives'][0], 2) + pow($candidate['objectives'][1], 2));
|
|
89
|
+
if ($distance < $minDistance) {
|
|
90
|
+
$minDistance = $distance;
|
|
91
|
+
$bestSolution = $candidate;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
$newConfig = $bestSolution['solution'];
|
|
96
|
+
$maxChangeVelocity = 0.15; // Max 15% inertial step per cycle
|
|
97
|
+
|
|
98
|
+
$applyInertialUpdate = function (array &$current, array $target) use ($maxChangeVelocity) {
|
|
99
|
+
$sumCurrent = array_sum($current);
|
|
100
|
+
if ($sumCurrent === 0) return;
|
|
101
|
+
$sumTarget = 0;
|
|
102
|
+
foreach ($current as $k => $v) {
|
|
103
|
+
if (isset($target[$k])) $sumTarget += $target[$k];
|
|
104
|
+
}
|
|
105
|
+
$ratio = ($sumTarget - $sumCurrent) / $sumCurrent;
|
|
106
|
+
$factor = 1 + max(-$maxChangeVelocity, min($maxChangeVelocity, $ratio));
|
|
107
|
+
foreach ($current as $k => &$v) {
|
|
108
|
+
if (isset($target[$k])) $v *= $factor;
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
$applyInertialUpdate($config['thresholds'], $newConfig['thresholds']);
|
|
113
|
+
$applyInertialUpdate($config['weights'], $newConfig['weights']);
|
|
114
|
+
$applyInertialUpdate($config['patterns'], $newConfig['patterns']);
|
|
115
|
+
|
|
116
|
+
// 6. Write back optimized parameters to configuration file
|
|
117
|
+
file_put_contents($configPath, json_encode($config, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
|
118
|
+
echo "[AutoTuning] Success: File {$configPath} updated with optimized parameters.\n";
|