-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathtest.py
More file actions
210 lines (166 loc) · 6 KB
/
test.py
File metadata and controls
210 lines (166 loc) · 6 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
import logging
from threading import Thread
import threading
import time
import argparse
import json
from curl_cffi import requests
from cloudflyer.log import apply_logging_adapter
from cloudflyer.server import main, stop_instances
EXAMPLE_TOKEN = "example_token"
def verify_cloudflare_challenge(result):
try:
# Extract necessary information from response
cookies = result["response"]["cookies"]
headers = result["response"]["headers"]
url = result["data"]["url"]
# Use curl_cffi to send request
response = requests.get(
url,
cookies=cookies,
headers={"User-Agent": headers["User-Agent"]},
impersonate="chrome",
allow_redirects=True,
)
# Check if response contains success marker
return "Captcha is passed successfully!" in response.text
except (KeyError, TypeError):
return False
def create_task(data):
headers = {"Content-Type": "application/json"}
response = requests.post("http://127.0.0.1:3000/createTask", json=data, headers=headers)
return response.json()
def get_task_result(task_id, client_key="123456"):
headers = {"Content-Type": "application/json"}
data = {"clientKey": client_key, "taskId": task_id}
response = requests.post(
"http://localhost:3000/getTaskResult",
json=data,
headers=headers,
)
return response.json()
def start_server():
ready = threading.Event()
t = Thread(
target=main,
kwargs={
"argl": ["-K", EXAMPLE_TOKEN],
"ready": ready,
"log": False,
},
daemon=True,
)
t.start()
ready.wait()
return t
def poll_task_result(task_id) -> dict:
while True:
cf_response = get_task_result(task_id)
if cf_response["status"] == "completed":
return cf_response["result"]
time.sleep(3)
def cloudflare_challenge(proxy=None):
start_server()
data = {
"clientKey": EXAMPLE_TOKEN,
"type": "CloudflareChallenge",
"url": "https://2captcha.com/demo/cloudflare-turnstile-challenge",
"userAgent": "CFNetwork/897.15 Darwin/17.5.0 (iPhone/6s iOS/11.3)",
}
# Add proxy configuration if provided
if proxy:
data["proxy"] = proxy
task_info = create_task(data)
result = poll_task_result(task_info["taskId"])
print(f"Challenge result:\n{json.dumps(result, indent=2)}")
success = verify_cloudflare_challenge(result)
print(f"\nChallenge verification result:\n{success}")
def turnstile(proxy=None):
start_server()
data = {
"clientKey": EXAMPLE_TOKEN,
"type": "Turnstile",
"url": "https://www.coronausa.com",
"siteKey": "0x4AAAAAAAH4-VmiV_O_wBN-",
}
# Add proxy configuration if provided
if proxy:
data["proxy"] = proxy
print("Task:")
print(json.dumps(data, indent=2))
task_info = create_task(data)
result = poll_task_result(task_info["taskId"])
print(f"Turnstile result:\n{json.dumps(result, indent=2)}")
response = result.get("response")
if response:
token = response.get("token")
else:
token = None
if token:
print(f"\nTurnstile token:\n{token}")
def recapcha_invisible(proxy=None):
start_server()
data = {
"clientKey": EXAMPLE_TOKEN,
"type": "RecaptchaInvisible",
"url": "https://antcpt.com/score_detector",
"siteKey": "6LcR_okUAAAAAPYrPe-HK_0RULO1aZM15ENyM-Mf",
"action": "homepage",
}
# Add proxy configuration if provided
if proxy:
data["proxy"] = proxy
task_info = create_task(data)
result = poll_task_result(task_info["taskId"])
print(f"Challenge result:\n{json.dumps(result, indent=2)}")
def parse_proxy_string(proxy_str):
"""Parse proxy string in format scheme://host:port"""
if not proxy_str:
return None
try:
scheme, rest = proxy_str.split('://')
host, port = rest.split(':')
return {
"scheme": scheme,
"host": host,
"port": int(port)
}
except (ValueError, AttributeError):
raise ValueError("Invalid proxy format. Use scheme://host:port (e.g., socks5://127.0.0.1:1080)")
def main_cli():
parser = argparse.ArgumentParser(description="Challenge solver CLI")
subparsers = parser.add_subparsers(dest="command", help="Available commands")
# Add proxy argument to each command
for cmd in ["turnstile", "cloudflare", "recaptcha"]:
parser_cmd = subparsers.add_parser(cmd, help=f"Solve {cmd.replace('_', ' ')} challenge")
parser_cmd.add_argument("-x", "--proxy", help="Proxy in format scheme://host:port (e.g., socks5://127.0.0.1:1080)")
parser_cmd.add_argument("-v", "--verbose", help="Show verbose output", action="store_true")
args = parser.parse_args()
if not args.command:
parser.print_help()
return
# Parse proxy string if provided
proxy = parse_proxy_string(args.proxy) if args.proxy else None
if args.verbose:
apply_logging_adapter([
('http.*->.*', logging.DEBUG),
('server disconnect', logging.DEBUG),
('client disconnect', logging.DEBUG),
('server connect', logging.DEBUG),
('client connect', logging.DEBUG),
], level=10)
logging.getLogger('hpack').setLevel(logging.WARNING)
# Execute corresponding function based on command
try:
if args.command == "turnstile":
turnstile(proxy)
elif args.command == "cloudflare":
cloudflare_challenge(proxy)
elif args.command == "recaptcha":
recapcha_invisible(proxy)
else:
parser.print_help()
finally:
stop_instances()
if __name__ == "__main__":
main_cli()