-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathantibotlinks_solver.py
More file actions
78 lines (67 loc) · 3.13 KB
/
Copy pathantibotlinks_solver.py
File metadata and controls
78 lines (67 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import requests
import json
import time
import re
class AntiBotLinksSolver:
def __init__(self, router_key, router_url="https://9router.indrayuda.my.id/v1/chat/completions", model="gemma", timeout=60, retries=3):
"""
Initialize the Universal Anti-Bot Links Solver using a Vision LLM.
:param router_key: API Key for the LLM router
:param router_url: URL for the completions endpoint
:param model: The vision model to use (e.g., gemma)
:param timeout: Timeout per request in seconds
:param retries: Number of retries on timeout/failure
"""
self.router_key = router_key
self.router_url = router_url
self.model = model
self.timeout = timeout
self.retries = retries
self.headers = {
"Authorization": f"Bearer {self.router_key}",
"Content-Type": "application/json"
}
def solve(self, target_sequence, base64_image_data):
"""
Solves the Anti-Bot links captcha by mapping a sequence of target words/symbols
to coordinates or grid indices in an image.
:param target_sequence: List of strings to click in order (e.g., ["Lion", "Tiger", "Bear"] or math operations)
:param base64_image_data: Raw base64 string of the captcha image
:return: JSON array of coordinates/indices to click
"""
prompt = (
f"This is an Anti-Bot Links captcha. You need to find the following sequence of items in the image: {target_sequence}. "
"Return the coordinates or the quadrant/index of each item in the exact order requested. "
"Output ONLY a valid JSON array of objects, e.g., [{\"word\": \"Lion\", \"index\": 1}, ...]."
)
payload = {
"model": self.model,
"stream": False,
"messages": [
{
"role": "user",
"content": [
{"type": "text", "text": prompt},
{"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{base64_image_data}"}}
]
}
]
}
for attempt in range(1, self.retries + 1):
try:
r = requests.post(self.router_url, headers=self.headers, json=payload, timeout=self.timeout)
if r.status_code != 200:
raise Exception(f"HTTP {r.status_code}: {r.text[:100]}")
content = r.json()['choices'][0]['message']['content']
if content.startswith("```json"):
content = content[7:-3].strip()
elif content.startswith("```"):
content = content[3:-3].strip()
return json.loads(content)
except Exception as e:
print(f"[AntiBotLinksSolver] Attempt {attempt} failed: {e}")
if attempt == self.retries:
raise e
time.sleep(2)
if __name__ == "__main__":
print("Universal Anti-Bot Links Solver Initialized.")