Zero Breach — local, read-only scanner that checks a computer for indicators of the AdFection / Candiru ad-delivered spyware campaign. No network, no admin, no dependencies.
Reject caught network attempts and stale displayed checksums
interplains99ce49474e02
diff --git a/TESTING.md b/TESTING.mdindex 85fbf91..a2fb7bb 100644--- a/TESTING.md+++ b/TESTING.md@@ -47,6 +47,8 @@ untested optional positives as a skip. Use `--require-patterns` before release.and temporary snapshots must be removed.- During fixture scans, an audit hook rejects socket activity, subprocesses andfile opens/listings outside fixture, project-code and Python-runtime roots.+ The scanner's network-guard recorder is checked too, so caught network+ attempts cannot pass silently. Each unit-suite run has its own temp directory.Each fixture process has a 45-second timeout; timeouts or assertion failuresmake the command fail. Results/logs stay under ignored`findings/release-checks/summary.json`. `PASS_WITH_SKIPS` names missing coverage.@@ -70,7 +72,7 @@ python tools/release_check.py --require-patterns --web-dir PATH_TO_SCAN_DIRECTOR`--web-dir` requires Node, `index.html`, `scan.js`, and`ops/test_scan_logic.js`. It runs the existing offline page-flow matrix and-requires the page's displayed checksum to match the candidate script. These+ requires the verification card's code text and copy value to match the candidate script. Theseare DOM/logic fixtures; actual rendering and touch behaviour still need thebrowser smoke check. `--scanner` requires the staged download to match thefresh build byte for byte. Omit it to test the freshly built download.diff --git a/scan/tests/test_release_check.py b/scan/tests/test_release_check.pynew file mode 100644index 0000000..76d0417--- /dev/null+++ b/scan/tests/test_release_check.py@@ -0,0 +1,60 @@+"""Regressions for false-green failures in the offline release gate itself."""+import importlib.util+from pathlib import Path+import subprocess+import sys+import tempfile+import unittest++ROOT = Path(__file__).resolve().parents[2]+spec = importlib.util.spec_from_file_location("release_gate", ROOT / "tools/release_check.py")+gate = importlib.util.module_from_spec(spec)+spec.loader.exec_module(gate)+++class TestWebDownloadChecksum(unittest.TestCase):+ DIGEST = "a" * 64++ def panel(self, displayed=None, copied=None):+ return ('<div id="verify-download"><div class="ea-copy"><code>{}</code>'+ '<button data-copy="{}">Copy SHA-256</button></div></div>').format(+ displayed or self.DIGEST, copied or self.DIGEST)++ def test_actual_code_and_copy_value_match(self):+ gate.check_web_checksum(self.panel(), self.DIGEST)++ def test_correct_hash_in_comment_does_not_mask_wrong_display(self):+ html = self.panel(displayed="b" * 64) + "<!-- " + self.DIGEST + " -->"+ with self.assertRaisesRegex(RuntimeError, "displayed/copied"):+ gate.check_web_checksum(html, self.DIGEST)++ def test_correct_display_does_not_mask_wrong_copy_value(self):+ with self.assertRaisesRegex(RuntimeError, "displayed/copied"):+ gate.check_web_checksum(self.panel(copied="b" * 64), self.DIGEST)+++class TestCaughtNetworkAttempt(unittest.TestCase):+ def test_scanner_cannot_hide_an_attempt_by_catching_guard_exception(self):+ with tempfile.TemporaryDirectory(prefix="zb_gate_regression_") as tmp:+ root = Path(tmp)+ candidate = root / "candidate.py"+ subprocess.run([sys.executable, "-B", str(ROOT / "build/bundle.py"),+ str(ROOT), str(candidate)], check=True, capture_output=True)+ source = candidate.read_text(encoding="utf-8")+ needle = "def _pattern_engine():"+ self.assertIn(needle, source)+ # no_network blocks this before any real resolution; the pattern+ # module catches it and would normally just report UNKNOWN.+ source = source.replace(needle, needle + '\n __import__("socket").'+ 'gethostbyname("release-fixture.invalid")')+ candidate.write_text(source, encoding="utf-8")+ proc = subprocess.run(+ [sys.executable, "-B", str(ROOT / "tools/release_fixture.py"),+ "bundle", "patterns", str(root / "fixture"), str(candidate)],+ stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=45)+ self.assertNotEqual(proc.returncode, 0)+ self.assertIn(b"blocked external activity occurred", proc.stderr)+++if __name__ == "__main__":+ unittest.main()diff --git a/tools/release_check.py b/tools/release_check.pyindex 889aa6a..25343a2 100644--- a/tools/release_check.py+++ b/tools/release_check.py@@ -2,6 +2,7 @@"""Small, offline pre-release gate. Never runs a scan against the real host."""import argparseimport hashlib+from html.parser import HTMLParserimport importlib.utilimport jsonimport os@@ -17,6 +18,59 @@ CASES = ("clean", "contact", "reference", "hash", "corrupt", "hit-and-gap", "qui"dns-cap-hit", "dns-cap-gap", "bad-feed", "patterns")+class DownloadPanel(HTMLParser):+ """Read code/copy values from the actual verification card, not comments."""+ def __init__(self):+ super().__init__()+ self.depth = 0+ self.group_depth = None+ self.group = None+ self.capture = None+ self.cards = 0+ self.groups = []++ def handle_starttag(self, tag, attributes):+ attrs = dict(attributes)+ if tag == "div":+ if attrs.get("id") == "verify-download":+ self.cards += 1+ self.depth = 1+ elif self.depth:+ self.depth += 1+ if self.depth and "ea-copy" in attrs.get("class", "").split():+ self.group = {"code": "", "label": "", "copy": None}+ self.groups.append(self.group)+ self.group_depth = self.depth+ elif self.group is not None and tag in ("code", "button"):+ self.capture = "code" if tag == "code" else "label"+ if tag == "button":+ self.group["copy"] = attrs.get("data-copy")++ def handle_endtag(self, tag):+ if tag in ("code", "button"):+ self.capture = None+ if tag == "div" and self.depth:+ if self.depth == self.group_depth:+ self.group = None+ self.group_depth = None+ self.depth -= 1++ def handle_data(self, text):+ if self.group is not None and self.capture:+ self.group[self.capture] += text+++def check_web_checksum(html, digest):+ panel = DownloadPanel()+ panel.feed(html)+ candidates = [g for g in panel.groups if g["label"].strip() == "Copy SHA-256"]+ if panel.cards != 1 or len(candidates) != 1:+ raise RuntimeError("Scan page must have one verification card and SHA-256 copy control")+ value = candidates[0]+ if value["code"].strip() != digest or value["copy"] != digest:+ raise RuntimeError("Scan page displayed/copied checksum differs from the candidate download")++def main():parser = argparse.ArgumentParser(description=__doc__)parser.add_argument("--require-patterns", action="store_true",@@ -38,10 +92,10 @@ def main():"scope": "Offline fixtures; OS collection is simulated; no personal scan"}env = dict(os.environ, PYTHONUTF8="1", PYTHONDONTWRITEBYTECODE="1")- def run(name, command, timeout=60):+ def run(name, command, timeout=60, environment=None):tick = time.monotonic()try:- proc = subprocess.run(command, cwd=ROOT, env=env, stdin=subprocess.DEVNULL,+ proc = subprocess.run(command, cwd=ROOT, env=environment or env, stdin=subprocess.DEVNULL,stdout=subprocess.PIPE, stderr=subprocess.STDOUT,timeout=timeout)text = proc.stdout.decode("utf-8", errors="replace")@@ -69,8 +123,12 @@ def main():summary["skipped"].append("Real YARA-X positives: engine not installed")if not args.e2e_only:- run("unit-tests", [sys.executable, "-B", "-m", "unittest", "discover",- "-s", "scan/tests"], timeout=180)+ # Snapshot-cleanup tests inspect the temp directory. Separate+ # release runs must not see each other's transient snapshots.+ with tempfile.TemporaryDirectory(prefix="zb_unit_") as unit_temp:+ unit_env = dict(env, TMP=unit_temp, TEMP=unit_temp, TMPDIR=unit_temp)+ run("unit-tests", [sys.executable, "-B", "-m", "unittest", "discover",+ "-s", "scan/tests"], timeout=180, environment=unit_env)with tempfile.TemporaryDirectory(prefix="zb_release_") as temp:work = Path(temp)@@ -108,12 +166,12 @@ def main():if web is not None:web = web.resolve()test = web / "ops/test_scan_logic.js"- if not test.is_file() or not shutil.which("node"):- raise RuntimeError("web check requires Node and ops/test_scan_logic.js")+ if not all((web / name).is_file() for name in+ ("index.html", "scan.js", "ops/test_scan_logic.js")) or not shutil.which("node"):+ raise RuntimeError("web check requires Node, index.html, scan.js and ops/test_scan_logic.js")run("web-logic", ["node", str(test)])html = (web / "index.html").read_text(encoding="utf-8")- if digest not in html:- raise RuntimeError("Scan page checksum differs from the candidate download")+ check_web_checksum(html, digest)steps.append({"name": "web-download-checksum", "seconds": 0})else:summary["skipped"].append("Website: separate site source not supplied (--web-dir)")diff --git a/tools/release_fixture.py b/tools/release_fixture.pyindex 2577cf2..95c6821 100644--- a/tools/release_fixture.py+++ b/tools/release_fixture.py@@ -94,6 +94,18 @@ def main():registered.write_bytes(b"ordinary registered file")before = snapshot(inputs)denied_activity = []+ original_network_guard = cli.no_network++ @contextlib.contextmanager+ def checked_network_guard():+ # The scanner's socket wrappers reject calls before Python emits an+ # audit event. Observe their recorder too, including caught attempts.+ with original_network_guard() as recorder:+ try:+ yield recorder+ finally:+ denied_activity.extend(recorder.attempts)+allowed = (root, ROOT, Path(sys.prefix).absolute(), Path(sys.prefix).resolve(),Path(sys.base_prefix).absolute(), Path(sys.base_prefix).resolve())@@ -143,6 +155,7 @@ def main():if case == "patterns":argv.append("--patterns")with contextlib.ExitStack() as stack:+ stack.enter_context(patch.object(cli, "no_network", checked_network_guard))for mod, name, value in ((browser, "CHROMIUM_ROOTS", [("fixture", str(profile.parent))]),(browser, "FIREFOX_ROOTS", []),