-
Notifications
You must be signed in to change notification settings - Fork 16
/
captcha_solver.py
326 lines (303 loc) · 13.1 KB
/
captcha_solver.py
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
import os, json, requests, time, colorama
from colorama import Fore
from io import BytesIO
import base64
from twocaptcha import TwoCaptcha
import urllib.parse
with open('config.json') as f:
config = json.load(f)
service = config['captcha']['hcaptcha_service'].lower()
api_key = config['captcha']['hcaptcha_key']
tservice = config['captcha']['TextToImage_service'].lower()
tapi_key = config['captcha']['TextToImage_key']
huntbot_key = config['captcha']['huntbot_key']
website = "https://owobot.com"
sitekey = "a6a1d5ce-612d-472d-8e37-7601408fbc09"
if service not in config['captcha']['avail_services']:
print(f"{Fore.RED}[Error]Invalid Captcha Solver Provider Provided Please Correct It.{Fore.RESET}")
else:
print(f"HCaptcha Solver: {service}")
print(f"TextToImage Solver: {tservice}")
def to_base64(image_location, is_url=True):
try:
if is_url:
response = requests.get(image_location)
if response.status_code == 200:
image_bytes = BytesIO(response.content)
else:
return "Unable to fetch image. Status code: " + str(response.status_code)
else:
with open(image_location, 'rb') as image_file:
image_bytes = BytesIO(image_file.read())
base64_string = base64.b64encode(image_bytes.read()).decode('utf-8')
return base64_string
except Exception as e:
return str(e)
def Hcaptcha_Solver():
if service == "capsolver":
payload = {
"clientKey": api_key,
"appId": "5122588A-8581-4440-8044-15D010D2B23C",
"task": {
"type": 'HCaptchaTaskProxyLess',
"websiteKey": sitekey,
"websiteURL": website
}
}
res = requests.post("https://api.capsolver.com/createTask", json=payload)
resp = res.json()
task_id = resp.get("taskId")
if not task_id:
print("Failed to create task:", res.text)
return
print(f"{Fore.LIGHTBLUE_EX}[{service}] Got taskId: {task_id} / Getting result...{Fore.RESET}")
while True:
time.sleep(1)
payload = {"clientKey": api_key, "taskId": task_id}
res = requests.post("https://api.capsolver.com/getTaskResult", json=payload)
resp = res.json()
status = resp.get("status")
if status == "ready":
print(f"{Fore.LIGHTBLUE_EX}[{service}] Solved Hcaptcha, Submitting results to owobot...{Fore.RESET}")
return resp.get("solution", {}).get('gRecaptchaResponse')
if status == "failed" or resp.get("errorId"):
print("Solve failed! response:", res.text)
return
elif service == "twocaptcha":
solver = TwoCaptcha(apiKey=api_key, softId=4663)
result = solver.hcaptcha(sitekey = sitekey, url = website)
if result:
print(f"{Fore.LIGHTBLUE_EX}[{service}] Solved Hcaptcha, Submitting results to owobot...{Fore.RESET}")
return result['code']
else:
print("Hcaptcha Solve failed!")
return
elif service == "capmonster":
payload = {
"clientKey": api_key,
"task": {
"type": 'HCaptchaTaskProxyLess',
"websiteKey": sitekey,
"websiteURL": website
}
}
res = requests.post("https://api.capmonster.cloud/createTask", json=payload)
resp = res.json()
task_id = resp.get("taskId")
if not task_id:
print("Failed to create task:", res.text)
return
print(f"{Fore.LIGHTBLUE_EX}[{service}] Got taskId: {task_id} / Getting result...{Fore.RESET}")
while True:
time.sleep(1)
payload = {"clientKey": api_key, "taskId": task_id}
res = requests.post("https://api.capmonster.cloud/getTaskResult", json=payload)
resp = res.json()
status = resp.get("status")
if status == "ready":
print(f"{Fore.LIGHTBLUE_EX}[{service}] Solved Hcaptcha, Submitting results to owobot...{Fore.RESET}")
return resp.get("solution", {}).get('gRecaptchaResponse')
if status == "failed" or resp.get("errorId"):
print("Solve failed! response:", res.text)
return
elif service == "captchaai":
res = requests.post(f"https://ocr.captchaai.com/in.php?key={api_key}&method=hcaptcha&sitekey={sitekey}&pageurl={website}")
resp = res.json()
task_id = resp.get("request")
if not task_id:
print("Failed to create task:", res.text)
return
print(f"{Fore.LIGHTBLUE_EX}[{service}] Got taskId: {task_id} / Getting result...{Fore.RESET}")
while True:
time.sleep(5)
res = requests.get(f"https://ocr.captchaai.com/res.php?key={api_key}8&action=get&id={task_id}")
resp = res.text
if resp.startswith("P"):
print(f"{Fore.LIGHTBLUE_EX}[{service}] Solved Hcaptcha, Submitting results to owobot...{Fore.RESET}")
return resp
if resp == "ERROR_CAPTCHA_UNSOLVABLE":
print("Solve failed! response:", res.text)
return
elif service == "nopecha":
res = requests.post(f'https://api.nopecha.com/token',
json = {
'type': 'hcaptcha',
'sitekey': sitekey,
'url': website,
'key': api_key,
})
task_id = res.json()['data']
if not task_id:
print("Failed to create task:", res.text)
return
print(f"{Fore.LIGHTBLUE_EX}[{service}] Got taskId: {task_id} / Getting result...{Fore.RESET}")
url = f"https://api.nopecha.com/token?key={api_key}&id={task_id}"
resp = requests.get(url)
if resp.json()['data']:
print(f"{Fore.LIGHTBLUE_EX}[{service}] Solved Hcaptcha, Submitting results to owobot...{Fore.RESET}")
return resp.json()['data'][0]
else:
print("Solve failed! response:", resp.text)
else:
print(f"{Fore.RED}[Error] invalid Captcha Provider{Fore.RESET}")
def solve_image_by_scrappey(image, mode):
if mode == "huntbot":
keytouse = tapi_key
else:
keytouse = tapi_key
encoded_url = urllib.parse.quote(image)
url = f'https://publisher.scrappey.com/api/v1?key={keytouse}'
headers = {'Content-Type': 'application/json'}
data = {
"cmd": "request.get",
"url": f"https://owo-captcha-solver.vercel.app/captcha_solution?url={encoded_url}",
"alwaysLoad": [
""
],
"browserActions": [
{
"type": "wait",
"wait": 3
},
{
"type": "solve_captcha",
"captcha": "custom",
"cssSelector": "img[class='captcha-image']",
"inputSelector": "input[id='solution']",
"clickSelector": "button[class='button']"
},
{
"type": "wait",
"wait": 10
}
]
}
response = requests.post(url, headers=headers, json=data)
if response.status_code == 200:
try:
print(f"{Fore.LIGHTBLUE_EX}[{service}] Solved ImageToText, Submitting results to owobot...{Fore.RESET}")
return response.json()["solution"]["innerText"]
except:
print("Solve failed! response:", response.text)
return
else:
print("Solve failed! response:", response.text)
return
def ImageToTextSolver(image, length, mode):
if service == "capsolver":
base64Image = to_base64(image_location=image, is_url=True)
res = requests.post("https://api.capsolver.com/createTask",
json={
"clientKey": tapi_key,
"appId": "5122588A-8581-4440-8044-15D010D2B23C",
"task": {
"type": "ImageToTextTask",
"body":base64Image
}
})
return res.json().get("solution", {}).get('text')
elif service == "twocaptcha":
solver = TwoCaptcha(apiKey=tapi_key, softId=4663)
result = solver.normal(image, numeric = 2, minLen = length, maxLen = length, phrase = 0, caseSensitive = 0, calc = 0, lang = "en")
return result['code']
elif service == "capmonster":
base64Image = to_base64(image_location=image, is_url=True)
payload = {
"clientKey": tapi_key,
"task": {
"type": 'ImageToTextTask',
"body": base64Image,
}
}
res = requests.post("https://api.capmonster.cloud/createTask", json=payload)
resp = res.json()
task_id = resp.get("taskId")
if not task_id:
print("Failed to create task:", res.text)
return
print(f"{Fore.LIGHTBLUE_EX}[{tservice}] Got taskId: {task_id} / Getting result...{Fore.RESET}")
while True:
time.sleep(1)
payload = {"clientKey": tapi_key, "taskId": task_id}
res = requests.post("https://api.capmonster.cloud/getTaskResult", json=payload)
resp = res.json()
status = resp.get("status")
if status == "ready":
print(f"{Fore.LIGHTBLUE_EX}[{tservice}] Solved ImageToText, Submitting results to owobot...{Fore.RESET}")
return resp.get("solution", {}).get('text')
if status == "failed" or resp.get("errorId"):
print("Solve failed! response:", res.text)
return
elif service == "captchaai":
base64Image = to_base64(image_location=image, is_url=True)
res = requests.post(f"https://ocr.captchaai.com/solve.php?key={tapi_key}&method=base64&body={base64Image}")
return res.text
elif service == "scrappey":
sol = solve_image_by_scrappey(image, mode=mode)
return sol
elif service == "nopecha":
base64Image = to_base64(image_location=image, is_url=True)
res = requests.post("https://api.nopecha.com/",
json={
"key": tapi_key,
"type": "textcaptcha",
"image_data": base64Image
})
task_id = res.json()['data']
sol = requests.get(f"https://api.nopecha.com/?key={tapi_key}&id={task_id}")
return sol.json()['data'][0]
def fetch_hcaptcha_balance():
'''
HCAPTCHA BALANCE
'''
if service == 'capsolver':
r = requests.post(f"https://api.capsolver.com/getBalance", json={
"clientKey": api_key
})
return r.json()['balance']
elif service == "twocaptcha":
r = requests.post(f"https://api.2captcha.com/getBalance", json={
"clientKey": api_key
})
return r.json()['balance']
elif service == "capmonster":
r = requests.post(f"https://api.capmonster.cloud/getBalance", json={
"clientKey": api_key
})
return r.json()['balance']
elif service == "captchaai":
r = requests.post(f"https://ocr.captchaai.com/res.php?key={api_key}&action=getbalance")
return r.text
elif service == 'scrappey':
r = requests.get(f"https://publisher.scrappey.com/api/v1/balance?key={api_key}")
return r.json()['balance']
elif service == 'nopecha':
r = requests.get(f" https://api.nopecha.com/status?key={api_key}")
return r.json()['credit']
def fetch_texttoimage_balance():
'''
TExtToImage'''
if tservice == 'capsolver':
r = requests.post(f"https://api.capsolver.com/getBalance", json={
"clientKey": tapi_key
})
return r.json()['balance']
elif tservice == "twocaptcha":
r = requests.post(f"https://api.2captcha.com/getBalance", json={
"clientKey": tapi_key
})
return r.json()['balance']
elif tservice == "capmonster":
r = requests.post(f"https://api.capmonster.cloud/getBalance", json={
"clientKey": tapi_key
})
return r.json()['balance']
elif tservice == "captchaai":
r = requests.post(f"https://ocr.captchaai.com/res.php?key={tapi_key}&action=getbalance")
return r.text
elif tservice == 'scrappey':
r = requests.get(f"https://publisher.scrappey.com/api/v1/balance?key={tapi_key}")
return r.json()['balance']
elif tservice == 'nopecha':
r = requests.get(f" https://api.nopecha.com/status?key={tapi_key}")
return r.json()['credit']