# Architecture **English** · [Português](pt-BR/arquitetura.md) Xexéu is a lightweight, continuous attack surface management and vulnerability audit system. It follows a decoupled two-service architecture distributed via Docker Compose: a privileged packet emitter (`scanner`) and an unprivileged analytical server (`xexeu`). ## Technology Stack | Layer | Component | Rationale | |---|---|---| | Core Engine & CLI | Rust 2021 (MSRV 1.88) | Memory safety, native networking performance, single binary deployment. | | API Layer | Axum + Tokio | Asynchronous HTTP service with minimal overhead. | | Web Dashboard | Vanilla HTML/CSS/JS | Zero-dependency frontend embedded directly into the binary via `rust-embed`. | | Storage Engine | DuckDB + Parquet | Embedded columnar storage, fast analytic queries, dynamic linking to precompiled `libduckdb.so`. | | Deployment | Docker Compose | Strict privilege isolation, container hardening, immutable batches over named volumes. | ## System Topology & Data Flow ``` config/xexeu.toml (ro) │ ┌─────────────────────┴──────────────────────┐ ▼ ▼ scanner (NET_RAW, host net) xexeu (zero capabilities) - Multi-group scheduler - Batch ingestion (:ro) - ARP/ICMP discovery - Scoped diff calculation - TCP SYN & UDP probes - CPE -> CVE matching (NVD/KEV) - Service banner grabbing - State storage (DuckDB) │ - Axum API & embedded web UI ▼ ▲ xexeu-sweeps (Parquet batches + manifest.json) ───┘ ``` ### 1. Privilege Separation - **`scanner`:** Emits raw network packets to discover hosts and scan ports. It requires `network_mode: host` and `cap_add: [NET_RAW]`, but drops all other capabilities (`cap_drop: [ALL]`), runs with a read-only root filesystem, and only has write access to the `xexeu-sweeps` volume. It never opens listening ports, has no API, and does not access DuckDB. - **`xexeu`:** Runs as an unprivileged user (UID 10001) with zero capabilities. It mounts `xexeu-sweeps` as read-only, acts as the **exclusive writer** to DuckDB (`xexeu-data`), correlates findings against local vulnerability feeds, and serves the Axum API and web interface bound to `127.0.0.1:8788`. ### 2. Batch Contract & Idempotency Communication between the scanner and the server occurs through filesystem batches: - Each scan execution writes to `sweeps///observations.parquet`. - Upon successful completion, the scanner atomically creates `manifest.json` containing metadata, scope, and cryptographic hashes. - The server watches the sweeps volume, ingests batches idempotently by checking `sweep_id`, and prunes processed batches based on retention policy. ### 3. Tiered Scheduling & Scope Boundaries Target configuration in `xexeu.toml` decouples asset definitions from execution policies: - **`[escopo]`:** Mandatory boundary. Any target or DNS resolution outside the authorized CIDR blocks causes validation failure and terminates startup. - **`[padrao]`:** Global default cron schedule (e.g. `@daily`), jitter, and shared packet-per-second (`taxa_maxima_pps`) budgets. - **`[[grupo]]`:** Named networks with customized cron cadences (e.g. `*/5 * * * *` for critical DMZs vs. `0 3 * * *` for exhaustive core audits) and assigned probe profiles. ### 4. Scoped Diffs & Event History Rather than generating disconnected point-in-time reports, Xexéu evaluates state differences against the specific scope of the completed scan: - **State Tables:** Maintains deduplicated current state for `assets`, `services`, and `findings`. - **Scoped Diff Algorithm:** Ports outside a group's profile are never marked closed by that group's scan. - **Oscillation Debounce:** Transient network failures require multiple consecutive missed scans (`ausencias_para_sumir`) before emitting `host_sumiu` or `porta_fechada`. - **Event Log:** Immutable append-only log recording surface transitions (`host_novo`, `porta_aberta`, `servico_alterado`, `vulnerabilidade_nova`, `vulnerabilidade_corrigida`) paired with deterministic JSON evidence.