netsec-scan: second-tick gate for web-port egress novelty (kill CDN churn)

One CI run produced 20 one-shot AWS/GitHub CDN destinations in a single 5-minute
tick (21-line message, nothing reached the operator only because delivery was
unresolved). First-seen tuples now carry per-tick observation counts in state:
web ports (80/443/8080/8443) need two distinct ticks before alerting, non-web
ports and any DROPPED verdict still alert on first sight. A beacon/exfil
destination is retried; CDN rotation is not.

Also: cron deliver switched to local because this profile has
platforms.telegram.enabled=false (deliver=telegram errors 'no delivery target
resolved'), and the README now documents that constraint.
This commit is contained in:
sirius 2026-11-27 00:32:25 -05:00
commit be60d74159
6 changed files with 94 additions and 33 deletions

View file

@ -196,7 +196,8 @@ def _window_label(hours: float) -> str:
def rule_egress_first_seen(flows: Iterable[Flow], seen: Dict[str, dict],
now: datetime, window_h: float = None) -> List[Finding]:
counts: Dict[str, dict], now: datetime,
window_h: float = None, tick: int = 0) -> List[Finding]:
"""First-seen egress tuple = candidate beacon/exfil.
Novelty is gated on the **cumulative seen-set only** (fingerprint presence),
@ -204,14 +205,14 @@ def rule_egress_first_seen(flows: Iterable[Flow], seen: Dict[str, dict],
fingerprint from `seen` re-arms the rule, which is what the acceptance
procedure exercises.
The alert says how long this sensor has actually been watching
(`window_h`): the collector caps at 1 GiB, which at the measured ~2 MB/min
is days, not the month the design note assumed. Never imply a longer
baseline than was observed.
`counts` (tuple -> {n, first, last_tick}) exists only to separate one-shot
CDN rotation from a repeat destination: a web-port tuple must be seen in
`EGRESS_WEB_MIN_TICKS` distinct ticks before it is worth a line. Non-web
ports alert immediately, and a `DROPPED` verdict is always HIGH.
A `DROPPED` verdict on a new to-world tuple is its own signal (the pod tried
something that policy refused), so it is keyed and graded separately from
the forwarded traffic for the same destination.
The alert says how long this sensor has actually been watching
(`window_h`): the collector caps at 1 GiB, which is days, not the month the
design note assumed. Never imply a longer baseline than was observed.
"""
out: List[Finding] = []
window = (" (no prior in ~%s of observed flows)" % _window_label(window_h)
@ -220,13 +221,21 @@ def rule_egress_first_seen(flows: Iterable[Flow], seen: Dict[str, dict],
key = _egress_key(flow)
if not key:
continue
entry = counts.get(key)
if entry is None:
entry = {"n": 1, "first": (flow.time or now).isoformat(timespec="seconds"),
"last_tick": tick}
counts[key] = entry
elif entry.get("last_tick") != tick:
entry["n"] = int(entry.get("n", 1)) + 1
entry["last_tick"] = tick
dropped = flow.verdict == "DROPPED"
if dropped:
key += "/dropped"
if flow.dst_port in config.WEB_PORTS and not dropped:
severity = "MEDIUM"
else:
severity = "HIGH"
web = flow.dst_port in config.WEB_PORTS
if web and not dropped and int(entry.get("n", 1)) < config.EGRESS_WEB_MIN_TICKS:
continue # one-shot CDN destination: not worth a line yet
severity = "MEDIUM" if web and not dropped else "HIGH"
finding = Finding(
rule="egress-new-dst", kind="novelty", severity=severity, entity=key,
detail="%s first-seen %s%s" % (key, _ts(flow.time), window),