Repository navigation
Expand file tree
/
Copy pathAdsCaptcha.py
More file actions
64 lines (44 loc) · 2.07 KB
/
Copy pathAdsCaptcha.py
File metadata and controls
64 lines (44 loc) · 2.07 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
# -*- coding: utf-8 -*-
import random
import re
from module.plugins.internal.CaptchaService import CaptchaService
class AdsCaptcha(CaptchaService):
__name__ = "AdsCaptcha"
__type__ = "captcha"
__version__ = "0.10"
__status__ = "testing"
__description__ = """AdsCaptcha captcha service plugin"""
__license__ = "GPLv3"
__authors__ = [("pyLoad Team", "admin@pyload.org")]
CAPTCHAID_PATTERN = r'api\.adscaptcha\.com/Get\.aspx\?.*?CaptchaId=(\d+)'
PUBLICKEY_PATTERN = r'api\.adscaptcha\.com/Get\.aspx\?.*?PublicKey=([\w-]+)'
def detect_key(self, data=None):
html = data or self.retrieve_data()
m = re.search(self.PUBLICKEY_PATTERN, html)
n = re.search(self.CAPTCHAID_PATTERN, html)
if m and n:
self.key = (m.group(1).strip(), n.group(1).strip()) #: Key is the tuple(PublicKey, CaptchaId)
self.log_debug("Key: %s | ID: %s" % self.key)
return self.key
else:
self.log_warning(_("Key or id pattern not found"))
return None
def challenge(self, key=None, data=None):
PublicKey, CaptchaId = key or self.retrieve_key(data)
html = self.plugin.load("http://api.adscaptcha.com/Get.aspx",
get={'CaptchaId': CaptchaId,
'PublicKey': PublicKey})
try:
challenge = re.search("challenge: '(.+?)',", html).group(1)
server = re.search("server: '(.+?)',", html).group(1)
except AttributeError:
self.fail(_("AdsCaptcha challenge pattern not found"))
self.log_debug("Challenge: %s" % challenge)
return self.result(server, challenge), challenge
def result(self, server, challenge):
result = self.decrypt("%sChallenge.aspx" % server,
get={'cid': challenge, 'dummy': random.random()},
cookies=True,
input_type="jpg")
self.log_debug("Result: %s" % result)
return result