Commit graph

8 commits

Author SHA1 Message Date
Hermes
63bac6e06f netsec-scan: HTTP attack-shape rules over the gateway access log (§4d)
F7 (t_e662b03a) gave every Gateway listener a JSON access line and shipped it to
Loki; this is the §4d consumer that had none. New `http_rules.py` classifies
candidate lines and `loki.py` reads them through the logging/loki Service proxy
with two LogQL queries per tick - a `|~` prefilter for attack-shaped lines and a
`sum by (client_ip, peer)` 1-minute matrix for 401/403. Loki does the volume
reduction: a calm 10-minute window (5 474 requests / 3.5 MB) puts ~150 lines on
the wire.

Rules (one line per host+client+category, fingerprint excludes the path):
http-traversal, -sqli, -nul-byte, -secret-probe, -vcs-probe, -backup-probe,
-scanner-ua, http-auth-brute (401/403 only, >=20/min and >=30 in 5m per
coalesce(client_ip, peer)), http-flood (cap 12 new fingerprints/tick).

FP control is the point: Forgejo is 93.5 % of the stream, so smart-HTTP git
endpoints and browse/archive/RSS URLs on the Forgejo hosts are excluded from
path rules, and severity escalates only when the shape is in the path component
AND the origin answered 2xx (a 200 on `/?file=../../.env` is the landing page).
Measured: 17 639 of 35 445 lines/hour are 303 -> /user/login (3xx, never
counted); 293 are 404 crawler churn; the noisiest legitimate 401/403 client does
3/min.

Verified on the live stream: calm window 07:03:40-07:13:40Z -> 0 findings, empty
stdout, exit 0; the 06:48-06:53Z 91.92.47.0/24 burst -> 8 findings; crafted
requests fired all nine rule kinds (public via Cloudflare and direct to the
overlay for the peer fallback); first tick baselines silently, next emits, next
is silent, deleting one fingerprint re-emits exactly one line. 85 unit tests.
Docs: docs/gateway-http-rules.md.

run.sh now cds to its own directory so a worktree runs its own code.
2026-11-27 02:17:50 -05:00
Sirius DevOps
bde343c75f netsec-scan: a seed is silent for its whole span, --dry-run included
The seeding guard only ran in on_batch for the archive path, so a cold
start still announced the entire retained window whenever the tick was a
--dry-run (11-14 egress-new-dst lines: history reported as news, all of it
inside the window the line itself quoted). The guard also lived *after*
the flow rules had already produced findings, and it was skipped entirely
for dry runs.

- absorption now happens in on_batch and is keyed on 'seeded' alone, so it
  covers the cold start, every resume tick of a budget-limited seed, and
  --dry-run (history is not news in a dry run either);
- each seeding tick explains its silence on stderr: 'seed: N tuple(s)
  absorbed, 0 reported; window Xh from <stamp>, N file(s)', including the
  still-pending count when the budget stopped the pass;
- the warm-state archive pass gets the same one-line summary;
- state.seed.absorbed records the count, and absorb() reports whether a
  fingerprint was new so the number is the baseline's growth, not a loop
  counter.

tests/test_seed.py pins all four: cold start, dry-run cold start, resume
tick while unseeded, and single-fire from a seeded state (the guard must
not turn into a permanently silent sensor).
2026-11-27 02:17:16 -05:00
Sirius DevOps
ba1bef3814 netsec-scan: read flows-*.jsonl.gz so a cold start baselines the retained window, not the live file
The collector gzips on rotation, so FLOW_PATTERN 'flows-*.jsonl' saw 1 of 5
files (measured: 1/72 of the retained window). Archives are immutable, so each
is read once, whole, decrypted lazily and recorded in state['archives'].

- archives are bounded (ARCHIVE_MAX_SECONDS/BYTES/FILES, newest first) and
  flows are consumed in batches; a partial pass leaves state seeded=false and
  reports the unread files as pending, so the next tick continues instead of
  alerting from a window it has not examined
- the alert window comes from the coverage start in the consumed filenames
  (monotone), so 'no prior in ~Xh of observed flows' is now verifiable
- the seed absorbs every egress tuple in the window, not just findings (a
  web-port tuple never becomes one on its first tick); a warm state meeting
  archives for the first time absorbs them the same way
- a torn .gz keeps its readable prefix, is noted in state/seed.failed, and does
  not abort the tick; in-flight *.gz.tmp.* markers are never read
- report.json carries window_h/covered_since/seed; 12 new tests
2026-11-27 02:09:51 -05:00
sirius
f4001d589e 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.
2026-11-27 00:41:41 -05:00
sirius
b595d21bec README: document deliver=local constraint (no gateway channel in this profile) 2026-11-27 00:36:40 -05:00
sirius
be60d74159 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.
2026-11-27 00:32:25 -05:00
sirius
c31d46a037 netsec-scan: honest observation window, /dropped tuples, report baseline counts
- first-seen egress is gated by the cumulative seen-set only (deleting a
  fingerprint re-arms the rule); the alert states the observed window
  (~20m / 3.2h / 2.1d) instead of implying the collector holds weeks.
- a DROPPED attempt on a new to-world tuple is keyed separately from forwarded
  traffic to the same destination and graded HIGH.
- daily report counts every external tuple seen that day, not just novel ones.
- drop-prune of the dead state['egress'] map; tests cover the single-fire rearm,
  day counters and the egress union.
- README: measured collector volume/tombstones/partial-tail behaviour, scheduler
  shim path.
2026-11-27 00:24:22 -05:00
sirius
68b2616cc5 netsec-scan: deterministic sensor (6 PromQL tripwires + 2 flow-store novelty rules)
Silent ticks (empty stdout, exit 0), one line per stable fingerprint, cumulative
union-only seen-set at ~/.hermes/cron/netsec-scan-state.json, memoized sensor-
degradation line, daily baseline report. Stdlib only; reads the collector's
JSONL over SSH with per-file byte offsets and Prometheus via the k8s API proxy.
40 unit tests against fixtures recorded from the live collector.
2026-11-27 00:20:46 -05:00