70 lines
2.8 KiB
Python
70 lines
2.8 KiB
Python
#!/usr/bin/env python3
|
|
"""网页版密码登录 -> 直接拿全套长 cookie(udb_cred/udb_passdata/yyuid...)。
|
|
|
|
用法: python tools/web_cookie_login.py <账号> <密码>
|
|
"""
|
|
import sys, json, re, hashlib, time, uuid
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parent.parent
|
|
sys.path.insert(0, str(ROOT))
|
|
import requests
|
|
from core.huya.device_fingerprint import get_huya_sdid
|
|
|
|
URL = "https://udblgn.huya.com/web/v2/passwordLogin"
|
|
|
|
|
|
def main():
|
|
acct, pwd = sys.argv[1], sys.argv[2]
|
|
if not acct.startswith("hy_"):
|
|
acct = "hy_" + acct
|
|
sha1 = hashlib.sha1(pwd.encode()).hexdigest()
|
|
try:
|
|
sdid = get_huya_sdid(allow_fallback=True).sdid
|
|
except Exception:
|
|
sdid = "0UnHUgv0_qmfD4KAKlwzhqaKn105aUYt7oVTYd8Axc4iQSNyLE_nmgRB8tPxnndI8Th1nJ_003VaxeRFLVvpJcTJXFa3qhMVoHC9dykeCz3DWVkn9LtfFJw_Qo4kgKr8OZHDqNnuwg612sGyflFn1dutzDtufJ9ExmL1Pr7Bhq2nTk7vCmHfM2aTlTZvNeXfn"
|
|
ctx = f"WB-{uuid.uuid4().hex}-" + uuid.uuid4().hex.upper()[:24]
|
|
beh = json.dumps({
|
|
"furl": "https://www.huya.com/", "curl": "https://www.huya.com/g",
|
|
"user_action": [{"id": "7", "d": 712,
|
|
"t": str(int(time.time() * 1000))}]})
|
|
body = {
|
|
"uri": "30001", "version": "2.6", "context": ctx,
|
|
"appId": "5002", "appSign": "1ce3bf682483d03f146f58232ec10635",
|
|
"authId": "", "sdid": sdid, "lcid": "2052", "byPass": "3",
|
|
"requestId": str(int(time.time())%100000000),
|
|
"data": {"userName": acct, "password": sha1, "domainList": "",
|
|
"remember": "1",
|
|
"behavior": requests.utils.quote(beh, safe="")}}
|
|
s = requests.Session()
|
|
s.trust_env = False
|
|
r = s.post(URL, json=body, timeout=15, headers={
|
|
"Content-Type": "application/json;charset=UTF-8",
|
|
"Origin": "https://www.huya.com",
|
|
"Referer": "https://www.huya.com/",
|
|
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) "
|
|
"AppleWebKit/537.36 Chrome/150.0 Safari/537.36"})
|
|
print("HTTP", r.status_code)
|
|
j = r.json()
|
|
print("returnCode:", j.get("returnCode"), "|",
|
|
j.get("description") or j.get("message"))
|
|
if j.get("returnCode") != 0:
|
|
print(json.dumps(j, ensure_ascii=False)[:400])
|
|
return 1
|
|
print("\n=== 全套 Cookie ===")
|
|
total = 0
|
|
for c in s.cookies:
|
|
v = c.value or ""
|
|
total += len(c.name) + len(v) + 2
|
|
mark = " ← 长" if len(v) > 100 else ""
|
|
print(f"{c.name:16s} = {v[:70]}{'...' if len(v)>70 else ''}{mark}")
|
|
ck = "; ".join(f"{c.name}={c.value}" for c in s.cookies)
|
|
(ROOT / "evidence/web_cookies.txt").write_text(ck)
|
|
print(f"\n总长 {len(ck)} 字符, 已存 evidence/web_cookies.txt")
|
|
print("用法: requests.get(url, headers={'Cookie': open('evidence/web_cookies.txt').read()})")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|