The Begin/End hook was placed before the WAF-inspection block, so a request the WAF blocks (403 warning/ban) still refreshed last_request_ts — scanner/bot traffic against public on-demand vhosts (near-constant internet-wide scanning) kept the signal "fresh" forever, so should_sleep()'s idle-age check never passed. Defeated auto-sleep for the feature's primary deployment (public on-demand vhosts). Move the Begin/defer End bracket to right after the WAF-inspection block's 403/warning/ban early-returns, immediately before the media-cache-hit check. One placement still covers three real-response exit paths via the single defer: the media-cache hit (counts — genuine content served), media-cache-miss proxy, and the plain proxy. Blocked, banned, waker, and 421 requests never reach this line. Adds TestVhostSignalsExcludedForWAFBlock (verified RED against the old placement, GREEN after the move). Co-Authored-By: Gerald KERMA <devel@cybermind.fr> |
||
|---|---|---|
| .. | ||
| cmd | ||
| debian | ||
| internal | ||
| packs/base | ||
| sbin | ||
| testdata | ||
| tmpfiles | ||
| vendor | ||
| .gitignore | ||
| go.mod | ||
| go.sum | ||
| README.md | ||
| sbx-sentinel | ||
secubox-toolbox-ng — Go MITM engine (migration spike, #662 Phase 1)
De-risking PoC for migrating the R3 toolbox MITM engine off Python mitmproxy (GIL-bound, ~1 core) onto a multi-core Go core, without losing the 18-addon feature set. See:
- Analysis:
docs/superpowers/specs/2026-06-18-mitm-engine-migration-analysis.md - Phased plan:
docs/superpowers/plans/2026-06-18-mitm-engine-migration.md
Status: Phase 1 — PoC only. NOT wired into the live R3 path. The live tunnel still runs on the Python mitmproxy workers (8081-8084). This binary is a standalone CONNECT-proxy spike that proves the risky capabilities.
What the PoC proves (the discriminating risks from the analysis)
- CA-compat forging — loads the existing
ca-wg/{ca.pem,key.pem}and forges per-host leaf certs the R3 clients already trust (no re-enroll). Cached per host. - request 204 — short-circuit block (ad_ghost / privacy_guard).
- response body inject — marker before
</head>/</body>(banner / ad-CSS). - SNI splice — raw passthrough, no MITM, by SNI suffix (tls_splice).
- JA4 material capture —
crypto/tlsGetCertificatereceives theClientHelloInfo(SNI, cipher suites, ALPN, TLS versions) → proves theja4addon's handshake fingerprint is reachable in Go (full JA4 extension-hash needs a raw-ClientHello peek — Phase 4).
All stdlib (no external modules → builds offline). Tests are network-free (localhost handshake + temp self-signed CA).
Build & test
cd packages/secubox-toolbox-ng
go test ./... # network-free PoC tests
GOOS=linux GOARCH=arm64 go build -o sbxmitm ./cmd/sbxmitm # appliance target
Try it (CONNECT proxy, against the board CA)
./sbxmitm --ca-cert /etc/secubox/toolbox/ca-wg/ca.pem \
--ca-key /etc/secubox/toolbox/ca-wg/key.pem --listen :8090
curl -x localhost:8090 --cacert /etc/secubox/toolbox/ca-wg/ca.pem https://doubleclick.net/ # → 204
curl -x localhost:8090 --cacert /etc/secubox/toolbox/ca-wg/ca.pem https://example.com/ # → body has the sbx-ng marker
# logs print `ja4 t0304_cNN_a... sni=...` per handshake
Capability → engine map (recap)
Go covers request-204 / body-rewrite / header-cookie-mod / splice / async-sidecars cleanly; JA4 needs the ClientHello shim (proven here); streaming inject + the anti-track HMAC-jar/poison port land in Phase 3/4. Heavy analysis (social-graph, classify, DB/report writers) stays in the existing Python sidecars, fed fire-and-forget over unix sockets.
Roadmap (do NOT cut over without the gates)
- ✅ PoC (this) — forge + 204 + inject + splice + ClientHello capture, compiled + tested.
- arm64 packaging + board bench on :8090 (no DNAT) — forge/throughput vs mitmproxy.
- Hot-path feature parity (block lists + allowlist + own-infra guard, header/cookie strip, banner, splice) — parity harness vs the Python addons.
- Analysis sidecars (unix-socket fire-and-forget) + anti-track HMAC-jar/forge port (exhaustively tested vs
privacy.py). - Shadow run — mirror a fraction of R3, compare outputs. No client served yet.
- Cutover — flip nft
numgenfanout 8081-8084 → 8090-8093; mitmproxy stays up for instant rollback. - Decommission mitmproxy after a stable soak.
Rollback is an nft DNAT-map edit at every step; the Python engine is the live path until Phase 6.