#!/usr/bin/env python3 """Hardened container with one flag group removed at a time; shows which probe each flag stops.""" import subprocess, pathlib, sys sys.argv = ["x", "on"] HERE = pathlib.Path(__file__).parent.resolve() src = (HERE / "test_sandbox.py").read_text().split("mode = sys.argv[1]")[0] ns = {"__file__": str(HERE / "test_sandbox.py")}; exec(src, ns); PROBES = ns["PROBES"] GROUPS = { "network none": ["--network", "none"], "read-only": ["--read-only"], "cap-drop ALL": ["--cap-drop", "ALL"], "non-root user": ["--user", "10001:10001"], "pids-limit": ["--pids-limit", "64"], "memory limit": ["--memory", "128m", "--memory-swap", "128m"], } def args(drop): a = ["docker","run","--rm","--security-opt","no-new-privileges","--cpus","1","--tmpfs","/tmp:rw,noexec,nosuid,size=16m", "-v",f"{HERE}/work:/work","-w","/work","-e","HOME=/home/agent"] for k,v in GROUPS.items(): if k != drop and not (drop == 'read-only+user' and k in ('read-only','non-root user')): a += v return a + ["alpine:3.20","sh","-c"] for drop in [None] + list(GROUPS) + ['read-only+user']: hits = [] for name, cmd in PROBES.items(): p = subprocess.run(args(drop)+[cmd], capture_output=True, text=True, timeout=40) if "ATTACK_SUCCEEDED" in p.stdout: hits.append(name) print(f"without {drop or 'nothing (full set)':<15} -> succeeded: {hits or 'none'}")