From 8642584cc984c2b3362ce15f888e3b55457cf26a Mon Sep 17 00:00:00 2001 From: randomizedcoder Date: Sun, 6 Dec 2026 10:28:43 -0800 Subject: [PATCH] =?UTF-8?q?redteam:=20rt-11-13=20=E2=80=94=20the=20RT-6=20?= =?UTF-8?q?attacks=20from=20a=20Docker-topology=20neighbor:=20CONFIRMED=20?= =?UTF-8?q?21/21,=20the=20shared=20volume=20IS=20the=20attack=20(#400/#401?= =?UTF-8?q?=20legs,=20no=20new=20issue)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The deferred task-5.8 leg closed (the plan: 'rt-6-2/6-3/6-4 applied from a privileged neighbor; repeat here in the Docker topology'). The topology: the victim twin (health on the shared UDS path, metrics on loopback, its own baseline in the shared /var/lib/xtcp2, its own catcher), a real xtcp2 neighbor container (the tier-3 cap shape, BOTH victim volumes rw, busybox+socat docker-cp'd in — socat static joins the attacker tools tar, and the per-name static check replaces the bin/* glob so socat's shipped shell script does not gate the build), and a capability-less co-tenant (docker create --cap-drop=ALL + cp busybox + start, parked as busybox sleep). THEFT (the #400 leg): the neighbor unlinks the victim twin's LIVE socket (0600 in docker's 0755 bind dir — the rt-6-3 private-parent defense never runs on a pre-mounted dir) and binds its fake at the path; the twin keeps running, /metrics stays 200, records keep flowing (catcher 22346→24168 through the theft), and NO function="listener" series exists in the exposition — there is no daemon-side counter for a stolen socket path, the operator's probe is the only detector. POISON (the #401 leg): the neighbor overwrites the LIVE baseline file through the rw mount and it is LATENT — Store.LoadAndLock runs at startup only (12 s with the poison in place: delta ≈0, ready=1), then ANY restart (crash, upgrade, node reboot) loads it as a healthy baseline and fires go_link_monitor_up_links_delta = -99997 — the fake ~100k alert from one neighbor write. The restart's stale-unlink re-take of the path (removing the attacker's fake, /healthz 200) is both the ONLY theft recovery AND the poison's trigger. NOCAP (the stronger result): a capability-less co-tenant (--cap-drop=ALL — not even xtcp2's two fatal caps) unlinks a live socket through the rw volume all the same — uid 0 owns the shared dir, owner-write needs no CAP_DAC_OVERRIDE. The volume mount, not any cap, is the attack; the plan's 'privileged neighbor' overstates the requirement. Evidence: 20261206T180851-173217a25-1948319 (21/21) + solo re-verify 20261206T181854-173217a25-2105850 (21/21). The 55-row matrix runs on the branch head before the PR merges. Harness lessons (run 1, all encoded in the findings row): the scratch image has NO /bin/sh — socat's SYSTEM: runs its command through sh -c, so the fake-socket echo needs busybox docker-cp'd AS /bin/sh (the rt-5-4 argv[0] lesson's flip side: the name must BE the applet you want); it has no /tmp either — docker cp needs an existing parent, so the poison rides the shared mount; and docker start has no --entrypoint flag — the entrypoint is set at docker create. --- docs/redteam-implementation.md | 4 +- docs/redteam-plan.md | 2 +- docs/security.md | 30 ++ nix/redteam.nix | 21 +- vagrant/redteam/findings.md | 1 + vagrant/scenarios/rt-11-13-uds-neighbor.sh | 400 +++++++++++++++++++++ 6 files changed, 452 insertions(+), 6 deletions(-) create mode 100755 vagrant/scenarios/rt-11-13-uds-neighbor.sh diff --git a/docs/redteam-implementation.md b/docs/redteam-implementation.md index dff03d6da..825ca266b 100644 --- a/docs/redteam-implementation.md +++ b/docs/redteam-implementation.md @@ -293,7 +293,7 @@ cap matrix, and ship the runbook. | 5.5 | RDMA subscription on stock 6.8 (rxe) + bonding rows (shared with §29) | rt-5-5 | | 5.6 | Mount-propagation rows: `rprivate` vs `ro,rslave` gauge asserts on Docker | rt-5-6 (**DONE 2026-12-04**: 15/15, BLOCKED — the rslave row holds, the regression guard is exact, and the rprivate failure mode is two defects: the real ns never collected + the host's socket inventory emitted under the tenant's name silently — the mode-0000 staging file → EACCES open → the collector proceeds anyway; see the findings row and `docs/security.md` "Minimum-capability recipe") | | 5.7 | `/proc` pressure side effects | rt-5-7 (**DONE 2026-12-04**: 14/14, BLOCKED — at 10k host processes: scan p99 0.088s, no reconcile incompletes, coverage lag 0s, CPU 121%; the skipped counter's growth is exactly one-per-pid-per-scan, the docker-default AppArmor ptrace-read line) | -| 5.8 | RT-11 tier 3: docker.sock kill, host netfilter blind, netns flood via rslave, docker netns entry poisoning, UDS unlink/baseline poisoning in Docker topology | rt-11-9..13 (**DONE 2026-12-05** for rt-11-9..12: CONFIRMED/BLOCKED/CONFIRMED/BLOCKED — two new findings: the netns-flood daemon death (**#389**) and the docker.sock kill (a deployment-invariant finding — no product issue, the RUNBOOK rule is the defense); **rt-11-13 deferred after task 5.9** — it reuses the RT-6 rows in the Docker topology) | +| 5.8 | RT-11 tier 3: docker.sock kill, host netfilter blind, netns flood via rslave, docker netns entry poisoning, UDS unlink/baseline poisoning in Docker topology | rt-11-9..13 (**DONE**: rt-11-9..12 on 2026-12-05 — CONFIRMED/BLOCKED/CONFIRMED/BLOCKED, two new findings: the netns-flood daemon death (**#389**) and the docker.sock kill (a deployment-invariant finding — no product issue, the RUNBOOK rule is the defense); **rt-11-13 DONE 2026-12-06** — CONFIRMED 21/21 `20261206T180851-173217a25-1948319`, the #400/#401 legs land unchanged from a Docker-topology neighbor: the shared volume is the attack (even for a capability-less co-tenant), and the baseline poison is latent-until-restart) | | 5.9 | UDS suite: symlink attack, stale-socket unlink DoS, replacement race, secret-file modes audit, GOIP_WRITE_OUT confinement | rt-6-1..6 (**DONE 2026-12-05**: BLOCKED/CONFIRMED/CONFIRMED/CONFIRMED/BLOCKED/BLOCKED — three findings: the stale-unlink footgun and the world-writable-parent hijack (**#400** — the private-parent-dir doc arm) and the baseline integrity gap (**#401**); rt-6-5 REFUTED its own premise — the listener already refuses group/world-readable secret files at startup | | 5.10 | **Blind-detection runbook**: per cut link (discover/dump/enrich/batch/deliver/scrape/process) × tier, the metric/log that reveals it; external-watchdog requirement; written into `docs/security.md` + `vagrant/redteam/RUNBOOK.md` | RT-11 deliverable | @@ -304,7 +304,7 @@ cap matrix, and ship the runbook. - [x] **Phase 5 part 2 complete (the capability rows)**: rt-5-3 **CONFIRMED** (35/35, `20261203T093134-e811a90f2-3244581` — **the blast-radius answer: a compromised daemon container is a host-trust domain in EVERY cap shape, including the minimum-cap recipe**: an 8-probe busybox battery (docker-cp'd into the shell-less scratch image and docker-exec'd — the takeover shape) run against four shapes — the deployed min recipe, the §29 compose shape (docker defaults + NET_ADMIN/SYS_ADMIN/SYS_CHROOT), `--privileged --pid host`, and a plain co-tenant — found host link state flappable and every mounted co-tenant netns enterable from all three daemon shapes (NET_ADMIN + SYS_ADMIN are the collector's own powers; caps cannot minimize them away), while what actually bounds mount and host-process ptrace on Ubuntu is the `docker-default` AppArmor profile (mount denied even with SYS_ADMIN; /proc/1 ptrace denied to non-same-profile targets) — `--privileged` (or `apparmor=unconfined`) removes that bound entirely, lifting mount, host-PID-1 environ, and insmod to the kernel; the min recipe's real win over the compose shape is dropping MKNOD/DAC_OVERRIDE/SETUID-class caps, and the plain co-tenant is denied every host-mutating probe. The full matrix is in `docs/security.md` "Blast radius of a compromised daemon container"), rt-5-4 **BLOCKED** (46/46, `20261203T102631-e811a90f2-3633767` — **the capability contract holds**: six one-cap-dropped daemons (`--cap-drop=ALL` + per-row adds, otherwise the exact victim.sh host-mode shape, each on its own loopback prometheus port and link-monitor baseline file — the baseline lock is per-file) measured per feature: dropping NET_ADMIN or SYS_ADMIN → exit 1 with the actionable message naming the cap (the all-dropped floor names both fatal caps after all three soft WARN lines); dropping SYS_PTRACE → runs, WARNs, the /proc-scan discovery goes fully blind (foundProc 5→0 per scan — ptrace_may_access + Yama ptrace_scope=1) while netns coverage survives via the /run/netns + /run/docker/netns bind mounts (found/start stays 5/scan — the init_capabilities.go claim "found stays at 1" is wrong in the docker shape; corrected in docs/security.md); dropping NET_RAW or SYS_RESOURCE → runs, WARNs, zero degradation (udp dests and io_uring are the only consumers); inet_diag, ethtool (the settings collector), the RDMA netlink backend, and the link monitor are unaffected by every soft drop. The matrix + minimum-cap recipe are in `docs/security.md` "Capability × feature matrix". Three more harness lessons surfaced on the way, all encoded in the scenario: `grep -q` on a pipe of a big variable is a SIGPIPE coin flip under pipefail (the rt-5-1 lesson's third shape — printf-dies-at-first-match; herestring or remote grep instead), an unanchored metric grep matches the exposition's `# HELP` line (line-anchor every probe), and busybox dispatches on argv[0] (a cp'd `bb` is "applet not found" — keep the name busybox)). **Final regression: 42/42 PASS, 0 failed on `d2307610a` (matrix run `20261203T164451-d2307610a`; the first 42-row run on `10b26a71e` was 41/42 — rt-11-4's torn-read false "premise WON", root-caused as the harness bug, fixed with the tolerant catcher reader, rt-11-4 14/14 `20261203T162907-10b26a71e-4174803` + rt-11-8 18/18 `20261203T163709-10b26a71e-133485` re-verified solo; the runbook commit `8053629d5` landed mid-run — docs only, no scenario code changed after the run started).** - [x] Cap matrix table PR'd into `docs/security.md` (cap × feature), each cell evidenced by a scenario run. (DONE 2026-12-03: the "Capabilities and container blast radius" section — the capability × feature matrix from rt-5-4, the four-shape blast-radius table from rt-5-3, and the minimum-cap recipe `--cap-drop=ALL` + NET_ADMIN/SYS_ADMIN/SYS_PTRACE/NET_RAW/SYS_RESOURCE with the drop conditions per soft cap) - [ ] **Phase 5 part 3, first half complete (the propagation + pressure rows)**: rt-5-6 **BLOCKED** (15/15, `20261203T231843-b48e19d1e-3186309` — **the rslave row holds and the e13287e7b regression guard is exact (gauges 0/WARN silent on the row, gauges 1/WARN fired on an rprivate twin), but the rprivate failure mode is two defects, not the documented one**: a named netns created after the daemon started is never collected (no records for its listener in the twin's catcher — the /proc-scan fallback is also blind: docker-default AppArmor denies ptrace-read of unconfined host peers regardless of CAP_SYS_PTRACE, dmesg-evidenced), AND the twin emits misattributed records — `ip netns add(8)` stages the entry as a mode-0000 file over which rprivate never propagates the nsfs mount, so the resolver's readdir+fstat admits the bare FILE, the daemon's open fails EACCES (the counter that fires is `openAndSetNSWithRetries{variable="open"}` — setns is never attempted), and `netNamespaceInstance` proceeds anyway: the diag socket opens in its own (host) netns and gets stored as that namespace's collector, so the HOST's socket inventory flows under the tenant's name (~8.5k records/run, netnsInode = the file's tmpfs inode) — silently, every poll — a product issue to file; `rslave` guidance + the detectors are in `docs/security.md` and the RUNBOOK), rt-5-7 **BLOCKED** (14/14, `20261204T003453-b48e19d1e-3641655` — **bounded at fleet scale**: at 10k host processes the discoverNamespaces p99 is 0.088s (baseline ~0.005s, bound 1.0s), no `reconcile_incomplete` fires, victim coverage lag stays 0s through the flood and after the drain, daemon CPU 121% (<250% bound) with RSS +27MB, and the skipped counter's growth is exactly one-per-pid-per-scan (+179,912 over 21 scans) — the docker-default ptrace-read line again, no retry storm. Two more pipefail-in-assignment silent-death lessons encoded (guard every grep pipeline feeding a `$()`, bound curls and docker stats with timeouts), and the twin's metrics/logs/mountinfo snapshot before asserting — the counters overturned the first mechanism theory. -- [x] **Phase 5 part 3, second half complete (the RT-11 tier-3 rows)**: rt-11-9 **CONFIRMED** (11/11, `20261204T104157-ad321054a-3536908` — **the one-line full blind: the docker socket is uid-equivalent root** — a plain curl via the bind-mounted socket POSTs the daemon to `stop` (204), or `pkill -9` over --pid host; no daemon-side counter can exist (the daemon is dead — /metrics 000, the catcher freezes); the socket restarts it too — the attacker owns lifecycle in both directions; the plain tier has neither vector, which IS the invariant, and the external arrival check is the only detector), rt-11-10 **BLOCKED** (13/13, `20261205T020601-ad321054a-2280188` — **firewall tampering is only detectable via delivery health, and the counters DO page**: the deliver blind (OUTPUT DROP to :9999) freezes the catcher while the daemon stays healthy-while-dark; the envelope queue fills within ~30 s, queueFull + a `queue_depth` drop every poll after, Write/Dial on the 30 s deadline + 3×30 s dial cycle → the `attempts` drop (226 evictions over 480 s in the calibration run); rule-out → the queue drains, delivery recovers; the scrape blind (INPUT DROP to :9088) is absence-only by construction — no daemon-side counter can exist for its own exposition failing, the external watchdog is the detector, exactly as the RUNBOOK documents), rt-11-11 **CONFIRMED — #389 (S2)** (8/8, `20261205T023850-ad321054a-2612158` — **the netns flood KILLS the daemon**: the per-namespace collector inits (each holding a locked OS thread) pass the Go runtime's 2000-thread ceiling BEFORE the 4096 `-maxNetns` cap — `fatal error: thread exhaustion`, exit 2, the catcher freezes (the full-fleet blind); the admission bounds and the thread ceiling are mutually inconsistent — the cap sits ABOVE the budget; fix = cap under the thread budget, unlock after init, limit concurrent inits, or raise SetMaxThreads; the scenario's survives path is the regression guard), rt-11-12 **BLOCKED** (11/11, `20261205T032136-ad321054a-3074828` — **the entry-file poison is counted and pageable — and the #386 misattribution is the measured setns leg**: a drop+re-add poison (`ip netns del`, gap, `ln -s /dev/null`) makes the fresh collector's open succeed on the symlink and all 10 setns retries fail EINVAL (`Setns` +10, `SetnsAfterRetries` +1), then the caller PROCEEDS on fd -1 — host dumps under the tenant's name, 15 → 6679 records with the listener-port count frozen (the discriminator); the ro,rslave row daemon is untouched). rt-11-13 deferred after task 5.9 (it reuses the RT-6 rows). Harness lessons (all encoded, the big four): **matrix.sh leaves `RT_READ_TOKEN` EMPTY until `xtcp2_victim_read_token()` runs** — a scenario reading authed metrics without it reads a permanent 0 and can hang forever on a counter that never lights (rt-11-10 runs 1–3); **`|| echo 000` double-prints on one line** (curl -w's 000 has no trailing newline — `000000`, which tail -n1 cannot dedupe; the fix is `|| true` + exact equality); **every metric read through a possibly-DEAD daemon is a vacuous 0** — check liveness first, and a monotonic counter that appears to decrease is a dead-scrape proof (rt-11-11 run 1); **the /run/netns entry file IS the nsfs bind mount** — `rm -f` fails EBUSY (the drop must be `ip netns del`; pre-clean idempotently, or the next `ip netns add` collides). **Final regression: green in one `redteam-matrix` run on `79375582b` — 48 rows, 0 failed** (the review-fix commit re-verified all three restructured scenarios solo first — rt-11-10 `20261205T044330-1a5a5db1e-3510733` 13/13, rt-11-11 `20261205T044835-1a5a5db1e-3660263` 8/8, rt-11-12 `20261205T045802-1a5a5db1e-3675844` 11/11 — then the full sweep confirmed the forks hold under matrix `XTCP2_EXPECT` control: rt-11-10 BLOCKED, rt-11-11 CONFIRMED, rt-11-12 BLOCKED, all PASS). +- [x] **Phase 5 part 3, second half complete (the RT-11 tier-3 rows)**: rt-11-9 **CONFIRMED** (11/11, `20261204T104157-ad321054a-3536908` — **the one-line full blind: the docker socket is uid-equivalent root** — a plain curl via the bind-mounted socket POSTs the daemon to `stop` (204), or `pkill -9` over --pid host; no daemon-side counter can exist (the daemon is dead — /metrics 000, the catcher freezes); the socket restarts it too — the attacker owns lifecycle in both directions; the plain tier has neither vector, which IS the invariant, and the external arrival check is the only detector), rt-11-10 **BLOCKED** (13/13, `20261205T020601-ad321054a-2280188` — **firewall tampering is only detectable via delivery health, and the counters DO page**: the deliver blind (OUTPUT DROP to :9999) freezes the catcher while the daemon stays healthy-while-dark; the envelope queue fills within ~30 s, queueFull + a `queue_depth` drop every poll after, Write/Dial on the 30 s deadline + 3×30 s dial cycle → the `attempts` drop (226 evictions over 480 s in the calibration run); rule-out → the queue drains, delivery recovers; the scrape blind (INPUT DROP to :9088) is absence-only by construction — no daemon-side counter can exist for its own exposition failing, the external watchdog is the detector, exactly as the RUNBOOK documents), rt-11-11 **CONFIRMED — #389 (S2)** (8/8, `20261205T023850-ad321054a-2612158` — **the netns flood KILLS the daemon**: the per-namespace collector inits (each holding a locked OS thread) pass the Go runtime's 2000-thread ceiling BEFORE the 4096 `-maxNetns` cap — `fatal error: thread exhaustion`, exit 2, the catcher freezes (the full-fleet blind); the admission bounds and the thread ceiling are mutually inconsistent — the cap sits ABOVE the budget; fix = cap under the thread budget, unlock after init, limit concurrent inits, or raise SetMaxThreads; the scenario's survives path is the regression guard), rt-11-12 **BLOCKED** (11/11, `20261205T032136-ad321054a-3074828` — **the entry-file poison is counted and pageable — and the #386 misattribution is the measured setns leg**: a drop+re-add poison (`ip netns del`, gap, `ln -s /dev/null`) makes the fresh collector's open succeed on the symlink and all 10 setns retries fail EINVAL (`Setns` +10, `SetnsAfterRetries` +1), then the caller PROCEEDS on fd -1 — host dumps under the tenant's name, 15 → 6679 records with the listener-port count frozen (the discriminator); the ro,rslave row daemon is untouched). rt-11-13 deferred after task 5.9 (it reuses the RT-6 rows). Harness lessons (all encoded, the big four): **matrix.sh leaves `RT_READ_TOKEN` EMPTY until `xtcp2_victim_read_token()` runs** — a scenario reading authed metrics without it reads a permanent 0 and can hang forever on a counter that never lights (rt-11-10 runs 1–3); **`|| echo 000` double-prints on one line** (curl -w's 000 has no trailing newline — `000000`, which tail -n1 cannot dedupe; the fix is `|| true` + exact equality); **every metric read through a possibly-DEAD daemon is a vacuous 0** — check liveness first, and a monotonic counter that appears to decrease is a dead-scrape proof (rt-11-11 run 1); **the /run/netns entry file IS the nsfs bind mount** — `rm -f` fails EBUSY (the drop must be `ip netns del`; pre-clean idempotently, or the next `ip netns add` collides). **Final regression: green in one `redteam-matrix` run on `79375582b` — 48 rows, 0 failed** (the review-fix commit re-verified all three restructured scenarios solo first — rt-11-10 `20261205T044330-1a5a5db1e-3510733` 13/13, rt-11-11 `20261205T044835-1a5a5db1e-3660263` 8/8, rt-11-12 `20261205T045802-1a5a5db1e-3675844` 11/11 — then the full sweep confirmed the forks hold under matrix `XTCP2_EXPECT` control: rt-11-10 BLOCKED, rt-11-11 CONFIRMED, rt-11-12 BLOCKED, all PASS). **rt-11-13 — DONE 2026-12-06, the deferred leg closed (the RT-6 attacks from a Docker-topology neighbor, CONFIRMED 21/21 `20261206T180851-173217a25-1948319`)**: the neighbor (a real xtcp2 co-tenant container, the tier-3 cap shape, BOTH victim volumes rw) lands all three legs with no exploit — **THEFT**: an unlink of the victim twin's LIVE socket (0600 in docker's 0755 bind dir — the rt-6-3 private-parent defense never runs on a pre-mounted dir) + the neighbor's own socat fake at the path, while the twin keeps running, /metrics stays 200, records keep flowing (catcher 22346→24168 through the theft), and NO `function="listener"` series exists in the exposition — there is no daemon-side counter for a stolen socket path, the operator's probe is the only detector; **POISON**: the neighbor overwrites the LIVE baseline through the rw mount and it is LATENT — Store.LoadAndLock runs at startup only (12 s with the poison in place: delta ≈0, ready=1), then ANY restart (crash, upgrade, node reboot) loads it as a healthy baseline and fires `go_link_monitor_up_links_delta = -99997` — the fake ~100k alert from one neighbor write (#401, and the restart's stale-unlink re-take of the path is both the only theft recovery AND the poison's trigger); **NOCAP**: a capability-less co-tenant (`--cap-drop=ALL`, not even xtcp2's two fatal caps — docker create + cp busybox + start, parked as busybox sleep) unlinks a live socket all the same — uid 0 owns the shared dir, owner-write needs no CAP_DAC_OVERRIDE: the volume mount, not any cap, is the attack, and the plan's 'privileged neighbor' overstates the requirement. Harness lessons (run 1, all encoded): the scratch image has NO /bin/sh — socat's `SYSTEM:` runs its command through `sh -c`, so the neighbor needs busybox docker-cp'd AS /bin/sh (the rt-5-4 argv[0] lesson's flip side: the name must BE the applet you want); it has no /tmp either — docker cp needs an existing parent, so the poison rides the shared mount; and `docker start` has no `--entrypoint` flag — the entrypoint is set at `docker create`. Final regression: the 55-row matrix on the branch head (the rt-6 suite's 54 + rt-11-13). - [x] rt-11-12 (netns entry poisoning) resolves BLOCKED (errors counted + gauge) or CONFIRMED (silent drop → S2 issue). (DONE 2026-12-05, 11/11 BLOCKED `20261205T032136-ad321054a-3074828`: the failure IS counted — `Setns` +10 and `SetnsAfterRetries` +1 at the re-add — and the measured shape is the #386 misattribution setns leg: host dumps under the tenant's name, 15 → 6679 records with the listener-port count frozen; the per-ns gauge gap stays #371) - [x] **Phase 5 part 4 complete (the UDS suite)**: rt-6-1 **BLOCKED** (13/13, `20261205T181303-4a9a9345b-3515947` — **all three shapes refused, nothing clobbered**: a symlink, a regular file, and a symlink pointing at a LIVE socket (the sneakiest — following it would stale-unlink the real one) all exit 1 with the by-name 'exists and is not a socket' at startup; the attacker's files survive untouched — the Lstat never follows, the unlink policy never runs), rt-6-2 **CONFIRMED — #400 (S3)** (10/10, `20261205T181938-4a9a9345b-3973716` — **the default stale-socket policy unlinks a LIVE service's socket, no liveness probe**: a socat victim on a shared dir is orphaned on an unlinked inode (inode changed, the victim's echo gone, the twin answers /healthz 200 on the victim's path) while its PROCESS still runs — the DoS is silent; `unlinkStale=false` refuses by name and the victim survives — the regression guard for the #400 fix), rt-6-3 **CONFIRMED — #400 (S3)** (10/10, `20261205T201441-4a9a9345b-1022919` — **the chmod enforcement is real, the world-writable parent is the hole**: the daemon's own created dirs are 0750 (socketDirMode) and the sockets 0600 (DefaultUnixSocketMode), a non-root process IN THE SAME CONTAINER (docker exec -u 1000) cannot unlink from them — but chmod 777 (the operator mistake) hands the path to the attacker: their fake socket owns it, the probe answers 'rt-6-3-attacker', the daemon never notices (its listener is orphaned, not dead) — the documented requirement: dir 0700 owned by the daemon user), rt-6-4 **CONFIRMED — #401 (S3)** (17/17, `20261205T212243-4a9a9345b-1502677` — **the two shapes split exactly**: the CORRUPT baseline degrades safely (gauge 0, counted, /healthz 200, TCP collection UNAFFECTED — the runLinkMonitor contract, now repeated on Ubuntu/Docker), while the CRAFTED-VALID baseline is accepted with no integrity check and drives `go_link_monitor_up_links_delta = -99997` — a fake ~100k 'links missing' alert from ONE file write; `expected_up_links` is the poison lever), rt-6-5 **BLOCKED** (10/10, `20261205T221425-4a9a9345b-1938524` — **the plan's premise is STALE**: the listener REFUSES a group/world-readable secret file at startup ('a secret file must not be accessible by group or others', chmod 0400, Kubernetes defaultMode: 0400) — the row's 'consider refusing world-readable secret files at startup' is already the product behavior, so the verdict is BLOCKED, not CONFIRMED; the read-side audit stands: the 0644 file is still world-readable ON THE MOUNT (the refusal stops the use, not the read), and the 0400 twin starts and serves — the working reference), rt-6-6 **BLOCKED** (14/14, `20261205T235143-4a9a9345b-2820953` — **the confinement holds on every axis**: with GOIP_WRITE_OUT the write verbs (the goip_write build docker-cp'd into the daemon's own container — the rt-5-3 busybox pattern) write the request FILE only — the loopback flags, the route table, and the daemon all unchanged; without the variable the verbs refuse outright (ErrWriteNotApplied, exit 1); the /ip listener is OFF by default (404) and with -linkMonitorIPPaths the read verbs serve (200) while the write verb /i/l/s/dev/lo/down is refused 400 BY NAME — with no write encoder in the binary (no-write-encoders, the flake check). Harness lessons (all encoded, per-run): a bind-mounted socket dir is DOCKER'S (0755), not the daemon's — the 0750 socketDirMode only applies to dirs the daemon creates itself, so the enforcement leg must mount nothing (rt-6-3 runs 1–4); a class is served by exactly ONE listener (metrics+metrics is a config error, `ip` needs -linkMonitorIPPaths, `debug` needs an admin credential — grpc-read is the flagless read class); a twin with NO -dest runs the KAFKA default and dies of redpanda dial retries ~30 s in (every twin runs -dest tcp:127.0.0.1:9999, the row's catcher); the expected-refusal exit code must be captured with the &&/|| idiom, never the bare $? after the command (set -e kills the scenario first — rt-6-6 run c); and goip's loopback prints 'state UNKNOWN' — the up/down signal is the flags list, not the state keyword). **Final regression: the 54-row matrix on the branch head `aebef83a1` — 53/54 PASS + rt-4-6 FAIL (`20261206T020955-aebef83a1-3637319`, `only 79 churn cycles` — a harness-side driver underrun, the target ~240; NOT a product regression, the assert fired on the driver's own telemetry). Solo re-run of rt-4-6 on the same commit: PASS 16/16 (`20261206T032052-aebef83a1-4118058`), identical to the green 48-row run of task 5.8 — the flake is the driver's, not the daemon's.** - [x] RUNBOOK.md complete for all 7 links × 4 tiers (28 cells), each naming a concrete metric/log/absence-alert. (DONE 2026-12-03, `8053629d5`: `vagrant/redteam/RUNBOOK.md` — every cell names its detector, evidence cited (V) for every cell as of 2026-12-05 — the last four (rt-11-9..12) landed their measured evidence when task 5.8's rows ran; rt-11-11's cell is V-CONFIRMED/#389, rt-11-12's open question is answered in the gaps section. First rule, alert rules 1–8, and the known gaps #337/#370/#371 up front; docs/security.md carries the companion section.) diff --git a/docs/redteam-plan.md b/docs/redteam-plan.md index 8175a6fe2..dd46e2fee 100644 --- a/docs/redteam-plan.md +++ b/docs/redteam-plan.md @@ -298,7 +298,7 @@ userns, or `docker.sock` mounted — common in practice): | rt-11-10 | Host netfilter blind | `iptables -I OUTPUT ... --dport 9092 -j DROP` (or INPUT to :9088/:8889) — silent delivery or scrape blind while the daemon is healthy | delivery-error metrics must light up; finding: firewall tampering is only detectable via delivery health, so those metrics must page | | rt-11-11 | Netns flood via mount propagation | thousands of netns registered into a `rslave`-propagated `/run/netns` → discovery/reconcile every cycle stretches past cadence; each flooded netns can also carry rt-11-4's socket bomb | **MEASURED 2026-12-05: the flood KILLS the daemon — CONFIRMED (S2)** — the per-namespace collector inits (each locking an OS thread) pass the Go runtime's 2000-thread ceiling BEFORE the `-maxNetns` cap (4096) is reached (`fatal error: thread exhaustion`, exit 2, the catcher freezes — the full-fleet blind; the admission bounds and the thread ceiling are mutually inconsistent; fix = cap netns under the thread budget, unlock after init, or raise SetMaxThreads — a surviving build resolves the bounds path: coverage lag vs. netns count, the `checkNetnsPropagation` gauge stays correct, add_rate/max_netns engage) | | rt-11-12 | Docker netns entry poisoning | with an rw bind of `/run/docker/netns` + shared propagation, replace victim netns files with dead inodes/symlinks → setns errors for *victim* namespaces → their sockets silently vanish from reports | error counters must increment and a namespace-level gauge must show the failure; silent drop = S2 finding | -| rt-11-13 | UDS unlink / baseline poisoning | rt-6-2/6-3/6-4 applied from a privileged neighbor | covered by RT-6 rows; repeat here in the Docker topology | +| rt-11-13 | UDS unlink / baseline poisoning | rt-6-2/6-3/6-4 applied from a privileged neighbor | **VERIFIED 2026-12-06: CONFIRMED (the #400/#401 legs land unchanged from the neighbor)** — the shared volume IS the attack: the neighbor unlinks the victim's LIVE socket (0600 in docker's 0755 bind dir — the rt-6-3 private-parent defense never runs on a pre-mounted dir) and binds its fake at the path (the twin keeps running and delivering — no `function="listener"` counter exists at all), while a capability-LESS co-tenant (‑‑cap-drop=ALL, not even xtcp2's two fatal caps — it parks as busybox) unlinks all the same: uid 0 owns the shared dir, owner-write needs no CAP_DAC_OVERRIDE; the baseline poison is written through the same mount and is LATENT (Store.LoadAndLock runs at startup only — 12 s with the poison in place: delta ≈0, ready=1) until ANY restart loads it: `go_link_monitor_up_links_delta = -99997` — the fake ~100k alert from one neighbor write, and the restart's stale-unlink re-take of the path is both the only theft recovery AND the poison's trigger (21/21, `20261206T180851-173217a25-1948319`) | **Tier 4 — admin access** (auth disabled by default, or a stolen admin token): the one-RPC full blind — `ConfigService.Set` with `dest: null:` diff --git a/docs/security.md b/docs/security.md index b5cbc89f6..5f353a32b 100644 --- a/docs/security.md +++ b/docs/security.md @@ -722,3 +722,33 @@ requirement is enforced, not just documented. The file on the mount is still readable by whatever uid owns the host path: the 0400 requirement and the read-only, daemon-owned parent dir are the deployment's to honor. (10/10, `20261205T221425-4a9a9345b-1938524`.) + +### The shared-volume topology (measured, red-team rt-11-13) + +A **shared volume is the world-writable parent** — no chmod can repair it +(rt-11-13, 21/21, `20261206T180851-173217a25-1948319`). A neighbor +container with the victim's socket dir or baseline dir mounted `rw` +needs no exploit and **no capability** (a `--cap-drop=ALL` co-tenant +unlinks a live socket too — uid 0 owns the mount, owner-write needs no +CAP_DAC_OVERRIDE; the "privileged neighbor" overstates the requirement): + +- **The unlink/hijack lands silently.** The neighbor unlinks the LIVE + socket (0600 in docker's 0755 bind dir — the `0750` socketDirMode only + creates, it never tightens a pre-mounted dir) and binds its own at the + path. The daemon keeps running, keeps delivering, and its exposition + has **no listener-family counter at all** — there is no daemon-side + signal for a stolen socket path; the operator's probe through the path + is the only detector (the RUNBOOK's external-watchdog rule). +- **The baseline poison is latent, then fires on any restart.** The + neighbor's single write to the shared baseline file does nothing to the + running daemon (`Store.LoadAndLock` runs at startup only) — the poison + waits for the next crash, upgrade, or node reboot, then loads as a + healthy baseline and pages a fake `up_links_delta ≈ −100k` alert + (#401's delivery leg). The one recovery for the stolen path — a + restart, whose stale-unlink re-takes it — is also the poison's + trigger. + +The requirement is the deployment invariant: **never mount the daemon's +socket dir or `/var/lib/xtcp2` into another container** (the same rule +as the docker socket in "Blast radius of a compromised daemon +container"). diff --git a/nix/redteam.nix b/nix/redteam.nix index 12fefef0b..70f500d93 100644 --- a/nix/redteam.nix +++ b/nix/redteam.nix @@ -86,6 +86,7 @@ let goip ; busybox = pkgs.pkgsStatic.busybox; # static musl build; argv[0] must be busybox + socat = pkgs.pkgsStatic.socat; # static musl build; rt-11-13 docker-cp's it into the neighbor container (the fake-socket bind) }; attackerTools = pkgs.runCommand "xtcp2-redteam-attacker-tools.tar" @@ -101,10 +102,23 @@ let # gRPC scenarios get a static build of their own when Phase 1 needs them # (see docs/redteam-harness.md "Open questions"). for b in ${ - lib.concatStringsSep " " (lib.mapAttrsToList (_: drv: "${drv}/bin/*") attackerToolsBinaries) + lib.concatStringsSep " " ( + lib.mapAttrsToList (name: drv: "${drv}/bin/${name}") attackerToolsBinaries + ) }; do - # -L follows symlinks: busybox's /bin is one real ELF plus one - # symlink per applet, and the applets must pass the check too. + # The check covers exactly what the tar copies: every binary below + # must be a static ELF or it would not run on the Ubuntu guests. + # (socat's bin/ also ships a shell script — checked per-name, not by + # the glob, so only the real binary gates the build.) + file -L "$b" | grep -q 'statically linked' || { + echo "redteam-attacker-tools: $b is not a static ELF — it would not run on the Ubuntu guests" >&2 + exit 1 + } + done + # -L follows symlinks: busybox's /bin is one real ELF plus one symlink + # per applet, and every applet must pass the check too (argv[0] is the + # applet name when docker exec runs /bin/busybox rm etc.). + for b in ${pkgs.pkgsStatic.busybox}/bin/*; do file -L "$b" | grep -q 'statically linked' || { echo "redteam-attacker-tools: $b is not a static ELF — it would not run on the Ubuntu guests" >&2 exit 1 @@ -272,6 +286,7 @@ in redteam-rt-11-10 redteam-rt-11-11 redteam-rt-11-12 + redteam-rt-11-13 redteam-rt-6-1 redteam-rt-6-2 redteam-rt-6-3 diff --git a/vagrant/redteam/findings.md b/vagrant/redteam/findings.md index 0eb740d4a..9593f32e4 100644 --- a/vagrant/redteam/findings.md +++ b/vagrant/redteam/findings.md @@ -94,3 +94,4 @@ that gets fixed flips its `EXPECT` in the same PR as the fix | rt-6-4 | 2026-12-05 | host+raw+min; the row daemon (its own link monitor up — the healthy reference) untouched; two twins, each with its own baseline file in its own bind-mounted /var/lib/xtcp2 and its own socat catcher (:9995 corrupt, :9996 craft) | CONFIRMED | #401 (S3) | `20261205T212243-4a9a9345b-1502677` (17/17; runs a–c were scenario bugs: the authed 9088 scrape needs the read token (a 401 read as a permanent 0), a `catcher_gt 0` call left `$2` unbound under set -u (the silent death), and my twin-scoped `catcher_lines` shadowed invariant.sh's main-catcher one inside `victim_still_reporting` — renamed `twin_catcher_lines`) | **The two shapes split exactly: corrupt degrades safely, crafted-valid is the finding.** CORRUPT: the twin's monitor stops ONLY itself — `xtcp_gauges{function="linkMonitor",variable="up"}` 1→0, the failure counted, /healthz 200, and TCP collection UNAFFECTED (the twin's records keep flowing to its catcher) — the runLinkMonitor contract, repeated on Ubuntu/Docker. CRAFTED-VALID: `{"version":1,"expected_up_links":99999,"recorded_at":…}` is accepted without complaint (no hash, no mode check — `go_link_monitor_baseline_ready 1`; the poisoned record IS the durable baseline) and produces **`go_link_monitor_up_links_delta = -99997` — a fake ~100k "links missing" alert from ONE file write**, with the monitor up the whole time. Fix space (#401): an integrity check at load (the #341 family) or a bound: 99999 expected vs ~2 collectable up links should refuse. | | rt-6-5 | 2026-12-05 | host+raw+min; the row daemon (its 0400 secrets — the reference) untouched; one twin with fresh 0644 tokens (the mistake shape) bind-mounted read-only | BLOCKED | — (the plan's premise is STALE — the refusal already exists) | `20261205T221425-4a9a9345b-1938524` (10/10; run 1 designed the row as CONFIRMED on the plan's "loader does not check file modes" premise — the measured refusal refuted it, and the row's "consider refusing world-readable secret files at startup" is already the product behavior) | **The listener REFUSES a group/world-readable secret file at startup — the row's premise is refuted.** The 0644 twin exits at startup: "listener 'prometheus': … a secret file must not be accessible by group or others (chmod 0400; Kubernetes secret defaultMode: 0400)" — the refusal names the rule and the fix. The read-side audit stands: the 0644 file is still world-readable ON THE MOUNT (`sudo -u nobody cat` reads the token — the refusal stops the daemon's USE, not the file's read; the 0400 requirement is the deployment's to honor), and the leaked token has nothing to answer (000 — no listener): the refusal precedes the exposure. The positive control: the 0400 twin starts and serves /metrics 200 with the token, and the row daemon's own secrets ship 0400 (victim.sh's provision). | | rt-6-6 | 2026-12-05 | host+raw+min; the ROW daemon is the target (goip docker-cp'd into its own shell-less container — the rt-5-3 busybox pattern; argv[0] stays goip), plus a /ip twin (-linkMonitorIPPaths, `serves=…+ip`) | BLOCKED | — | `20261205T235143-4a9a9345b-2820953` (14/14; runs a–f were scenario bugs: goip prints "state UNKNOWN" for a loopback — the up/down signal is the flags list ``; a multiline awk program is a newline inside a single-quoted string; the expected-refusal exit 1 must be captured with the &&/|| idiom, never the bare $? after the command (set -e kills the scenario first); the /ip paths are an endpoint CLASS — the listener needs `serves=ip`) | **The confinement holds on every axis.** With `GOIP_WRITE_OUT` set, the write verbs (the goip_write-tagged build, run from the daemon's own container) write the request FILE only — the loopback flags `` unchanged after `link set lo down`, the route table unchanged after `route add 203.0.113.0/24`, the daemon undisturbed; without the variable the verbs refuse outright ("goip never applies a write", exit 1). The API: the row daemon serves /ip OFF by default (404); the /ip twin serves the read verb /ip/link (200) and refuses the write verb /i/l/s/dev/lo/down 400 BY NAME ("A write verb counts, so /i/l/s is refused as `ip link set`") — with no write encoder in the binary to reach (no-write-encoders, the flake check). | +| rt-11-13 | 2026-12-06 | host+raw+min; the row daemon untouched; the victim twin (health on the shared UDS path, metrics on loopback :9317, its own baseline in the shared /var/lib/xtcp2, its own catcher :9995) + the neighbor (a real xtcp2 co-tenant, the tier-3 cap shape, BOTH volumes rw, busybox+socat docker-cp'd in) + a capability-less co-tenant (docker create --cap-drop=ALL + cp busybox + start, parked as busybox sleep) for the no-cap leg | CONFIRMED | #400/#401 (the Docker-topology delivery legs — no new issue: the shared volume IS the attack) | `20261206T180851-173217a25-1948319` (21/21; run 1 was three scenario bugs: the scratch image has NO /bin/sh — socat's SYSTEM: runs its command through `sh -c`, so the fake-socket echo needs busybox docker-cp'd AS /bin/sh; it has no /tmp either — docker cp needs an existing parent, so the poison rides the shared mount; and `docker start` has no --entrypoint flag — the entrypoint is set at docker create) | **The RT-6 attacks land from a neighbor with no exploit at all — and the caps are irrelevant.** THEFT: the neighbor unlinks the victim twin's LIVE socket (0600, root-owned, in docker's 0755 bind dir — the rt-6-3 private-parent defense never runs on a pre-mounted dir) and binds its own fake at the path; the twin keeps running, /metrics stays 200, records keep flowing (catcher 22346→24168 through the theft), and NO `function="listener"` series exists in the exposition — there is no daemon-side counter for a stolen socket path, the operator's probe is the only detector. POISON: the neighbor overwrites the LIVE baseline file through the rw mount and it is LATENT — Store.LoadAndLock runs at startup only (12 s with the poison in place: delta ≈0, baseline_ready=1, the running daemon never re-reads it), then ANY restart (crash, upgrade, node reboot) loads it as a healthy baseline and fires `go_link_monitor_up_links_delta = -99997` — the fake ~100k alert from one neighbor write; and the restart's stale-unlink policy re-taking the path (removing the attacker's fake, /healthz 200) is both the ONLY theft recovery AND the poison's trigger. NOCAP: a capability-less co-tenant (--cap-drop=ALL — not even xtcp2's two fatal caps, it parks as busybox sleep) unlinks a live socket through the rw volume all the same — uid 0 owns the shared dir, owner-write needs no CAP_DAC_OVERRIDE: the volume mount, not any cap, is the attack, and the plan's "privileged neighbor" overstates the requirement. | diff --git a/vagrant/scenarios/rt-11-13-uds-neighbor.sh b/vagrant/scenarios/rt-11-13-uds-neighbor.sh new file mode 100755 index 000000000..5b50b8530 --- /dev/null +++ b/vagrant/scenarios/rt-11-13-uds-neighbor.sh @@ -0,0 +1,400 @@ +#!/usr/bin/env bash +# vagrant/scenarios/rt-11-13-uds-neighbor.sh — RT-11 tier 3: the RT-6 attacks +# from a privileged neighbor (docs/redteam-plan.md row rt-11-13, task 5.8's +# deferred leg; the plan: "rt-6-2/6-3/6-4 applied from a privileged neighbor — +# covered by RT-6 rows; repeat here in the Docker topology"). +# +# THE PREMISE: the RT-6 rows measured the UDS unlink/hijack and the baseline +# poison from the VM host and the daemon's own container. The Docker-topology +# shape is a NEIGHBOR container sharing the victim's volumes: whatever is +# bind-mounted into two containers is writable by both, so the neighbor needs +# no exploit at all — an unlink and a file write. Measured in three legs: +# +# THEFT — the neighbor unlinks the victim twin's LIVE health socket +# (0600, root-owned, in a 0755 dir) through the shared volume and +# binds its own fake at the path. The chmod enforcement rt-6-3 +# measured is structurally unavailable here: the bind dir is +# docker's (0755), and container root passes the owner DAC check +# on it without any capability. The victim keeps running and +# delivering — no daemon-side counter exists (there is no +# function="listener" series at all) — the operator's probe +# through the path now talks to the ATTACKER (#400's family). +# +# POISON — the neighbor overwrites the twin's LIVE baseline file +# (-linkMonitorBaselineFile, shared /var/lib/xtcp2) with a +# crafted-valid record (expected_up_links=99999). The running +# daemon never re-reads it (Store.LoadAndLock runs once; the +# file is read at startup only — the runLinkMonitor contract: +# "the operator repairs or removes it and restarts xtcp2"), so +# the poison is LATENT: the next restart — crash, upgrade, node +# reboot, any — loads it as a healthy baseline and fires +# go_link_monitor_up_links_delta ≈ -99997: a fake ~100k alert +# from one neighbor write (#401's family, measured delivery). +# +# NOCAP — the plan says "privileged neighbor"; the caps are not what +# buys the unlink. A capability-less co-tenant (--cap-drop=ALL, +# not even the daemon's fatal caps) with the volume mounted +# unlinks a live socket all the same: uid 0 owns the shared dir, +# owner-write needs no CAP_DAC_OVERRIDE. The volume mount is the +# whole attack — the deployment invariant. +# +# THE VERDICT CRITERIA (the row): the attacks land from the neighbor +# (CONFIRMED — #400's shared-volume leg: the private-parent-dir defense does +# not survive a shared volume, and #401's latent-until-restart delivery). +set -euo pipefail + +: "${XTCP2_MODE:=host}" +: "${XTCP2_AUTH:=raw}" +: "${XTCP2_CAPS:=min}" +: "${XTCP2_ATTACKER:=plain}" +XTCP2_EXPECT="${XTCP2_EXPECT:-CONFIRMED}" + +RT1113_SOCKDIR=/var/lib/xtcp2-rt1113-sock # the shared socket dir (bind source) +RT1113_BASEDIR=/var/lib/xtcp2-rt1113-base # the shared /var/lib/xtcp2 (bind source) +RT1113_NOCAPDIR=/var/lib/xtcp2-rt1113-nocap # the leg-D decoy dir +RT1113_TWIN_CATCHER=/var/lib/xtcp2-catcher/rt-11-13.jsonl +RT1113_NB_CATCHER=/var/lib/xtcp2-catcher/rt-11-13-neighbor.jsonl + +# shellcheck source=/dev/null +source "$(dirname "${BASH_SOURCE[0]}")/../lib/matrix.sh" +# shellcheck source=/dev/null +source "$(dirname "${BASH_SOURCE[0]}")/../lib/evidence.sh" +# shellcheck source=/dev/null +source "$(dirname "${BASH_SOURCE[0]}")/../lib/ssh.sh" +# shellcheck source=/dev/null +source "$(dirname "${BASH_SOURCE[0]}")/../lib/deploy.sh" +# shellcheck source=/dev/null +source "$(dirname "${BASH_SOURCE[0]}")/../lib/invariant.sh" +# shellcheck source=/dev/null +source "$(dirname "${BASH_SOURCE[0]}")/../lib/assert.sh" + +xtcp2_matrix_defaults +xtcp2_preflight +evidence_init + +echo "rt-11-13: evidence in $RT_EVIDENCE (the RT-6 attacks from a Docker-topology neighbor)" + +# --- helpers ----------------------------------------------------------------------- + +# mval — one metric value from the twin's loopback +# exposition (auth=disabled, so no token; the twins never share the row +# daemon's 9088). Every pipeline in a $() is || true-guarded (the rt-5-6 +# lesson) and defaults to 0 through ${v:-0} — never `|| echo 0` on a curl -w +# (the double-print lesson). +mval() { + local v + v="$(vm_exec_root victim "curl -s --max-time 15 http://127.0.0.1:9317/metrics | grep '$1' | grep -v '^#' | grep -oE '[0-9.e+-]+\$' | awk 'NR==1 {print \$1}'" || true)" + echo "${v:-0}" +} + +twin_status() { # twin_status + vm_exec_root victim "docker inspect '$1' --format '{{.State.Status}}'" || true +} + +twin_catcher_lines() { # twin_catcher_lines (twin-named: invariant.sh owns the argless catcher_lines) + vm_exec_root victim "wc -l < '$1'" || echo 0 +} + +twin_catcher_gt() { # twin_catcher_gt — per-poll predicate + [ "$(twin_catcher_lines "$1")" -gt "$2" ] +} + +# path_owner: who answers the shared socket path RIGHT NOW — 'attacker' when +# the neighbor's fake echoes, 'daemon:' when the twin answers /healthz +# (pre-theft, and again after the restart's stale-unlink re-take), else +# 'gone:'. +path_owner() { + local reply code + reply="$(vm_exec_root victim "echo probe | timeout 3 socat - UNIX-CONNECT:'$RT1113_SOCKDIR/svc.sock'" || true)" + if [ "$reply" = "rt-11-13-attacker" ]; then + echo "attacker" + return 0 + fi + code="$(vm_exec_root victim "curl -s --max-time 5 --unix-socket '$RT1113_SOCKDIR/svc.sock' -o /dev/null -w '%{http_code}' http://localhost/healthz" || true)" + code="${code:-000}" + case "$code" in + 200 | 401 | 403) echo "daemon:$code" ;; + *) echo "gone:$code" ;; + esac +} + +path_is() { # path_is — per-poll quiet/wait_for predicate + [ "$(path_owner)" = "$1" ] +} + +metrics_code() { # the twin's loopback /metrics HTTP code + local c + c="$(vm_exec_root victim "curl -s --max-time 10 -o /dev/null -w '%{http_code}' http://127.0.0.1:9317/metrics" || true)" + echo "${c:-000}" +} + +metrics_is_200() { # per-poll predicate + [ "$(metrics_code)" = "200" ] +} + +# twin_baseline_ready / twin_delta_small — per-poll predicates. +twin_baseline_ready() { + [ "$(mval 'go_link_monitor_baseline_ready')" = "1" ] +} + +delta_abs_lt() { # delta_abs_lt — |up_links_delta| < bound (awk: NaN-safe) + local d + d="$(mval 'go_link_monitor_up_links_delta')" + awk -v v="$d" -v b="$1" 'BEGIN { exit !(v <= b && v >= -b) }' +} + +delta_lt() { # delta_lt — up_links_delta < bound + local d + d="$(mval 'go_link_monitor_up_links_delta')" + awk -v v="$d" -v b="$1" 'BEGIN { exit !(v < b) }' +} + +cleanup() { + for t in rt-1113-victim rt-1113-neighbor rt-1113-nocap; do + vm_exec_root victim "docker logs '$t' 2>&1 | tail -n 25" \ + >"$RT_EVIDENCE/$t.log" 2>/dev/null || true + vm_exec_root victim "docker rm -f '$t'" >/dev/null 2>&1 || true + done + vm_exec_root victim "stat '$RT1113_SOCKDIR/svc.sock'" \ + >"$RT_EVIDENCE/path-stat.txt" 2>&1 || true + vm_exec_root victim "cat '$RT1113_BASEDIR/lm.json'" \ + >"$RT_EVIDENCE/baseline-file.txt" 2>/dev/null || true + for f in rt-11-13.jsonl rt-11-13-neighbor.jsonl; do + vm_exec_root victim "tail -n 20 /var/lib/xtcp2-catcher/'$f'" \ + >"$RT_EVIDENCE/$f.tail" 2>/dev/null || true + done + vm_exec_root victim "pkill -f 'TCP-LISTEN:9995'" >/dev/null 2>&1 || true + vm_exec_root victim "pkill -f 'TCP-LISTEN:9996'" >/dev/null 2>&1 || true + vm_exec_root victim "pkill -f 'UNIX-LISTEN:$RT1113_NOCAPDIR/decoy.sock'" >/dev/null 2>&1 || true + vm_exec_root victim "rm -rf '$RT1113_SOCKDIR' '$RT1113_BASEDIR' '$RT1113_NOCAPDIR' '$RT1113_TWIN_CATCHER' '$RT1113_NB_CATCHER' /tmp/rt1113-poison.json" \ + >/dev/null 2>&1 || true +} +trap cleanup EXIT + +# ============================================================================= +# deploy + baseline: the row daemon is the healthy fleet this row never touches +# ============================================================================= + +xtcp2_deploy victim +wait_for 120 "daemon answers on the victim VM" vm_exec victim \ + "curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:9088/metrics | grep -qE '^(200|401|403)\$'" +victim_still_reporting_tap + +# ============================================================================= +# the topology: the victim twin (both volumes), the privileged neighbor (both +# volumes rw), the twin's own catcher. The twin's health listener IS the +# shared path; its metrics stay on loopback TCP so the scenario can read the +# daemon's own state after the path is stolen. +# ============================================================================= + +vm_exec_root victim "rm -rf '$RT1113_SOCKDIR' '$RT1113_BASEDIR' '$RT1113_NOCAPDIR'; mkdir -p '$RT1113_SOCKDIR' '$RT1113_BASEDIR' '$RT1113_NOCAPDIR' /var/lib/xtcp2-catcher; truncate -s 0 '$RT1113_TWIN_CATCHER' '$RT1113_NB_CATCHER'; (socat TCP-LISTEN:9995,reuseaddr,fork SYSTEM:'cat >> $RT1113_TWIN_CATCHER' &) >/dev/null 2>&1; (socat TCP-LISTEN:9996,reuseaddr,fork SYSTEM:'cat >> $RT1113_NB_CATCHER' &) >/dev/null 2>&1" + +# The victim twin: health on the SHARED unix path (auth=disabled is always +# allowed on a unix socket), metrics+metrics-detail on loopback TCP (allowed +# with a warning), the baseline in the SHARED /var/lib/xtcp2. +vm_exec_root victim "docker rm -f rt-1113-victim >/dev/null 2>&1 || true" +vm_exec_root victim "docker run -d --name rt-1113-victim \ + --network host --pid host --ipc host \ + --cap-drop=ALL --cap-add=NET_ADMIN --cap-add=SYS_ADMIN \ + --cap-add=SYS_PTRACE --cap-add=NET_RAW --cap-add=SYS_RESOURCE \ + -v '$RT1113_SOCKDIR':/run/xtcp2-shared \ + -v '$RT1113_BASEDIR':/var/lib/xtcp2 \ + -v /run/netns:/run/netns:ro,rslave \ + -v /run/docker/netns:/run/docker/netns:ro,rslave \ + xtcp2:latest \ + -listener 'name=healthz,serves=health,address=/run/xtcp2-shared/svc.sock,network=unix,auth=disabled' \ + -listener 'name=prometheus,serves=metrics+metrics-detail,address=127.0.0.1:9317,network=tcp,auth=disabled' \ + -dest 'tcp:127.0.0.1:9995' -marshal jsonl \ + -linkMonitorBaselineFile /var/lib/xtcp2/lm.json \ + -frequency 2s -timeout 1s \ + -hostname rt-11-13-victim" + +# The privileged neighbor: the tier-3 co-tenant cap shape, BOTH victim +# volumes mounted rw — the whole attack surface. It is a real xtcp2 (the +# image's entrypoint), parked on its own loopback listener, baseline and +# catcher; busybox+socat (static, from the attacker tools tar) are +# docker-cp'd in for the unlink/bind/write battery (the rt-5-3 pattern). +vm_exec_root victim "docker rm -f rt-1113-neighbor >/dev/null 2>&1 || true" +vm_exec_root victim "docker run -d --name rt-1113-neighbor \ + --network host --pid host --ipc host \ + --cap-drop=ALL --cap-add=NET_ADMIN --cap-add=SYS_ADMIN \ + --cap-add=SYS_PTRACE --cap-add=NET_RAW --cap-add=SYS_RESOURCE \ + -v '$RT1113_SOCKDIR':/run/xtcp2-shared \ + -v '$RT1113_BASEDIR':/var/lib/xtcp2 \ + xtcp2:latest \ + -listener 'name=nmetrics,serves=metrics,address=127.0.0.1:9318,network=tcp,auth=disabled' \ + -dest 'tcp:127.0.0.1:9996' -marshal jsonl \ + -linkMonitorBaselineFile /var/lib/xtcp2/neighbor.json \ + -frequency 2s -timeout 1s \ + -hostname rt-11-13-neighbor" +vm_exec_root victim "docker cp /opt/xtcp2-redteam/bin/busybox rt-1113-neighbor:/bin/busybox" +vm_exec_root victim "docker cp /opt/xtcp2-redteam/bin/socat rt-1113-neighbor:/bin/socat" +# The scratch image has NO /bin/sh — and socat's SYSTEM: runs its command +# through `sh -c`, so the fake-socket echo needs one. busybox AS /bin/sh +# dispatches on argv[0] (the rt-5-4 lesson's flip side: the name must BE the +# applet you want). +vm_exec_root victim "docker cp /opt/xtcp2-redteam/bin/busybox rt-1113-neighbor:/bin/sh" + +# ============================================================================= +# leg A — the healthy twin: the operator's probe, its learned baseline, flow +# ============================================================================= + +if quiet 60 path_is "daemon:200"; then + ok "the twin serves /healthz through the shared path (the operator's probe answers 200)" +else + not_ok "the twin never served on the shared path ($(path_owner))" + finish rt-11-13 NA +fi + +if quiet 150 twin_baseline_ready; then + ok "the twin learned and saved its own baseline (baseline_ready=1, monitor up=$(mval 'function=\"linkMonitor\",type=\"gauge\",variable=\"up\"'))" +else + not_ok "the twin's baseline never became ready (150 s)" +fi + +if delta_abs_lt 10; then + ok "go_link_monitor_up_links_delta ≈ 0 ($(mval 'go_link_monitor_up_links_delta')) — the healthy reference" +else + not_ok "the healthy delta is not ~0 ($(mval 'go_link_monitor_up_links_delta'))" +fi + +if quiet 60 twin_catcher_gt "$RT1113_TWIN_CATCHER" 30; then + ok "the twin is delivering records to its catcher (>30 lines)" +else + not_ok "the twin's records never flowed (catcher $(twin_catcher_lines "$RT1113_TWIN_CATCHER") lines)" +fi + +# ============================================================================= +# leg B — THE THEFT: the neighbor unlinks the LIVE socket and binds its fake +# ============================================================================= + +SOCK_MODE="$(vm_exec_root victim "stat -c %a '$RT1113_SOCKDIR/svc.sock'" || true)" +DIR_MODE="$(vm_exec_root victim "stat -c %a '$RT1113_SOCKDIR'" || true)" +if [ "$SOCK_MODE" = "600" ] && [ "$DIR_MODE" = "755" ]; then + ok "the shared shape: the socket is 0600 in a 0755 dir — the bind dir is DOCKER's, not the daemon's (the rt-6-3 private-parent default never runs on a pre-mounted dir)" +else + not_ok "the shared shape differs (socket ${SOCK_MODE:-?}, dir ${DIR_MODE:-?}) — the chmod leg changed" +fi + +vm_exec_root victim "docker exec rt-1113-neighbor /bin/busybox rm -f /run/xtcp2-shared/svc.sock" +vm_exec_root victim "docker exec -d rt-1113-neighbor /bin/socat UNIX-LISTEN:/run/xtcp2-shared/svc.sock,fork SYSTEM:'echo rt-11-13-attacker'" +ok "the attack: the neighbor unlinks the LIVE socket and binds its own fake at the path (no exploit — the rw volume)" + +if quiet 30 path_is "attacker"; then + ok "the neighbor's fake OWNS the path: the operator's probe now talks to the attacker" +else + not_ok "the neighbor's fake did not take the path ($(path_owner))" +fi + +if [ "$(twin_status rt-1113-victim)" = "running" ] && [ "$(metrics_code)" = "200" ]; then + ok "the twin is still running and /metrics still 200 — the theft is silent for the daemon" +else + not_ok "the twin is gone or dark ($(twin_status rt-1113-victim), metrics $(metrics_code)) — a different failure than the theft" +fi + +THEFT_C0="$(twin_catcher_lines "$RT1113_TWIN_CATCHER")" +if quiet 45 twin_catcher_gt "$RT1113_TWIN_CATCHER" "$THEFT_C0"; then + ok "the twin's records kept flowing through the theft (catcher $THEFT_C0 → $(twin_catcher_lines "$RT1113_TWIN_CATCHER")) — the fleet's view is normal" +else + not_ok "the twin's records stopped at the theft — the theft is not silent" +fi + +LISTENER_SERIES="$(vm_exec_root victim "curl -s --max-time 15 http://127.0.0.1:9317/metrics | grep -c 'function=.listener'" || true)" +LISTENER_SERIES="${LISTENER_SERIES:-0}" +if [ "$LISTENER_SERIES" = "0" ]; then + ok "no function=\"listener\" series exists in the twin's exposition — there is no daemon-side counter for a stolen socket path (the external probe is the only detector)" +else + not_ok "a listener series exists ($LISTENER_SERIES lines) — re-check what it counts before keeping this verdict" +fi + +# ============================================================================= +# leg C — THE POISON: the neighbor overwrites the LIVE baseline file; the +# running daemon never re-reads it; the next restart loads it and fires +# ============================================================================= + +vm_exec_root victim "printf '%s' '{\"version\":1,\"expected_up_links\":99999,\"recorded_at\":\"2026-12-06T00:00:00Z\"}' > /tmp/rt1113-poison.json" +# The scratch image has no /tmp either — docker cp needs an existing parent, +# and the neighbor's shared mount is guaranteed to exist. The cp INTO the +# mount is just transport; the ATTACK WRITE is the neighbor's busybox cp. +vm_exec_root victim "docker cp /tmp/rt1113-poison.json rt-1113-neighbor:/var/lib/xtcp2/.poison" +vm_exec_root victim "docker exec rt-1113-neighbor /bin/busybox cp /var/lib/xtcp2/.poison /var/lib/xtcp2/lm.json" + +POISON_SEEN="$(vm_exec_root victim "cat '$RT1113_BASEDIR/lm.json'" || true)" +if [ "$POISON_SEEN" = '{"version":1,"expected_up_links":99999,"recorded_at":"2026-12-06T00:00:00Z"}' ]; then + ok "the neighbor's write landed: the LIVE baseline file is the crafted record (one write through the rw volume)" +else + not_ok "the baseline file is not the neighbor's craft — the write did not land" +fi + +sleep 12 # 6 poll cycles with the poison in place — the latent check +if delta_abs_lt 10 && [ "$(mval 'go_link_monitor_baseline_ready')" = "1" ]; then + ok "LATENT: 12 s later the running twin's delta is still ≈0 and ready=1 — the baseline file is read at STARTUP only; the poison waits for the next restart" +else + not_ok "the running twin reacted to the poison (delta $(mval 'go_link_monitor_up_links_delta')) — a different shape than the one-shot load" +fi + +vm_exec_root victim "docker restart rt-1113-victim" >/dev/null +ok "the restart: crash, upgrade, node reboot — any restart loads the file" + +if quiet 60 path_is "daemon:200"; then + ok "the restarted twin's stale-unlink policy removed the ATTACKER's fake and re-took the path (/healthz 200) — the only recovery is also the poison's trigger" +else + not_ok "the restarted twin did not re-take the path ($(path_owner))" +fi + +if quiet 60 metrics_is_200 && quiet 150 twin_baseline_ready; then + ok "the twin is back: /metrics 200, monitor up=$(mval 'function=\"linkMonitor\",type=\"gauge\",variable=\"up\"'), baseline_ready=1 — the poison loaded as a HEALTHY baseline" +else + not_ok "the restarted twin never settled (metrics $(metrics_code), ready $(mval 'go_link_monitor_baseline_ready'))" +fi + +echo "rt-11-13: post-restart up_links_delta = $(mval 'go_link_monitor_up_links_delta')" +if delta_lt -10000; then + ok "go_link_monitor_up_links_delta = $(mval 'go_link_monitor_up_links_delta') — the FAKE ~100k 'links missing' alert fires from ONE neighbor write, no integrity check anywhere (#401)" +else + not_ok "the fake alert did not fire ($(mval 'go_link_monitor_up_links_delta'))" +fi + +RESTART_C1="$(twin_catcher_lines "$RT1113_TWIN_CATCHER")" +if quiet 60 twin_catcher_gt "$RT1113_TWIN_CATCHER" "$((RESTART_C1 + 20))"; then + ok "records flow again post-restart (catcher $RESTART_C1 → $(twin_catcher_lines "$RT1113_TWIN_CATCHER")) — the daemon is fine; the fake alert is the ONLY symptom" +else + not_ok "records did not resume post-restart (catcher $(twin_catcher_lines "$RT1113_TWIN_CATCHER"))" +fi + +# ============================================================================= +# leg D — NOCAP: the caps were never the attack. A capability-less co-tenant +# (docker create + cp + start --entrypoint busybox — a zero-cap container +# cannot even run xtcp2, its two caps are fatal-drop ones) unlinks a live +# socket through the rw volume all the same. +# ============================================================================= + +vm_exec_root victim "(socat UNIX-LISTEN:'$RT1113_NOCAPDIR/decoy.sock',fork SYSTEM:'echo rt-11-13-decoy' &) >/dev/null 2>&1; sleep 2" +DECOY_REPLY="$(vm_exec_root victim "echo probe | timeout 3 socat - UNIX-CONNECT:'$RT1113_NOCAPDIR/decoy.sock'" || true)" + +# --entrypoint at CREATE (docker start has no --entrypoint flag); the cp +# lands busybox before the start, and the parked co-tenant runs busybox sleep. +vm_exec_root victim "docker rm -f rt-1113-nocap >/dev/null 2>&1 || true" +vm_exec_root victim "docker create --name rt-1113-nocap --cap-drop=ALL --network host -v '$RT1113_NOCAPDIR':/run/xtcp2-shared --entrypoint /bin/busybox xtcp2:latest sleep 900" +vm_exec_root victim "docker cp /opt/xtcp2-redteam/bin/busybox rt-1113-nocap:/bin/busybox" +vm_exec_root victim "docker start rt-1113-nocap" + +if [ "$DECOY_REPLY" = "rt-11-13-decoy" ] && [ "$(twin_status rt-1113-nocap)" = "running" ]; then + ok "the decoy service is live on the shared dir and the no-cap co-tenant is running (--cap-drop=ALL, no adds)" +else + not_ok "the leg-D shape broke (decoy '${DECOY_REPLY:-}', nocap $(twin_status rt-1113-nocap))" + finish rt-11-13 NA +fi + +vm_exec_root victim "docker exec rt-1113-nocap /bin/busybox rm -f /run/xtcp2-shared/decoy.sock" +if [ -z "$(vm_exec_root victim "stat -c %i '$RT1113_NOCAPDIR/decoy.sock'" || true)" ]; then + ok "the capability-less co-tenant unlinked the LIVE socket too — uid 0 owns the shared dir; the volume mount, not any cap, is the attack ('privileged neighbor' overstates the requirement)" +else + not_ok "the no-cap co-tenant could not unlink — re-examine (the DAC story changed?)" +fi + +# ============================================================================= +# verdict +# ============================================================================= + +finish rt-11-13 CONFIRMED