Files
acaua/crates/acaua-cli/src/main.rs
T
Lucas RayanandClaude Sonnet 5 c64bbbf775 feat: implement Pillars 2-4 and fix a production false-positive in Pillar 1
Pillar 1 v1.1 (shipped earlier) flagged benign browsing bursts as
beaconing: on short captures, grid periods longer than the observed
span never complete a cycle, so significance saturates to 1 and the
score sticks at exactly 0.5. v1.2 caps the grid at a third of the
observed span, requires a minimum number of completed cycles, and
excludes protocols that are periodic by nature (NTP, DNS, mDNS,
ICMP). Validated against 300 seeds per scenario: false positives on
bursty traffic drop from the 290-300/300 that v1.1 produced to 0/300,
with every beacon-detection scenario scoring unchanged.

Add Pillar 2 (persistent/long-lived sessions, with Zeek's fragmented
TCP sessions rejoined after a 5-minute gap), Pillar 3 (DNS tunneling
via Shannon-entropy information volume per subdomain per hour; the
Jensen-Shannon divergence was measured and does not separate tunnels
from benign CDN subdomains, so it stays in the evidence at zero
weight instead of in the score), and Pillar 4 (deterministic
noisy-OR fusion across the three pillars).

The fusion formula was validated against 8 labeled real-traffic
vectors (IoT-23, CTU-Normal) with tolerance <= 1e-4. A known
limitation is kept, not hidden: a benign Philips HUE bulb's strict
periodic polling and a 21.9h session score it above three real C2
hosts. No weight or threshold was tuned to mask this; it is
documented in the architecture docs instead.

Also fixes real bugs found along the way: ingest_dir's partition
count summed file names instead of distinct dates, DuckDB errors
were counted as bad rows, /api/alerts always returned an empty list
regardless of the last analysis, and the dashboard still claimed
every pillar was unimplemented.

Restores four design corrections that were missing from
docs/architecture.md (KL to Jensen-Shannon, the persistent-session
detector, the JA4 licensing boundary, and deterministic reduction
order), and catalogs the public datasets used for validation
(IoT-23, CTU-Normal, Mendeley DTQBC) with their licenses and SHA-256
checksums under research/validation/.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VAyr8d7HuAdUGB6aA5xmDD
2026-11-01 00:28:54 -03:00

142 lines
4.4 KiB
Rust

mod web;
use acaua_core::{doctor, update, zeek};
use clap::{Parser, Subcommand};
use std::path::PathBuf;
#[derive(Parser)]
#[command(
name = "acaua",
about = "Acauã — caça determinística a ameaças em rede",
version
)]
struct Cli {
#[command(subcommand)]
command: Command,
}
#[derive(Subcommand)]
enum Command {
Serve {
#[arg(long, default_value = "127.0.0.1:8787")]
bind: String,
#[arg(long, default_value = ".acaua")]
data_dir: PathBuf,
},
Analyze {
directory: PathBuf,
#[arg(long, default_value = ".acaua")]
data_dir: PathBuf,
#[arg(long)]
json: bool,
},
Doctor {
#[arg(long)]
json: bool,
},
Update,
}
#[tokio::main]
async fn main() {
let cli = Cli::parse();
if let Err(error) = run(cli).await {
eprintln!("erro: {error}");
std::process::exit(1);
}
}
async fn run(cli: Cli) -> acaua_core::Result<()> {
match cli.command {
Command::Serve { bind, data_dir } => web::serve(&bind, data_dir).await,
Command::Analyze {
directory,
data_dir,
json,
} => {
let report = zeek::analyze_dir(&directory, &data_dir)?;
if json {
println!("{}", serde_json::to_string_pretty(&report)?);
} else {
println!("diretório: {}", report.directory);
println!("logs lidos: {}", report.logs_seen);
println!("registros: {}", report.records);
println!("alertas: {}", report.alerts.len());
for alert in &report.alerts {
println!(" [{:.3}] {}", alert.score, alert.summary);
}
if !report.hosts.is_empty() {
println!("hosts:");
for host in report.hosts.iter().take(10) {
let m1 = host
.terms
.iter()
.find(|t| t.pillar == 1)
.map(|t| t.m)
.unwrap_or(0.0);
let m2 = host
.terms
.iter()
.find(|t| t.pillar == 2)
.map(|t| t.m)
.unwrap_or(0.0);
let m3 = host
.terms
.iter()
.find(|t| t.pillar == 3)
.map(|t| t.m)
.unwrap_or(0.0);
println!(
" [{:.3}] {:<18} {:.3}/{:.3}/{:.3}",
host.score, host.orig_h, m1, m2, m3
);
}
}
println!("estado: {}", report.status);
}
Ok(())
}
Command::Doctor { json } => {
let report = doctor::run();
if json {
println!("{}", serde_json::to_string_pretty(&report)?);
} else {
for check in &report.checks {
println!(
"{:<10} {:<5} {}",
check.name,
if check.ok { "ok" } else { "falha" },
check.detail
);
}
println!("estado: {}", report.status);
}
Ok(())
}
Command::Update => {
let status = update::check(env!("CARGO_PKG_VERSION"))?;
println!(
"versão atual: {} | última: {}",
status.current_version,
status.latest_version.as_deref().unwrap_or("desconhecida")
);
println!(
"atualização disponível: {}",
if status.update_available {
"sim"
} else {
"não"
}
);
if status.update_available {
if std::env::var("ACAUA_RUNTIME").as_deref() == Ok("container") {
println!("para atualizar: docker compose pull && docker compose up -d");
} else {
println!("para atualizar: baixe a nova imagem ou recompile a partir da tag");
}
}
Ok(())
}
}
}