netsec-scan: three-tick web-port gate (2 still leaked ~2 lines per CI build)
Measured on the 00:40 run: a second-tick gate cut a 21-line CDN burst to 2 lines, still noise for a channel whose whole value is being quiet. A beacon/exfil destination persists for hours (rule 8 catches periodicity at >=20 conns/2h), a CDN endpoint used by one job does not survive 15 minutes. Stated cost documented in config + README.
This commit is contained in:
parent
b595d21bec
commit
f4001d589e
3 changed files with 44 additions and 28 deletions
19
README.md
19
README.md
|
|
@ -94,14 +94,17 @@ destination (`…/dropped` in the entity, HIGH): a pod trying to reach a new hos
|
|||
and being refused is a stronger signal than one that succeeded, and collapsing
|
||||
them would hide it behind the forwarded tuple's fingerprint.
|
||||
|
||||
Rule 7 also keeps **web-port novelty** (80/443/8080/8443) on a second-tick gate:
|
||||
a first-seen web destination is only worth a line once it appears in **two**
|
||||
distinct ticks. Measured 2026-11-27: one CI run produced 20 one-shot AWS/GitHub
|
||||
CDN destinations inside a single 5-minute window, which is a 20-line message and
|
||||
exactly how a channel gets muted. CDN rotation is one-shot by nature; a beacon or
|
||||
an exfil destination is retried, so it still fires — a tick later. Non-web ports
|
||||
and any `DROPPED` verdict alert on first sight, and a `DROPPED` web-port tuple is
|
||||
HIGH. Rationale and the two-tick evidence live in `config.EGRESS_WEB_MIN_TICKS`.
|
||||
Rule 7 also keeps **web-port novelty** (80/443/8080/8443) on a **three-tick
|
||||
(~15 min) persistence gate**: a first-seen web destination is only worth a line
|
||||
once it appears in three distinct ticks. Measured 2026-11-27: one CI run
|
||||
produced 20 one-shot AWS/GitHub CDN destinations inside a single 5-minute window
|
||||
(a 20-line message) and a two-tick gate still let ~2 per build through. CDN
|
||||
rotation is one-shot or short-lived; a beacon or an exfil destination persists.
|
||||
**Stated cost**: a smash-and-grab that contacts a brand-new host twice and stops
|
||||
is not alerted on 80/443/8080/8443 — it is on any other port and on any
|
||||
`DROPPED` verdict, and periodic C2 is rule 8's job (`beacon-shape`, ≥ 20 conns
|
||||
in 2 h). Non-web ports alert on first sight; a `DROPPED` web-port tuple is HIGH.
|
||||
Rationale and the measured numbers live in `config.EGRESS_WEB_MIN_TICKS`.
|
||||
|
||||
**Deliberately not implemented** (and why):
|
||||
|
||||
|
|
|
|||
|
|
@ -81,12 +81,15 @@ BEACON_MAX_INTERVAL = 900.0 # mean interval ceiling; 30s beacons fit, 1h cron-i
|
|||
# Severity for a first-seen egress tuple: standard web ports are common CDN
|
||||
# churn, everything else is a much stronger beacon/exfil signal.
|
||||
WEB_PORTS = frozenset({80, 443, 8080, 8443})
|
||||
# A first-seen *web-port* tuple must also be observed in a second tick before it
|
||||
# alerts. Measured 2026-11-27: one CI run produced 20 one-shot AWS/GitHub CDN
|
||||
# destinations in a single 5-minute window, which is a 20-line message and
|
||||
# exactly how a channel gets muted. CDN rotation is one-shot; a beacon or an
|
||||
# exfil destination is retried. Non-web ports still alert on first sight.
|
||||
EGRESS_WEB_MIN_TICKS = 2
|
||||
# A first-seen *web-port* tuple must also be observed in three distinct ticks
|
||||
# (~15 min) before it alerts. Measured 2026-11-27: one CI run produced 20
|
||||
# one-shot AWS/GitHub CDN destinations inside a single 5-minute window, and a
|
||||
# second-tick gate still let ~2 through per build. CDN rotation is one-shot or
|
||||
# short-lived; a beacon or an exfil destination persists. Stated cost: a
|
||||
# smash-and-grab that contacts a brand-new host twice and stops is NOT alerted
|
||||
# on 80/443/8080/8443 (it is on any other port, and on any DROPPED verdict),
|
||||
# and periodic C2 is rule 8's job (`beacon-shape`, >= 20 conns in 2 h).
|
||||
EGRESS_WEB_MIN_TICKS = 3
|
||||
MAX_EGRESS_COUNTS = 20000
|
||||
|
||||
# Re-alert cooldown for *state* tripwires (current-condition rules). Flow
|
||||
|
|
|
|||
|
|
@ -24,17 +24,19 @@ class TestFirstSeenEgress(unittest.TestCase):
|
|||
now or self.NOW, 0.5, tick)
|
||||
|
||||
def warmed(self, flows):
|
||||
"""Baseline tick: populates counts, emits nothing for web ports."""
|
||||
"""Run the ticks *before* the gate fires; emit nothing, fill counts."""
|
||||
counts = {}
|
||||
self.assertEqual(self.evaluate(flows, {}, counts, tick=1), [])
|
||||
for tick in range(1, config.EGRESS_WEB_MIN_TICKS):
|
||||
self.assertEqual(self.evaluate(flows, {}, counts, tick=tick), [])
|
||||
return counts
|
||||
|
||||
def test_web_port_tuple_needs_a_second_tick(self):
|
||||
"""One-shot CDN destinations must not produce a line on first sight."""
|
||||
def test_web_port_tuple_needs_three_ticks(self):
|
||||
"""One-shot / short-lived CDN destinations must not produce a line."""
|
||||
flows = fixture_flows("egress-sample.jsonl")
|
||||
counts = {}
|
||||
self.assertEqual(self.evaluate(flows, {}, counts, tick=1), [])
|
||||
findings = self.evaluate(flows, {}, counts, tick=2)
|
||||
self.assertEqual(self.evaluate(flows, {}, counts, tick=2), [])
|
||||
findings = self.evaluate(flows, {}, counts, tick=3)
|
||||
self.assertTrue(findings)
|
||||
self.assertTrue(all(f.rule == "egress-new-dst" for f in findings))
|
||||
self.assertTrue(all(f.severity == "MEDIUM" for f in findings))
|
||||
|
|
@ -60,27 +62,29 @@ class TestFirstSeenEgress(unittest.TestCase):
|
|||
def test_seen_fingerprint_suppresses_the_rule(self):
|
||||
flows = fixture_flows("egress-sample.jsonl")
|
||||
counts = self.warmed(flows)
|
||||
first = self.evaluate(flows, {}, counts, tick=2)
|
||||
first = self.evaluate(flows, {}, counts, tick=config.EGRESS_WEB_MIN_TICKS)
|
||||
self.assertTrue(first)
|
||||
seen = {f.fingerprint: {"rule": f.rule} for f in first}
|
||||
self.assertEqual(self.evaluate(flows, seen, counts, tick=3), [])
|
||||
self.assertEqual(self.evaluate(flows, seen, counts,
|
||||
tick=config.EGRESS_WEB_MIN_TICKS + 1), [])
|
||||
|
||||
def test_single_fire_then_rearm_when_one_key_is_deleted(self):
|
||||
"""The acceptance procedure: delete exactly one fp -> exactly one line."""
|
||||
from netsec_scan.__main__ import apply_dedupe
|
||||
|
||||
fires = config.EGRESS_WEB_MIN_TICKS
|
||||
flows = fixture_flows("egress-sample.jsonl")
|
||||
counts = self.warmed(flows)
|
||||
seen = {}
|
||||
first = apply_dedupe(self.evaluate(flows, seen, counts, tick=2),
|
||||
first = apply_dedupe(self.evaluate(flows, seen, counts, tick=fires),
|
||||
seen, self.NOW.timestamp(), False)
|
||||
self.assertTrue(first)
|
||||
again = apply_dedupe(self.evaluate(flows, seen, counts, tick=3),
|
||||
again = apply_dedupe(self.evaluate(flows, seen, counts, tick=fires + 1),
|
||||
seen, self.NOW.timestamp(), False)
|
||||
self.assertEqual(again, [])
|
||||
target = first[0].fingerprint
|
||||
del seen[target]
|
||||
rearmed = apply_dedupe(self.evaluate(flows, seen, counts, tick=4),
|
||||
rearmed = apply_dedupe(self.evaluate(flows, seen, counts, tick=fires + 2),
|
||||
seen, self.NOW.timestamp(), False)
|
||||
self.assertEqual([f.fingerprint for f in rearmed], [target])
|
||||
|
||||
|
|
@ -89,20 +93,26 @@ class TestFirstSeenEgress(unittest.TestCase):
|
|||
|
||||
flows = fixture_flows("egress-sample.jsonl")
|
||||
seen = {"deadbeef0000": {"rule": "egress-new-dst", "kind": "novelty"}}
|
||||
apply_dedupe(self.evaluate(flows, seen, self.warmed(flows), tick=2),
|
||||
apply_dedupe(self.evaluate(flows, seen, self.warmed(flows),
|
||||
tick=config.EGRESS_WEB_MIN_TICKS),
|
||||
seen, self.NOW.timestamp(), False)
|
||||
self.assertIn("deadbeef0000", seen)
|
||||
self.assertGreater(len(seen), 1)
|
||||
|
||||
def test_fingerprint_is_stable_across_runs(self):
|
||||
flows = fixture_flows("egress-sample.jsonl")
|
||||
a = self.evaluate(flows, {}, self.warmed(flows), tick=2, now=utc(2026, 11, 27, 5, 20))
|
||||
b = self.evaluate(flows, {}, self.warmed(flows), tick=2, now=utc(2027, 1, 2, 9, 0))
|
||||
fires = config.EGRESS_WEB_MIN_TICKS
|
||||
a = self.evaluate(flows, {}, self.warmed(flows), tick=fires,
|
||||
now=utc(2026, 11, 27, 5, 20))
|
||||
b = self.evaluate(flows, {}, self.warmed(flows), tick=fires,
|
||||
now=utc(2027, 1, 2, 9, 0))
|
||||
self.assertEqual([f.fingerprint for f in a], [f.fingerprint for f in b])
|
||||
|
||||
def test_nonexternal_and_reserved_are_ignored(self):
|
||||
flows = fixture_flows("egress-sample.jsonl")
|
||||
findings = self.evaluate(flows, {}, self.warmed(flows), tick=2)
|
||||
findings = self.evaluate(flows, {}, self.warmed(flows),
|
||||
tick=config.EGRESS_WEB_MIN_TICKS)
|
||||
self.assertTrue(findings)
|
||||
for f in findings:
|
||||
self.assertNotIn("reserved:", f.entity)
|
||||
self.assertNotIn("192.168.", f.entity)
|
||||
|
|
|
|||
Loading…
Reference in a new issue