reg: PAC per account (site via proxy, github direct) + device-verification via IMAP code; guide updated
This commit is contained in:
@@ -4,14 +4,14 @@
|
||||
Usage: python reg.py --start 0 --count 3 [--headless 1]
|
||||
State: done.json (logins tried), bank.jsonl (keys ok), fail.jsonl (reasons)
|
||||
"""
|
||||
import argparse, json, os, re, subprocess, sys, time, traceback
|
||||
import argparse, imaplib, json, os, re, ssl, subprocess, sys, time, traceback
|
||||
|
||||
from playwright.sync_api import sync_playwright
|
||||
import pyotp
|
||||
|
||||
CHROME = "C:/Program Files/Google/Chrome/Application/chrome.exe"
|
||||
ROOT = "C:/Users/User/tmp/numes"
|
||||
POOL = "C:/Users/User/tmp/cometwork/gh_alive.jsonl"
|
||||
ROOT = os.environ.get("NUMES_ROOT", "C:/Users/User/tmp/numes")
|
||||
POOL = os.environ.get("NUMES_POOL", ROOT + "/pool_all.jsonl")
|
||||
BANK = ROOT + "/bank.jsonl"
|
||||
FAIL = ROOT + "/fail.jsonl"
|
||||
DONE = ROOT + "/done.json"
|
||||
@@ -100,6 +100,56 @@ def fill_profile_if_asked(page, acc):
|
||||
log("profile fill err", e)
|
||||
|
||||
|
||||
IMAP_PRESET = {
|
||||
"t-online.de": "secureimap.t-online.de",
|
||||
"gmail.com": "imap.gmail.com",
|
||||
"googlemail.com": "imap.gmail.com",
|
||||
"outlook.com": "outlook.office365.com",
|
||||
"hotmail.com": "outlook.office365.com",
|
||||
"live.com": "outlook.office365.com",
|
||||
"yahoo.com": "imap.mail.yahoo.com",
|
||||
"gmx.de": "imap.gmx.net",
|
||||
"web.de": "imap.web.de",
|
||||
}
|
||||
|
||||
|
||||
def mail_code(acc, timeout=150):
|
||||
"""GitHub device-verification code from the account mailbox (IMAP)."""
|
||||
addr = (acc.get("email") or "").strip()
|
||||
pw = (acc.get("email_pw") or "").strip()
|
||||
if not addr or not pw:
|
||||
return ""
|
||||
dom = addr.split("@")[-1].lower()
|
||||
hosts = ([IMAP_PRESET[dom]] if dom in IMAP_PRESET else []) + \
|
||||
["imap." + dom, "mail." + dom, dom]
|
||||
t0 = time.time()
|
||||
while time.time() - t0 < timeout:
|
||||
for h in hosts:
|
||||
try:
|
||||
ctx = ssl.create_default_context()
|
||||
ctx.check_hostname = False
|
||||
ctx.verify_mode = ssl.CERT_NONE
|
||||
M = imaplib.IMAP4_SSL(h, 993, ssl_context=ctx, timeout=20)
|
||||
M.login(addr, pw)
|
||||
M.select("INBOX", readonly=True)
|
||||
typ, data = M.search(None, "FROM", '"github"')
|
||||
ids = (data[0].split() if data and data[0] else [])[-4:]
|
||||
for i in reversed(ids):
|
||||
typ, msg = M.fetch(i, "(RFC822)")
|
||||
raw = msg[0][1].decode("utf-8", "replace")
|
||||
if "device" not in raw.lower() and "verification" not in raw.lower():
|
||||
continue
|
||||
m = re.search(r"\b(\d{6})\b", raw)
|
||||
if m:
|
||||
M.logout()
|
||||
return m.group(1)
|
||||
M.logout()
|
||||
except Exception:
|
||||
continue
|
||||
time.sleep(8)
|
||||
return ""
|
||||
|
||||
|
||||
def do_login(page, acc):
|
||||
"""Возвращает (ok, reason)."""
|
||||
login, pw = acc["login"], acc["password"]
|
||||
@@ -130,8 +180,22 @@ def do_login(page, acc):
|
||||
except Exception as e:
|
||||
return False, f"2fa_fill_fail:{e}"
|
||||
|
||||
if "verified-device" in page.url or "sessions/verified" in page.url:
|
||||
return False, "gh_device_verification"
|
||||
if ("verified-device" in page.url or "sessions/verified" in page.url
|
||||
or ("github.com" in page.url and page.locator("input[name=value], #otp, input[autocomplete='one-time-code']").count())):
|
||||
log("device verification, читаю почту", login)
|
||||
code = mail_code(acc)
|
||||
if not code:
|
||||
return False, "gh_device_verification_no_code"
|
||||
try:
|
||||
sel = ("#otp" if page.locator("#otp").count() else
|
||||
("input[name=value]" if page.locator("input[name=value]").count()
|
||||
else "input[autocomplete='one-time-code']"))
|
||||
page.fill(sel, code)
|
||||
page.click("button[type=submit], input[type=submit]")
|
||||
page.wait_for_timeout(7000)
|
||||
log("device verification ok", login, code[:2] + "****")
|
||||
except Exception as e:
|
||||
return False, "dv_fill_fail:" + str(e)[:80]
|
||||
if "/session" in page.url and "github.com" in page.url:
|
||||
return False, "gh_login_failed"
|
||||
if page.locator("#signup-form, [data-testid=signup-form]").count() and "join" in page.url:
|
||||
@@ -308,7 +372,18 @@ def main():
|
||||
args = ["--disable-dev-shm-usage", "--disable-gpu", "--no-first-run",
|
||||
"--no-default-browser-check"]
|
||||
if px:
|
||||
args.append("--proxy-server=http://" + px)
|
||||
# PAC: сайт через прокси, GitHub напрямую (свежий egress на OAuth = device verification)
|
||||
host, _, port = px.rpartition(":")
|
||||
pac = ("function FindProxyForURL(url, host) {\n"
|
||||
" if (host == 'github.com' || shExpMatch(host, '*.github.com')\n"
|
||||
" || shExpMatch(host, '*.githubusercontent.com')\n"
|
||||
" || shExpMatch(host, '*.githubassets.com')\n"
|
||||
" || shExpMatch(host, '*.githubapp.com')) return 'DIRECT';\n"
|
||||
" return 'PROXY %s:%s';\n}\n" % (host, port))
|
||||
pac_path = os.path.join(ROOT, "proxy_%d.pac" % ((a.start + idx + attempt) % 120))
|
||||
with open(pac_path, "w", encoding="ascii") as pf:
|
||||
pf.write(pac)
|
||||
args.append("--proxy-pac-url=file:///" + pac_path.replace("\\", "/"))
|
||||
ctx = p.chromium.launch_persistent_context(
|
||||
prof,
|
||||
executable_path=CHROME,
|
||||
|
||||
Reference in New Issue
Block a user