Example #1
0
    def submit(self, captcha, captchaType="file", match=None):
        req = getRequest()
        #raise timeout threshold
        req.c.setopt(LOW_SPEED_TIME, 80)

        try:
            #@NOTE: Workaround multipart-post bug in HTTPRequest.py
            if re.match("^\w*$", self.getConfig('passkey')):
                multipart = True
                data = (FORM_FILE, captcha)
            else:
                multipart = False
                with open(captcha, 'rb') as f:
                    data = f.read()
                data = b64encode(data)

            res = req.load(self.SUBMIT_URL,
                           post={'action': "UPLOADCAPTCHA",
                                 'username': self.getConfig('username'),
                                 'password': self.getConfig('passkey'), "file": data},
                           multipart=multipart)
        finally:
            req.close()

        if res.startswith("ERROR"):
            raise ImageTyperzException(res)
        else:
            data = res.split('|')
            if len(data) == 2:
                ticket, result = data
            else:
                raise ImageTyperzException("Unknown response: %s" % res)

        return ticket, result
Example #2
0
    def api_response(self, api="captcha", post=False, multipart=False):
        req = getRequest()
        req.c.setopt(HTTPHEADER, ["Accept: application/json", "User-Agent: pyLoad %s" % self.core.version])

        if post:
            if not isinstance(post, dict):
                post = {}
            post.update({"username": self.getConfig('username'),
                         "password": self.getConfig('passkey')})

        res = None
        try:
            json = req.load("%s%s" % (self.API_URL, api),
                            post=post,
                            multipart=multipart)
            self.logDebug(json)
            res = json_loads(json)

            if "error" in res:
                raise DeathByCaptchaException(res['error'])
            elif "status" not in res:
                raise DeathByCaptchaException(str(res))

        except BadHeader, e:
            if 403 == e.code:
                raise DeathByCaptchaException('not-logged-in')
            elif 413 == e.code:
                raise DeathByCaptchaException('invalid-captcha')
            elif 503 == e.code:
                raise DeathByCaptchaException('service-overload')
            elif e.code in (400, 405):
                raise DeathByCaptchaException('invalid-request')
            else:
                raise
Example #3
0
    def api_response(self, api="captcha", post=False, multipart=False):
        req = getRequest()
        req.c.setopt(pycurl.HTTPHEADER, ["Accept: application/json", "User-Agent: pyLoad %s" % self.core.version])

        if post:
            if not isinstance(post, dict):
                post = {}
            post.update({"username": self.getConfig('username'),
                         "password": self.getConfig('passkey')})

        res = None
        try:
            json = req.load("%s%s" % (self.API_URL, api),
                            post=post,
                            multipart=multipart)
            self.logDebug(json)
            res = json_loads(json)

            if "error" in res:
                raise DeathByCaptchaException(res['error'])
            elif "status" not in res:
                raise DeathByCaptchaException(str(res))

        except BadHeader, e:
            if 403 == e.code:
                raise DeathByCaptchaException('not-logged-in')
            elif 413 == e.code:
                raise DeathByCaptchaException('invalid-captcha')
            elif 503 == e.code:
                raise DeathByCaptchaException('service-overload')
            elif e.code in (400, 405):
                raise DeathByCaptchaException('invalid-request')
            else:
                raise
Example #4
0
    def submit(self, captcha, captchaType="file", match=None):
        req = getRequest()

        # raise timeout threshold
        req.c.setopt(pycurl.LOW_SPEED_TIME, 80)

        try:
            res = req.load(self.SUBMIT_URL,
                           post={
                               'vendor_key': self.PYLOAD_KEY,
                               'key': self.getConfig('passkey'),
                               'gen_task_id': "1",
                               'file': (pycurl.FORM_FILE, captcha)
                           },
                           multipart=True)
        finally:
            req.close()

        data = dict(x.split(' ', 1) for x in res.splitlines())
        if not data or "Value" not in data:
            raise BypassCaptchaException(res)

        result = data['Value']
        ticket = data['TaskId']
        self.logDebug("Result %s : %s" % (ticket, result))

        return ticket, result
Example #5
0
    def submit(self, captcha, captchaType="file", match=None):
        req = getRequest()

        # raise timeout threshold
        req.c.setopt(LOW_SPEED_TIME, 80)

        try:
            res = req.load(self.SUBMIT_URL,
                           post={'vendor_key': self.PYLOAD_KEY,
                                 'key': self.getConfig('passkey'),
                                 'gen_task_id': "1",
                                 'file': (FORM_FILE, captcha)},
                           multipart=True)
        finally:
            req.close()

        data = dict(x.split(' ', 1) for x in res.splitlines())
        if not data or "Value" not in data:
            raise BypassCaptchaException(res)

        result = data['Value']
        ticket = data['TaskId']
        self.logDebug("Result %s : %s" % (ticket, result))

        return ticket, result
Example #6
0
    def submit(self, captcha, captchaType="file", match=None):
        req = getRequest()

        # raise timeout threshold
        req.c.setopt(pycurl.LOW_SPEED_TIME, 80)

        try:
            res = req.load(
                self.SUBMIT_URL,
                post={
                    "vendor_key": self.PYLOAD_KEY,
                    "key": self.getConfig("passkey"),
                    "gen_task_id": "1",
                    "file": (pycurl.FORM_FILE, captcha),
                },
                multipart=True,
            )
        finally:
            req.close()

        data = dict(x.split(" ", 1) for x in res.splitlines())
        if not data or "Value" not in data:
            raise BypassCaptchaException(res)

        result = data["Value"]
        ticket = data["TaskId"]
        self.logDebug("Result %s : %s" % (ticket, result))

        return ticket, result
Example #7
0
def decryptCaptcha(self,
                   url,
                   get={},
                   post={},
                   cookies=False,
                   forceUser=False,
                   imgtype='jpg',
                   result_type='textual'):
    img = self.load(url, get=get, post=post, cookies=cookies)

    id = ("%.2f" % time())[-6:].replace(".", "")
    temp_file = open(
        join("tmp", "tmpCaptcha_%s_%s.%s" % (self.__name__, id, imgtype)),
        "wb")
    temp_file.write(img)
    temp_file.close()

    Ocr = self.core.pluginManager.loadClass("captcha", self.__name__)

    if Ocr:
        log(DEBUG, "Using tesseract for captcha")
        sleep(randint(3000, 5000) / 1000.0)
        if self.pyfile.abort: raise Abort

        ocr = Ocr()
        result = ocr.get_captcha(temp_file.name)
    else:
        log(DEBUG, "Using ct for captcha")
        # put username and passkey into two lines in ct.conf
        conf = join(expanduser("~"), "ct.conf")
        if not exists(conf):
            raise Exception("CaptchaTrader config %s not found." % conf)
        f = open(conf, "rb")
        req = getRequest()

        #raise timeout threshold
        req.c.setopt(LOW_SPEED_TIME, 80)

        try:
            json = req.load("http://captchatrader.com/api/submit",
                            post={
                                "api_key": "9f65e7f381c3af2b076ea680ae96b0b7",
                                "username": f.readline().strip(),
                                "password": f.readline().strip(),
                                "value": (FORM_FILE, temp_file.name),
                                "type": "file"
                            },
                            multipart=True)
        finally:
            f.close()
            req.close()

        response = loads(json)
        log(DEBUG, str(response))
        result = response[1]

        self.cTask = response[0]

    return result
Example #8
0
def getInfo(urls):
    h = getRequest()
    h.c.setopt(pycurl.HTTPHEADER,
               ["Accept: text/html",
                "User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0"])

    for url in urls:
        html = h.load(url, decode=True)
        yield parseFileInfo(MegaRapidCz, url, html)
Example #9
0
def getInfo(urls):
    h = getRequest()
    h.c.setopt(pycurl.HTTPHEADER, [
        "Accept: text/html",
        "User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0"
    ])

    for url in urls:
        html = h.load(url, decode=True)
        yield parseFileInfo(MegaRapidCz, url, html)
Example #10
0
def decryptCaptcha(self, url, get={}, post={}, cookies=False, forceUser=False, imgtype='jpg',
                   result_type='textual'):
    img = self.load(url, get=get, post=post, cookies=cookies)

    id = ("%.2f" % time())[-6:].replace(".", "")
    temp_file = open(join("tmp", "tmpCaptcha_%s_%s.%s" % (self.__name__, id, imgtype)), "wb")
    temp_file.write(img)
    temp_file.close()

    Ocr = self.core.pluginManager.loadClass("captcha", self.__name__)

    if Ocr:
        log(DEBUG, "Using tesseract for captcha")
        sleep(randint(3000, 5000) / 1000.0)
        if self.pyfile.abort: raise Abort

        ocr = Ocr()
        result = ocr.get_captcha(temp_file.name)
    else:
        log(DEBUG, "Using ct for captcha")
        # put username and passkey into two lines in ct.conf
        conf = join(expanduser("~"), "ct.conf")
        if not exists(conf): raise Exception("CaptchaTrader config %s not found." % conf)
        f = open(conf, "rb")
        req = getRequest()

        #raise timeout threshold
        req.c.setopt(LOW_SPEED_TIME, 80)

        try:
            json = req.load("http://captchatrader.com/api/submit",
                post={"api_key": "9f65e7f381c3af2b076ea680ae96b0b7",
                      "username": f.readline().strip(),
                      "password": f.readline().strip(),
                      "value": (FORM_FILE, temp_file.name),
                      "type": "file"}, multipart=True)
        finally:
            f.close()
            req.close()

        response = loads(json)
        log(DEBUG, str(response))
        result = response[1]

        self.cTask = response[0]

    return result
Example #11
0
    def _processCaptcha(self, task):
        task.data['ticket'] = ticket = uuid.uuid4()
        result = None

        with open(task.captchaFile, 'rb') as f:
            data = f.read()

        req = getRequest()
        # raise timeout threshold
        req.c.setopt(pycurl.LOW_SPEED_TIME, 80)

        try:
            result = req.load(self.API_URL,
                              post={'action'     : "upload",
                                    'key'        : self.getConfig('passkey'),
                                    'file'       : base64.b64encode(data),
                                    'gen_task_id': ticket})
        finally:
            req.close()

        self.logDebug("Result %s : %s" % (ticket, result))
        task.setResult(result)
Example #12
0
    def _processCaptcha(self, task):
        task.data['ticket'] = ticket = uuid4()
        result = None

        with open(task.captchaFile, 'rb') as f:
            data = f.read()

        req = getRequest()
        # raise timeout threshold
        req.c.setopt(LOW_SPEED_TIME, 80)

        try:
            result = req.load(self.API_URL,
                              post={'action'     : "upload",
                                    'key'        : self.getConfig('passkey'),
                                    'file'       : b64encode(data),
                                    'gen_task_id': ticket})
        finally:
            req.close()

        self.logDebug("Result %s : %s" % (ticket, result))
        task.setResult(result)
Example #13
0
    def submit(self, captcha, captchaType="file", match=None):
        req = getRequest()
        #raise timeout threshold
        req.c.setopt(LOW_SPEED_TIME, 80)

        try:
            #@NOTE: Workaround multipart-post bug in HTTPRequest.py
            if re.match("^\w*$", self.getConfig('passkey')):
                multipart = True
                data = (FORM_FILE, captcha)
            else:
                multipart = False
                with open(captcha, 'rb') as f:
                    data = f.read()
                data = b64encode(data)

            res = req.load(self.SUBMIT_URL,
                           post={
                               'action': "UPLOADCAPTCHA",
                               'username': self.getConfig('username'),
                               'password': self.getConfig('passkey'),
                               "file": data
                           },
                           multipart=multipart)
        finally:
            req.close()

        if res.startswith("ERROR"):
            raise ImageTyperzException(res)
        else:
            data = res.split('|')
            if len(data) == 2:
                ticket, result = data
            else:
                raise ImageTyperzException("Unknown response: %s" % res)

        return ticket, result
Example #14
0
class CaptchaBrotherhood(Hook):
    __name = "CaptchaBrotherhood"
    __type = "hook"
    __version = "0.08"

    __config = [("username", "str", "Username", ""),
                ("force", "bool", "Force CT even if client is connected",
                 False), ("passkey", "password", "Password", "")]

    __description = """Send captchas to CaptchaBrotherhood.com"""
    __license = "GPLv3"
    __authors = [("RaNaN", "*****@*****.**"),
                 ("zoidberg", "*****@*****.**")]

    API_URL = "http://www.captchabrotherhood.com/"

    def activate(self):
        if self.getConfig('ssl'):
            self.API_URL = self.API_URL.replace("http://", "https://")

    def getCredits(self):
        res = getURL(self.API_URL + "askCredits.aspx",
                     get={
                         "username": self.getConfig('username'),
                         "password": self.getConfig('passkey')
                     })
        if not res.startswith("OK"):
            raise CaptchaBrotherhoodException(res)
        else:
            credits = int(res[3:])
            self.logInfo(_("%d credits left") % credits)
            self.info['credits'] = credits
            return credits

    def submit(self, captcha, captchaType="file", match=None):
        try:
            img = Image.open(captcha)
            output = StringIO.StringIO()
            self.logDebug("CAPTCHA IMAGE", img, img.format, img.mode)
            if img.format in ("GIF", "JPEG"):
                img.save(output, img.format)
            else:
                if img.mode != "RGB":
                    img = img.convert("RGB")
                img.save(output, "JPEG")
            data = output.getvalue()
            output.close()
        except Exception, e:
            raise CaptchaBrotherhoodException(
                "Reading or converting captcha image failed: %s" % e)

        req = getRequest()

        url = "%ssendNewCaptcha.aspx?%s" % (
            self.API_URL,
            urlencode({
                'username': self.getConfig('username'),
                'password': self.getConfig('passkey'),
                'captchaSource': "pyLoad",
                'timeout': "80"
            }))

        req.c.setopt(pycurl.URL, url)
        req.c.setopt(pycurl.POST, 1)
        req.c.setopt(pycurl.POSTFIELDS, data)
        req.c.setopt(pycurl.HTTPHEADER, ["Content-Type: text/html"])

        try:
            req.c.perform()
            res = req.getResponse()
        except Exception, e:
            raise CaptchaBrotherhoodException("Submit captcha image failed")