pub struct PortScanDetector<K>{ /* private fields */ }Expand description
Per-source scanner-likelihood detector.
State is bounded: a source is normally dropped the moment its
λ crosses either threshold, but a source that stays
Inconclusive — one SYN from each of a million spoofed
addresses, say — would otherwise persist forever. At
max_sources the least-recently-touched entry is evicted.
Evicting an Inconclusive source is harmless by the
detector’s own semantics: it restarts at λ = 0, exactly as it
would after a verdict.
Implementations§
Source§impl<K> PortScanDetector<K>
impl<K> PortScanDetector<K>
Sourcepub fn with_params(theta0: f64, theta1: f64, alpha: f64, beta: f64) -> Self
pub fn with_params(theta0: f64, theta1: f64, alpha: f64, beta: f64) -> Self
Custom-tuned: caller supplies success priors + error
rates. Asserts the parameters are in (0, 1) open
intervals.
Sourcepub fn with_capacity(self, max_sources: usize) -> Self
pub fn with_capacity(self, max_sources: usize) -> Self
Cap on concurrently tracked sources (default 10 000).
Only sources still awaiting a verdict occupy a slot — one that crosses either threshold is released immediately. Size this to the number of distinct hosts mid-evaluation you expect, not to your host count.
Sourcepub fn evicted(&self) -> u64
pub fn evicted(&self) -> u64
Sources dropped by the capacity bound rather than by a verdict. A climbing count means scan-like traffic from more distinct sources than the detector can hold — itself worth alerting on.
Trait Implementations§
Source§impl<K> Default for PortScanDetector<K>
impl<K> Default for PortScanDetector<K>
Source§impl<K: KeyFields + Send> Detector<K> for PortScanDetector<SrcHost>
Available on crate feature tracker only.
impl<K: KeyFields + Send> Detector<K> for PortScanDetector<SrcHost>
tracker only.Source§fn on_flow_end(
&mut self,
key: &K,
stats: &FlowStats,
history: &HistoryString,
l4: Option<L4Proto>,
ts: Timestamp,
out: &mut Vec<OwnedAnomaly>,
)
fn on_flow_end( &mut self, key: &K, stats: &FlowStats, history: &HistoryString, l4: Option<L4Proto>, ts: Timestamp, out: &mut Vec<OwnedAnomaly>, )
One TRW observation per finished flow, keyed by
SrcHost. Success derives statelessly from the flow
record (see the module-private flow_succeeded). Emits
only on a Scanner verdict — TRW resets the key’s state
at every terminal verdict, which is natural
re-alert dedup. No-op for keys without a source IP.
Source§fn kind(&self) -> DetectorKind
fn kind(&self) -> DetectorKind
Source§fn on_flow_start(
&mut self,
_key: &K,
_ts: Timestamp,
_out: &mut Vec<OwnedAnomaly>,
)
fn on_flow_start( &mut self, _key: &K, _ts: Timestamp, _out: &mut Vec<OwnedAnomaly>, )
FlowEvent::Started).Source§fn on_flow_established(
&mut self,
_key: &K,
_ts: Timestamp,
_out: &mut Vec<OwnedAnomaly>,
)
fn on_flow_established( &mut self, _key: &K, _ts: Timestamp, _out: &mut Vec<OwnedAnomaly>, )
FlowEvent::Established).Source§fn on_flow_tick(
&mut self,
_key: &K,
_stats: &FlowStats,
_ts: Timestamp,
_out: &mut Vec<OwnedAnomaly>,
)
fn on_flow_tick( &mut self, _key: &K, _stats: &FlowStats, _ts: Timestamp, _out: &mut Vec<OwnedAnomaly>, )
FlowEvent::Tick — only
fires when FlowTrackerConfig::flow_tick_interval is
set). Note tick stats are cumulative; delta-track
inside the detector if you need per-interval values.Source§fn on_dns_query(
&mut self,
_key: &K,
_qname: &str,
_ts: Timestamp,
_out: &mut Vec<OwnedAnomaly>,
)
fn on_dns_query( &mut self, _key: &K, _qname: &str, _ts: Timestamp, _out: &mut Vec<OwnedAnomaly>, )
key. Pre-extracted
&str (e.g. from a DnsMessage::Query’s first question)
— feed it via DetectorRegistry::observe_dns from your
DNS slot drain, resolver log, or any other name source.Source§fn evict_expired(&mut self, _now: Timestamp)
fn evict_expired(&mut self, _now: Timestamp)
now — bounds
memory across key churn.