http rules: make the LogQL prefilter a superset of classify()
`http-sqli` was unreachable end to end: the prefilter admitted only `union select`, so boolean (`' OR '1'='1`, `%27%20OR%20…`) and time-based (`sleep(`, `waitfor delay`) payloads were dropped in Loki before Python saw them, and the canary passed because it used the one admitted shape. The prefilter now carries the missing shapes as plain literals (a nested `(?:...)` group made Loki's filter 10x slower, and re-ordering the alternation measured 20-60 s, so the old block stays first and the additions append). Over-match measured on 2026-11-27 06:00-07:00Z over 29 426 lines: 1 202 -> 1 548 lines/h (+29 %), 10-minute query 3.9 s. The extra lines are Forgejo browse URLs that classify() drops; a calm 10-minute window of 394 admitted lines yields 0 findings. Durability: tests/fixtures/attack-shapes.json is one table of 105 payload shapes iterated by both tests - classify() must flag each one and config.HTTP_LINE_FILTER must match its serialized access line. It fails with 44 dropped shapes on the old filter and passes now, so this class of drift (any rule kind, not just sqli) cannot come back silently. Docs also record the data-source limit the bug surfaced: Cloudflare collapses dot-segments in the path, so `/../../etc/passwd` arrives as `/etc/passwd` and path traversal is only detectable in a query string (or off-tunnel).
This commit is contained in:
parent
bdb1463630
commit
ef7e584d27
5 changed files with 867 additions and 18 deletions
25
README.md
25
README.md
|
|
@ -41,7 +41,7 @@ cd ~/Projects/netsec-agent && ./run.sh # silent tick, exit 0
|
|||
./run.sh --verbose # same, diagnostics on stderr
|
||||
./run.sh --fixture tests/fixtures/beacon-shaped.jsonl --dry-run # what-would-I-say
|
||||
./run.sh --http --flows-dir /tmp/empty --dry-run # gateway rules only, no SSH
|
||||
python3 -m unittest discover -s tests # 89 tests, no network
|
||||
python3 -m unittest discover -s tests # 93 tests, no network
|
||||
```
|
||||
|
||||
## Output contract
|
||||
|
|
@ -303,13 +303,16 @@ credentials, no LLM call, no secret reads.
|
|||
|
||||
## Verified behaviour (2026-11-27)
|
||||
|
||||
* 90 unit tests pass against recorded fixtures (`tests/test_archives.py` covers
|
||||
* 93 unit tests pass against recorded fixtures (`tests/test_archives.py` covers
|
||||
the gz path: read-once, torn archive, budget/pending, cold seed, warm-state
|
||||
archive absorption, single-fire; `tests/test_http_rules.py` covers the gateway
|
||||
rules: every category, the Forgejo browse/git FP shapes, `coalesce(client_ip,
|
||||
peer)`, the auth-rate floors and the flood cap; `tests/test_seed.py` covers
|
||||
seed silence: cold start, `--dry-run` cold start, a resume tick while still
|
||||
unseeded, a held PromQL tripwire reported by the first warm tick, and
|
||||
peer)`, the auth-rate floors and the flood cap, and the **prefilter superset**
|
||||
property — `tests/fixtures/attack-shapes.json` is iterated by both
|
||||
`classify()` and `config.HTTP_LINE_FILTER`, so a payload the classifier knows
|
||||
but Loki drops fails the suite instead of going quiet; `tests/test_seed.py`
|
||||
covers seed silence: cold start, `--dry-run` cold start, a resume tick while
|
||||
still unseeded, a held PromQL tripwire reported by the first warm tick, and
|
||||
single-fire from a seeded state).
|
||||
* **Gateway rules (§4d) on the live stream**: calm window `07:03:40–07:13:40Z`
|
||||
(5 474 requests, 154 candidate lines) → **0 findings, stdout empty, exit 0**.
|
||||
|
|
@ -319,6 +322,18 @@ credentials, no LLM call, no secret reads.
|
|||
kinds — including `http-auth-brute` on a 30× 403 burst (`40 x 401/403 in 5m,
|
||||
peak 33/min`). First tick baselined silently, the next emitted 10 findings,
|
||||
the next was silent; deleting one fingerprint re-emitted exactly that line.
|
||||
* **`http-sqli` reachable end to end (t_a3604aab)**: the LogQL prefilter was not
|
||||
a superset of `classify()` — only `union select` got through, so boolean and
|
||||
time-based injection never reached Python. The four payloads from the bug
|
||||
report now fire (`MEDIUM … http-sqli … client=10.10.0.3 / 137.118.156.124`,
|
||||
`4x`/`3x in 5m`, live tick at 08:10Z; the literal-space form has to travel as
|
||||
`%20` because envoy 400s a raw space). Over-match measured on the same hour
|
||||
(06:00–07:00Z, 29 426 lines): 1 202 → 1 548 lines/h (+29 %), 10-minute query
|
||||
3.9 s. Clean windows stay clean: 394 prefilter-admitted lines in
|
||||
`07:03:40–07:13:40Z` → 0 findings, and 6 h of `info/refs`, browse URLs,
|
||||
`/book`, `/lab` and runner `FetchTask` → 0. Superset test:
|
||||
`tests/fixtures/attack-shapes.json` (105 shapes) fails with 44 drops on the
|
||||
old filter, passes on the new one.
|
||||
* **Cold start on the live store** (state moved aside, `--no-prom --verbose`):
|
||||
`5 file(s) (4 archive(s), 1 plain), 150225 flows, 116 tuple(s), 116
|
||||
fingerprint(s), window 2.06h, 7.34s`, **stdout 0 bytes**, exit 0. The window is
|
||||
|
|
|
|||
Loading…
Reference in a new issue