def process_result(): # Disable communicator until we start another job Comunicator.disable() # Check if process exited cleanly if Cracker.crt_process is not None: Cracker.crt_process.check_clean_exit() show_stdout = list( filter( None, SingleProcess(Cracker.attack_command + " --show").split_stdout())) password = "" # Check if we cracked something! if len(show_stdout) != 0: for line in show_stdout: cracked_obj = Configuration.hashcat_show_regex.match(line) die( cracked_obj is None, "REGEX error! could not match the --show line:%s" % show_stdout) password = cracked_obj.group(1) msg = "[FAIL] Password for '%s' is not contained in rule '%s'" %\ (Cracker.mac_ssid_job, Cracker.crt_rule["name"]) if len(password) > 7: msg = "[SUCCESS] The password for '%s' is '%s'" % ( Cracker.mac_ssid_job, password) Comunicator.printer(msg) Cracker.safe_send_result(password) Cracker.clean_variables()
def process_result(): # Disable communicator until we start another job Comunicator.disable() # Check if process exited cleanly Cracker.crt_process.check_clean_exit() show_stdout = list( filter( None, SingleProcess(Cracker.attack_command + " --show").split_stdout())) password = "" # Check if we cracked something! if len(show_stdout) != 0: for line in show_stdout: cracked_obj = Configuration.hashcat_show_regex.match(line) die( cracked_obj is None, "REGEX error! could not match the --show line:%s" % show_stdout) password = cracked_obj.group(1) Cracker.safe_send_result(password) Cracker.clean_variables()
def is_already_cracked(command): show_stdout = list( filter(None, SingleProcess(command + " --show").split_stdout())) if len(show_stdout) > 0: return True return False
def is_potfile_duplicated(command): show_stdout = list( filter(None, SingleProcess(command + " --show").split_stdout())) if len(show_stdout) > 0: return True return False
def start_cracking(work): Cracker.mac_ssid_job = "%s-%s" % (work["handshake"]["mac"], work["handshake"]["ssid"]) msg = "Running '%s' with rule '%s'" % (Cracker.mac_ssid_job, work["rule"]["name"]) Comunicator.enable(interactive=False) Comunicator.dual_printer(Comunicator.logger.info, msg) _, Cracker.path_temp_file = mkstemp(prefix="psknow_crack") if work["handshake"]["file_type"] == "16800": with open(Cracker.path_temp_file, "w") as fd: fd.write(work["handshake"]["data"]) else: with open(Cracker.path_temp_file, "wb") as fd: fd.write(b64decode(work["handshake"]["data"].encode("utf8"))) # Memorize attack type - we need it to decode the output attack_type = work["handshake"]["handshake_type"] Cracker.crt_rule = work["rule"] attacked_file = Cracker.path_temp_file # Get commands needed to run hashcat generator_command, Cracker.attack_command, Cracker.scrambler =\ Cracker.get_attack_command(Cracker.crt_rule, attack_type, attacked_file, work["handshake"]["ssid"]) Comunicator.info_logger( "Trying rule %s on '%s-%s'" % (Cracker.crt_rule["name"], work["handshake"]["mac"], work["handshake"]["ssid"])) if Cracker.is_already_cracked(Cracker.attack_command): Comunicator.warning_logger( "'%s' has already been cracked. Attempting to send result." % Cracker.mac_ssid_job) Cracker.process_result() return if generator_command == "": Cracker.crt_process = SingleProcess(Cracker.attack_command) else: Cracker.crt_process = DoubleProcess(generator_command, Cracker.attack_command)
def start_cracking(work): Cracker.mac_ssid_job = "%s-%s" % (work["handshake"]["mac"], work["handshake"]["ssid"]) msg = "Running '%s' with rule '%s'" % (Cracker.mac_ssid_job, work["rule"]["name"]) Comunicator.enable(interactive=False) Comunicator.dual_printer(msg, Configuration.logger.info) _, Cracker.path_temp_file = mkstemp(prefix="psknow_crack") if work["handshake"]["file_type"] == "16800": with open(Cracker.path_temp_file, "w") as fd: fd.write(work["handshake"]["data"]) else: with open(Cracker.path_temp_file, "wb") as fd: fd.write(b64decode(work["handshake"]["data"].encode("utf8"))) # Memorize attack type - we need it to decode the output attack_type = work["handshake"]["handshake_type"] Cracker.crt_rule = work["rule"] attacked_file = Cracker.path_temp_file # Get commands needed to run hashcat generator_command, Cracker.attack_command, Cracker.scrambler =\ Cracker.get_attack_command(Cracker.crt_rule, attack_type, attacked_file, work["handshake"]["ssid"]) Configuration.logger.info( "Trying rule %s on '%s-%s'" % (Cracker.crt_rule["name"], work["handshake"]["mac"], work["handshake"]["ssid"])) if Cracker.is_potfile_duplicated(Cracker.attack_command): msg = "Duplication for %s happened. It is already present in potfile!" % Cracker.mac_ssid_job Configuration.dual_print(Configuration.logger.critical, msg) fast_stop() if generator_command == "": Cracker.crt_process = SingleProcess(Cracker.attack_command) else: Cracker.crt_process = DoubleProcess(generator_command, Cracker.attack_command)
def test_john(): """ Function that tests if john the ripper properly works Tests if john can be run and if the setting for running local config files is active :return: True if john the ripper properly works "<ERROR>" otherwise """ # Test if regular john the ripper works _, passwd_file = mkstemp(prefix="psknow_crack") try: with open(passwd_file, "w") as fd: fd.write("password\n") test_john_runs = "%s --wordlist=%s --stdout --rules=None" % ( Configuration.john_path, passwd_file) p = SingleProcess(test_john_runs, crit=False) p.generate_output() retcode = p.poll() if retcode != 0: return "process '%s' crashed with return code '%d'\nStdout: %s\nStderr: %s" % \ (test_john_runs, retcode, p.stdout(), p.stderr()) test_john_runs = "%s --wordlist=%s --stdout --rules=TestRulePSKnow" % ( Configuration.john_path, passwd_file) p = SingleProcess(test_john_runs, crit=False) p.generate_output() retcode = p.poll() if 'No "TestRulePSKnow" mode rules found in' in p.stderr(): return "john-local.conf was not loaded by john. Check the configuration file '%s.conf' and uncomment" \ "the line `#.include './john-local.conf'`" % Configuration.john_path if retcode != 0: return "process '%s' crashed with return code '%d'\nStdout: %s\nStderr: %s" % \ (test_john_runs, retcode, p.stdout(), p.stderr()) except Exception as e: raise e finally: os.remove(passwd_file) return True