int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra, hashes_t *hashes) { // note: if module_hash_binary_parse exists, then module_hash_decode is not called FILE *fp = fopen (hashes->hashfile, "rb"); if (fp == NULL) return (PARSER_HASH_FILE); #define TC_HEADER_SIZE 512 char *in = (char *) hcmalloc (TC_HEADER_SIZE); const size_t n = hc_fread (in, 1, TC_HEADER_SIZE, fp); fclose (fp); if (n != TC_HEADER_SIZE) return (PARSER_TC_FILE_SIZE); hash_t *hashes_buf = hashes->hashes_buf; hash_t *hash = &hashes_buf[0]; const int parser_status = module_hash_decode (hashconfig, hash->digest, hash->salt, hash->esalt, hash->hook_salt, hash->hash_info, in, TC_HEADER_SIZE); if (parser_status != PARSER_OK) return 0; hcfree (in); // keyfiles tc_t *tc = (tc_t *) hash->esalt; if (user_options->truecrypt_keyfiles) { char *keyfiles = hcstrdup (user_options->truecrypt_keyfiles); char *saveptr = NULL; char *keyfile = strtok_r (keyfiles, ",", &saveptr); while (keyfile) { if (hc_path_read (keyfile)) { cpu_crc32 (keyfile, (u8 *) tc->keyfile_buf); } keyfile = strtok_r ((char *) NULL, ",", &saveptr); } free (keyfiles); } // keyboard layout mapping if (user_options->keyboard_layout_mapping) { if (hc_path_read (user_options->keyboard_layout_mapping)) { initialize_keyboard_layout_mapping (user_options->keyboard_layout_mapping, tc->keyboard_layout_mapping_buf, &tc->keyboard_layout_mapping_cnt); } } return 1; }
int straight_ctx_init (hashcat_ctx_t *hashcat_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; straight_ctx->enabled = false; if (user_options->example_hashes == true) return 0; 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_BF) return 0; straight_ctx->enabled = true; /** * generate NOP rules */ if ((user_options->rp_files_cnt == 0) && (user_options->rp_gen == 0)) { straight_ctx->kernel_rules_buf = (kernel_rule_t *) hcmalloc (sizeof (kernel_rule_t)); straight_ctx->kernel_rules_buf[0].cmds[0] = RULE_OP_MANGLE_NOOP; straight_ctx->kernel_rules_cnt = 1; } else { if (user_options->rp_files_cnt) { const int rc_kernel_load = kernel_rules_load (hashcat_ctx, &straight_ctx->kernel_rules_buf, &straight_ctx->kernel_rules_cnt); if (rc_kernel_load == -1) return -1; } else if (user_options->rp_gen) { const int rc_kernel_generate = kernel_rules_generate (hashcat_ctx, &straight_ctx->kernel_rules_buf, &straight_ctx->kernel_rules_cnt); if (rc_kernel_generate == -1) return -1; } } /** * wordlist based work */ if (user_options->attack_mode == ATTACK_MODE_STRAIGHT) { if (user_options_extra->wordlist_mode == WL_MODE_FILE) { for (int i = 0; i < user_options_extra->hc_workc; i++) { char *l0_filename = user_options_extra->hc_workv[i]; // at this point we already verified the path actually exist and is readable if (hc_path_is_directory (l0_filename) == true) { char **dictionary_files; dictionary_files = scan_directory (l0_filename); if (dictionary_files != NULL) { qsort (dictionary_files, (size_t) count_dictionaries (dictionary_files), sizeof (char *), sort_by_stringptr); for (int d = 0; dictionary_files[d] != NULL; d++) { char *l1_filename = dictionary_files[d]; if (hc_path_read (l1_filename) == false) { event_log_error (hashcat_ctx, "%s: %s", l1_filename, strerror (errno)); hcfree (dictionary_files); return -1; } if (hc_path_is_file (l1_filename) == true) { const int rc = straight_ctx_add_wl (hashcat_ctx, l1_filename); if (rc == -1) { hcfree (dictionary_files); return -1; } } } } hcfree (dictionary_files); } else { const int rc = straight_ctx_add_wl (hashcat_ctx, l0_filename); if (rc == -1) return -1; } } if (straight_ctx->dicts_cnt == 0) { event_log_error (hashcat_ctx, "No usable dictionary file found."); return -1; } } } else if (user_options->attack_mode == ATTACK_MODE_COMBI) { } else if (user_options->attack_mode == ATTACK_MODE_BF) { } else if (user_options->attack_mode == ATTACK_MODE_HYBRID1) { for (int i = 0; i < user_options_extra->hc_workc - 1; i++) { char *l0_filename = user_options_extra->hc_workv[i]; // at this point we already verified the path actually exist and is readable if (hc_path_is_directory (l0_filename) == true) { char **dictionary_files; dictionary_files = scan_directory (l0_filename); if (dictionary_files != NULL) { qsort (dictionary_files, (size_t) count_dictionaries (dictionary_files), sizeof (char *), sort_by_stringptr); for (int d = 0; dictionary_files[d] != NULL; d++) { char *l1_filename = dictionary_files[d]; if (hc_path_read (l1_filename) == false) { event_log_error (hashcat_ctx, "%s: %s", l1_filename, strerror (errno)); hcfree (dictionary_files); return -1; } if (hc_path_is_file (l1_filename) == true) { const int rc = straight_ctx_add_wl (hashcat_ctx, l1_filename); if (rc == -1) { hcfree (dictionary_files); return -1; } } } } hcfree (dictionary_files); } else { const int rc = straight_ctx_add_wl (hashcat_ctx, l0_filename); if (rc == -1) return -1; } } if (straight_ctx->dicts_cnt == 0) { event_log_error (hashcat_ctx, "No usable dictionary file found."); return -1; } } else if (user_options->attack_mode == ATTACK_MODE_HYBRID2) { for (int i = 1; i < user_options_extra->hc_workc; i++) { char *l0_filename = user_options_extra->hc_workv[i]; // at this point we already verified the path actually exist and is readable if (hc_path_is_directory (l0_filename) == true) { char **dictionary_files; dictionary_files = scan_directory (l0_filename); if (dictionary_files != NULL) { qsort (dictionary_files, (size_t) count_dictionaries (dictionary_files), sizeof (char *), sort_by_stringptr); for (int d = 0; dictionary_files[d] != NULL; d++) { char *l1_filename = dictionary_files[d]; if (hc_path_read (l1_filename) == false) { event_log_error (hashcat_ctx, "%s: %s", l1_filename, strerror (errno)); hcfree (dictionary_files); return -1; } if (hc_path_is_file (l1_filename) == true) { const int rc = straight_ctx_add_wl (hashcat_ctx, l1_filename); if (rc == -1) { hcfree (dictionary_files); return -1; } } } } hcfree (dictionary_files); } else { const int rc = straight_ctx_add_wl (hashcat_ctx, l0_filename); if (rc == -1) return -1; } } if (straight_ctx->dicts_cnt == 0) { event_log_error (hashcat_ctx, "No usable dictionary file found."); return -1; } } return 0; }