Fuzzing, property tests, CLI split, and 1.1.0 #2
No files matched your search
@@ -0,0 +1,61 @@
|
||||
name: Weekly
|
||||
|
||||
# Checks that do not depend on a push: a new RustSec advisory can land on a
|
||||
# dependency while the code stands still, and fuzzing finds more the longer
|
||||
# its corpus grows. The corpus lives on the persistent runner volume, so every
|
||||
# run starts where the last one stopped.
|
||||
on:
|
||||
schedule:
|
||||
- cron: '17 6 * * 1'
|
||||
workflow_dispatch:
|
||||
|
||||
concurrency:
|
||||
group: weekly
|
||||
cancel-in-progress: false
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
CARGO_HOME: /opt/hostedtoolcache/cargo
|
||||
RUSTUP_HOME: /opt/hostedtoolcache/rustup
|
||||
|
||||
jobs:
|
||||
audit:
|
||||
name: Dependency audit
|
||||
runs-on: linux-arm64
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
- uses: dtolnay/rust-toolchain@stable
|
||||
- name: cargo audit
|
||||
run: |
|
||||
command -v cargo-audit >/dev/null || cargo install cargo-audit --locked
|
||||
cargo audit
|
||||
|
||||
fuzz:
|
||||
name: Fuzz (${{ matrix.target }})
|
||||
runs-on: linux-arm64
|
||||
env:
|
||||
CARGO_TARGET_DIR: /opt/hostedtoolcache/cargo-target/xexeu-fuzz
|
||||
strategy:
|
||||
fail-fast: false
|
||||
max-parallel: 1
|
||||
matrix:
|
||||
target: [der_certificate, service_banner, vuln_feeds, operator_input]
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
- uses: dtolnay/rust-toolchain@nightly
|
||||
- name: cargo-fuzz
|
||||
run: command -v cargo-fuzz >/dev/null || cargo install cargo-fuzz --locked
|
||||
- name: Fuzz for 10 minutes
|
||||
run: |
|
||||
corpus=/opt/hostedtoolcache/fuzz-corpus/xexeu/${{ matrix.target }}
|
||||
mkdir -p "$corpus"
|
||||
cargo +nightly fuzz run "${{ matrix.target }}" "$corpus" -- -max_total_time=600
|
||||
# A crash fails the job; its input is printed here so it can be replayed
|
||||
# with `cargo +nightly fuzz run <target> <file>` and turned into a test.
|
||||
- name: Crash input
|
||||
if: failure()
|
||||
run: |
|
||||
for f in fuzz/artifacts/${{ matrix.target }}/*; do
|
||||
[ -f "$f" ] || continue
|
||||
echo "== $f"; base64 -w0 "$f"; echo
|
||||
done
|
||||
@@ -8,3 +8,7 @@ __pycache__/
|
||||
.DS_Store
|
||||
/data
|
||||
/config
|
||||
/fuzz/target
|
||||
/fuzz/corpus
|
||||
/fuzz/artifacts
|
||||
/fuzz/coverage
|
||||
@@ -22,6 +22,18 @@ scripts/check.sh
|
||||
|
||||
The interface source text is Portuguese. English translations reside in `apps/gui/ui/i18n-en.js` and are applied at runtime by `i18n.js`. When adding or updating visible text, run `node scripts/check-ui-i18n.mjs` and supply the English translation pair.
|
||||
|
||||
## Untrusted input and fuzzing
|
||||
|
||||
Everything Xexéu reads from the network, from feeds or from the group form is hostile until parsed: it must come back as an error, never a panic. `crates/xexeu-core/tests/untrusted_input.rs` checks this with property tests on every `cargo test`, and the diff engine's guarantees (no removal from a partial sweep, no closed port that was not scanned, disappearance exactly at the threshold) are properties in `diff.rs`. A new parser gets an entry in both places plus a target in `fuzz/`.
|
||||
|
||||
For longer runs (nightly toolchain and `cargo install cargo-fuzz`):
|
||||
|
||||
```bash
|
||||
cargo +nightly fuzz run der_certificate -- -max_total_time=300
|
||||
```
|
||||
|
||||
The `Weekly` workflow fuzzes every target for ten minutes on a persistent corpus and runs `cargo audit`. A crash becomes a regression test before the fix.
|
||||
|
||||
## Documentation
|
||||
|
||||
Always maintain document pairs: every `*.md` and `docs/*` file has an English version and a Portuguese version (`*.pt-BR.md`, `docs/pt-BR/`). File names are translated only when the word changes (e.g. `architecture.md` → `arquitetura.md`).
|
||||
|
||||
@@ -22,6 +22,18 @@ scripts/check.sh
|
||||
|
||||
O texto original da interface é em português. O inglês reside em `apps/gui/ui/i18n-en.js`, aplicado em runtime por `i18n.js`. Ao adicionar texto visível, execute `node scripts/check-ui-i18n.mjs` e forneça o par correspondente em inglês.
|
||||
|
||||
## Entrada não confiável e fuzzing
|
||||
|
||||
Tudo o que o Xexéu lê da rede, dos feeds ou do formulário de grupos é hostil até ser interpretado: precisa voltar como erro, nunca como pânico. O `crates/xexeu-core/tests/untrusted_input.rs` verifica isso com testes de propriedade a cada `cargo test`, e as garantias do motor de diff (nenhuma remoção a partir de varredura parcial, nenhuma porta fechada que não foi varrida, desaparecimento exatamente no limite) são propriedades em `diff.rs`. Um parser novo ganha entrada nos dois lugares e um alvo em `fuzz/`.
|
||||
|
||||
Para corridas longas (toolchain nightly e `cargo install cargo-fuzz`):
|
||||
|
||||
```bash
|
||||
cargo +nightly fuzz run der_certificate -- -max_total_time=300
|
||||
```
|
||||
|
||||
O workflow `Weekly` fuzza cada alvo por dez minutos sobre um corpus persistente e roda o `cargo audit`. Um crash vira teste de regressão antes da correção.
|
||||
|
||||
## Documentação
|
||||
|
||||
Mantenha sempre os pares: todo arquivo `*.md` e `docs/*` possui uma versão em inglês e uma em português (`*.pt-BR.md`, `docs/pt-BR/`). Nomes de arquivo são traduzidos apenas quando a palavra de fato muda (ex: `architecture.md` → `arquitetura.md`).
|
||||
|
||||
Generated
+145
-3
@@ -240,6 +240,25 @@ version = "0.23.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac07cdecf99051d9a5238b80f35af32cdeba5b336e55d957b318b50137e18da5"
|
||||
|
||||
[[package]]
|
||||
name = "bit-set"
|
||||
version = "0.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "56d87354e4229f54a44f7bf2435906a4656dba36026ab6eaca629a2c436a691c"
|
||||
dependencies = [
|
||||
"bit-vec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bit-vec"
|
||||
version = "0.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5727b15fa97d4f4fee0a3b7c3d550ed0269f54329207b86388de918604e31269"
|
||||
dependencies = [
|
||||
"borsh",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.13.2"
|
||||
@@ -255,6 +274,30 @@ dependencies = [
|
||||
"generic-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "borsh"
|
||||
version = "1.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "553c5d846a6ba5150c65e3b1b8ec073bcf1abc20f9b7220de384a4443ea4e20a"
|
||||
dependencies = [
|
||||
"borsh-derive",
|
||||
"bytes",
|
||||
"cfg_aliases",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "borsh-derive"
|
||||
version = "1.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "12cdfe656708a01f89b451a7d36466e6fe6c414de0aa18fc54f864f6f9ca9f56"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"proc-macro-crate",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.20.3"
|
||||
@@ -386,6 +429,12 @@ version = "0.8.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
|
||||
|
||||
[[package]]
|
||||
name = "core_detect"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f8f80099a98041a3d1622845c271458a2d73e688351bf3cb999266764b81d48"
|
||||
|
||||
[[package]]
|
||||
name = "cpufeatures"
|
||||
version = "0.2.17"
|
||||
@@ -1164,6 +1213,15 @@ dependencies = [
|
||||
"zerovec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-crate"
|
||||
version = "3.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e67ba7e9b2b56446f1d419b1d807906278ffa1a658a8a5d8a39dcb1f5a78614f"
|
||||
dependencies = [
|
||||
"toml_edit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.107"
|
||||
@@ -1173,6 +1231,32 @@ dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proptest"
|
||||
version = "1.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b8530004ccb15eae51c7e40009fbe317f341f804db54dc033eec1c50be28cfa0"
|
||||
dependencies = [
|
||||
"bit-set",
|
||||
"bit-vec",
|
||||
"bitflags",
|
||||
"chacha20",
|
||||
"core_detect",
|
||||
"num-traits",
|
||||
"rand",
|
||||
"rand_xorshift",
|
||||
"regex-syntax",
|
||||
"rusty-fork",
|
||||
"tempfile",
|
||||
"unarray",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quick-error"
|
||||
version = "1.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
|
||||
|
||||
[[package]]
|
||||
name = "quinn"
|
||||
version = "0.11.11"
|
||||
@@ -1276,6 +1360,21 @@ dependencies = [
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_xorshift"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "60aa6af80be32871323012e02e6e65f8a7cc7890931ae421d217ad8fe0df2ccf"
|
||||
dependencies = [
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.8.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4"
|
||||
|
||||
[[package]]
|
||||
name = "reqwest"
|
||||
version = "0.12.28"
|
||||
@@ -1421,6 +1520,18 @@ version = "1.0.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f"
|
||||
|
||||
[[package]]
|
||||
name = "rusty-fork"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cc6bf79ff24e648f6da1f8d1f011e9cac26491b619e6b9280f2b47f1774e6ee2"
|
||||
dependencies = [
|
||||
"fnv",
|
||||
"quick-error",
|
||||
"tempfile",
|
||||
"wait-timeout",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.23"
|
||||
@@ -1677,7 +1788,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd"
|
||||
dependencies = [
|
||||
"fastrand",
|
||||
"getrandom 0.3.4",
|
||||
"getrandom 0.4.3",
|
||||
"once_cell",
|
||||
"rustix",
|
||||
"windows-sys 0.61.2",
|
||||
@@ -1809,6 +1920,18 @@ dependencies = [
|
||||
"serde_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_edit"
|
||||
version = "0.25.17+spec-1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e3641d5bbb5349a79e1020a242d251efbc546ad8048d133958323ce9c40a9c9c"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"toml_datetime",
|
||||
"toml_parser",
|
||||
"winnow",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_parser"
|
||||
version = "1.1.5+spec-1.1.0"
|
||||
@@ -1919,6 +2042,12 @@ dependencies = [
|
||||
"web-time",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unarray"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.27"
|
||||
@@ -1976,6 +2105,15 @@ version = "0.9.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
||||
|
||||
[[package]]
|
||||
name = "wait-timeout"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09ac3b126d3914f9849036f826e054cbabdc8519970b8998ddaf3b5bd3c65f11"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "want"
|
||||
version = "0.3.2"
|
||||
@@ -2230,6 +2368,9 @@ name = "winnow"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "23b97319f7b8343df12cc98938e5c3eb436064524c8d2b4e30a1d3a36eecdf81"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen"
|
||||
@@ -2245,7 +2386,7 @@ checksum = "3ad82d2a33cdc9674dc7465672f271e096168fcdbe0f799d9e6db8c5892679dc"
|
||||
|
||||
[[package]]
|
||||
name = "xexeu-cli"
|
||||
version = "1.0.0"
|
||||
version = "1.1.0"
|
||||
dependencies = [
|
||||
"axum",
|
||||
"chrono",
|
||||
@@ -2260,7 +2401,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "xexeu-core"
|
||||
version = "1.0.0"
|
||||
version = "1.1.0"
|
||||
dependencies = [
|
||||
"arrow-array",
|
||||
"arrow-schema",
|
||||
@@ -2268,6 +2409,7 @@ dependencies = [
|
||||
"croner",
|
||||
"ipnet",
|
||||
"parquet",
|
||||
"proptest",
|
||||
"reqwest",
|
||||
"rusqlite",
|
||||
"rustls",
|
||||
|
||||
@@ -28,3 +28,6 @@ thiserror = "1"
|
||||
ulid = { version = "3", features = ["serde"] }
|
||||
toml = "1"
|
||||
tokio = { version = "1", features = ["io-util", "macros", "net", "rt", "rt-multi-thread", "sync", "time"] }
|
||||
|
||||
[dev-dependencies]
|
||||
proptest = "1"
|
||||
@@ -1043,4 +1043,174 @@ mod tests {
|
||||
let findings = [1_u8, 2, 3];
|
||||
assert!(diff_vulnerabilities(&findings, &findings).is_empty());
|
||||
}
|
||||
|
||||
// Property tests for the guarantees in the module docs, over generated
|
||||
// previous states and sweeps inside 203.0.113.0/28.
|
||||
mod properties {
|
||||
use super::*;
|
||||
use proptest::prelude::*;
|
||||
|
||||
const SCOPE: &str = "203.0.113.0/28";
|
||||
|
||||
fn host_ip(index: u8) -> IpAddr {
|
||||
IpAddr::from([203, 0, 113, index % 16])
|
||||
}
|
||||
|
||||
fn previous_state() -> impl Strategy<Value = CurrentState> {
|
||||
prop::collection::btree_map(
|
||||
0u8..16,
|
||||
(0u32..3, prop::collection::btree_set(1u16..40, 0..4)),
|
||||
0..8,
|
||||
)
|
||||
.prop_map(|hosts| {
|
||||
CurrentState::new(
|
||||
hosts
|
||||
.into_iter()
|
||||
.map(|(index, (absences, ports))| {
|
||||
asset(
|
||||
&host_ip(index).to_string(),
|
||||
absences,
|
||||
ports.into_iter().map(open_port).collect(),
|
||||
)
|
||||
})
|
||||
.collect(),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn host_state() -> impl Strategy<Value = HostState> {
|
||||
prop_oneof![Just(HostState::Alive), Just(HostState::Unresponsive)]
|
||||
}
|
||||
|
||||
fn port_state() -> impl Strategy<Value = PortState> {
|
||||
prop_oneof![
|
||||
Just(PortState::Open),
|
||||
Just(PortState::Closed),
|
||||
Just(PortState::Filtered)
|
||||
]
|
||||
}
|
||||
|
||||
/// Hosts observed by a sweep and, for each, the ports it scanned.
|
||||
type Observed = Vec<(u8, HostState, Vec<(u16, PortState)>)>;
|
||||
|
||||
fn observed() -> impl Strategy<Value = Observed> {
|
||||
prop::collection::btree_map(
|
||||
0u8..16,
|
||||
(
|
||||
host_state(),
|
||||
prop::collection::btree_map(1u16..40, port_state(), 0..5),
|
||||
),
|
||||
0..10,
|
||||
)
|
||||
.prop_map(|hosts| {
|
||||
hosts
|
||||
.into_iter()
|
||||
.map(|(index, (state, ports))| (index, state, ports.into_iter().collect()))
|
||||
.collect()
|
||||
})
|
||||
}
|
||||
|
||||
fn sweep(status: SweepStatus, observed: &Observed) -> SweepBatch {
|
||||
batch(
|
||||
status,
|
||||
&[SCOPE],
|
||||
observed
|
||||
.iter()
|
||||
.map(|(index, state, _)| (host_ip(*index), *state))
|
||||
.collect(),
|
||||
observed
|
||||
.iter()
|
||||
.filter(|(_, state, _)| *state == HostState::Alive)
|
||||
.map(|(index, _, ports)| (host_ip(*index), ports.clone()))
|
||||
.collect(),
|
||||
vec![],
|
||||
)
|
||||
}
|
||||
|
||||
fn is_removal(kind: EventKind) -> bool {
|
||||
matches!(kind, EventKind::HostDisappeared | EventKind::PortClosed)
|
||||
}
|
||||
|
||||
proptest! {
|
||||
#[test]
|
||||
fn partial_or_aborted_sweeps_never_remove_anything(
|
||||
previous in previous_state(),
|
||||
observed in observed(),
|
||||
aborted in any::<bool>(),
|
||||
threshold in 1u32..4,
|
||||
) {
|
||||
let status = if aborted { SweepStatus::Aborted } else { SweepStatus::Partial };
|
||||
let options = DiffOptions { absences_before_disappear: threshold };
|
||||
let result = diff_batch(&previous, &sweep(status, &observed), &options).unwrap();
|
||||
prop_assert!(result.events.iter().all(|event| !is_removal(event.kind)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_port_is_closed_only_if_the_sweep_scanned_it(
|
||||
previous in previous_state(),
|
||||
observed in observed(),
|
||||
threshold in 1u32..4,
|
||||
) {
|
||||
let options = DiffOptions { absences_before_disappear: threshold };
|
||||
let result = diff_batch(&previous, &sweep(SweepStatus::Complete, &observed), &options).unwrap();
|
||||
for event in result.events.iter().filter(|event| event.kind == EventKind::PortClosed) {
|
||||
let port = event.service.as_ref().expect("port events carry the service").port;
|
||||
let scanned = observed.iter().any(|(index, state, ports)| {
|
||||
event.asset_key == format!("dmz/{}", host_ip(*index))
|
||||
&& *state == HostState::Alive
|
||||
&& ports.iter().any(|(scanned, _)| *scanned == port)
|
||||
});
|
||||
prop_assert!(scanned, "{} closed port {port} it never scanned", event.asset_key);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_same_inputs_give_the_same_events(
|
||||
previous in previous_state(),
|
||||
observed in observed(),
|
||||
) {
|
||||
let batch = sweep(SweepStatus::Complete, &observed);
|
||||
let options = DiffOptions::default();
|
||||
let summary = |result: DiffResult| {
|
||||
result
|
||||
.events
|
||||
.into_iter()
|
||||
.map(|event| (event.kind, event.asset_key, event.service.map(|s| s.port)))
|
||||
.collect::<Vec<_>>()
|
||||
};
|
||||
let first = summary(diff_batch(&previous, &batch, &options).unwrap());
|
||||
let second = summary(diff_batch(&previous, &batch, &options).unwrap());
|
||||
prop_assert_eq!(first, second);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_silent_host_disappears_exactly_at_the_threshold(threshold in 1u32..5) {
|
||||
let options = DiffOptions { absences_before_disappear: threshold };
|
||||
let silent: Observed = vec![(5, HostState::Unresponsive, vec![])];
|
||||
let mut state = CurrentState::new(vec![asset("203.0.113.5", 0, vec![open_port(22)])]);
|
||||
for round in 1..=threshold + 2 {
|
||||
let result = diff_batch(&state, &sweep(SweepStatus::Complete, &silent), &options).unwrap();
|
||||
let gone = result.events.iter().filter(|e| e.kind == EventKind::HostDisappeared).count();
|
||||
prop_assert_eq!(gone, usize::from(round == threshold), "round {}", round);
|
||||
state = CurrentState::new(result.state);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn assets_outside_the_swept_scope_are_untouched(
|
||||
observed in observed(),
|
||||
absences in 0u32..3,
|
||||
) {
|
||||
let outside = asset("198.51.100.7", absences, vec![open_port(443)]);
|
||||
let previous = CurrentState::new(vec![outside.clone()]);
|
||||
let result = diff_batch(&previous, &sweep(SweepStatus::Complete, &observed), &DiffOptions::default()).unwrap();
|
||||
prop_assert!(result.events.iter().all(|event| event.asset_key != outside.asset_key));
|
||||
// `state` holds the assets the sweep covered (storage upserts it), so an
|
||||
// asset outside the scope is either left out or passed through unchanged.
|
||||
if let Some(kept) = result.state.iter().find(|asset| asset.asset_key == outside.asset_key) {
|
||||
prop_assert_eq!(kept, &outside);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -73,7 +73,8 @@ impl ServerCertVerifier for CertCaptureVerifier {
|
||||
}
|
||||
}
|
||||
|
||||
fn extract_server_header(response: &str) -> Option<String> {
|
||||
/// Value of the `Server:` header in a raw HTTP response, if any.
|
||||
pub fn extract_server_header(response: &str) -> Option<String> {
|
||||
for line in response.lines() {
|
||||
let trimmed = line.trim();
|
||||
if trimmed.is_empty() {
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
# Seeds for failure cases proptest has generated in the past. It is
|
||||
# automatically read and these particular cases re-run before any
|
||||
# novel cases are generated.
|
||||
#
|
||||
# It is recommended to check this file in to source control so that
|
||||
# everyone who runs the test benefits from these saved cases.
|
||||
cc db1aea305a4a09f7917f604c37fb8b18b04241a9a8101a9e7083a6634fae4848 # shrinks to serial = [0], filler = [], not_after = [226, 130, 172, 195, 169, 45, 90, 45, 45, 195, 169, 226, 130, 172, 48, 90], utc = false, flips = [], cut = Index(0)
|
||||
@@ -0,0 +1,204 @@
|
||||
//! Parsers that read data Xexéu does not control (service banners, HTTP
|
||||
//! responses, certificates, NVD/KEV feeds, operator-typed targets and cron
|
||||
//! expressions) must reject bad input with an error, never panic.
|
||||
//!
|
||||
//! These run on stable with every `cargo test`; `fuzz/` drives the same entry
|
||||
//! points with cargo-fuzz for longer runs.
|
||||
|
||||
use std::io::Cursor;
|
||||
use std::net::IpAddr;
|
||||
|
||||
use proptest::prelude::*;
|
||||
use xexeu_core::scan::fingerprint::extract_server_header;
|
||||
use xexeu_core::schedule::{CronSpec, Jitter};
|
||||
use xexeu_core::targets::{
|
||||
merge_ranges, parse_exclusion, parse_scope_entry, parse_target, IpRange,
|
||||
};
|
||||
use xexeu_core::vuln::checks::{evaluate_http_admin_response, parse_x509_der_not_after};
|
||||
use xexeu_core::vuln::feeds::{parse_kev_reader, parse_nvd_json, Cpe};
|
||||
use xexeu_core::vuln::matcher::parse_banner_to_cpe;
|
||||
|
||||
/// DER TLV with a definite length, short or long form.
|
||||
fn tlv(tag: u8, body: &[u8]) -> Vec<u8> {
|
||||
let mut out = vec![tag];
|
||||
let len = body.len();
|
||||
if len < 0x80 {
|
||||
out.push(len as u8);
|
||||
} else {
|
||||
let bytes: Vec<u8> = len
|
||||
.to_be_bytes()
|
||||
.iter()
|
||||
.copied()
|
||||
.skip_while(|b| *b == 0)
|
||||
.collect();
|
||||
out.push(0x80 | bytes.len() as u8);
|
||||
out.extend(bytes);
|
||||
}
|
||||
out.extend_from_slice(body);
|
||||
out
|
||||
}
|
||||
|
||||
/// A certificate skeleton shaped like the parser expects, with arbitrary contents.
|
||||
fn certificate(serial: &[u8], filler: &[u8], not_after: &[u8], utc: bool) -> Vec<u8> {
|
||||
let time_tag = if utc { 0x17 } else { 0x18 };
|
||||
let validity = [tlv(time_tag, b"240101000000Z"), tlv(time_tag, not_after)].concat();
|
||||
let tbs = [
|
||||
tlv(0xA0, &tlv(0x02, &[2])),
|
||||
tlv(0x02, serial),
|
||||
tlv(0x30, filler),
|
||||
tlv(0x30, filler),
|
||||
tlv(0x30, &validity),
|
||||
]
|
||||
.concat();
|
||||
tlv(0x30, &tlv(0x30, &tbs))
|
||||
}
|
||||
|
||||
fn addr(low: u16) -> IpAddr {
|
||||
IpAddr::from([10, 0, (low >> 8) as u8, low as u8])
|
||||
}
|
||||
|
||||
fn range((start, len): (u16, u16)) -> IpRange {
|
||||
IpRange::new(addr(start), addr(start.saturating_add(len))).expect("start <= end")
|
||||
}
|
||||
|
||||
/// Found by `cargo fuzz run der_certificate`: a validity time with a multi-byte
|
||||
/// UTF-8 character used to panic on a byte-offset slice.
|
||||
#[test]
|
||||
fn non_ascii_validity_is_rejected() {
|
||||
for (stamp, utc) in [("20240ţ0101000000Z", false), ("2401ţ0100000Z", true)] {
|
||||
let der = certificate(&[1], b"x", stamp.as_bytes(), utc);
|
||||
assert!(parse_x509_der_not_after(&der).is_err(), "{stamp}");
|
||||
}
|
||||
}
|
||||
|
||||
proptest! {
|
||||
#![proptest_config(ProptestConfig::with_cases(512))]
|
||||
|
||||
#[test]
|
||||
fn der_parser_never_panics_on_bytes(bytes in prop::collection::vec(any::<u8>(), 0..512)) {
|
||||
let _ = parse_x509_der_not_after(&bytes);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn der_parser_never_panics_on_corrupted_certificates(
|
||||
serial in prop::collection::vec(any::<u8>(), 1..24),
|
||||
filler in prop::collection::vec(any::<u8>(), 0..300),
|
||||
not_after in prop_oneof![
|
||||
prop::collection::vec(any::<u8>(), 0..24),
|
||||
"[0-9ţé€Z.+-]{10,20}".prop_map(String::into_bytes),
|
||||
],
|
||||
utc in any::<bool>(),
|
||||
flips in prop::collection::vec((any::<prop::sample::Index>(), any::<u8>()), 0..4),
|
||||
cut in any::<prop::sample::Index>(),
|
||||
) {
|
||||
let mut der = certificate(&serial, &filler, ¬_after, utc);
|
||||
let _ = parse_x509_der_not_after(&der);
|
||||
for (index, byte) in flips {
|
||||
let at = index.index(der.len());
|
||||
der[at] = byte;
|
||||
}
|
||||
let _ = parse_x509_der_not_after(&der);
|
||||
let _ = parse_x509_der_not_after(&der[..cut.index(der.len() + 1)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn well_formed_validity_is_read_back(
|
||||
year in 50u32..150,
|
||||
month in 1u32..13,
|
||||
day in 1u32..29,
|
||||
hour in 0u32..24,
|
||||
) {
|
||||
let (stamp, utc) = if year < 100 {
|
||||
(format!("{year:02}{month:02}{day:02}{hour:02}0000Z"), true)
|
||||
} else {
|
||||
(format!("{}{month:02}{day:02}{hour:02}0000Z", 1900 + year), false)
|
||||
};
|
||||
let der = certificate(&[1], b"x", stamp.as_bytes(), utc);
|
||||
prop_assert!(parse_x509_der_not_after(&der).is_ok(), "{}", stamp);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn banner_and_http_parsers_never_panic(text in ".{0,300}", port in any::<u16>()) {
|
||||
let _ = parse_banner_to_cpe(&text);
|
||||
let _ = extract_server_header(&text);
|
||||
let _ = evaluate_http_admin_response(port, &text);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn banner_parser_never_panics_on_service_like_text(
|
||||
product in "(SSH-2\\.0-OpenSSH|Apache|nginx|Microsoft-IIS|lighttpd|vsFTPd)[_/ -]?",
|
||||
version in "[0-9a-z.p_-]{0,20}",
|
||||
tail in "[ -~]{0,40}",
|
||||
) {
|
||||
let _ = parse_banner_to_cpe(&format!("{product}{version}{tail}"));
|
||||
let _ = extract_server_header(&format!(
|
||||
"HTTP/1.1 200 OK\r\nServer: {product}{version}{tail}\r\n\r\n"
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn feed_parsers_never_panic(
|
||||
bytes in prop::collection::vec(any::<u8>(), 0..1024),
|
||||
text in ".{0,400}",
|
||||
) {
|
||||
let _ = parse_nvd_json(Cursor::new(&bytes));
|
||||
let _ = parse_kev_reader(Cursor::new(&bytes));
|
||||
let _ = parse_nvd_json(Cursor::new(text.as_bytes()));
|
||||
let _ = parse_kev_reader(Cursor::new(text.as_bytes()));
|
||||
let _ = Cpe::parse(&text);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cpe_parser_never_panics_on_cpe_like_text(
|
||||
parts in prop::collection::vec("[a-z0-9_.*\\\\:-]{0,12}", 0..14),
|
||||
) {
|
||||
let _ = Cpe::parse(&format!("cpe:2.3:{}", parts.join(":")));
|
||||
let _ = Cpe::parse(&format!("cpe:/{}", parts.join(":")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn operator_input_parsers_never_panic(text in ".{0,80}", like in "[0-9a-f.:/ -]{0,48}") {
|
||||
for input in [&text, &like] {
|
||||
let _ = parse_target(input);
|
||||
let _ = parse_exclusion(input);
|
||||
let _ = parse_scope_entry(input);
|
||||
let _ = CronSpec::parse(input);
|
||||
let _ = Jitter::parse(input);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ipv4_cidr_covers_exactly_its_block(
|
||||
a in any::<u8>(), b in any::<u8>(), c in any::<u8>(), d in any::<u8>(),
|
||||
prefix in 8u8..=32,
|
||||
) {
|
||||
let spec = parse_target(&format!("{a}.{b}.{c}.{d}/{prefix}"));
|
||||
prop_assert!(spec.is_ok());
|
||||
let range = spec.unwrap().range().expect("CIDR targets are ranges");
|
||||
prop_assert_eq!(range.count(), 1u128 << (32 - prefix));
|
||||
prop_assert!(range.contains([a, b, c, d].into()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn subtract_and_merge_keep_membership(
|
||||
bounds in prop::collection::vec((any::<u16>(), 0u16..512), 1..6),
|
||||
hole in (any::<u16>(), 0u16..512),
|
||||
probes in prop::collection::vec(any::<u16>(), 16),
|
||||
) {
|
||||
let ranges: Vec<IpRange> = bounds.into_iter().map(range).collect();
|
||||
let hole = range(hole);
|
||||
let merged = merge_ranges(ranges.clone());
|
||||
for pair in merged.windows(2) {
|
||||
prop_assert!(pair[0].end() < pair[1].start(), "merged ranges overlap or are unsorted");
|
||||
}
|
||||
for probe in probes {
|
||||
let ip = addr(probe);
|
||||
let inside = ranges.iter().any(|range| range.contains(ip));
|
||||
prop_assert_eq!(merged.iter().any(|range| range.contains(ip)), inside);
|
||||
for range in &ranges {
|
||||
let kept = range.subtract(&hole).iter().any(|part| part.contains(ip));
|
||||
prop_assert_eq!(kept, range.contains(ip) && !hole.contains(ip));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Generated
+2203
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,43 @@
|
||||
[package]
|
||||
name = "xexeu-fuzz"
|
||||
version = "0.0.0"
|
||||
publish = false
|
||||
edition = "2021"
|
||||
|
||||
[package.metadata]
|
||||
cargo-fuzz = true
|
||||
|
||||
[dependencies]
|
||||
libfuzzer-sys = "0.4"
|
||||
xexeu-core = { path = "../crates/xexeu-core" }
|
||||
|
||||
# Kept out of the main workspace: it needs a nightly toolchain.
|
||||
[workspace]
|
||||
|
||||
[[bin]]
|
||||
name = "der_certificate"
|
||||
path = "fuzz_targets/der_certificate.rs"
|
||||
test = false
|
||||
doc = false
|
||||
bench = false
|
||||
|
||||
[[bin]]
|
||||
name = "service_banner"
|
||||
path = "fuzz_targets/service_banner.rs"
|
||||
test = false
|
||||
doc = false
|
||||
bench = false
|
||||
|
||||
[[bin]]
|
||||
name = "vuln_feeds"
|
||||
path = "fuzz_targets/vuln_feeds.rs"
|
||||
test = false
|
||||
doc = false
|
||||
bench = false
|
||||
|
||||
[[bin]]
|
||||
name = "operator_input"
|
||||
path = "fuzz_targets/operator_input.rs"
|
||||
test = false
|
||||
doc = false
|
||||
bench = false
|
||||
@@ -0,0 +1,9 @@
|
||||
#![no_main]
|
||||
//! TLS certificates come from any host in scope.
|
||||
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
use xexeu_core::vuln::checks::parse_x509_der_not_after;
|
||||
|
||||
fuzz_target!(|der: &[u8]| {
|
||||
let _ = parse_x509_der_not_after(der);
|
||||
});
|
||||
@@ -0,0 +1,15 @@
|
||||
#![no_main]
|
||||
//! Targets, exclusions, scope entries and cron come from the config file and
|
||||
//! from the dashboard's group form.
|
||||
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
use xexeu_core::schedule::{CronSpec, Jitter};
|
||||
use xexeu_core::targets::{parse_exclusion, parse_scope_entry, parse_target};
|
||||
|
||||
fuzz_target!(|text: &str| {
|
||||
let _ = parse_target(text);
|
||||
let _ = parse_exclusion(text);
|
||||
let _ = parse_scope_entry(text);
|
||||
let _ = CronSpec::parse(text);
|
||||
let _ = Jitter::parse(text);
|
||||
});
|
||||
@@ -0,0 +1,13 @@
|
||||
#![no_main]
|
||||
//! Banners and HTTP responses come from any host in scope.
|
||||
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
use xexeu_core::scan::fingerprint::extract_server_header;
|
||||
use xexeu_core::vuln::checks::evaluate_http_admin_response;
|
||||
use xexeu_core::vuln::matcher::parse_banner_to_cpe;
|
||||
|
||||
fuzz_target!(|text: &str| {
|
||||
let _ = parse_banner_to_cpe(text);
|
||||
let _ = extract_server_header(text);
|
||||
let _ = evaluate_http_admin_response(8080, text);
|
||||
});
|
||||
@@ -0,0 +1,15 @@
|
||||
#![no_main]
|
||||
//! NVD and KEV feeds are downloaded or imported from files.
|
||||
|
||||
use std::io::Cursor;
|
||||
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
use xexeu_core::vuln::feeds::{parse_kev_reader, parse_nvd_json, Cpe};
|
||||
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
let _ = parse_nvd_json(Cursor::new(data));
|
||||
let _ = parse_kev_reader(Cursor::new(data));
|
||||
if let Ok(text) = std::str::from_utf8(data) {
|
||||
let _ = Cpe::parse(text);
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user