def safe_send_result(password): written_flag = False while True: try: res = Cracker.req.sendresult(password) die( res is True, "Sending result '%s' for job '%s' produced an error" % (password, Cracker.mac_ssid_job)) if os.path.exists(Configuration.save_result_filename): os.remove(Configuration.save_result_filename) if res is False: Comunicator.warning_logger( "Server cancelled last job. Requesting stopwork.") Cracker.req.stopwork() break except Cracker.req.ServerDown: if not written_flag: msg = "Trying to send result '%s' for last job but the server is unreachable" % password Comunicator.dual_printer(Comunicator.logger.warning, msg) written_flag = True with open(Configuration.save_result_filename, "w") as fp: fp.write(password) sleep(10)
def complete_missing(): gather_flag = False try: missings = Cracker.req.getmissing() except Cracker.req.ServerDown: return die(missings is True, "Server side error occurred.") if missings is None: return for missing in missings: if missing["type"] == "program": Comunicator.info_logger("Please install program '%s'" % missing["name"]) elif missing["type"] in [ "dict", "maskfile", "generator", "john-local.conf" ]: Comunicator.dual_printer( Comunicator.logger.info, "Downloading '%s'..." % missing["path"]) gather_flag = True if "/" in missing["path"]: directory, filename = missing["path"].rsplit('/', 1) # Create directory if they do not exist os.makedirs(directory, exist_ok=True) else: filename = missing["path"] try: if Cracker.req.checkfile(filename) is None and \ Cracker.req.getfile(filename, missing["path"]) is None: Comunicator.dual_printer( Comunicator.logger.info, "Downloaded '%s'" % missing["path"]) if missing["type"] == "generator": os.chmod( missing["path"], stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR) except Cracker.req.ServerDown: return else: Comunicator.warning_logger("Unknown missing type '%s'" % missing) if gather_flag: Configuration.gather_capabilities()
def do_work(): # Something just finished! if Cracker.crt_process is not None and Cracker.crt_process.isdead(): Cracker.process_result() # Process is still running - update eta if Cracker.crt_process is not None: Cracker.update_eta() return if slow_stop_flag: Comunicator.info_logger( "Slow shutdown signal received - shutting down!") sys.exit(0) # Before getting more work make sure we are up to date Cracker.complete_missing() # Test capabilities once if not Cracker.capabilities_tested: Configuration.test_capabilities() Cracker.capabilities_tested = True # Nothing is running - getting more work try: work = Cracker.req.getwork() except Cracker.req.ServerDown: Comunicator.printer(Comunicator.printer(Requester.DownMessage)) return die(work is True, "A server side error occured while getting work!") # No work to be done right now if work is None: Comunicator.printer( "No work to be done, checking in 10 seconds again.") return # Redundant check if work is False: Comunicator.warning_logger("Capabilities out of date!") return # Make status seem a bit more responsive Cracker.old_eta = "Cracking process starting" Cracker.start_cracking(work)
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)