static int inner2_loop (hashcat_ctx_t *hashcat_ctx) { hashes_t *hashes = hashcat_ctx->hashes; induct_ctx_t *induct_ctx = hashcat_ctx->induct_ctx; logfile_ctx_t *logfile_ctx = hashcat_ctx->logfile_ctx; opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; restore_ctx_t *restore_ctx = hashcat_ctx->restore_ctx; status_ctx_t *status_ctx = hashcat_ctx->status_ctx; user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; user_options_t *user_options = hashcat_ctx->user_options; //status_ctx->run_main_level1 = true; //status_ctx->run_main_level2 = true; //status_ctx->run_main_level3 = true; status_ctx->run_thread_level1 = true; status_ctx->run_thread_level2 = true; status_ctx->devices_status = STATUS_INIT; logfile_generate_subid (hashcat_ctx); logfile_sub_msg ("START"); status_progress_reset (hashcat_ctx); status_ctx->msec_paused = 0; status_ctx->words_off = 0; status_ctx->words_cur = 0; if (restore_ctx->rd) { restore_data_t *rd = restore_ctx->rd; if (rd->words_cur > 0) { status_ctx->words_off = rd->words_cur; status_ctx->words_cur = status_ctx->words_off; rd->words_cur = 0; // --restore always overrides --skip user_options->skip = 0; } } if (user_options->skip > 0) { status_ctx->words_off = user_options->skip; status_ctx->words_cur = status_ctx->words_off; user_options->skip = 0; } opencl_session_reset (hashcat_ctx); cpt_ctx_reset (hashcat_ctx); /** * Update attack-mode specific stuff based on mask */ const int rc_mask_ctx_update_loop = mask_ctx_update_loop (hashcat_ctx); if (rc_mask_ctx_update_loop == -1) return 0; /** * Update attack-mode specific stuff based on wordlist */ const int rc_straight_ctx_update_loop = straight_ctx_update_loop (hashcat_ctx); if (rc_straight_ctx_update_loop == -1) return 0; // words base const u64 amplifier_cnt = user_options_extra_amplifier (hashcat_ctx); status_ctx->words_base = status_ctx->words_cnt / amplifier_cnt; EVENT (EVENT_CALCULATED_WORDS_BASE); if (user_options->keyspace == true) return 0; // restore stuff if (status_ctx->words_off > status_ctx->words_base) { event_log_error (hashcat_ctx, "Restore value is greater than keyspace."); return -1; } const u64 progress_restored = status_ctx->words_off * amplifier_cnt; for (u32 i = 0; i < hashes->salts_cnt; i++) { status_ctx->words_progress_restored[i] = progress_restored; } /** * limit kernel loops by the amplification count we have from: * - straight_ctx, combinator_ctx or mask_ctx for fast hashes * - hash iteration count for slow hashes * this is required for autotune */ opencl_ctx_devices_kernel_loops (hashcat_ctx); /** * prepare thread buffers */ thread_param_t *threads_param = (thread_param_t *) hccalloc (opencl_ctx->devices_cnt, sizeof (thread_param_t)); hc_thread_t *c_threads = (hc_thread_t *) hccalloc (opencl_ctx->devices_cnt, sizeof (hc_thread_t)); /** * create autotune threads */ EVENT (EVENT_AUTOTUNE_STARTING); status_ctx->devices_status = STATUS_AUTOTUNE; for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) { thread_param_t *thread_param = threads_param + device_id; thread_param->hashcat_ctx = hashcat_ctx; thread_param->tid = device_id; hc_thread_create (c_threads[device_id], thread_autotune, thread_param); } hc_thread_wait (opencl_ctx->devices_cnt, c_threads); EVENT (EVENT_AUTOTUNE_FINISHED); /** * autotune modified kernel_accel, which modifies opencl_ctx->kernel_power_all */ opencl_ctx_devices_update_power (hashcat_ctx); /** * Begin loopback recording */ if (user_options->loopback == true) { loopback_write_open (hashcat_ctx); } /** * Prepare cracking stats */ hc_timer_set (&status_ctx->timer_running); hc_time_t runtime_start; hc_time (&runtime_start); status_ctx->runtime_start = runtime_start; /** * create cracker threads */ EVENT (EVENT_CRACKER_STARTING); status_ctx->devices_status = STATUS_RUNNING; status_ctx->accessible = true; for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) { thread_param_t *thread_param = threads_param + device_id; thread_param->hashcat_ctx = hashcat_ctx; thread_param->tid = device_id; if (user_options_extra->wordlist_mode == WL_MODE_STDIN) { hc_thread_create (c_threads[device_id], thread_calc_stdin, thread_param); } else { hc_thread_create (c_threads[device_id], thread_calc, thread_param); } } hc_thread_wait (opencl_ctx->devices_cnt, c_threads); hcfree (c_threads); hcfree (threads_param); if ((status_ctx->devices_status == STATUS_RUNNING) && (status_ctx->checkpoint_shutdown == true)) { myabort_checkpoint (hashcat_ctx); } if ((status_ctx->devices_status != STATUS_CRACKED) && (status_ctx->devices_status != STATUS_ABORTED) && (status_ctx->devices_status != STATUS_ABORTED_CHECKPOINT) && (status_ctx->devices_status != STATUS_ABORTED_RUNTIME) && (status_ctx->devices_status != STATUS_QUIT) && (status_ctx->devices_status != STATUS_BYPASS)) { status_ctx->devices_status = STATUS_EXHAUSTED; } // update some timer hc_time_t runtime_stop; hc_time (&runtime_stop); status_ctx->runtime_stop = runtime_stop; logfile_sub_uint (runtime_start); logfile_sub_uint (runtime_stop); if (hashcat_get_status (hashcat_ctx, status_ctx->hashcat_status_final) == -1) { fprintf (stderr, "Initialization problem: the hashcat status monitoring function returned an unexpected value\n"); } status_ctx->accessible = false; EVENT (EVENT_CRACKER_FINISHED); // mark sub logfile logfile_sub_var_uint ("status-after-work", status_ctx->devices_status); logfile_sub_msg ("STOP"); // stop loopback recording if (user_options->loopback == true) { loopback_write_close (hashcat_ctx); } // New induction folder check, which is a controlled recursion if (induct_ctx->induction_dictionaries_cnt == 0) { induct_ctx_scan (hashcat_ctx); while (induct_ctx->induction_dictionaries_cnt) { for (induct_ctx->induction_dictionaries_pos = 0; induct_ctx->induction_dictionaries_pos < induct_ctx->induction_dictionaries_cnt; induct_ctx->induction_dictionaries_pos++) { if (status_ctx->devices_status == STATUS_EXHAUSTED) { const int rc_inner2_loop = inner2_loop (hashcat_ctx); if (rc_inner2_loop == -1) myabort (hashcat_ctx); if (status_ctx->run_main_level3 == false) break; } unlink (induct_ctx->induction_dictionaries[induct_ctx->induction_dictionaries_pos]); } hcfree (induct_ctx->induction_dictionaries); induct_ctx_scan (hashcat_ctx); } } return 0; }
int mask_ctx_update_loop (hashcat_ctx_t *hashcat_ctx) { combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx; hashconfig_t *hashconfig = hashcat_ctx->hashconfig; hashes_t *hashes = hashcat_ctx->hashes; logfile_ctx_t *logfile_ctx = hashcat_ctx->logfile_ctx; mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx; status_ctx_t *status_ctx = hashcat_ctx->status_ctx; user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; user_options_t *user_options = hashcat_ctx->user_options; if (user_options_extra->attack_kern == ATTACK_KERN_COMBI) { if (user_options->attack_mode == ATTACK_MODE_COMBI) { } else if ((user_options->attack_mode == ATTACK_MODE_HYBRID1) || (user_options->attack_mode == ATTACK_MODE_HYBRID2)) { if (((hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL) == 0) && (user_options->attack_mode == ATTACK_MODE_HYBRID2)) { mask_ctx->mask = mask_ctx->masks[mask_ctx->masks_pos]; const int rc_mask_file = mask_ctx_parse_maskfile (hashcat_ctx); if (rc_mask_file == -1) return -1; mask_ctx->css_buf = (cs_t *) hccalloc (256, sizeof (cs_t)); const int rc_gen_css = mp_gen_css (hashcat_ctx, mask_ctx->mask, strlen (mask_ctx->mask), mask_ctx->mp_sys, mask_ctx->mp_usr, mask_ctx->css_buf, &mask_ctx->css_cnt); if (rc_gen_css == -1) return -1; u32 uniq_tbls[SP_PW_MAX][CHARSIZ] = { { 0 } }; mp_css_to_uniq_tbl (hashcat_ctx, mask_ctx->css_cnt, mask_ctx->css_buf, uniq_tbls); sp_tbl_to_css (mask_ctx->root_table_buf, mask_ctx->markov_table_buf, mask_ctx->root_css_buf, mask_ctx->markov_css_buf, user_options->markov_threshold, uniq_tbls); const int rc_get_sum = sp_get_sum (0, mask_ctx->css_cnt, mask_ctx->root_css_buf, &mask_ctx->bfs_cnt); if (rc_get_sum == -1) { event_log_error (hashcat_ctx, "Integer overflow detected in keyspace of mask: %s", mask_ctx->mask); return -1; } const int rc_update_mp = opencl_session_update_mp (hashcat_ctx); if (rc_update_mp == -1) return -1; } else { mask_ctx->mask = mask_ctx->masks[mask_ctx->masks_pos]; const int rc_mask_file = mask_ctx_parse_maskfile (hashcat_ctx); if (rc_mask_file == -1) return -1; mask_ctx->css_buf = (cs_t *) hccalloc (256, sizeof (cs_t)); const int rc_gen_css = mp_gen_css (hashcat_ctx, mask_ctx->mask, strlen (mask_ctx->mask), mask_ctx->mp_sys, mask_ctx->mp_usr, mask_ctx->css_buf, &mask_ctx->css_cnt); if (rc_gen_css == -1) return -1; u32 uniq_tbls[SP_PW_MAX][CHARSIZ] = { { 0 } }; mp_css_to_uniq_tbl (hashcat_ctx, mask_ctx->css_cnt, mask_ctx->css_buf, uniq_tbls); sp_tbl_to_css (mask_ctx->root_table_buf, mask_ctx->markov_table_buf, mask_ctx->root_css_buf, mask_ctx->markov_css_buf, user_options->markov_threshold, uniq_tbls); const int rc_get_sum = sp_get_sum (0, mask_ctx->css_cnt, mask_ctx->root_css_buf, &combinator_ctx->combs_cnt); if (rc_get_sum == -1) { event_log_error (hashcat_ctx, "Integer overflow detected in keyspace of mask: %s", mask_ctx->mask); return -1; } const int rc_update_mp = opencl_session_update_mp (hashcat_ctx); if (rc_update_mp == -1) return -1; } } const int rc_update_combinator = opencl_session_update_combinator (hashcat_ctx); if (rc_update_combinator == -1) return -1; } else if (user_options_extra->attack_kern == ATTACK_KERN_BF) { mask_ctx->mask = mask_ctx->masks[mask_ctx->masks_pos]; const int rc_mask_file = mask_ctx_parse_maskfile (hashcat_ctx); if (rc_mask_file == -1) return -1; if (user_options->attack_mode == ATTACK_MODE_BF) // always true { mask_ctx->css_buf = (cs_t *) hccalloc (256, sizeof (cs_t)); const int rc_gen_css = mp_gen_css (hashcat_ctx, mask_ctx->mask, strlen (mask_ctx->mask), mask_ctx->mp_sys, mask_ctx->mp_usr, mask_ctx->css_buf, &mask_ctx->css_cnt); if (rc_gen_css == -1) return -1; // special case for benchmark u32 pw_min = hashconfig->pw_min; u32 pw_max = hashconfig->pw_max; if (user_options->benchmark == true) { pw_min = mp_get_length (mask_ctx->mask); pw_max = pw_min; } hashconfig->pw_min = pw_min; hashconfig->pw_max = pw_max; // check if mask is not too large or too small for pw_min/pw_max u32 mask_min = hashconfig->pw_min; u32 mask_max = hashconfig->pw_max; if ((mask_ctx->css_cnt < mask_min) || (mask_ctx->css_cnt > mask_max)) { if (mask_ctx->css_cnt < mask_min) { event_log_warning (hashcat_ctx, "Skipping mask '%s' because it is smaller than the minimum password length.", mask_ctx->mask); event_log_warning (hashcat_ctx, NULL); } if (mask_ctx->css_cnt > mask_max) { event_log_warning (hashcat_ctx, "Skipping mask '%s' because it is larger than the maximum password length.", mask_ctx->mask); event_log_warning (hashcat_ctx, NULL); } // skip to next mask logfile_sub_msg ("STOP"); return -1; } if (hashconfig->opts_type & OPTS_TYPE_PT_UTF16LE) { const int rc = mp_css_utf16le_expand (hashcat_ctx); if (rc == -1) return -1; } else if (hashconfig->opts_type & OPTS_TYPE_PT_UTF16BE) { const int rc = mp_css_utf16be_expand (hashcat_ctx); if (rc == -1) return -1; } u32 css_cnt_orig = mask_ctx->css_cnt; if (hashconfig->opti_type & OPTI_TYPE_SINGLE_HASH) { if (hashconfig->opti_type & OPTI_TYPE_APPENDED_SALT) { const int rc = mp_css_append_salt (hashcat_ctx, &hashes->salts_buf[0]); if (rc == -1) return -1; } } u32 uniq_tbls[SP_PW_MAX][CHARSIZ] = { { 0 } }; mp_css_to_uniq_tbl (hashcat_ctx, mask_ctx->css_cnt, mask_ctx->css_buf, uniq_tbls); sp_tbl_to_css (mask_ctx->root_table_buf, mask_ctx->markov_table_buf, mask_ctx->root_css_buf, mask_ctx->markov_css_buf, user_options->markov_threshold, uniq_tbls); const int rc_get_sum1 = sp_get_sum (0, mask_ctx->css_cnt, mask_ctx->root_css_buf, &status_ctx->words_cnt); if (rc_get_sum1 == -1) { event_log_error (hashcat_ctx, "Integer overflow detected in keyspace of mask: %s", mask_ctx->mask); return -1; } // copy + args u32 css_cnt_lr[2]; mp_css_split_cnt (hashcat_ctx, css_cnt_orig, css_cnt_lr); const int rc_get_sum2 = sp_get_sum (0, css_cnt_lr[1], mask_ctx->root_css_buf, &mask_ctx->bfs_cnt); if (rc_get_sum2 == -1) { event_log_error (hashcat_ctx, "Integer overflow detected in keyspace of mask: %s", mask_ctx->mask); return -1; } const int rc_update_mp_rl = opencl_session_update_mp_rl (hashcat_ctx, css_cnt_lr[0], css_cnt_lr[1]); if (rc_update_mp_rl == -1) return -1; } } return 0; }
int straight_ctx_update_loop (hashcat_ctx_t *hashcat_ctx) { combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx; induct_ctx_t *induct_ctx = hashcat_ctx->induct_ctx; logfile_ctx_t *logfile_ctx = hashcat_ctx->logfile_ctx; mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx; status_ctx_t *status_ctx = hashcat_ctx->status_ctx; straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx; user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; user_options_t *user_options = hashcat_ctx->user_options; if (user_options->attack_mode == ATTACK_MODE_STRAIGHT) { if (user_options_extra->wordlist_mode == WL_MODE_FILE) { if (induct_ctx->induction_dictionaries_cnt) { straight_ctx->dict = induct_ctx->induction_dictionaries[induct_ctx->induction_dictionaries_pos]; } else { straight_ctx->dict = straight_ctx->dicts[straight_ctx->dicts_pos]; } logfile_sub_string (straight_ctx->dict); for (u32 i = 0; i < user_options->rp_files_cnt; i++) { logfile_sub_var_string ("rulefile", user_options->rp_files[i]); } FILE *fd = fopen (straight_ctx->dict, "rb"); if (fd == NULL) { event_log_error (hashcat_ctx, "%s: %s", straight_ctx->dict, strerror (errno)); return -1; } const int rc = count_words (hashcat_ctx, fd, straight_ctx->dict, &status_ctx->words_cnt); fclose (fd); if (rc == -1) { event_log_error (hashcat_ctx, "Integer overflow detected in keyspace of wordlist: %s", straight_ctx->dict); return -1; } if (status_ctx->words_cnt == 0) { logfile_sub_msg ("STOP"); return 0; } } } else if (user_options->attack_mode == ATTACK_MODE_COMBI) { logfile_sub_string (combinator_ctx->dict1); logfile_sub_string (combinator_ctx->dict2); if (combinator_ctx->combs_mode == COMBINATOR_MODE_BASE_LEFT) { FILE *fd = fopen (combinator_ctx->dict1, "rb"); if (fd == NULL) { event_log_error (hashcat_ctx, "%s: %s", combinator_ctx->dict1, strerror (errno)); return -1; } const int rc = count_words (hashcat_ctx, fd, combinator_ctx->dict1, &status_ctx->words_cnt); fclose (fd); if (rc == -1) { event_log_error (hashcat_ctx, "Integer overflow detected in keyspace of wordlist: %s", combinator_ctx->dict1); return -1; } } else if (combinator_ctx->combs_mode == COMBINATOR_MODE_BASE_RIGHT) { FILE *fd = fopen (combinator_ctx->dict2, "rb"); if (fd == NULL) { event_log_error (hashcat_ctx, "%s: %s", combinator_ctx->dict2, strerror (errno)); return -1; } const int rc = count_words (hashcat_ctx, fd, combinator_ctx->dict2, &status_ctx->words_cnt); fclose (fd); if (rc == -1) { event_log_error (hashcat_ctx, "Integer overflow detected in keyspace of wordlist: %s", combinator_ctx->dict2); return -1; } } if (status_ctx->words_cnt == 0) { logfile_sub_msg ("STOP"); return 0; } } else if (user_options->attack_mode == ATTACK_MODE_BF) { logfile_sub_string (mask_ctx->mask); } else if ((user_options->attack_mode == ATTACK_MODE_HYBRID1) || (user_options->attack_mode == ATTACK_MODE_HYBRID2)) { if (induct_ctx->induction_dictionaries_cnt) { straight_ctx->dict = induct_ctx->induction_dictionaries[induct_ctx->induction_dictionaries_pos]; } else { straight_ctx->dict = straight_ctx->dicts[straight_ctx->dicts_pos]; } logfile_sub_string (straight_ctx->dict); logfile_sub_string (mask_ctx->mask); FILE *fd = fopen (straight_ctx->dict, "rb"); if (fd == NULL) { event_log_error (hashcat_ctx, "%s: %s", straight_ctx->dict, strerror (errno)); return -1; } const int rc = count_words (hashcat_ctx, fd, straight_ctx->dict, &status_ctx->words_cnt); fclose (fd); if (rc == -1) { event_log_error (hashcat_ctx, "Integer overflow detected in keyspace of wordlist: %s", straight_ctx->dict); return -1; } if (status_ctx->words_cnt == 0) { logfile_sub_msg ("STOP"); return 0; } } return 0; }