mfa_bind.py: real MFA+protection binder (proven -100/-101 2-state flow, vk21 E2E); auto.py: mfa_bind before DNS writes; gname_core: aqbh send-cooldown + freshness anchor; README: 4/4 domains proven
This commit is contained in:
+115
-25
@@ -1,26 +1,116 @@
|
||||
import os, json, time, re
|
||||
#!/usr/bin/env python3
|
||||
"""mfa_bind.py — bind TOTP MFA + enable operation-protection channels on a gname account.
|
||||
|
||||
WHY: gname DNS/domain writes fail in two opposite states:
|
||||
-100 "Please remove operation protection" -> session must pass aqbh email-code unlock FIRST
|
||||
-101 "please set operation protection" -> protection channels must be SET (czyz [1,4])
|
||||
Proven sequence (2026-10-16, uid 510198 / reformvk21.eu.cc):
|
||||
1. login -> GET secret from #/safeModify/lx=4/type=0/txt= (input[name=secret] or img src secret=)
|
||||
2. if writes return -100: aqbh_session_unlock (email code via IMAP; GM_EMAIL/GM_APPPW env)
|
||||
3. POST /user_zh/set_aqlb {secret, code=totp(secret)} -> MFA bound
|
||||
4. POST /user_zh/set_czyz czyz[]=1&czyz[]=4 -> email+MFA channels ON
|
||||
5. now /user_ym/jx_edit writes succeed (setup_dns.py)
|
||||
|
||||
Usage:
|
||||
python mfa_bind.py [--uid 510198] [--bank path/to/gname_accounts.jsonl] [--out mfa.json]
|
||||
Env: GM_EMAIL, GM_APPPW (gmail app-password) for the -100 email-code unlock.
|
||||
Secrets stay local: writes mfa_secret to --out (default gname_mfa.json, gitignored).
|
||||
"""
|
||||
import argparse, base64, hashlib, hmac, json, os, re, struct, sys, time
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
from playwright.sync_api import sync_playwright
|
||||
BASE = os.environ.get("GNAME_HOME", os.path.join(os.path.dirname(os.path.abspath(__file__)), "data"))
|
||||
with sync_playwright() as pw:
|
||||
b = pw.chromium.launch(headless=True, args=["--no-sandbox"])
|
||||
ctx = b.new_context(viewport={"width":1440,"height":950}, locale="en-US",
|
||||
user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/154.0.0.0 Safari/537.36")
|
||||
ctx.add_cookies(json.load(open(BASE+"/gname_cookies.json")))
|
||||
page = ctx.new_page()
|
||||
page.goto("https://www.gname.com/user/iframe#/safeModify/lx=4/type=0/txt=", wait_until="domcontentloaded", timeout=60000)
|
||||
time.sleep(9)
|
||||
body = page.evaluate("() => document.body.innerText.split(String.fromCharCode(10)).filter(l=>l.trim()).join(' | ').slice(0,1400)")
|
||||
print("BODY:", body, flush=True)
|
||||
fields = page.evaluate("""() => [...document.querySelectorAll('input,select')].map(e=>e.tagName+':'+(e.type||'')+':'+(e.name||'')+':'+(e.placeholder||'')+':'+(e.offsetParent?'vis':'hid'))""")
|
||||
print("FIELDS:", json.dumps(fields[:20]), flush=True)
|
||||
imgs = page.evaluate("""() => [...document.querySelectorAll('img')].filter(i=>i.offsetParent!==null).map(i=>({src:(i.src||'').slice(0,120), w:i.width, h:i.height}))""")
|
||||
print("IMGS:", json.dumps(imgs[:8]), flush=True)
|
||||
scripts = page.evaluate("""() => [...document.querySelectorAll('script')].filter(s=>!s.src && s.textContent.length>800).map(s=>s.textContent)""")
|
||||
for i,s in enumerate(scripts):
|
||||
eps = sorted(set(re.findall(r'["\']/[a-z_0-9/]{4,50}["\']', s)))
|
||||
eps = [e for e in eps if any(k in e for k in ('user_zh','request','mfa','aqbh','user_'))]
|
||||
if eps: print("script %d (%db) EPS:" % (i, len(s)), eps[:20], flush=True)
|
||||
open(BASE+"/mfa_inline_%d.js"%i,"w",encoding="utf-8").write(s)
|
||||
page.screenshot(path=BASE+"/mfa_page.png", full_page=True)
|
||||
json.dump(ctx.cookies(), open(BASE+"/gname_cookies.json","w"))
|
||||
b.close()
|
||||
import gname_core as G
|
||||
from gname_core import mk_context, save_cookies, csrf, inpost_json, inpost, aqbh_session_unlock
|
||||
|
||||
SITE = G.SITE
|
||||
|
||||
|
||||
def totp(secret, period=30, digits=6):
|
||||
key = base64.b32decode(secret.upper().replace(" ", ""), casefold=True)
|
||||
ctr = int(time.time()) // period
|
||||
h = hmac.new(key, struct.pack(">Q", ctr), hashlib.sha1).digest()
|
||||
o = h[-1] & 0x0F
|
||||
return str((struct.unpack(">I", h[o:o + 4])[0] & 0x7FFFFFFF) % (10 ** digits)).zfill(digits)
|
||||
|
||||
|
||||
def get_secret(page):
|
||||
return page.evaluate("""() => {
|
||||
let s = (document.querySelector('input[name=secret]')||{}).value || '';
|
||||
if (!s) { const img=[...document.querySelectorAll('img')].map(i=>i.src).find(x=>x.includes('secret=')); if(img) s=new URL(img).searchParams.get('secret'); }
|
||||
return s;
|
||||
}""")
|
||||
|
||||
|
||||
def main():
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument("--uid", default=os.environ.get("GNAME_UID", ""))
|
||||
ap.add_argument("--bank", default=os.environ.get("GNAME_BANK", "gname_accounts.jsonl"))
|
||||
ap.add_argument("--out", default="gname_mfa.json")
|
||||
a = ap.parse_args()
|
||||
|
||||
acc = None
|
||||
for line in open(a.bank, encoding="utf-8"):
|
||||
line = line.strip()
|
||||
if not line:
|
||||
continue
|
||||
d = json.loads(line)
|
||||
if a.uid and str(d.get("uid")) == str(a.uid):
|
||||
acc = d
|
||||
elif not a.uid:
|
||||
acc = d # first without --uid
|
||||
if acc:
|
||||
break
|
||||
if not acc:
|
||||
print("FATAL: uid not found in bank"); sys.exit(2)
|
||||
G.EMAIL = acc["email"]
|
||||
|
||||
with sync_playwright() as pw:
|
||||
browser, ctx = mk_context(pw, cookies=True)
|
||||
page = ctx.new_page()
|
||||
page.goto(SITE + "/user", wait_until="domcontentloaded", timeout=60000)
|
||||
time.sleep(4)
|
||||
tok = csrf(page)
|
||||
r = inpost_json(page, "/user_ym/get_ym_list", {"page": 1, "limit": 50, "csrf_token": tok}, "idcheck")
|
||||
d = (r or {}).get("data") or {}
|
||||
lst = d.get("data") if isinstance(d, dict) else d
|
||||
print("ACCOUNT DOMAINS:", [x.get("ym") for x in (lst or [])], flush=True)
|
||||
|
||||
page.goto(SITE + "/user/iframe#/safeModify/lx=4/type=0/txt=", wait_until="domcontentloaded", timeout=60000)
|
||||
time.sleep(8)
|
||||
sec = get_secret(page)
|
||||
print("SECRET len:", len(sec or ""), flush=True)
|
||||
if not sec:
|
||||
print("FATAL: no secret (page may require aqbh unlock first)"); save_cookies(ctx); browser.close(); sys.exit(5)
|
||||
|
||||
bound = False
|
||||
for rnd in range(3):
|
||||
r = inpost_json(page, "/user_zh/set_aqlb",
|
||||
{"secret": sec, "code": totp(sec), "csrf_token": csrf(page)}, "bind%d" % rnd)
|
||||
print("SET_AQLB try%d:" % rnd, str(r)[:200], flush=True)
|
||||
s = str(r)
|
||||
if isinstance(r, dict) and str(r.get("code")) == "1":
|
||||
bound = True; break
|
||||
if "remove operation protection" in s:
|
||||
if not aqbh_session_unlock(page, email=os.environ.get("GM_EMAIL")):
|
||||
time.sleep(20); continue
|
||||
r2 = inpost_json(page, "/user_zh/set_aqlb",
|
||||
{"secret": sec, "code": totp(sec), "csrf_token": csrf(page)}, "bindB%d" % rnd)
|
||||
print("SET_AQLB after unlock:", str(r2)[:200], flush=True)
|
||||
if isinstance(r2, dict) and str(r2.get("code")) == "1":
|
||||
bound = True; break
|
||||
time.sleep(2); continue
|
||||
break
|
||||
|
||||
r = inpost(page, "/user_zh/set_czyz", {"czyz[]": ["1", "4"], "csrf_token": csrf(page)}, "cz")
|
||||
print("SET_CZYZ[1,4]:", str(r)[:200], flush=True)
|
||||
json.dump({"uid": str(acc.get("uid", "")), "mfa_secret": sec, "bound": bound, "ts": int(time.time())},
|
||||
open(a.out, "w"))
|
||||
save_cookies(ctx)
|
||||
browser.close()
|
||||
print("MFA_BIND DONE bound=%s czyz=%s" % (bound, str(r)[:60]), flush=True)
|
||||
sys.exit(0 if bound else 3)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user