sdfgrtg commited on
Commit
ce89ece
·
verified ·
1 Parent(s): 3cdf80d

Update proxy.py

Browse files
Files changed (1) hide show
  1. proxy.py +33 -25
proxy.py CHANGED
@@ -1,4 +1,4 @@
1
- # proxy.py (全量替换云端 - 接收动作直控版)
2
  import os
3
  import time
4
  import asyncio
@@ -27,58 +27,49 @@ async def ws_handler(websocket, path):
27
  print("🔌 影子控制链路切入...")
28
  try:
29
  async for message in websocket:
30
- # 区分传过来的是普通 URL 还是动作指令
31
- if isinstance(message, bytes):
32
- cmd = message.decode('utf-8', errors='ignore')
33
- else:
34
- cmd = str(message)
35
 
36
- # 动作1:切入并查看 URL
37
  if cmd.startswith("http"):
38
  print(f"🌐 正在导航至: {cmd}")
39
  await GLOBAL_PAGE.goto(cmd, timeout=90000, wait_until="networkidle")
40
  await asyncio.sleep(5)
41
- # 拍张照传回本地
42
  screenshot_bytes = await GLOBAL_PAGE.screenshot(type="png")
43
  await websocket.send(screenshot_bytes)
44
 
45
- # 动作2:输入邮箱
46
  elif cmd.startswith("ACTION_EMAIL:"):
47
  email = cmd.split("ACTION_EMAIL:")[1]
48
  print(f"⌨️ 正在输入邮箱...")
49
- await GLOBAL_PAGE.locator('input[type="email"]').fill(email)
 
 
50
  await asyncio.sleep(1)
51
  await GLOBAL_PAGE.locator('#identifierNext').click()
52
- await asyncio.sleep(6) # 等待密码框渲染
53
- # 拍张照传回本地
54
  screenshot_bytes = await GLOBAL_PAGE.screenshot(type="png")
55
  await websocket.send(screenshot_bytes)
56
 
57
- # 动作3:输入密码
58
  elif cmd.startswith("ACTION_PASSWORD:"):
59
  password = cmd.split("ACTION_PASSWORD:")[1]
60
  print(f"⌨️ 正在输入密码...")
61
- await GLOBAL_PAGE.locator('input[type="password"]').fill(password)
 
62
  await asyncio.sleep(1)
63
  await GLOBAL_PAGE.locator('#passwordNext').click()
64
- await asyncio.sleep(10) # 登录跳转耗时较长
65
- # 拍张照传回本地
66
  screenshot_bytes = await GLOBAL_PAGE.screenshot(type="png")
67
  await websocket.send(screenshot_bytes)
68
 
69
- # 动作4:输入两步验证码
70
  elif cmd.startswith("ACTION_CODE:"):
71
  code = cmd.split("ACTION_CODE:")[1]
72
- print(f"⌨️ 正在处理验证码/设备确认...")
73
  try:
74
- # 尝试寻找验证码输入框,如果只是设备确认,这里会跳过
75
- await GLOBAL_PAGE.locator('input[id="idvanyphoneverifycode"]').fill(code)
76
  await asyncio.sleep(1)
77
  await GLOBAL_PAGE.locator('#idvanyphoneverifynext').click()
78
  except:
79
  pass
80
  await asyncio.sleep(10)
81
- # 拍张照传回本地
82
  screenshot_bytes = await GLOBAL_PAGE.screenshot(type="png")
83
  await websocket.send(screenshot_bytes)
84
 
@@ -90,19 +81,36 @@ async def main_async():
90
  sync_from_dataset()
91
 
92
  playwright_context = await async_playwright().start()
 
 
93
  browser_context = await playwright_context.chromium.launch_persistent_context(
94
  user_data_dir=CLOUD_PROFILE_DIR,
95
  headless=True,
 
 
 
 
 
96
  args=[
97
- "--no-sandbox", "--disable-setuid-sandbox",
98
- "--disable-gpu", "--disable-dev-shm-usage",
99
- "--disable-blink-features=AutomationControlled"
 
 
 
 
 
 
100
  ]
101
  )
 
 
102
  GLOBAL_PAGE = await browser_context.new_page()
 
 
103
  await GLOBAL_PAGE.set_viewport_size({"width": 1280, "height": 800})
104
 
105
- print(f"🟢 升级控制网桥已就绪...")
106
  async with websockets.serve(ws_handler, "0.0.0.0", HTTP_PORT):
107
  while True:
108
  await asyncio.sleep(3600)
 
1
+ # proxy.py (全量替换云端 - 彻底过 Google 浏览器安全风控版)
2
  import os
3
  import time
4
  import asyncio
 
27
  print("🔌 影子控制链路切入...")
28
  try:
29
  async for message in websocket:
30
+ cmd = message.decode('utf-8', errors='ignore') if isinstance(message, bytes) else str(message)
 
 
 
 
31
 
 
32
  if cmd.startswith("http"):
33
  print(f"🌐 正在导航至: {cmd}")
34
  await GLOBAL_PAGE.goto(cmd, timeout=90000, wait_until="networkidle")
35
  await asyncio.sleep(5)
 
36
  screenshot_bytes = await GLOBAL_PAGE.screenshot(type="png")
37
  await websocket.send(screenshot_bytes)
38
 
 
39
  elif cmd.startswith("ACTION_EMAIL:"):
40
  email = cmd.split("ACTION_EMAIL:")[1]
41
  print(f"⌨️ 正在输入邮箱...")
42
+ # 模拟真人打字速度,防止被识别为机械输入
43
+ await GLOBAL_PAGE.locator('input[type="email"]').click()
44
+ await GLOBAL_PAGE.locator('input[type="email"]').type(email, delay=100)
45
  await asyncio.sleep(1)
46
  await GLOBAL_PAGE.locator('#identifierNext').click()
47
+ await asyncio.sleep(6)
 
48
  screenshot_bytes = await GLOBAL_PAGE.screenshot(type="png")
49
  await websocket.send(screenshot_bytes)
50
 
 
51
  elif cmd.startswith("ACTION_PASSWORD:"):
52
  password = cmd.split("ACTION_PASSWORD:")[1]
53
  print(f"⌨️ 正在输入密码...")
54
+ await GLOBAL_PAGE.locator('input[type="password"]').click()
55
+ await GLOBAL_PAGE.locator('input[type="password"]').type(password, delay=120)
56
  await asyncio.sleep(1)
57
  await GLOBAL_PAGE.locator('#passwordNext').click()
58
+ await asyncio.sleep(10)
 
59
  screenshot_bytes = await GLOBAL_PAGE.screenshot(type="png")
60
  await websocket.send(screenshot_bytes)
61
 
 
62
  elif cmd.startswith("ACTION_CODE:"):
63
  code = cmd.split("ACTION_CODE:")[1]
64
+ print(f"⌨️ 正在处理验证码...")
65
  try:
66
+ await GLOBAL_PAGE.locator('input[id="idvanyphoneverifycode"]').click()
67
+ await GLOBAL_PAGE.locator('input[id="idvanyphoneverifycode"]').type(code, delay=80)
68
  await asyncio.sleep(1)
69
  await GLOBAL_PAGE.locator('#idvanyphoneverifynext').click()
70
  except:
71
  pass
72
  await asyncio.sleep(10)
 
73
  screenshot_bytes = await GLOBAL_PAGE.screenshot(type="png")
74
  await websocket.send(screenshot_bytes)
75
 
 
81
  sync_from_dataset()
82
 
83
  playwright_context = await async_playwright().start()
84
+
85
+ # 💡 核心改良:注入完美的真人全套浏览器指纹环境,洗白机房特征
86
  browser_context = await playwright_context.chromium.launch_persistent_context(
87
  user_data_dir=CLOUD_PROFILE_DIR,
88
  headless=True,
89
+ accept_downloads=True,
90
+ # 伪装成标准的 Windows 桌面版 Chrome 浏览器 User-Agent
91
+ user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36",
92
+ locale="zh-CN,zh;q=0.9,en;q=0.8", # 注入正常的语言链
93
+ timezone_id="Asia/Shanghai", # 注入时区
94
  args=[
95
+ "--no-sandbox",
96
+ "--disable-setuid-sandbox",
97
+ "--disable-gpu",
98
+ "--disable-dev-shm-usage",
99
+ # 抹除 WebDriver 自动化标记
100
+ "--disable-blink-features=AutomationControlled",
101
+ # 允许混入正常的机器特征
102
+ "--lang=zh-CN",
103
+ "--password-store=basic"
104
  ]
105
  )
106
+
107
+ # 利用底层脚本进一步抹除 window.navigator.webdriver 属性,做到绝对伪装
108
  GLOBAL_PAGE = await browser_context.new_page()
109
+ await GLOBAL_PAGE.add_init_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})")
110
+
111
  await GLOBAL_PAGE.set_viewport_size({"width": 1280, "height": 800})
112
 
113
+ print(f"🟢 真人伪装升级控制网桥已就绪...")
114
  async with websockets.serve(ws_handler, "0.0.0.0", HTTP_PORT):
115
  while True:
116
  await asyncio.sleep(3600)