Beispiel #1
0
 def do_first_verify(self):
     start_time = get_timestamp()
     # trace_list = self._generate_trace(vtype="first")
     # trace_list_info, _ = self._add_click_point(trace_list=trace_list, last_point=trace_list[-1])
     trace_list_info = []
     P0o = hb_trace_encrypt(ctx=self.__fullpage_ctx,
                            trace_list=trace_list_info)
     S0o = hb_trace_encrypt(ctx=self.__fullpage_ctx, trace_list=[])
     magic_msg = self._get_i_param(sep="magic data")
     info = {
         "lang":
         "zh-cn",
         "type":
         "fullpage",
         "tt":
         m5_encrypt(ctx=self.__fullpage_ctx,
                    message=P0o,
                    arr=self._geetest_params.get("c"),
                    mstr=self._geetest_params.get("s")),
         "light":
         "INPUT_0",
         "s":
         get_md5(text=hb_encrypt(ctx=self.__fullpage_ctx, message=S0o)
                 ),  # md5(D8[B5Y.c78(1283)](S0o))
         "h":
         get_md5(
             text=hb_encrypt(ctx=self.__fullpage_ctx, message=magic_msg)),
         "hh":
         get_md5(text=magic_msg),  # md5(i)
         "hi":
         get_md5(text=self._get_i_param(sep="!!")),  # md5(i)
         "ep":
         self.get_ep_param(),
     }
     end_time = get_timestamp()
     passtime = end_time - start_time
     info.update({
         "passtime":
         passtime,
         "rp":
         get_md5("".join([self.gt, self.challenge,
                          str(passtime)]))
     })
     encrypt_msg = final_encrypt(ctx=self.__fullpage_ctx,
                                 message=info,
                                 aes_key=self.__aes_key)
     ret_info = self.fetch(self.urls["verify"],
                           extra_params={"w": encrypt_msg})
     self.logger.debug("First verify result:{0}, challenge:{1}".format(
         ret_info, self.challenge))
     return ret_info
Beispiel #2
0
 def start(self):
     source = self.fetch(self.urls["index"], get_json=False)
     cookies = self.get_cookies(js_code=source)
     captcha_url = self.urls["captcha"].format(get_timestamp())
     challenge_info = self.fetch(captcha_url, cookies=cookies)
     self.gt = challenge_info.get("gt")
     self.challenge = challenge_info.get("challenge")
     self.offline = not bool(challenge_info.get("success"))
     if self.offline:
         return get_md5(text=self.challenge)
     self.new_captcha = challenge_info.get("new_captcha", False)
     # self.token = self.get_token()
     self._type_info = self.get_type_info()
     self._geetest_params = self.get_geetest_params()
     verify_ret = self.do_first_verify()
     if "validate" in verify_ret.keys():
         return verify_ret.get("validate", "").split("|")[0]
     else:
         verify_type = verify_ret.get("result")
         self._geetest_params = self.get_next_params(
             verify_type=verify_type)
         verify_func = self.verify_type[verify_type]["func"]
         vret = verify_func()
         if vret.get("status") == "error":
             pass
         else:
             return vret.get("data", {}).get("validate", "").split("|")[0]
Beispiel #3
0
 def do_first_verify(self):
     start_time = get_timestamp()
     trace_list = self._generate_trace(vtype="first")
     P0o = hb_trace_encrypt(ctx=self.__ctx, trace_list=trace_list)
     S0o = hb_trace_encrypt(ctx=self.__ctx, trace_list=[])
     magic_msg = self._get_i_param(sep="magic data")
     info = {
         "lang":
         "zh-cn",
         "type":
         "fullpage",
         "tt":
         m5_encrypt(ctx=self.__ctx,
                    message=P0o,
                    arr=self._geetest_params.get("c"),
                    mstr=self._geetest_params.get("s")),
         "light":
         "INPUT_0",
         "s":
         get_md5(text=hb_encrypt(
             ctx=self.__ctx, message=S0o)),  # md5(D8[B5Y.c78(1283)](S0o))
         "h":
         get_md5(text=hb_encrypt(ctx=self.__ctx, message=magic_msg)),
         "hh":
         get_md5(text=magic_msg),  # md5(i)
         "hi":
         get_md5(text=self._get_i_param(sep="!!")),  # md5(i)
         "ep":
         self.get_ep_param(),
     }
     end_time = get_timestamp()
     passtime = end_time - start_time
     info.update({
         "passtime":
         passtime,
         "rp":
         get_md5("".join([self.gt, self.challenge,
                          str(passtime)]))
     })
     encrypt_msg = get_Q0o(ctx=self.__ctx,
                           message=info,
                           aes_key=self.__aes_key)
     ret_info = self.fetch(self.urls["verify"],
                           extra_params={"w": encrypt_msg})
     print(ret_info)
     return ret_info.get("data", {})
Beispiel #4
0
 def do_click_verify(self):
     start_time = get_timestamp()
     img_url = self.urls["resources_host"] + self._geetest_params["pic"]
     self.logger.info("challenge: {0}, image url:{1}".format(
         self.challenge, img_url))
     click_img = self.fetch(url=img_url, get_json=False, get_bytes=True)
     point_list = self._get_coordinate(vtype="click", image=click_img)
     a = self.__get_a_param(point_list=point_list)
     trace_list = self._generate_trace(vtype="click")
     P0o = hb_click_trace_encrypt(ctx=self.__click_ctx,
                                  trace_list=trace_list)
     info = {
         "lang":
         "zh-cn",
         "tt":
         m5_encrypt(ctx=self.__fullpage_ctx,
                    message=P0o,
                    arr=self._geetest_params.get("c"),
                    mstr=self._geetest_params.get("s")),
         "pic":
         self._geetest_params.get("pic"),
         "a":
         a,
         "ep":
         self.get_ep_param(vtype="click", start_time=start_time),
     }
     passtime = get_timestamp() - start_time
     info.update({
         "passtime":
         passtime,
         "rp":
         get_md5("".join([self.gt, self.challenge[:32],
                          str(passtime)]))
     })
     aes_key = generate_aes_key()
     encrypt_key_msg = rsa_encrypt(ctx=self.__fullpage_ctx, message=aes_key)
     encrypt_msg = final_encrypt(ctx=self.__fullpage_ctx,
                                 message=info,
                                 aes_key=aes_key)
     ret_info = self.fetch(
         self.urls["verify"],
         extra_params={"w": encrypt_msg + encrypt_key_msg})
     if not self.debug:
         trace_info = {
             "fid": self.challenge,
             "trace_type": "click",
             "image": base64_encode(click_img),
             "point_list": point_list,
             "params": self._generate_trace_params.get("click", {}),
             "trace_list": trace_list,
             "result": ret_info.get("result")
         }
         TraceInfo(**trace_info).save()
     return ret_info
Beispiel #5
0
 def get_challenge(self):
     source = self.fetch(self.urls["index"], get_json=False)
     cookies = self.get_cookies(js_code=source)
     captcha_url = self.urls["captcha"].format(get_timestamp())
     challenge_info = self.fetch(captcha_url, cookies=cookies)
     gt = challenge_info.get("gt")
     challenge = challenge_info.get("challenge")
     offline = not bool(challenge_info.get("success"))
     validate = ""
     if offline:
         if challenge:
             validate = get_md5(text=challenge)
         else:
             raise GetParamsError(extra_msg="challenge_info")
     return gt, challenge, validate
Beispiel #6
0
 def do_click_verify(self):
     start_time = get_timestamp()
     img_url = self.urls["resources_host"] + self._geetest_params["pic"]
     print(img_url)
     click_img = self.fetch(url=img_url, get_json=False, get_bytes=True)
     point_list = self._get_coordinate(vtype="click",
                                       image_info={
                                           "type": "click",
                                           "image": click_img
                                       })
     a = self.__get_a_param(point_list=point_list)
     trace_list = self._generate_trace(vtype="click")
     P0o = hb_click_trace_encrypt(ctx=self.__click_ctx,
                                  trace_list=trace_list)
     info = {
         "lang":
         "zh-cn",
         "tt":
         m5_encrypt(ctx=self.__ctx,
                    message=P0o,
                    arr=self._geetest_params.get("c"),
                    mstr=self._geetest_params.get("s")),
         "pic":
         self._geetest_params.get("pic"),
         "a":
         a,
         "ep":
         self.get_ep_param(vtype="click"),
     }
     end_time = get_timestamp()
     passtime = end_time - start_time
     info.update({
         "passtime":
         passtime,
         "rp":
         get_md5("".join([self.gt, self.challenge[:32],
                          str(passtime)]))
     })
     aes_key = generate_aes_key()
     encrypt_key_msg = rsa_encrypt(ctx=self.__ctx, message=aes_key)
     encrypt_msg = get_Q0o(ctx=self.__ctx, message=info, aes_key=aes_key)
     ret_info = self.fetch(
         self.urls["verify"],
         extra_params={"w": encrypt_msg + encrypt_key_msg})
     return ret_info
Beispiel #7
0
 def _do_recognition(self, image, im_type=6907):
     result = do_recognition(image, im_type=im_type)
     if result.get("Error"):
         self.logger.error("===>>>recognition error: {0}".format(result))
         raise RecognitionError(extra_msg=result.get("Error"))
     else:
         pos_str = result.get("Result")
         self._image_id = result.get("Id")
         self.logger.info("===>recognition result: {0}".format(pos_str))
         if not self.debug:
             rec_info = {
                 "image": base64_encode(content=image),
                 "im_type": im_type,
                 "result": pos_str,
                 "md5": get_md5(text=image),
                 "record_id": self._image_id
             }
             RecognizeInfo(**rec_info).save()
         return pos_str
Beispiel #8
0
 def do_slide_verify(self):
     start_time = get_timestamp()
     trace_list = self._generate_trace(vtype="slide")
     P0o = hb_slide_trace_encrypt(ctx=self.__slide_ctx,
                                  trace_list=trace_list)
     J72 = "64"  # last point x
     info = {
         "lang":
         "zh-cn",
         "aa":
         m5_encrypt(ctx=self.__fullpage_ctx,
                    message=P0o,
                    arr=self._geetest_params.get("c"),
                    mstr=self._geetest_params.get("s")),
         "imgload":
         random.randint(90, 150),
         "userresponse":
         j5_encrypt(ctx=self.__slide_ctx,
                    vint=int(J72),
                    vstr=self.challenge),
         "ep":
         self.get_ep_param(vtype="slide"),
     }
     end_time = get_timestamp()
     passtime = end_time - start_time
     info.update({
         "passtime":
         passtime,
         "rp":
         get_md5("".join([self.gt, self.challenge[:32],
                          str(passtime)]))
     })
     aes_key = generate_aes_key()
     encrypt_key_msg = rsa_encrypt(ctx=self.__fullpage_ctx, message=aes_key)
     encrypt_msg = final_encrypt(ctx=self.__fullpage_ctx,
                                 message=info,
                                 aes_key=aes_key)
     ret_info = self.fetch(
         self.urls["verify"],
         extra_params={"w": encrypt_msg + encrypt_key_msg})
     return ret_info
Beispiel #9
0
 def get_ep_param(self, vtype="first", **kwargs):
     base_info = {
         "f": get_md5("".join([self.gt, self.challenge])),
         "te": False,  # touchEvent
         "me": True,  # mouseEvent
         "tm": self._generate_tm()
     }
     if vtype == "first":
         # tm < fp < lp < ts
         ep_info = {
             "v":
             "8.6.1",
             "ip":
             "10.8.10.128",
             "de":
             False,  # deviceorientation
             "ven":
             "Intel Open Source Technology Center",
             "ren":
             "Mesa DRI Intel(R) Sandybridge Mobile ",
             "ac":
             "f930496cb2084fa8e08a507beb9e3871",  # md5(window.AudioContext)
             "pu":
             False,  # puppet
             "ph":
             False,  # phantom
             "ni":
             False,  # nightmare
             "se":
             False,  # selenium
             "fp": [
                 "move",
                 random.randint(750, 850),
                 random.randint(300, 400),
                 get_timestamp(), "pointermove"
             ],
             "lp": [
                 "up",
                 random.randint(800, 1200),
                 random.randint(250, 450),
                 get_timestamp() + random.randint(500, 1500), "pointerup"
             ],
             "em": {
                 "ph": 0,
                 "cp": 0,
                 "ek": "11",
                 "wd": 0,
                 "nt": 0,
                 "si": 0,
                 "sc": 0
             },
             "by":
             -1,
             "ts":
             get_timestamp(),
         }
     elif vtype == "slide":
         ep_info = {"v": "7.4.3"}
     elif vtype == "click":
         ca = []
         lts = kwargs.get("start_time")
         for index, p in enumerate(self._click_points):
             x, y, ts = p
             dt = ts - lts
             if index == len(self._click_points) - 1:
                 tp = 3
             else:
                 tp = 1
             ca.append({"x": x, "y": y, "t": tp, "dt": dt})
             lts = ts
         ep_info = {"v": "2.6.4", "ca": ca}
     else:
         ep_info = {}
     ep_info.update(base_info)
     return ep_info