import urllib.request import urllib.parse import http.cookiejar def test_login(ip): cj = http.cookiejar.CookieJar() opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj)) # 1. Fetch login page to get CSRF/session login_url = f"http://{ip}/admin/login" req = urllib.request.Request(login_url, headers={"User-Agent": "Mozilla/5.0"}) with opener.open(req) as resp: html = resp.read().decode('utf-8') # 2. Submit password post_data = urllib.parse.urlencode({"pw": "snarfnetadmin", "login": "Log in (uses cookie)"}).encode('ascii') req_post = urllib.request.Request(f"http://{ip}/admin/login", data=post_data, headers={"User-Agent": "Mozilla/5.0", "Referer": login_url}) try: with opener.open(req_post) as resp: content = resp.read().decode('utf-8') if "Wrong password" in content: print(f"Server {ip}: WRONG PASSWORD!") else: print(f"Server {ip}: LOGIN SUCCESSFUL! Redirected to {resp.geturl()}") except Exception as e: print(f"Server {ip}: Exception during login: {e}") test_login("140.44.4.36") test_login("140.44.4.65")