int outcheck_ctx_init (hashcat_ctx_t *hashcat_ctx) { folder_config_t *folder_config = hashcat_ctx->folder_config; outcheck_ctx_t *outcheck_ctx = hashcat_ctx->outcheck_ctx; user_options_t *user_options = hashcat_ctx->user_options; outcheck_ctx->enabled = false; if (user_options->keyspace == true) return 0; if (user_options->benchmark == true) return 0; if (user_options->speed_only == true) return 0; if (user_options->opencl_info == true) return 0; if (user_options->outfile_check_timer == 0) return 0; if ((user_options->hash_mode == 5200) || ((user_options->hash_mode >= 6200) && (user_options->hash_mode <= 6299)) || ((user_options->hash_mode >= 13700) && (user_options->hash_mode <= 13799)) || (user_options->hash_mode == 9000)) return 0; if (user_options->outfile_check_dir == NULL) { outcheck_ctx->root_directory = (char *) hcmalloc (HCBUFSIZ_TINY); snprintf (outcheck_ctx->root_directory, HCBUFSIZ_TINY - 1, "%s/%s.%s", folder_config->session_dir, user_options->session, OUTFILES_DIR); } else { outcheck_ctx->root_directory = user_options->outfile_check_dir; } hc_stat_t outfile_check_stat; if (hc_stat (outcheck_ctx->root_directory, &outfile_check_stat) == 0) { const u32 is_dir = S_ISDIR (outfile_check_stat.st_mode); if (is_dir == 0) { event_log_error (hashcat_ctx, "Directory specified in outfile-check '%s' is not a valid directory", outcheck_ctx->root_directory); return -1; } } else { if (hc_mkdir (outcheck_ctx->root_directory, 0700) == -1) { event_log_error (hashcat_ctx, "%s: %m", outcheck_ctx->root_directory); return -1; } } outcheck_ctx->enabled = true; return 0; }
int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx) { combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx; user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; user_options_t *user_options = hashcat_ctx->user_options; combinator_ctx->enabled = false; if (user_options->left == true) return 0; if (user_options->opencl_info == true) return 0; if (user_options->show == true) return 0; if (user_options->usage == true) return 0; if (user_options->version == true) return 0; if ((user_options->attack_mode != ATTACK_MODE_COMBI) && (user_options->attack_mode != ATTACK_MODE_HYBRID1) && (user_options->attack_mode != ATTACK_MODE_HYBRID2)) return 0; combinator_ctx->enabled = true; combinator_ctx->scratch_buf = (char *) hcmalloc (HCBUFSIZ_LARGE); if (user_options->attack_mode == ATTACK_MODE_STRAIGHT) { // nothing to do } else if (user_options->attack_mode == ATTACK_MODE_COMBI) { // display char *dictfile1 = user_options_extra->hc_workv[0]; char *dictfile2 = user_options_extra->hc_workv[1]; // find the bigger dictionary and use as base FILE *fp1 = NULL; FILE *fp2 = NULL; hc_stat_t tmp_stat; if ((fp1 = fopen (dictfile1, "rb")) == NULL) { event_log_error (hashcat_ctx, "%s: %m", dictfile1); return -1; } if (hc_stat (dictfile1, &tmp_stat) == -1) { event_log_error (hashcat_ctx, "%s: %m", dictfile1); fclose (fp1); return -1; } if (S_ISDIR (tmp_stat.st_mode)) { event_log_error (hashcat_ctx, "%s must be a regular file", dictfile1); fclose (fp1); return -1; } if ((fp2 = fopen (dictfile2, "rb")) == NULL) { event_log_error (hashcat_ctx, "%s: %m", dictfile2); fclose (fp1); return -1; } if (hc_stat (dictfile2, &tmp_stat) == -1) { event_log_error (hashcat_ctx, "%s: %m", dictfile2); fclose (fp1); fclose (fp2); return -1; } if (S_ISDIR (tmp_stat.st_mode)) { event_log_error (hashcat_ctx, "%s must be a regular file", dictfile2); fclose (fp1); fclose (fp2); return -1; } combinator_ctx->combs_cnt = 1; const u64 words1_cnt = count_words (hashcat_ctx, fp1, dictfile1); if (words1_cnt == 0) { event_log_error (hashcat_ctx, "%s: empty file", dictfile1); fclose (fp1); fclose (fp2); return -1; } combinator_ctx->combs_cnt = 1; const u64 words2_cnt = count_words (hashcat_ctx, fp2, dictfile2); if (words2_cnt == 0) { event_log_error (hashcat_ctx, "%s: empty file", dictfile2); fclose (fp1); fclose (fp2); return -1; } fclose (fp1); fclose (fp2); combinator_ctx->dict1 = dictfile1; combinator_ctx->dict2 = dictfile2; if (words1_cnt >= words2_cnt) { combinator_ctx->combs_mode = COMBINATOR_MODE_BASE_LEFT; combinator_ctx->combs_cnt = words2_cnt; } else { combinator_ctx->combs_mode = COMBINATOR_MODE_BASE_RIGHT; combinator_ctx->combs_cnt = words1_cnt; // we also have to switch wordlist related rules! char *tmpc = user_options->rule_buf_l; user_options->rule_buf_l = user_options->rule_buf_r; user_options->rule_buf_r = tmpc; u32 tmpi = user_options_extra->rule_len_l; user_options_extra->rule_len_l = user_options_extra->rule_len_r; user_options_extra->rule_len_r = tmpi; } } else if (user_options->attack_mode == ATTACK_MODE_BF) { // nothing to do } else if (user_options->attack_mode == ATTACK_MODE_HYBRID1) { combinator_ctx->combs_mode = COMBINATOR_MODE_BASE_LEFT; } else if (user_options->attack_mode == ATTACK_MODE_HYBRID2) { combinator_ctx->combs_mode = COMBINATOR_MODE_BASE_RIGHT; } return 0; }
int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx) { hashconfig_t *hashconfig = hashcat_ctx->hashconfig; hashes_t *hashes = hashcat_ctx->hashes; user_options_t *user_options = hashcat_ctx->user_options; user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; char *hash_or_file = user_options_extra->hc_hash; /** * load hashes, part I: find input mode, count hashes */ u32 hashlist_mode = 0; u32 hashlist_format = HLFMT_HASHCAT; u32 hashes_avail = 0; if ((user_options->benchmark == false) && (user_options->stdout_flag == false)) { hc_stat_t f; hashlist_mode = (hc_stat (hash_or_file, &f) == 0) ? HL_MODE_FILE : HL_MODE_ARG; if (hashconfig->opts_type & OPTS_TYPE_BINARY_HASHFILE) { hashlist_mode = HL_MODE_ARG; char *hashfile = hash_or_file; hashes->hashfile = hashfile; } if (hashlist_mode == HL_MODE_ARG) { if (hashconfig->hash_mode == 2500) { hc_stat_t st; if (hc_stat (hashes->hashfile, &st) == -1) { event_log_error (hashcat_ctx, "%s: %m", hashes->hashfile); return -1; } hashes_avail = st.st_size / sizeof (hccap_t); } else { hashes_avail = 1; } } else if (hashlist_mode == HL_MODE_FILE) { char *hashfile = hash_or_file; hashes->hashfile = hashfile; FILE *fp = NULL; if ((fp = fopen (hashfile, "rb")) == NULL) { event_log_error (hashcat_ctx, "%s: %m", hashfile); return -1; } EVENT_DATA (EVENT_HASHLIST_COUNT_LINES_PRE, hashfile, strlen (hashfile)); hashes_avail = count_lines (fp); EVENT_DATA (EVENT_HASHLIST_COUNT_LINES_POST, hashfile, strlen (hashfile)); rewind (fp); if (hashes_avail == 0) { event_log_error (hashcat_ctx, "hashfile is empty or corrupt"); fclose (fp); return -1; } hashlist_format = hlfmt_detect (hashcat_ctx, fp, 100); // 100 = max numbers to "scan". could be hashes_avail, too if ((user_options->remove == 1) && (hashlist_format != HLFMT_HASHCAT)) { event_log_error (hashcat_ctx, "remove not supported in native hashfile-format mode"); fclose (fp); return -1; } fclose (fp); } } else { hashlist_mode = HL_MODE_ARG; hashes_avail = 1; } if (hashconfig->hash_mode == 3000) hashes_avail *= 2; hashes->hashlist_mode = hashlist_mode; hashes->hashlist_format = hashlist_format; /** * load hashes, part II: allocate required memory, set pointers */ hash_t *hashes_buf = NULL; void *digests_buf = NULL; salt_t *salts_buf = NULL; void *esalts_buf = NULL; hashes_buf = (hash_t *) hccalloc (hashes_avail, sizeof (hash_t)); digests_buf = (void *) hccalloc (hashes_avail, hashconfig->dgst_size); if ((user_options->username == true) || (hashconfig->opts_type & OPTS_TYPE_HASH_COPY)) { u32 hash_pos; for (hash_pos = 0; hash_pos < hashes_avail; hash_pos++) { hashinfo_t *hash_info = (hashinfo_t *) hcmalloc (sizeof (hashinfo_t)); hashes_buf[hash_pos].hash_info = hash_info; if (user_options->username == true) { hash_info->user = (user_t*) hcmalloc (sizeof (user_t)); } if (user_options->benchmark == true) { hash_info->orighash = (char *) hcmalloc (256); } } } if (hashconfig->is_salted) { salts_buf = (salt_t *) hccalloc (hashes_avail, sizeof (salt_t)); if (hashconfig->esalt_size) { esalts_buf = (void *) hccalloc (hashes_avail, hashconfig->esalt_size); } } else { salts_buf = (salt_t *) hccalloc (1, sizeof (salt_t)); } for (u32 hash_pos = 0; hash_pos < hashes_avail; hash_pos++) { hashes_buf[hash_pos].digest = ((char *) digests_buf) + (hash_pos * hashconfig->dgst_size); if (hashconfig->is_salted) { hashes_buf[hash_pos].salt = &salts_buf[hash_pos]; if (hashconfig->esalt_size) { hashes_buf[hash_pos].esalt = ((char *) esalts_buf) + (hash_pos * hashconfig->esalt_size); } } else { hashes_buf[hash_pos].salt = &salts_buf[0]; } } hashes->hashes_buf = hashes_buf; hashes->digests_buf = digests_buf; hashes->salts_buf = salts_buf; hashes->esalts_buf = esalts_buf; /** * load hashes, part III: parse hashes or generate them if benchmark */ u32 hashes_cnt = 0; if (user_options->benchmark == true) { hashconfig_benchmark_defaults (hashcat_ctx, hashes_buf[0].salt, hashes_buf[0].esalt); hashes->hashfile = "-"; hashes_cnt = 1; } else if (user_options->keyspace == true) { } else if (user_options->stdout_flag == true) { } else if (user_options->opencl_info == true) { } else { if (hashes_avail == 0) { // ??? } else if (hashlist_mode == HL_MODE_ARG) { char *input_buf = hash_or_file; u32 input_len = strlen (input_buf); char *hash_buf = NULL; int hash_len = 0; hlfmt_hash (hashcat_ctx, hashlist_format, input_buf, input_len, &hash_buf, &hash_len); bool hash_fmt_error = 0; if (hash_len < 1) hash_fmt_error = 1; if (hash_buf == NULL) hash_fmt_error = 1; if (hash_fmt_error) { event_log_warning (hashcat_ctx, "Failed to parse hashes using the '%s' format", strhlfmt (hashlist_format)); } else { if (hashconfig->opts_type & OPTS_TYPE_HASH_COPY) { hashinfo_t *hash_info_tmp = hashes_buf[hashes_cnt].hash_info; hash_info_tmp->orighash = hcstrdup (hash_buf); } if (hashconfig->is_salted) { memset (hashes_buf[0].salt, 0, sizeof (salt_t)); } int parser_status = PARSER_OK; if (hashconfig->hash_mode == 2500) { if (hash_len == 0) { event_log_error (hashcat_ctx, "hccap file not specified"); return -1; } hashlist_mode = HL_MODE_FILE; hashes->hashlist_mode = hashlist_mode; FILE *fp = fopen (hash_buf, "rb"); if (fp == NULL) { event_log_error (hashcat_ctx, "%s: %m", hash_buf); return -1; } if (hashes_avail < 1) { event_log_error (hashcat_ctx, "hccap file is empty or corrupt"); fclose (fp); return -1; } char *in = (char *) hcmalloc (sizeof (hccap_t)); while (!feof (fp)) { const int nread = fread (in, sizeof (hccap_t), 1, fp); if (nread == 0) break; if (hashes_avail == hashes_cnt) { event_log_warning (hashcat_ctx, "Hashfile '%s': File changed during runtime, skipping new data", hash_buf); break; } parser_status = hashconfig->parse_func ((u8 *) in, sizeof (hccap_t), &hashes_buf[hashes_cnt], hashconfig); if (parser_status != PARSER_OK) { event_log_warning (hashcat_ctx, "Hashfile '%s': %s", hash_buf, strparser (parser_status)); continue; } hashes_cnt++; } hcfree (in); fclose (fp); } else if (hashconfig->hash_mode == 3000) { if (hash_len == 32) { parser_status = hashconfig->parse_func ((u8 *) hash_buf, 16, &hashes_buf[hashes_cnt], hashconfig); if (parser_status == PARSER_OK) { hashes_cnt++; } else { event_log_warning (hashcat_ctx, "Hash '%s': %s", input_buf, strparser (parser_status)); } parser_status = hashconfig->parse_func ((u8 *) hash_buf + 16, 16, &hashes_buf[hashes_cnt], hashconfig); if (parser_status == PARSER_OK) { hashes_cnt++; } else { event_log_warning (hashcat_ctx, "Hash '%s': %s", input_buf, strparser (parser_status)); } } else { parser_status = hashconfig->parse_func ((u8 *) hash_buf, hash_len, &hashes_buf[hashes_cnt], hashconfig); if (parser_status == PARSER_OK) { hashes_cnt++; } else { event_log_warning (hashcat_ctx, "Hash '%s': %s", input_buf, strparser (parser_status)); } } } else { parser_status = hashconfig->parse_func ((u8 *) hash_buf, hash_len, &hashes_buf[hashes_cnt], hashconfig); if (parser_status == PARSER_OK) { hashes_cnt++; } else { event_log_warning (hashcat_ctx, "Hash '%s': %s", input_buf, strparser (parser_status)); } } } } else if (hashlist_mode == HL_MODE_FILE) { char *hashfile = hashes->hashfile; FILE *fp; if ((fp = fopen (hashfile, "rb")) == NULL) { event_log_error (hashcat_ctx, "%s: %m", hashfile); return -1; } u32 line_num = 0; char *line_buf = (char *) hcmalloc (HCBUFSIZ_LARGE); time_t prev = 0; time_t now = 0; while (!feof (fp)) { line_num++; int line_len = fgetl (fp, line_buf); if (line_len == 0) continue; if (hashes_avail == hashes_cnt) { event_log_warning (hashcat_ctx, "Hashfile '%s' on line %u: File changed during runtime, skipping new data", hashes->hashfile, line_num); break; } char *hash_buf = NULL; int hash_len = 0; hlfmt_hash (hashcat_ctx, hashlist_format, line_buf, line_len, &hash_buf, &hash_len); bool hash_fmt_error = 0; if (hash_len < 1) hash_fmt_error = 1; if (hash_buf == NULL) hash_fmt_error = 1; if (hash_fmt_error) { event_log_warning (hashcat_ctx, "failed to parse hashes using the '%s' format", strhlfmt (hashlist_format)); continue; } if (user_options->username == true) { char *user_buf = NULL; int user_len = 0; hlfmt_user (hashcat_ctx, hashlist_format, line_buf, line_len, &user_buf, &user_len); user_t **user = &hashes_buf[hashes_cnt].hash_info->user; *user = (user_t *) hcmalloc (sizeof (user_t)); user_t *user_ptr = *user; if (user_buf != NULL) { user_ptr->user_name = hcstrdup (user_buf); } else { user_ptr->user_name = hcstrdup (""); } user_ptr->user_len = user_len; } if (hashconfig->opts_type & OPTS_TYPE_HASH_COPY) { hashinfo_t *hash_info_tmp = hashes_buf[hashes_cnt].hash_info; hash_info_tmp->orighash = hcstrdup (hash_buf); } if (hashconfig->is_salted) { memset (hashes_buf[hashes_cnt].salt, 0, sizeof (salt_t)); } if (hashconfig->hash_mode == 3000) { if (hash_len == 32) { int parser_status = hashconfig->parse_func ((u8 *) hash_buf, 16, &hashes_buf[hashes_cnt], hashconfig); if (parser_status < PARSER_GLOBAL_ZERO) { event_log_warning (hashcat_ctx, "Hashfile '%s' on line %u (%s): %s", hashes->hashfile, line_num, line_buf, strparser (parser_status)); continue; } hashes_cnt++; parser_status = hashconfig->parse_func ((u8 *) hash_buf + 16, 16, &hashes_buf[hashes_cnt], hashconfig); if (parser_status < PARSER_GLOBAL_ZERO) { event_log_warning (hashcat_ctx, "Hashfile '%s' on line %u (%s): %s", hashes->hashfile, line_num, line_buf, strparser (parser_status)); continue; } hashes_cnt++; } else { int parser_status = hashconfig->parse_func ((u8 *) hash_buf, hash_len, &hashes_buf[hashes_cnt], hashconfig); if (parser_status < PARSER_GLOBAL_ZERO) { event_log_warning (hashcat_ctx, "Hashfile '%s' on line %u (%s): %s", hashes->hashfile, line_num, line_buf, strparser (parser_status)); continue; } hashes_cnt++; } } else { int parser_status = hashconfig->parse_func ((u8 *) hash_buf, hash_len, &hashes_buf[hashes_cnt], hashconfig); if (parser_status < PARSER_GLOBAL_ZERO) { event_log_warning (hashcat_ctx, "Hashfile '%s' on line %u (%s): %s", hashes->hashfile, line_num, line_buf, strparser (parser_status)); continue; } hashes_cnt++; } time (&now); if ((now - prev) == 0) continue; time (&prev); hashlist_parse_t hashlist_parse; hashlist_parse.hashes_cnt = hashes_cnt; hashlist_parse.hashes_avail = hashes_avail; EVENT_DATA (EVENT_HASHLIST_PARSE_HASH, &hashlist_parse, sizeof (hashlist_parse_t)); } hashlist_parse_t hashlist_parse; hashlist_parse.hashes_cnt = hashes_cnt; hashlist_parse.hashes_avail = hashes_avail; EVENT_DATA (EVENT_HASHLIST_PARSE_HASH, &hashlist_parse, sizeof (hashlist_parse_t)); hcfree (line_buf); fclose (fp); } } hashes->hashes_cnt = hashes_cnt; if (hashes_cnt) { EVENT (EVENT_HASHLIST_SORT_HASH_PRE); if (hashconfig->is_salted) { hc_qsort_r (hashes_buf, hashes_cnt, sizeof (hash_t), sort_by_hash, (void *) hashconfig); } else { hc_qsort_r (hashes_buf, hashes_cnt, sizeof (hash_t), sort_by_hash_no_salt, (void *) hashconfig); } EVENT (EVENT_HASHLIST_SORT_HASH_POST); } return 0; }
static int outfile_remove (hashcat_ctx_t *hashcat_ctx) { // some hash-dependent constants hashconfig_t *hashconfig = hashcat_ctx->hashconfig; hashes_t *hashes = hashcat_ctx->hashes; outcheck_ctx_t *outcheck_ctx = hashcat_ctx->outcheck_ctx; status_ctx_t *status_ctx = hashcat_ctx->status_ctx; user_options_t *user_options = hashcat_ctx->user_options; u32 dgst_size = hashconfig->dgst_size; u32 is_salted = hashconfig->is_salted; u32 esalt_size = hashconfig->esalt_size; u32 hash_mode = hashconfig->hash_mode; char separator = hashconfig->separator; char *root_directory = outcheck_ctx->root_directory; u32 outfile_check_timer = user_options->outfile_check_timer; // buffers hash_t hash_buf = { 0, 0, 0, 0, 0, NULL, 0 }; hash_buf.digest = hcmalloc (dgst_size); if (is_salted) hash_buf.salt = (salt_t *) hcmalloc (sizeof (salt_t)); if (esalt_size) hash_buf.esalt = (void *) hcmalloc (esalt_size); u32 digest_buf[64] = { 0 }; outfile_data_t *out_info = NULL; char **out_files = NULL; time_t folder_mtime = 0; int out_cnt = 0; u32 check_left = outfile_check_timer; // or 1 if we want to check it at startup while (status_ctx->shutdown_inner == false) { hc_sleep (1); if (status_ctx->devices_status != STATUS_RUNNING) continue; check_left--; if (check_left == 0) { hc_stat_t outfile_check_stat; if (hc_stat (root_directory, &outfile_check_stat) == 0) { u32 is_dir = S_ISDIR (outfile_check_stat.st_mode); if (is_dir == 1) { if (outfile_check_stat.st_mtime > folder_mtime) { char **out_files_new = scan_directory (root_directory); int out_cnt_new = count_dictionaries (out_files_new); outfile_data_t *out_info_new = NULL; if (out_cnt_new > 0) { out_info_new = (outfile_data_t *) hccalloc (out_cnt_new, sizeof (outfile_data_t)); for (int i = 0; i < out_cnt_new; i++) { out_info_new[i].file_name = out_files_new[i]; // check if there are files that we have seen/checked before (and not changed) for (int j = 0; j < out_cnt; j++) { if (strcmp (out_info[j].file_name, out_info_new[i].file_name) == 0) { hc_stat_t outfile_stat; if (hc_stat (out_info_new[i].file_name, &outfile_stat) == 0) { if (outfile_stat.st_ctime == out_info[j].ctime) { out_info_new[i].ctime = out_info[j].ctime; out_info_new[i].seek = out_info[j].seek; } } } } } } hcfree (out_info); hcfree (out_files); out_files = out_files_new; out_cnt = out_cnt_new; out_info = out_info_new; folder_mtime = outfile_check_stat.st_mtime; } for (int j = 0; j < out_cnt; j++) { FILE *fp = fopen (out_info[j].file_name, "rb"); if (fp != NULL) { //hc_thread_mutex_lock (status_ctx->mux_display); hc_stat_t outfile_stat; hc_fstat (fileno (fp), &outfile_stat); if (outfile_stat.st_ctime > out_info[j].ctime) { out_info[j].ctime = outfile_stat.st_ctime; out_info[j].seek = 0; } fseeko (fp, out_info[j].seek, SEEK_SET); char *line_buf = (char *) hcmalloc (HCBUFSIZ_LARGE); while (!feof (fp)) { char *ptr = fgets (line_buf, HCBUFSIZ_LARGE - 1, fp); if (ptr == NULL) break; size_t line_len = strlen (line_buf); if (line_len == 0) continue; size_t iter = MAX_CUT_TRIES; for (size_t i = line_len - 1; i && iter; i--, line_len--) { if (line_buf[i] != separator) continue; iter--; int parser_status = PARSER_OK; if ((hash_mode != 2500) && (hash_mode != 6800)) { parser_status = hashconfig->parse_func ((u8 *) line_buf, line_len - 1, &hash_buf, hashconfig); } u32 found = 0; if (parser_status == PARSER_OK) { for (u32 salt_pos = 0; (found == 0) && (salt_pos < hashes->salts_cnt); salt_pos++) { if (hashes->salts_shown[salt_pos] == 1) continue; salt_t *salt_buf = &hashes->salts_buf[salt_pos]; for (u32 digest_pos = 0; (found == 0) && (digest_pos < salt_buf->digests_cnt); digest_pos++) { u32 idx = salt_buf->digests_offset + digest_pos; if (hashes->digests_shown[idx] == 1) continue; u32 cracked = 0; if (hash_mode == 6800) { if (i == salt_buf->salt_len) { cracked = (memcmp (line_buf, salt_buf->salt_buf, salt_buf->salt_len) == 0); } } else if (hash_mode == 2500) { // BSSID : MAC1 : MAC2 (:plain) if (i == (salt_buf->salt_len + 1 + 12 + 1 + 12)) { cracked = (memcmp (line_buf, salt_buf->salt_buf, salt_buf->salt_len) == 0); if (!cracked) continue; // now compare MAC1 and MAC2 too, since we have this additional info char *mac1_pos = line_buf + salt_buf->salt_len + 1; char *mac2_pos = mac1_pos + 12 + 1; wpa_t *wpas = (wpa_t *) hashes->esalts_buf; wpa_t *wpa = &wpas[salt_pos]; // compare hex string(s) vs binary MAC address(es) for (u32 mac_idx = 0, orig_mac_idx = 0; mac_idx < 6; mac_idx++, orig_mac_idx += 2) { if (wpa->orig_mac1[mac_idx] != hex_to_u8 ((const u8 *) &mac1_pos[orig_mac_idx])) { cracked = 0; break; } } // early skip ;) if (!cracked) continue; for (u32 mac_idx = 0, orig_mac_idx = 0; mac_idx < 6; mac_idx++, orig_mac_idx += 2) { if (wpa->orig_mac2[mac_idx] != hex_to_u8 ((const u8 *) &mac2_pos[orig_mac_idx])) { cracked = 0; break; } } } } else { char *digests_buf_ptr = (char *) hashes->digests_buf; memcpy (digest_buf, digests_buf_ptr + (hashes->salts_buf[salt_pos].digests_offset * dgst_size) + (digest_pos * dgst_size), dgst_size); cracked = (sort_by_digest_p0p1 (digest_buf, hash_buf.digest, hashconfig) == 0); } if (cracked == 1) { found = 1; hashes->digests_shown[idx] = 1; hashes->digests_done++; salt_buf->digests_done++; if (salt_buf->digests_done == salt_buf->digests_cnt) { hashes->salts_shown[salt_pos] = 1; hashes->salts_done++; if (hashes->salts_done == hashes->salts_cnt) mycracked (hashcat_ctx); } } } if (status_ctx->devices_status == STATUS_CRACKED) break; } } if (found) break; if (status_ctx->devices_status == STATUS_CRACKED) break; } if (status_ctx->devices_status == STATUS_CRACKED) break; } hcfree (line_buf); out_info[j].seek = ftello (fp); //hc_thread_mutex_unlock (status_ctx->mux_display); fclose (fp); } } } } check_left = outfile_check_timer; } } hcfree (hash_buf.esalt); hcfree (hash_buf.salt); hcfree (hash_buf.digest); hcfree (out_info); hcfree (out_files); return 0; }
int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) { mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx; user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; user_options_t *user_options = hashcat_ctx->user_options; mask_ctx->enabled = false; if (user_options->left == true) return 0; if (user_options->opencl_info == true) return 0; if (user_options->show == true) return 0; if (user_options->usage == true) return 0; if (user_options->version == true) return 0; if (user_options->attack_mode == ATTACK_MODE_STRAIGHT) return 0; if (user_options->attack_mode == ATTACK_MODE_COMBI) return 0; mask_ctx->enabled = true; mask_ctx->root_table_buf = (hcstat_table_t *) hccalloc (SP_ROOT_CNT, sizeof (hcstat_table_t)); mask_ctx->markov_table_buf = (hcstat_table_t *) hccalloc (SP_MARKOV_CNT, sizeof (hcstat_table_t)); sp_setup_tbl (hashcat_ctx); mask_ctx->root_css_buf = (cs_t *) hccalloc (SP_PW_MAX, sizeof (cs_t)); mask_ctx->markov_css_buf = (cs_t *) hccalloc (SP_PW_MAX * CHARSIZ, sizeof (cs_t)); mask_ctx->css_cnt = 0; mask_ctx->css_buf = NULL; mask_ctx->mask_from_file = false; mask_ctx->masks = NULL; mask_ctx->masks_pos = 0; mask_ctx->masks_cnt = 0; mask_ctx->mfs = (mf_t *) hccalloc (MAX_MFS, sizeof (mf_t)); mp_setup_sys (mask_ctx->mp_sys); if (user_options->custom_charset_1) { const int rc = mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_1, 0); if (rc == -1) return -1; } if (user_options->custom_charset_2) { const int rc = mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_2, 1); if (rc == -1) return -1; } if (user_options->custom_charset_3) { const int rc = mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_3, 2); if (rc == -1) return -1; } if (user_options->custom_charset_4) { const int rc = mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_4, 3); if (rc == -1) return -1; } if (user_options->attack_mode == ATTACK_MODE_BF) { if (user_options->benchmark == false) { if (user_options_extra->hc_workc) { char *arg = user_options_extra->hc_workv[0]; hc_stat_t file_stat; if (hc_stat (arg, &file_stat) == -1) { const int rc = mask_append (hashcat_ctx, arg, NULL); if (rc == -1) return -1; } else { mask_ctx->mask_from_file = true; for (int i = 0; i < user_options_extra->hc_workc; i++) { arg = user_options_extra->hc_workv[i]; if (hc_stat (arg, &file_stat) == -1) { event_log_error (hashcat_ctx, "%s: %m", arg); return -1; } if (S_ISREG (file_stat.st_mode)) { FILE *mask_fp = fopen (arg, "r"); if (mask_fp == NULL) { event_log_error (hashcat_ctx, "%s: %m", arg); return -1; } char *line_buf = (char *) hcmalloc (HCBUFSIZ_LARGE); while (!feof (mask_fp)) { const int line_len = fgetl (mask_fp, line_buf); if (line_len == 0) continue; if (line_buf[0] == '#') continue; char *mask_buf = mask_ctx_parse_maskfile_find_mask (line_buf, line_len); char *prepend_buf = NULL; if (line_buf != mask_buf) { // if we have custom charsets prepend_buf = line_buf; mask_buf[-1] = 0; } const int rc = mask_append (hashcat_ctx, mask_buf, prepend_buf); if (rc == -1) { fclose (mask_fp); return -1; } } hcfree (line_buf); fclose (mask_fp); } else { event_log_error (hashcat_ctx, "%s: unsupported file-type", arg); return -1; } } } } else { const char *mask = DEF_MASK; const int rc = mask_append (hashcat_ctx, mask, NULL); if (rc == -1) return -1; } } else { const char *mask = hashconfig_benchmark_mask (hashcat_ctx); const int rc = mask_append (hashcat_ctx, mask, NULL); if (rc == -1) return -1; } } else if (user_options->attack_mode == ATTACK_MODE_HYBRID1) { // display char *arg = user_options_extra->hc_workv[user_options_extra->hc_workc - 1]; // mod hc_stat_t file_stat; if (hc_stat (arg, &file_stat) == -1) { const int rc = mask_append (hashcat_ctx, arg, NULL); if (rc == -1) return -1; } else { if (S_ISREG (file_stat.st_mode)) { mask_ctx->mask_from_file = true; FILE *mask_fp = fopen (arg, "r"); if (mask_fp == NULL) { event_log_error (hashcat_ctx, "%s: %m", arg); return -1; } char *line_buf = (char *) hcmalloc (HCBUFSIZ_LARGE); while (!feof (mask_fp)) { const int line_len = fgetl (mask_fp, line_buf); if (line_len == 0) continue; if (line_buf[0] == '#') continue; char *mask_buf = mask_ctx_parse_maskfile_find_mask (line_buf, line_len); char *prepend_buf = NULL; if (line_buf != mask_buf) { // if we have custom charsets prepend_buf = line_buf; mask_buf[-1] = 0; } const int rc = mask_append (hashcat_ctx, mask_buf, prepend_buf); if (rc == -1) { fclose (mask_fp); return -1; } } hcfree (line_buf); fclose (mask_fp); } else { event_log_error (hashcat_ctx, "%s: unsupported file-type", arg); return -1; } } } else if (user_options->attack_mode == ATTACK_MODE_HYBRID2) { // display char *arg = user_options_extra->hc_workv[0]; // mod hc_stat_t file_stat; if (hc_stat (arg, &file_stat) == -1) { const int rc = mask_append (hashcat_ctx, arg, NULL); if (rc == -1) return -1; } else { if (S_ISREG (file_stat.st_mode)) { mask_ctx->mask_from_file = true; FILE *mask_fp = fopen (arg, "r"); if (mask_fp == NULL) { event_log_error (hashcat_ctx, "%s: %m", arg); return -1; } char *line_buf = (char *) hcmalloc (HCBUFSIZ_LARGE); while (!feof (mask_fp)) { const int line_len = fgetl (mask_fp, line_buf); if (line_len == 0) continue; if (line_buf[0] == '#') continue; char *mask_buf = mask_ctx_parse_maskfile_find_mask (line_buf, line_len); char *prepend_buf = NULL; if (line_buf != mask_buf) { // if we have custom charsets prepend_buf = line_buf; mask_buf[-1] = 0; } const int rc = mask_append (hashcat_ctx, mask_buf, prepend_buf); if (rc == -1) { fclose (mask_fp); return -1; } } hcfree (line_buf); fclose (mask_fp); } else { event_log_error (hashcat_ctx, "%s: unsupported file-type", arg); return -1; } } } if (mask_ctx->masks_cnt == 0) { event_log_error (hashcat_ctx, "Invalid mask"); return -1; } mask_ctx->mask = mask_ctx->masks[0]; return 0; }