zond-engine 0.18.0

The core networking library powering Zond. Raw packet injection, protocol parsing, service and OS fingerprinting, and asynchronous network scanning.
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
// Copyright (c) 2026 Erik Lening (hollowpointer) and Contributors
//
// This file is part of Zond Engine, licensed under the GNU Affero General
// Public License, version 3 or later. See the LICENSE file for details, or
// <https://www.gnu.org/licenses/agpl-3.0.html>.
//
// SPDX-License-Identifier: AGPL-3.0-or-later

//! # Global-match prefilter
//!
//! Selecting matching signatures on a non-standard port means matching against
//! the *whole* set. Running every regex would be O(number of signatures) per
//! response, which is fine at a few thousand and not as the set grows. A
//! [`Prefilter`] narrows the field to a small candidate set first, so global
//! matching stays sublinear in the size of the database.
//!
//! ## The literal engine
//!
//! [`LiteralPrefilter`] extracts, for each signature, a set of literals such
//! that **any match must contain at least one of them**, and indexes them in an
//! Aho-Corasick automaton. A response's candidates are the signatures whose
//! literal appears in it, plus a small "always-run" bucket of signatures no
//! usable literal could be extracted from (pure-structural patterns, and those
//! written with look-arounds, which the extractor's parser does not read).
//!
//! ### Soundness
//!
//! Only required literals are used, extracted from a pattern's prefix (handling
//! alternations), the guaranteed inner runs of its mandatory parts (handling
//! alternations too), or its suffix. Each is a substring every match must
//! contain, so a signature is never wrongly excluded. This is checked against
//! the recorded-example corpus (`corpus.rs`): every example that matches its
//! pattern must select that pattern as a candidate.
//!
//! ### Case-insensitive patterns
//!
//! A pattern under `(?i)` reaches the extractor with every letter a class of
//! its cases, `[Ll][Ii][Nn][Uu][Xx]`, and a class is no literal. So before
//! extraction each class that holds exactly one ASCII letter's two cases is
//! read as that letter in lower case, and the automaton, which ignores ASCII
//! case, finds it in either. Every match holds one of the class's two
//! members there, so the literal is still one every match contains. `k` and
//! `s` are not folded to one letter: Unicode case folding adds the Kelvin
//! sign and the long s to their classes, which a match may hold and an
//! ASCII-insensitive literal would miss. Each is read instead as the two
//! spellings a match may hold, the letter and that third member, and a run of
//! letters around it as every spelling of the run, so `bsd` is indexed as
//! `bsd` and `bſd` and found in `FreeBSD`. The spellings multiply with each
//! such letter, and a run is cut where they would pass
//! [`MAX_ALTERNATION_LITERALS`].
//!
//! ### Cost per response
//!
//! Selection runs once per response, and a scan fingerprints every open port on
//! every host, so this is a hot path. A signature contributes several literals
//! and a response can hit any of them repeatedly, so hits are deduplicated as
//! they arrive, through a bitset indexed by *signature*. Both halves of that
//! are load-bearing. Indexing the bitset by literal instead makes it eight
//! times wider to allocate and zero without filtering anything more, and
//! dropping it to let the closing sort absorb the duplicates is slower still:
//! a response at the 4 KiB read cap can carry over a hundred thousand literal
//! hits, and the sort would see every one.
//!
//! [`Prefilter`] is a trait so a faster backend (e.g. `hyperscan`/`vectorscan`)
//! can replace the engine without touching callers.

use aho_corasick::AhoCorasick;
use regex_syntax::hir::literal::{ExtractKind, Extractor};
use regex_syntax::hir::{Capture, Class, Hir, HirKind, Repetition};
use regex_syntax::parse;

use super::matcher::Signature;

/// Shortest literal worth indexing; below this, a literal is too common to
/// narrow anything and the signature is better left always-run.
const MIN_LITERAL_LEN: usize = 3;

/// The most literals an alternation contributes to a signature's set, past
/// which it guarantees nothing worth indexing. The corpus's widest guarded
/// alternation, a list of RPC program names, is a dozen.
const MAX_ALTERNATION_LITERALS: usize = 32;

/// Narrows the whole signature set to a candidate list for a response.
pub trait Prefilter: Send + Sync {
    /// Indices (into the signature set the prefilter was built from) that could
    /// possibly match `response`. Never omits a signature that would match.
    fn candidates(&self, response: &str) -> Vec<usize>;
}

/// A required-literal Aho-Corasick prefilter. See the module docs.
#[derive(Debug)]
pub struct LiteralPrefilter {
    automaton: AhoCorasick,
    /// Aho-Corasick pattern id -> the signature index that contributed it.
    literal_owner: Vec<usize>,
    /// Signatures with no usable required literal; always candidates.
    always_run: Vec<usize>,
    /// How many signatures were indexed, which is the width of the dedup
    /// bitset [`LiteralPrefilter::candidates`] allocates.
    signature_count: usize,
}

impl LiteralPrefilter {
    /// Builds the prefilter over `signatures`, indexing them by position.
    pub fn build(signatures: &[Signature]) -> Self {
        let mut literals: Vec<Vec<u8>> = Vec::new();
        let mut literal_owner: Vec<usize> = Vec::new();
        let mut always_run: Vec<usize> = Vec::new();

        for (idx, signature) in signatures.iter().enumerate() {
            match required_literals(signature.pattern()) {
                Some(lits) => {
                    for lit in lits {
                        literals.push(lit);
                        literal_owner.push(idx);
                    }
                }
                None => always_run.push(idx),
            }
        }

        // Ascii-case-insensitive so a literal indexed in one case still matches
        // a response in another; correctness (never dropping a match) is the
        // point, and the candidate's own regex makes the final decision.
        let automaton = AhoCorasick::builder()
            .ascii_case_insensitive(true)
            .build(&literals)
            .expect("aho-corasick construction over signature literals");

        Self {
            automaton,
            literal_owner,
            always_run,
            signature_count: signatures.len(),
        }
    }
}

impl LiteralPrefilter {
    /// The signatures no literal narrows, which are candidates for every
    /// response.
    #[cfg(test)]
    pub(crate) fn always_run(&self) -> &[usize] {
        &self.always_run
    }
}

impl Prefilter for LiteralPrefilter {
    fn candidates(&self, response: &str) -> Vec<usize> {
        let mut selected = vec![0u64; self.signature_count.div_ceil(64).max(1)];
        let mut candidates = self.always_run.clone();
        for &owner in &self.always_run {
            selected[owner / 64] |= 1u64 << (owner % 64);
        }

        for m in self.automaton.find_overlapping_iter(response) {
            let owner = self.literal_owner[m.pattern().as_usize()];
            let (word, bit) = (owner / 64, 1u64 << (owner % 64));
            if selected[word] & bit == 0 {
                selected[word] |= bit;
                candidates.push(owner);
            }
        }

        candidates.sort_unstable();
        candidates
    }
}

/// A set of literals such that every match of `pattern` contains at least one,
/// or `None` if no such bounded set could be extracted (the caller then treats
/// the signature as always-run).
///
/// Tries, in order: the prefix literal set (which captures leading
/// alternations), the longest guaranteed inner literal, then the suffix set.
///
/// Extracted from the pattern with its case classes read as literals; see
/// [`folded`] and the module docs.
fn required_literals(pattern: &str) -> Option<Vec<Vec<u8>>> {
    let hir = folded(&parse(pattern).ok()?);

    if let Some(set) = literal_set(&hir, ExtractKind::Prefix) {
        return Some(set);
    }
    if let Some(inner) = required_set(&hir) {
        return Some(inner);
    }
    literal_set(&hir, ExtractKind::Suffix)
}

/// `hir` with each class holding exactly one ASCII letter's two cases read as
/// that letter in lower case, which every match of `hir` holds in one case or
/// the other, and the automaton finds in either.
fn folded(hir: &Hir) -> Hir {
    match hir.kind() {
        HirKind::Class(class) => match case_pair(class) {
            Some(lower) => Hir::literal([lower]),
            None => hir.clone(),
        },
        HirKind::Repetition(rep) => Hir::repetition(Repetition {
            sub: Box::new(folded(&rep.sub)),
            ..rep.clone()
        }),
        HirKind::Capture(capture) => Hir::capture(Capture {
            sub: Box::new(folded(&capture.sub)),
            ..capture.clone()
        }),
        HirKind::Concat(parts) => Hir::concat(parts.iter().map(folded).collect()),
        HirKind::Alternation(branches) => Hir::alternation(branches.iter().map(folded).collect()),
        _ => hir.clone(),
    }
}

/// The lower-case letter `class` holds both cases of and nothing else.
fn case_pair(class: &Class) -> Option<u8> {
    let members: Vec<u32> = match class {
        Class::Unicode(class) => class
            .ranges()
            .iter()
            .flat_map(|range| u32::from(range.start())..=u32::from(range.end()))
            .take(3)
            .collect(),
        Class::Bytes(class) => class
            .ranges()
            .iter()
            .flat_map(|range| u32::from(range.start())..=u32::from(range.end()))
            .take(3)
            .collect(),
    };
    let [upper, lower] = members[..] else {
        return None;
    };
    let lower = u8::try_from(lower).ok()?;
    (lower.is_ascii_lowercase() && u32::from(lower.to_ascii_uppercase()) == upper).then_some(lower)
}

/// The spellings of a letter whose `(?i)` class Unicode case folding widens
/// past its two cases: `k` with the Kelvin sign, `s` with the long s. Each
/// spelling is in lower case where it is ASCII, which the automaton finds in
/// either case.
fn case_triple(class: &Class) -> Option<Vec<Vec<u8>>> {
    let Class::Unicode(class) = class else {
        return None;
    };
    let members: Vec<u32> = class
        .ranges()
        .iter()
        .flat_map(|range| u32::from(range.start())..=u32::from(range.end()))
        .take(4)
        .collect();
    let (lower, third) = match members[..] {
        [0x4B, 0x6B, 0x212A] => ('k', '\u{212A}'),
        [0x53, 0x73, 0x17F] => ('s', '\u{17F}'),
        _ => return None,
    };
    Some(vec![vec![lower as u8], third.to_string().into_bytes()])
}

/// Every string `hir` can match, where it matches only a few, each exact up to
/// ASCII case, which the automaton ignores: a literal, a letter of
/// [`case_triple`], and what those make in a concatenation or an alternation,
/// up to [`MAX_ALTERNATION_LITERALS`]. `None` for anything else.
fn exact_set(hir: &Hir) -> Option<Vec<Vec<u8>>> {
    match hir.kind() {
        HirKind::Literal(literal) => Some(vec![literal.0.to_vec()]),
        HirKind::Class(class) => case_triple(class),
        HirKind::Capture(capture) => exact_set(&capture.sub),
        HirKind::Concat(parts) => parts.iter().try_fold(vec![Vec::new()], |run, part| {
            joined(&run, &exact_set(part)?)
        }),
        HirKind::Alternation(branches) => {
            let mut set = Vec::new();
            for branch in branches {
                set.extend(exact_set(branch)?);
            }
            (set.len() <= MAX_ALTERNATION_LITERALS).then_some(set)
        }
        _ => None,
    }
}

/// Each of `before` followed by each of `after`, or `None` where there would
/// be more than [`MAX_ALTERNATION_LITERALS`].
fn joined(before: &[Vec<u8>], after: &[Vec<u8>]) -> Option<Vec<Vec<u8>>> {
    if before.len() * after.len() > MAX_ALTERNATION_LITERALS {
        return None;
    }
    Some(
        before
            .iter()
            .flat_map(|head| {
                after.iter().map(move |tail| {
                    let mut literal = head.clone();
                    literal.extend_from_slice(tail);
                    literal
                })
            })
            .collect(),
    )
}

/// The prefix or suffix literal set, if bounded and free of empty literals.
fn literal_set(hir: &Hir, kind: ExtractKind) -> Option<Vec<Vec<u8>>> {
    let mut extractor = Extractor::new();
    extractor.kind(kind);
    let seq = extractor.extract(hir);

    let literals = seq.literals()?; // `None` => unbounded => not usable
    if literals.is_empty() {
        return None;
    }

    let mut out = Vec::with_capacity(literals.len());
    for literal in literals {
        if literal.as_bytes().is_empty() {
            // An empty literal matches anywhere, so it cannot narrow the field.
            return None;
        }
        out.push(literal.as_bytes().to_vec());
    }
    Some(out)
}

/// A set of literals, each at least [`MIN_LITERAL_LEN`] long, one of which
/// appears in every match, found by walking the mandatory positions of the
/// HIR. `None` where none is guaranteed: a class, an optional repetition, or
/// an alternation with a branch that guarantees none.
///
/// Of a concatenation's parts, and of its runs of parts each matching one of
/// a few exact strings, joined into every spelling of the run (see
/// [`exact_set`]), the one whose shortest literal is longest is taken, and of
/// those the one with fewest literals: a longer literal is rarer in a
/// response, and every literal is one more way to be selected. An alternation
/// guarantees one of its branches' literals, so its set is theirs together,
/// up to [`MAX_ALTERNATION_LITERALS`].
fn required_set(hir: &Hir) -> Option<Vec<Vec<u8>>> {
    match hir.kind() {
        HirKind::Literal(literal) => {
            (literal.0.len() >= MIN_LITERAL_LEN).then(|| vec![literal.0.to_vec()])
        }
        HirKind::Capture(capture) => required_set(&capture.sub),
        HirKind::Repetition(rep) if rep.min >= 1 => required_set(&rep.sub),
        HirKind::Concat(parts) => {
            let mut sets: Vec<Vec<Vec<u8>>> = parts.iter().filter_map(required_set).collect();
            sets.extend(exact_runs(parts));
            sets.into_iter()
                .filter(|set| set.iter().all(|literal| literal.len() >= MIN_LITERAL_LEN))
                .max_by(|a, b| {
                    let shortest = |set: &Vec<Vec<u8>>| set.iter().map(Vec::len).min();
                    shortest(a)
                        .cmp(&shortest(b))
                        .then_with(|| b.len().cmp(&a.len()))
                })
        }
        HirKind::Alternation(branches) => {
            let mut set = Vec::new();
            for branch in branches {
                set.extend(required_set(branch)?);
            }
            (set.len() <= MAX_ALTERNATION_LITERALS).then_some(set)
        }
        _ => None,
    }
}

/// The runs of consecutive `parts` that each match one of a few exact
/// strings, each run as every spelling of it. Every match of the
/// concatenation holds one spelling of each run, in one piece. A run whose
/// spellings would pass [`MAX_ALTERNATION_LITERALS`] is cut there and the
/// next begins at the part that would have passed it.
fn exact_runs(parts: &[Hir]) -> Vec<Vec<Vec<u8>>> {
    let mut runs = Vec::new();
    let mut run: Option<Vec<Vec<u8>>> = None;
    for part in parts {
        match (exact_set(part), run.take()) {
            (Some(set), Some(before)) => match joined(&before, &set) {
                Some(longer) => run = Some(longer),
                None => {
                    runs.push(before);
                    run = Some(set);
                }
            },
            (Some(set), None) => run = Some(set),
            (None, before) => runs.extend(before),
        }
    }
    runs.extend(run);
    runs
}

// ╔════════════════════════════════════════════╗
// ║ ████████╗███████╗███████╗████████╗███████╗ ║
// ║ ╚══██╔══╝██╔════╝██╔════╝╚══██╔══╝██╔════╝ ║
// ║    ██║   █████╗  ███████╗   ██║   ███████╗ ║
// ║    ██║   ██╔══╝  ╚════██║   ██║   ╚════██║ ║
// ║    ██║   ███████╗███████║   ██║   ███████║ ║
// ║    ╚═╝   ╚══════╝╚══════╝   ╚═╝   ╚══════╝ ║
// ╚════════════════════════════════════════════╝

#[cfg(test)]
mod tests {
    use super::*;
    use crate::fingerprint::signature::MatchRule;
    use proptest::prelude::*;

    fn sig(pattern: &str) -> Signature {
        Signature::new(
            "svc",
            &MatchRule {
                name: None,
                pattern: pattern.to_string(),
                version_group: None,
                vendor: None,
                product: None,
                context: None,
                example: None,
                metadata: None,
            },
        )
    }

    #[test]
    fn selects_by_prefix_literal_and_skips_non_candidates() {
        let sigs = [sig(r"^SSH-[\d.]+-OpenSSH"), sig(r"^HTTP/1\.[01]")];
        let pf = LiteralPrefilter::build(&sigs);

        let ssh = pf.candidates("SSH-2.0-OpenSSH_9.6");
        assert!(ssh.contains(&0));
        assert!(!ssh.contains(&1)); // the HTTP signature is filtered out
    }

    #[test]
    fn selects_by_inner_literal() {
        // No prefix literal (leading capture/class), but a strong inner literal.
        let sigs = [sig(r"^(\S{1,64}) FTP Server \(Version ([\d.]+)\)")];
        let pf = LiteralPrefilter::build(&sigs);
        assert!(
            pf.candidates("host.example FTP Server (Version 1.2.3)")
                .contains(&0)
        );
        assert!(pf.candidates("SSH-2.0-OpenSSH_9.6").is_empty());
    }

    #[test]
    fn unfilterable_pattern_is_always_a_candidate() {
        // A pure-structural pattern yields no usable literal: always-run.
        let sigs = [sig(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$")];
        let pf = LiteralPrefilter::build(&sigs);
        assert!(pf.candidates("anything at all").contains(&0));
    }

    /// The claim the dedup bitset makes: a signature is listed once, however
    /// many of its literals the response carries and however often.
    #[test]
    fn a_signature_is_listed_once_however_many_of_its_literals_hit() {
        let sigs = [
            sig(r"^(?:Postfix|Sendmail|Exim) SMTP"),
            sig(r"^HTTP/1\.[01]"),
        ];
        let pf = LiteralPrefilter::build(&sigs);

        let response = "Postfix SMTP / Sendmail SMTP / Exim SMTP / Postfix SMTP";
        let owned = pf.literal_owner.iter().filter(|&&o| o == 0).count();
        assert!(owned > 1, "the alternation gives it several literals");
        assert_eq!(pf.candidates(response), vec![0]);
    }

    #[test]
    fn case_insensitive_literal_still_selects() {
        let sigs = [sig(r"^Server: nginx")];
        let pf = LiteralPrefilter::build(&sigs);
        assert!(pf.candidates("server: NGINX/1.25").contains(&0));
    }

    /// A case-insensitive pattern is narrowed by its letters like any other,
    /// in whichever case a response writes them, rather than matched against
    /// every response.
    #[test]
    fn a_case_insensitive_pattern_is_narrowed_by_its_letters() {
        let sigs = [sig(r"(?i)^(.{0,64}) Linux ([\w.-]*)$")];
        let pf = LiteralPrefilter::build(&sigs);

        assert!(pf.always_run().is_empty(), "left to run on everything");
        assert!(pf.candidates("host LINUX 6.1.0").contains(&0));
        assert!(pf.candidates("host linux 6.1.0").contains(&0));
        assert!(pf.candidates("host FreeBSD 14.1").is_empty());
    }

    /// A `k` under `(?i)` also matches the Kelvin sign, which no ASCII-folded
    /// literal finds, so it is not read as a literal and a response spelling
    /// it that way is still selected.
    #[test]
    fn a_letter_whose_class_is_wider_than_its_two_cases_is_not_read_as_a_literal() {
        let pattern = r"(?i)^.{0,8}kernel";
        let response = "\u{212A}ERNEL";
        assert!(
            regex::Regex::new(pattern)
                .expect("compiles")
                .is_match(response),
            "the Kelvin sign is a k to the pattern"
        );

        let pf = LiteralPrefilter::build(&[sig(pattern)]);
        assert!(pf.candidates(response).contains(&0));
    }

    /// **A case-insensitive word with a `k` or an `s` in it is narrowed by
    /// every way a match can spell it.** Unicode case folding gives each of
    /// the two a third member, the Kelvin sign and the long s, so neither is a
    /// letter an ASCII-folded literal stands for alone; spelled out as the
    /// letter or that third member, and joined to the letters around it, the
    /// word is still a set every match holds one of. A rule matching `BSD`
    /// anywhere in a reply was otherwise run against every reply.
    #[test]
    fn a_word_split_by_a_k_or_an_s_is_narrowed_by_each_spelling_of_it() {
        let pattern = r"(?i)^(.{0,256}?BSD)[ /-]([\d.]+)";
        let pf = LiteralPrefilter::build(&[sig(pattern)]);
        assert!(pf.always_run().is_empty(), "left to run on everything");

        let matching = regex::Regex::new(pattern).expect("compiles");
        for response in [
            "FreeBSD 14.1",
            "freebsd-13.2",
            "Free B\u{17F}D 1",
            "B\u{17F}D/9",
        ] {
            if matching.is_match(response) {
                assert!(
                    pf.candidates(response).contains(&0),
                    "{response:?} matches and was not selected"
                );
            }
        }
        assert!(
            matching.is_match("B\u{17F}D/9"),
            "the long s is an s to the pattern"
        );
        assert!(pf.candidates("Linux 6.1").is_empty());

        let kernel = LiteralPrefilter::build(&[sig(r"(?i)^.{0,8}kernel")]);
        assert!(kernel.always_run().is_empty(), "left to run on everything");
        assert!(kernel.candidates("\u{212A}ERNEL").contains(&0));
        assert!(kernel.candidates("KERNEL").contains(&0));
    }

    /// An alternation every branch of which holds a literal guarantees one of
    /// them, wherever in the pattern it stands.
    #[test]
    fn a_required_alternation_narrows_by_its_branches() {
        let sigs = [sig(r"^(.{0,16}) (?:Junos|ScreenOS) ([\d.]+)$")];
        let pf = LiteralPrefilter::build(&sigs);

        assert!(pf.always_run().is_empty(), "left to run on everything");
        assert!(pf.candidates("fw1 ScreenOS 6.3").contains(&0));
        assert!(pf.candidates("r1 Junos 23.4").contains(&0));
        assert!(pf.candidates("r1 IOS 15.2").is_empty());
    }

    proptest! {
        /// Candidate selection scans arbitrary response text through the
        /// Aho-Corasick automaton; it must never panic on any input, including
        /// non-ASCII and control characters.
        #[test]
        fn candidates_never_panics_on_arbitrary_input(response in "(?s).*") {
            let sigs = [sig(r"^HTTP/\d"), sig(r"Server: (\w+)"), sig(r"^\d{3} ")];
            let pf = LiteralPrefilter::build(&sigs);
            let _ = pf.candidates(&response);
        }
    }
}