"""WaveSpeed autoreg worker. One account = GH OAuth + Turnstile(2cap) + NL egress -> $1 trial.""" import requests, re, json, sys, time, os, uuid import pyotp HOME = os.environ.get("WS_HOME", os.path.dirname(os.path.abspath(__file__))) BANK = os.path.join(HOME, "bank.jsonl") USED = os.path.join(HOME, "used_gh.txt") UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36" KEY2CAP = os.environ.get("TWOCAPTCHA_KEY", "").strip() or open(os.path.join(HOME, ".2cap_key")).read().strip() SITE = "0x4AAAAAADkE2yCxK2sRF0Q4" CLIENT = "Ov23liO4t6o6MsNlCsE9" BOXES = [b.strip() for b in os.environ.get("WS_BOXES", "").split(",") if b.strip()] PXAUTH = os.environ.get("PROXY_AUTH", "") # user:pass for the HTTP CONNECT proxy pool def proxies(i): b = BOXES[i % len(BOXES)] px = "http://%s@%s:8888" % (PXAUTH, b) return {"http": px, "https": px} def ts_token(): s = requests.Session() r = s.post("https://api.2captcha.com/createTask", json={"clientKey": KEY2CAP, "task": { "type": "TurnstileTaskProxyless", "websiteURL": "https://wavespeed.ai/sign-in", "websiteKey": SITE, "action": "login", "userAgent": UA}}, timeout=30).json() tid = r.get("taskId") if not tid: raise RuntimeError("2cap: %s" % str(r)[:150]) for _ in range(40): time.sleep(5) res = s.post("https://api.2captcha.com/getTaskResult", json={"clientKey": KEY2CAP, "taskId": tid}, timeout=30).json() if res.get("status") == "ready": return res["solution"]["token"] if res.get("errorId"): raise RuntimeError("2cap err: %s" % str(res)[:150]) raise RuntimeError("turnstile timeout") def gh_login(s, login, password, totp_secret): r = s.get("https://github.com/login", timeout=45) m = re.search(r'name="authenticity_token" value="([^"]+)"', r.text) if not m: return "no-csrf" r = s.post("https://github.com/session", data={"authenticity_token": m.group(1), "login": login, "password": password, "commit": "Sign in", "return_to": ""}, timeout=45, allow_redirects=True) if "two-factor" in r.url: if not totp_secret: return "2fa-no-secret" code = pyotp.TOTP(totp_secret).now() m2 = re.search(r'name="authenticity_token" value="([^"]+)"', r.text) r = s.post("https://github.com/sessions/two-factor", data={"authenticity_token": m2.group(1) if m2 else "", "otp": code}, timeout=45, allow_redirects=True) if "two-factor" in r.url: return "2fa-fail" if "github.com/login" in r.url: return "login-fail" return "ok" def balance_of(s): d = s.get("https://wavespeed.ai/dashboard", timeout=60) m = re.search(r'Current credit balance.{0,220}?\$\s*([0-9.]+)', d.text, re.S) return (m.group(1) if m else None), d.text def reg(acc, idx=0): t0 = time.time() out = {"gh_login": acc["login"], "ts": int(t0), "box": BOXES[idx % len(BOXES)]} gs = requests.Session(); gs.headers.update({"User-Agent": UA, "Accept-Language": "en-US,en;q=0.9"}) st = gh_login(gs, acc["login"], acc["password"], acc.get("totp", "")) out["gh"] = st if st != "ok": return out ws = requests.Session(); ws.headers.update({"User-Agent": UA, "Accept-Language": "en-US,en;q=0.9"}) ws.proxies.update(proxies(idx)) _host = "api.ipify.org" if "127.0.0.1" in ws.proxies.get("http", "") else "api6.ipify.org" try: out["egress"] = requests.get("https://%s?format=json" % _host, proxies=ws.proxies, timeout=25).json().get("ip", "?") except Exception as e: out["egress"] = "?" tok = ts_token() r = ws.get("https://wavespeed.ai/center/default/github/login", params={"cf-turnstile-response": tok}, allow_redirects=False, timeout=60) if r.status_code != 302: out["err"] = "hop %s" % r.status_code return out authz = r.headers["location"] code = None for attempt in range(2): r2 = gs.get(authz, timeout=45, allow_redirects=False) loc = r2.headers.get("location", "") if loc.startswith("https://wavespeed.ai/center/default/github/callback"): code = loc break if "login/oauth/authorize" in r2.url: m = re.search(r'name="authenticity_token" value="([^"]+)"', r2.text) r2 = gs.post(r2.url, data={"authenticity_token": m.group(1) if m else "", "authorize": "1"}, timeout=45, allow_redirects=False) loc = r2.headers.get("location", "") if loc.startswith("https://wavespeed.ai/center/default/github/callback"): code = loc break if loc.startswith("https://wavespeed.ai"): code = loc break time.sleep(2) if not code: out["err"] = "no-callback(%s)" % (loc[:60] if loc else "empty") return out r3 = ws.get(code, timeout=60, allow_redirects=True) out["landed"] = r3.url if "dashboard" not in r3.url: t = re.sub(r"\s+", " ", re.sub(r"<[^>]+>", " ", r3.text)) out["err"] = "landed " + r3.url[:80] out["note"] = t[t.find("Welcome"):t.find("Welcome") + 200] if "Welcome" in t else "" return out bal, html = balance_of(ws) out["balance"] = bal kr = ws.post("https://wavespeed.ai/center/default/api/v1/accesskey/create", json={"name": "k" + uuid.uuid4().hex[:6]}, timeout=60) try: kd = kr.json(); out["key"] = (kd.get("data") or {}).get("key") except Exception: out["key_err"] = kr.text[:120] out["cookies"] = {c.name: c.value for c in ws.cookies if c.name.startswith("wavespeed")} out["secs"] = round(time.time() - t0, 1) return out def main(n): pool = json.load(open(r"C:\Users\User\tmp\runware\gh_ok.json", encoding="utf-8")) used = set(open(USED).read().split()) if os.path.exists(USED) else set() todo = [a for a in pool if a["login"] not in used] done = 0 for i, acc in enumerate(todo): if done >= n: break try: o = reg(acc, i) except Exception as e: o = {"gh_login": acc["login"], "error": repr(e)[:200]} with open(BANK, "a", encoding="utf-8") as f: f.write(json.dumps(o, ensure_ascii=False) + "\n") with open(USED, "a") as f: f.write(acc["login"] + "\n") done += 1 print(json.dumps({k: o.get(k) for k in ("gh_login", "gh", "balance", "key", "err", "note", "secs")}, ensure_ascii=False), flush=True) if __name__ == "__main__": main(int(sys.argv[1]) if len(sys.argv) > 1 else 1)