bench_dict[str(sender.hash_mode).strip( )] = sender.hashcat_status_get_status()['Speed Raw'] def benchmark_status(sender): print(sender.hashcat_status_get_status()) bench_dict = {} print("-------------------------------") print("---- pyhashcat Benchmark ----") print("-------------------------------") finished = False hc = Hashcat() hc.benchmark = True hc.benchmark_all = True hc.workload_profile = 4 print("[!] Hashcat object init with id: ", id(hc)) print( "[!] cb_id finished: ", hc.event_connect(callback=finished_callback, signal="EVENT_OUTERLOOP_FINISHED")) print( "[!] cb_id benchmark_status: ", hc.event_connect(callback=jobfinish_callback, signal="EVENT_CRACKER_FINISHED")) print("[!] Starting Benchmark Mode") print("[+] Running hashcat")
def runner(self, hash_file=None, hash_mode=1000, attack_mode=0, rules=None, mask=None, wordlist=None, session=None, outfile=None, restore=None, username=False, pot_path=None, show=False, brain=True, increment=False, increment_min=None, increment_max=False, speed=False, benchmark=False, benchmark_all=False, wordlist2=None): logger.info('Running hashcat') rconf = CRACK_CONF['redis'] redis_con = Redis(rconf['host'], rconf['port']) redis_q = Queue(connection=redis_con) hc = Hashcat() logger.debug('Hashcat object ID: {}'.format(id(hc))) hc.session = session if benchmark: logger.debug('Running in benchmark mode') hc.benchmark = True if benchmark_all: hc.benchmark_all = True hc.hashcat_session_execute() return hc hc.potfile_disable = False hc.restore_disable = True hc.show = show if pot_path: hc.potfile_path = pot_path hc.quiet = False hc.optimized_kernel_enable = True hc.workload_profile = 4 if username is True: hc.username = True if increment is True: hc.increment = True if increment_min: if isinstance(increment_min, int): hc.increment_min = increment_min if increment_max: if isinstance(increment_max, int): hc.increment_max = increment_max hc.hash = hash_file hc.attack_mode = attack_mode if rules: hc.rules = rules hc.rp_files_cnt = len(rules) hc.hash_mode = hash_mode if wordlist: hc.dict1 = wordlist if wordlist2: hc.dict2 = wordlist2 if mask: hc.mask = mask if speed: hc.speed_only = True hc.hashcat_session_execute() return hc if brain: speed_q = Queue('speed_check', connection=redis_con) speed_session = '{}_speed'.format(session) job = redis_q.fetch_job(session) if 'brain_check' in job.meta: logger.debug('Restored job already has brain check state') speed_job = None if job.meta['brain_check'] is True: hc.brain_client = brain hc.brain_client_features = 3 ###***replace with random string hc.brain_password = '******' speed_job = None else: speed_job = speed_q.fetch_job(speed_session) else: speed_job = speed_q.fetch_job(speed_session) wait_count = 0 if speed_job: while len(speed_job.meta) < 1 and wait_count < 410: logger.debug('RUNNER loop') logger.debug('Speed meta not populated, waiting...') if job: if del_check(job): return hc if 'failed' in speed_job.get_status(): crack_q = crackqueue.Queuer() err_msg = crack_q.error_parser(speed_job) logger.error('Speed check failed: {}'.format(err_msg)) if job: job.meta['brain_check'] = None job.save_meta() raise ValueError( 'Aborted, speed check failed: {}'.format(err_msg)) elif 'finished' in speed_job.get_status(): logger.debug( 'Breaking runner loop speed check job has finished' ) if job: if del_check(job): return hc elif 'CrackQ State' in speed_job.meta: if del_check(speed_job): return hc time.sleep(5) wait_count += 5 speed_job = speed_q.fetch_job(speed_session) logger.debug('RUNNER loop finished') if 'Mode Info' in speed_job.meta: mode_info = speed_job.meta['Mode Info'] salts = mode_info[-1] speed = int(mode_info[-2]) brain = self.brain_check(speed, salts) hc.brain_client = brain hc.brain_client_features = 3 ###***replace with random string hc.brain_password = '******' if brain is True: if job: job.meta['brain_check'] = True job.save_meta() if brain is False: if job: job.meta['brain_check'] = False job.save_meta() else: logger.error('Speed check error, disabling brain') if job: job.meta['brain_check'] = None if not del_check(job): job.meta['CrackQ State'] = 'Run/Restored' job.save_meta() else: logger.error('No speed job to check') if job and not del_check(job): job.meta['CrackQ State'] = 'Run/Restored' job.save_meta() ###*** update this to config file path and try/except hc.markov_hcstat2 = "/var/crackq/files/crackq.hcstat" hc.custom_charset_1 = '?l?d' hc.custom_charset_2 = '?l?d?u' hc.custom_charset_3 = '?l?d?s' hc.outfile = outfile logger.debug('HC. Hashcat Rules: {}'.format(hc.rules)) logger.debug('HC. Hashcat rp_files_cnt: {}'.format(hc.rp_files_cnt)) if restore: hc.skip = int(restore) hc.hashcat_session_execute() speed_started = rq.registry.StartedJobRegistry('speed_check', connection=redis_con) cur_speed = speed_started.get_job_ids() if len(cur_speed) > 0: job = redis_q.fetch_job(session) if job: if not del_check(job): logger.debug( 'Speed job running, setting new job to Paused') job.meta['CrackQ State'] = 'Pause' job.save_meta() return hc
def benchmark_status(sender): device_cnt = sender.status_get_device_info_cnt() print "HashType: ", str(sender.status_get_hash_type()) for i in range(device_cnt): print "Speed.Dev.#", str(i), ".....: ", str(sender.status_get_speed_sec_dev(i)),"H/s (", str(sender.status_get_exec_msec_dev(i)), "ms)" print "-------------------------------" print "---- pyhashcat Benchmark ----" print "-------------------------------" finished = False hc = Hashcat() hc.benchmark = True hc.workload_profile = 2 print "[!] Hashcat object init with id: ", id(hc) print "[!] cb_id finished: ", hc.event_connect(callback=finished_callback, signal="EVENT_OUTERLOOP_FINISHED") print "[!] cb_id benchmark_status: ", hc.event_connect(callback=benchmark_status, signal="EVENT_CRACKER_FINISHED") print "[!] Starting Benchmark Mode" cracked = [] print "[+] Running hashcat" if hc.hashcat_session_execute() >= 0: print"[.] Workload profile", str(hc.workload_profile) sleep(5) # hashcat should be running in a background thread # wait for it to finishing cracking