133 lines
6.6 KiB
Python
133 lines
6.6 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""MLH mass registration: signup + Turnstile (2captcha) + magic-link sign-in + onboarding name.
|
|
Usage: python mass_reg.py [N]
|
|
Output: mlh_farm_accounts.jsonl (email, name, cookies, signed)
|
|
Stdlib only, Python 3.11+."""
|
|
import json, time, random, string, urllib.request, urllib.parse, urllib.error
|
|
import http.cookiejar, re, imaplib, email, sys
|
|
|
|
N = int(sys.argv[1]) if len(sys.argv) > 1 else 5
|
|
OUT = "mlh_farm_accounts.jsonl"
|
|
CFG = json.load(open("creds.json"))
|
|
IMAP_USER = CFG["imap_user"]; IMAP_PASS = CFG["imap_pass"]
|
|
KK = CFG["twocaptcha_key"]; SITEKEY = CFG.get("mlh_sitekey", "0x4AAAAAAARi-8xgLgfKOXIb")
|
|
ALIAS_BASE = IMAP_USER.split("@")[0]
|
|
|
|
FIRST = ["Alex","Max","Dan","Nick","Sam","Leo","Ivan","Mark","Paul","Victor","Oleg","Roman","Egor","Timur","Kirill"]
|
|
LAST = ["Orlov","Kovalov","Smirnov","Petrov","Ivanov","Novak","Shevchenko","Morozov","Volkov","Lebedev","Sokolov","Popov","Ermakov","Zaitsev","Golubev"]
|
|
UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0 Safari/537.36"
|
|
|
|
def log(*a): print(time.strftime("%H:%M:%S"), *a, flush=True)
|
|
|
|
def api(url, data):
|
|
req = urllib.request.Request(url, data=urllib.parse.urlencode(data).encode())
|
|
return json.loads(urllib.request.urlopen(req, timeout=30).read())
|
|
|
|
def solve(action="authentication"):
|
|
r = api("https://api.2captcha.com/in.php", {"key": KK, "method": "turnstile", "sitekey": SITEKEY,
|
|
"pageurl": "https://www.mlh.com/", "action": action, "json": 1})
|
|
if r.get("status") != 1: return None
|
|
tid = r["request"]
|
|
for _ in range(90):
|
|
time.sleep(3)
|
|
rr = api("https://api.2captcha.com/res.php", {"key": KK, "action": "get", "id": tid, "json": 1})
|
|
if rr.get("status") == 1: return rr["request"]
|
|
if rr.get("request") != "CAPCHA_NOT_READY": return None
|
|
return None
|
|
|
|
def wait_magic(tag, timeout=300):
|
|
"""Poll Gmail for the 'Verify Your Identity' email addressed to the alias; return magic link."""
|
|
t0 = time.time()
|
|
while time.time() - t0 < timeout:
|
|
try:
|
|
M = imaplib.IMAP4_SSL("imap.gmail.com"); M.login(IMAP_USER, IMAP_PASS); M.select("INBOX")
|
|
typ, data = M.search(None, "ALL")
|
|
for i in reversed(data[0].split()[-25:]):
|
|
typ, hd = M.fetch(i, "(BODY.PEEK[HEADER.FIELDS (TO SUBJECT)])")
|
|
hs = hd[0][1].decode(errors="replace").lower()
|
|
if tag not in hs or "verify your identity" not in hs: continue
|
|
typ, full = M.fetch(i, "(BODY.PEEK[])")
|
|
msg = email.message_from_bytes(full[0][1]); b2 = ""
|
|
for p in msg.walk():
|
|
if p.get_content_type() == "text/plain":
|
|
b2 = p.get_payload(decode=True).decode(errors="replace"); break
|
|
lab = re.findall(r'Sign in\s*\(\s*(https://transactional\.mlh\.io/[^)\s]+)\s*\)', b2)
|
|
M.logout()
|
|
if lab: return lab[0]
|
|
except Exception as e:
|
|
log("imap err:", str(e)[:80])
|
|
time.sleep(6)
|
|
return None
|
|
|
|
def register_one():
|
|
tag = "mlh" + "".join(random.choices(string.ascii_lowercase, k=2)) + str(random.randint(10000, 99999))
|
|
addr = f"{ALIAS_BASE}+{tag}@gmail.com"
|
|
fn, ln = random.choice(FIRST), random.choice(LAST)
|
|
log("=== REG", addr)
|
|
cj = http.cookiejar.CookieJar()
|
|
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
|
|
opener.addheaders = [("User-Agent", UA)]
|
|
g = opener.open("https://www.mlh.com/signup", timeout=40); html = g.read().decode(errors="replace")
|
|
ver = re.search(r'"version":"([a-f0-9]+)"', html).group(1)
|
|
csrf = re.search(r'name="csrf-token" content="([^"]+)"', html).group(1)
|
|
tok = solve()
|
|
if not tok: return {"email": addr, "err": "no_token"}
|
|
body = json.dumps({"email": addr, "return_to": "", "cf-turnstile-response": tok}).encode()
|
|
req = urllib.request.Request("https://www.mlh.com/signin", data=body, method="POST")
|
|
for k, v in {"Content-Type": "application/json", "Accept": "text/html,application/xhtml+xml",
|
|
"X-Inertia": "true", "X-Inertia-Version": ver, "X-CSRF-Token": csrf,
|
|
"Referer": "https://www.mlh.com/signup", "Origin": "https://www.mlh.com"}.items():
|
|
req.add_header(k, v)
|
|
try:
|
|
resp = opener.open(req, timeout=45); resp.read()
|
|
log("step1:", resp.status, resp.url[:80])
|
|
except urllib.error.HTTPError as e:
|
|
return {"email": addr, "err": "step1_%s" % e.code}
|
|
link = wait_magic(tag)
|
|
if not link: return {"email": addr, "err": "no_magic"}
|
|
r = opener.open(link, timeout=60); d = r.read().decode(errors="replace")
|
|
signed = '"isSignedIn":true' in d
|
|
log("magic:", r.status, "signed:", signed)
|
|
if not signed:
|
|
return {"email": addr, "err": "not_signed", "cookies": "; ".join(f"{c.name}={c.value}" for c in cj)}
|
|
# onboarding: set name
|
|
try:
|
|
r2 = opener.open("https://www.mlh.com/account/onboarding", timeout=40)
|
|
d2 = r2.read().decode(errors="replace")
|
|
m = re.search(r'<script[^>]*type="application/json"[^>]*>(.*?)</script>', d2, re.S)
|
|
pg = json.loads(m.group(1)) if m else {}
|
|
c2 = re.search(r'name="csrf-token" content="([^"]+)"', d2)
|
|
ob = json.dumps({"user": {"first_name": fn, "last_name": ln}}).encode()
|
|
rq = urllib.request.Request("https://www.mlh.com/account/onboarding", data=ob, method="POST")
|
|
for k, v in {"Content-Type": "application/json", "X-Inertia": "true",
|
|
"X-Inertia-Version": pg.get("version", ""), "X-CSRF-Token": c2.group(1) if c2 else "",
|
|
"X-Requested-With": "XMLHttpRequest", "Origin": "https://www.mlh.com",
|
|
"Referer": "https://www.mlh.com/account/onboarding",
|
|
"Accept": "application/json, text/html"}.items():
|
|
rq.add_header(k, v)
|
|
try:
|
|
rr = opener.open(rq, timeout=40); log("onboard:", rr.status)
|
|
except urllib.error.HTTPError as e:
|
|
log("onboard err:", e.code)
|
|
except Exception as e:
|
|
log("onboard exc:", str(e)[:100])
|
|
ck = "; ".join(f"{c.name}={c.value}" for c in cj)
|
|
open(f"cookies_{tag}.txt", "w").write(ck)
|
|
rec = {"email": addr, "name": fn + " " + ln, "cookies_file": f"cookies_{tag}.txt",
|
|
"ts": int(time.time()), "signed": True, "event_reg": False}
|
|
with open(OUT, "a", encoding="utf-8") as f:
|
|
f.write(json.dumps(rec) + "\n")
|
|
log("SAVED", addr)
|
|
return rec
|
|
|
|
ok = 0
|
|
for i in range(N):
|
|
try:
|
|
r = register_one()
|
|
if r.get("signed"): ok += 1
|
|
else: log("FAIL:", json.dumps(r)[:200])
|
|
except Exception as e:
|
|
log("EXC:", str(e)[:200])
|
|
time.sleep(random.randint(20, 45))
|
|
log("DONE ok=%d/%d" % (ok, N))
|