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
print('Speed: ', sender.hashcat_status_get_status()['Speed Raw']) 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("CRACKED-", id(sender), "EVENT_CRACKER_HASH_CRACKED") def finished_callback(sender): print("FIN-", id(sender), "EVENT_CRACKER_FINISHED") def any_callback(sender): print("ANY-", id(sender), sender.status_get_status_string()) print("-------------------------------") print("---- Simple pyhashcat Test ----") print("-------------------------------") hc = Hashcat() # To view event types # hc.event_types print("[!] Hashcat object init with id: ", id(hc)) print("[!] cb_id cracked: ", hc.event_connect(callback=cracked_callback, signal="EVENT_CRACKER_HASH_CRACKED")) print("[!] cb_id finished: ", hc.event_connect(callback=finished_callback, signal="EVENT_CRACKER_FINISHED")) print("[!] cb_id any: ", hc.event_connect(callback=any_callback, signal="ANY")) hc.hash = "8743b52063cd84097a65d1633f5c74f5" hc.mask = "?l?l?l?l?l?l?l" hc.quiet = True hc.potfile_disable = True hc.outfile = os.path.join(os.path.expanduser('~'), "outfile.txt") print("[+] Writing to ", hc.outfile) hc.attack_mode = 3 hc.hash_mode = 0
def cracked_callback(sender): print id(sender), "EVENT_CRACKER_HASH_CRACKED" def finished_callback(sender): print id(sender), "EVENT_CRACKER_FINISHED" def any_callback(sender): print id(sender), sender.status_get_status_string() print "-------------------------------" print "---- Simple pyhashcat Test ----" print "-------------------------------" hc = Hashcat() # To view event types # hc.event_types print "[!] Hashcat object init with id: ", id(hc) print "[!] cb_id cracked: ", hc.event_connect(callback=cracked_callback, signal="EVENT_CRACKER_HASH_CRACKED") print "[!] cb_id finished: ", hc.event_connect(callback=finished_callback, signal="EVENT_CRACKER_FINISHED") print "[!] cb_id any: ", hc.event_connect(callback=any_callback, signal="ANY") hc.hash = "8743b52063cd84097a65d1633f5c74f5" hc.mask = "?l?l?l?l?l?l?l" hc.quiet = True hc.potfile_disable = True hc.outfile = os.path.join(os.path.expanduser('~'), "outfile.txt") hc.attack_mode = 3 hc.hash_mode = 0 hc.workload_profile = 3
""" script to update/create reference dictionary containing all hashcat hash modes """ #!/usr/bin/env python import json #import sys from time import sleep from pyhashcat import Hashcat bench_dict = {} finished = False hc = Hashcat() hc.hwmon_disable = True hc.usage = True hc.left = False hc.logfile_disable = True hc.spin_damp = 0 hc.potfile_disable = True hc.show = False hc.session = 'usage' # Using backend_info at the moment as a small hack to get # usage only with out full hc execution hc.backend_info = True hc.quiet = True print("[+] Running hashcat") if hc.hashcat_session_execute() >= 0: hashm_dict = hc.hashcat_list_hashmodes() if isinstance(hashm_dict, dict): print('[+] Hashmodes list gathered')
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): logger.info('Running hashcat') hc = Hashcat() logger.debug('Hashcat object ID: {}'.format(id(hc))) hc.potfile_disable = False hc.restore_disable = True hc.show = show if pot_path: hc.potfile_path = pot_path hc.quiet = False hc.session = session hc.brain_client = brain hc.brain_client_features = 3 hc.optimized_kernel_enable = True hc.workload_profile = 4 ###***replace with random string hc.brain_password = '******' if username is True: hc.username = True #hc.remove = True #hc.remove_timer = 20 ###*** 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.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 mask: hc.mask = mask 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() 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)
finished = True 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
def update_modes(cls): """ This method updates the dictionary containing the hashcat supported hash algorithms. Run this with every hashcat update if you want the latest hash types. """ hc = Hashcat() hc.hwmon_disable = True hc.usage = True hc.left = False hc.logfile_disable = True hc.spin_damp = 0 hc.potfile_disable = True hc.show = False hc.session = 'usage' hc.backend_info = True hc.quiet = True print("[+] Running hashcat") if hc.hashcat_session_execute() >= 0: hashm_dict = hc.hashcat_list_hashmodes() if isinstance(hashm_dict, dict): print('[+] Hashmodes list gathered') print('[+] Updating Hash Modes dictionary') hashm_file = '/var/crackq/files/hashm_dict.json' print('[+] Writing dicitonary to file: {}'.format(hashm_file)) with open(hashm_file, 'w') as fh_hashm: fh_hashm.write(json.dumps(hashm_dict)) print('[+] Done')
print("FIN-", id(sender), "EVENT_CRACKER_FINISHED") def any_callback(sender): status = sender.status_get_status_string() print("ANY-", id(sender), status) print(sender.status_get_event_ctx()) if status == "Aborted": print(sender.status_get_event_ctx()) print("-------------------------------") print("---- Simple pyhashcat Test ----") print("-------------------------------") hc = Hashcat() # To view event types # hc.event_types print("[!] Hashcat object init with id: ", id(hc)) print("[!] cb_id error: ", hc.event_connect(callback=error_callback, signal="EVENT_LOG_ERROR")) print("[!] cb_id warning: ", hc.event_connect(callback=warning_callback, signal="EVENT_LOG_WARNING")) print( "[!] cb_id cracked: ", hc.event_connect(callback=cracked_callback, signal="EVENT_CRACKER_HASH_CRACKED")) print( "[!] cb_id finished: ", hc.event_connect(callback=finished_callback, signal="EVENT_CRACKER_FINISHED"))