def is_positive(self, resp): if self.false_size is not None and get_response_size( resp) != self.false_size: return True if self.false_re and not self.false_re.findall(resp.text): return True if self.true_re and self.true_re.findall(resp.text): return True return False
def is_poitive_item(self, resp): if resp is None: return False if self.false_size is not None and get_response_size( resp) != self.false_size: return True search_scope = get_full_response_text(resp) if not self.false_re.findall(search_scope): return True return False
def test_log(self, target_obj, resp, positive_item): """ Log data for test mode :param target_obj: checked obj (params str, dir name, url, files set, ...) :param resp: :param positive_item: :return: """ if not self.is_test(): return if isinstance(target_obj, dict): target_obj = ",".join(target_obj.keys()) self.test_put( target_obj, { 'code': resp.status_code if resp is not None else 0, 'positive': positive_item, 'size': get_response_size(resp) if resp is not None else 0, 'content': resp.text if resp is not None else '', })
def run(self): """ Run thread """ need_retest = False word = False while not self.done and not self.is_pass_found(): try: self.last_action = int(time.time()) if self.delay: time.sleep(self.delay) if not need_retest: word = self.queue.get() if self.ignore_word(word): continue try: resp = self.http.get(self.url, auth=(self.login, word)) ErrorsCounter.flush() except ConnectionError: ErrorsCounter.up() need_retest = True self.http.change_proxy() continue if self.is_retest_need(word, resp): time.sleep(self.retest_delay) need_retest = True resp.close() continue positive_item = False if self.is_positive(resp): positive_item = True item_data = {'word': word, 'content': resp.text, 'size': get_response_size(resp)} self.result.append(item_data) self.xml_log(item_data) self.logger.log("F", False) self.log_item(word, resp, positive_item) self.check_positive_limit_stop(self.result) self.test_log(word, resp, positive_item) if positive_item and int(self.first_stop): self.done = True self.set_pass_found(True) break need_retest = False self.counter.up() resp.close() except queue.Empty: self.done = True break except ChunkedEncodingError as e: self.logger.ex(e) except BaseException as e: try: if str(e).count('Cannot connect to proxy'): need_retest = True else: self.logger.log(str(word) + " " + str(e)) except UnicodeDecodeError: pass except UnboundLocalError: self.logger.ex(e) finally: pass