1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-11-22 16:18:09 +00:00

Get rid of some old hack and cleanly distinguish between HL_MODE_FILE_PLAIN and HL_MODE_FILE_BINARY

This commit is contained in:
jsteube 2019-02-25 11:20:22 +01:00
parent 44cd17e7f1
commit 166f908241
5 changed files with 128 additions and 99 deletions

View File

@ -18,13 +18,11 @@ void check_hash (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, pl
int check_cracked (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, const u32 salt_pos);
void hashes_init_filename (hashcat_ctx_t *hashcat_ctx);
int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx);
int hashes_init_stage2 (hashcat_ctx_t *hashcat_ctx);
int hashes_init_stage3 (hashcat_ctx_t *hashcat_ctx);
int hashes_init_stage4 (hashcat_ctx_t *hashcat_ctx);
int hashes_init_filename (hashcat_ctx_t *hashcat_ctx);
int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx);
int hashes_init_stage2 (hashcat_ctx_t *hashcat_ctx);
int hashes_init_stage3 (hashcat_ctx_t *hashcat_ctx);
int hashes_init_stage4 (hashcat_ctx_t *hashcat_ctx);
int hashes_init_selftest (hashcat_ctx_t *hashcat_ctx);
int hashes_init_benchmark (hashcat_ctx_t *hashcat_ctx);

View File

@ -205,8 +205,9 @@ typedef enum wl_mode
typedef enum hl_mode
{
HL_MODE_FILE = 4,
HL_MODE_ARG = 5
HL_MODE_ARG = 2,
HL_MODE_FILE_PLAIN = 5,
HL_MODE_FILE_BINARY = 6,
} hl_mode_t;
@ -860,7 +861,6 @@ typedef struct logfile_ctx
typedef struct hashes
{
const char *hashfile;
char *hashfile_hcdmp;
u32 hashlist_mode;
u32 hashlist_format;

View File

@ -473,7 +473,9 @@ static int outer_loop (hashcat_ctx_t *hashcat_ctx)
* generate hashlist filename for later use
*/
hashes_init_filename (hashcat_ctx);
const int rc_hashes_init_filename = hashes_init_filename (hashcat_ctx);
if (rc_hashes_init_filename == -1) return -1;
/**
* load hashes, stage 1
@ -574,7 +576,7 @@ static int outer_loop (hashcat_ctx_t *hashcat_ctx)
if (status_ctx->devices_status == STATUS_CRACKED)
{
if ((user_options->remove == true) && (hashes->hashlist_mode == HL_MODE_FILE))
if ((user_options->remove == true) && ((hashes->hashlist_mode == HL_MODE_FILE_PLAIN) || (hashes->hashlist_mode == HL_MODE_FILE_BINARY)))
{
if (hashes->digests_saved != hashes->digests_done)
{

View File

@ -483,45 +483,44 @@ int check_cracked (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param,
return 0;
}
void hashes_init_filename (hashcat_ctx_t *hashcat_ctx)
int hashes_init_filename (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
*/
if ((user_options->benchmark == false) && (user_options->stdout_flag == false) && (user_options->keyspace == false))
if (hashconfig->opts_type & OPTS_TYPE_BINARY_HASHFILE)
{
if (hashconfig->opts_type & OPTS_TYPE_BINARY_HASHFILE)
hashes->hashlist_mode = HL_MODE_FILE_BINARY;
if ((user_options->benchmark == false) && (user_options->keyspace == false))
{
hashes->hashlist_mode = HL_MODE_ARG;
hashes->hashfile = hash_or_file;
hc_asprintf (&hashes->hashfile_hcdmp, "%s.hcdmp", hashes->hashfile);
}
else
{
hashes->hashlist_mode = (hc_path_exist (hash_or_file) == true) ? HL_MODE_FILE : HL_MODE_ARG;
if (hashes->hashlist_mode == HL_MODE_FILE)
if (hc_path_read (user_options_extra->hc_hash) == false)
{
hashes->hashfile = hash_or_file;
event_log_error (hashcat_ctx, "%s: %s", user_options_extra->hc_hash, strerror (errno));
hc_asprintf (&hashes->hashfile_hcdmp, "%s.hcdmp", hashes->hashfile);
return -1;
}
hashes->hashfile = user_options_extra->hc_hash;
}
}
else
{
hashes->hashlist_mode = HL_MODE_ARG;
hashes->hashlist_mode = (hc_path_exist (user_options_extra->hc_hash) == true) ? HL_MODE_FILE_PLAIN : HL_MODE_ARG;
if (hashes->hashlist_mode == HL_MODE_FILE_PLAIN)
{
hashes->hashfile = user_options_extra->hc_hash;
}
}
return 0;
}
int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx)
@ -547,43 +546,9 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx)
{
if (hashlist_mode == HL_MODE_ARG)
{
// binary files are listed here as a result of a hack
if (hashconfig->opts_type & OPTS_TYPE_BINARY_HASHFILE)
{
struct stat st;
if (stat (hashes->hashfile, &st) == -1)
{
event_log_error (hashcat_ctx, "%s: %s", hashes->hashfile, strerror (errno));
return -1;
}
if (module_ctx->module_hash_binary_count != MODULE_DEFAULT)
{
const int binary_count = module_ctx->module_hash_binary_count (hashes);
if (binary_count == -1)
{
event_log_error (hashcat_ctx, "%s: %s", hashes->hashfile, strerror (errno));
return -1;
}
hashes_avail = binary_count;
}
else
{
hashes_avail = 1;
}
}
else
{
hashes_avail = 1;
}
hashes_avail = 1;
}
else if (hashlist_mode == HL_MODE_FILE)
else if (hashlist_mode == HL_MODE_FILE_PLAIN)
{
FILE *fp = NULL;
@ -624,6 +589,35 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx)
fclose (fp);
}
else if (hashlist_mode == HL_MODE_FILE_BINARY)
{
struct stat st;
if (stat (hashes->hashfile, &st) == -1)
{
event_log_error (hashcat_ctx, "%s: %s", hashes->hashfile, strerror (errno));
return -1;
}
if (module_ctx->module_hash_binary_count != MODULE_DEFAULT)
{
const int binary_count = module_ctx->module_hash_binary_count (hashes);
if (binary_count == -1)
{
event_log_error (hashcat_ctx, "%s: %s", hashes->hashfile, strerror (errno));
return -1;
}
hashes_avail = binary_count;
}
else
{
hashes_avail = 1;
}
}
}
else
{
@ -749,11 +743,7 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx)
}
else
{
if (hashes_avail == 0)
{
// ???
}
else if (hashlist_mode == HL_MODE_ARG)
if (hashlist_mode == HL_MODE_ARG)
{
char *input_buf = user_options_extra->hc_hash;
@ -858,38 +848,22 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx)
}
else
{
if (module_ctx->module_hash_binary_parse != MODULE_DEFAULT)
{
const int hashes_parsed = module_ctx->module_hash_binary_parse (hashconfig, user_options, user_options_extra, hashes);
hash_t *hash = &hashes_buf[hashes_cnt];
if (hashes_parsed > 0)
{
hashes_cnt = hashes_parsed;
}
else
{
event_log_warning (hashcat_ctx, "Hashfile '%s': %s", hashes->hashfile, strerror (errno));
}
parser_status = module_ctx->module_hash_decode (hashconfig, hash->digest, hash->salt, hash->esalt, hash->hook_salt, hash->hash_info, hash_buf, hash_len);
if (parser_status == PARSER_OK)
{
hashes_cnt++;
}
else
{
hash_t *hash = &hashes_buf[hashes_cnt];
parser_status = module_ctx->module_hash_decode (hashconfig, hash->digest, hash->salt, hash->esalt, hash->hook_salt, hash->hash_info, hash_buf, hash_len);
if (parser_status == PARSER_OK)
{
hashes_cnt++;
}
else
{
event_log_warning (hashcat_ctx, "Hash '%s': %s", input_buf, strparser (parser_status));
}
event_log_warning (hashcat_ctx, "Hash '%s': %s", input_buf, strparser (parser_status));
}
}
}
}
else if (hashlist_mode == HL_MODE_FILE)
else if (hashlist_mode == HL_MODE_FILE_PLAIN)
{
FILE *fp;
@ -1134,6 +1108,63 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx)
fclose (fp);
}
else if (hashlist_mode == HL_MODE_FILE_BINARY)
{
char *input_buf = user_options_extra->hc_hash;
size_t input_len = strlen (input_buf);
if (hashconfig->opts_type & OPTS_TYPE_HASH_COPY)
{
hashinfo_t *hash_info_tmp = hashes_buf[hashes_cnt].hash_info;
hash_info_tmp->orighash = hcstrdup (input_buf);
}
if (hashconfig->is_salted == true)
{
memset (hashes_buf[0].salt, 0, sizeof (salt_t));
}
if (hashconfig->esalt_size > 0)
{
memset (hashes_buf[0].esalt, 0, hashconfig->esalt_size);
}
if (hashconfig->hook_salt_size > 0)
{
memset (hashes_buf[0].hook_salt, 0, hashconfig->hook_salt_size);
}
if (module_ctx->module_hash_binary_parse != MODULE_DEFAULT)
{
const int hashes_parsed = module_ctx->module_hash_binary_parse (hashconfig, user_options, user_options_extra, hashes);
if (hashes_parsed > 0)
{
hashes_cnt = hashes_parsed;
}
else
{
event_log_warning (hashcat_ctx, "Hashfile '%s': %s", hashes->hashfile, strerror (errno));
}
}
else
{
hash_t *hash = &hashes_buf[hashes_cnt];
int parser_status = module_ctx->module_hash_decode (hashconfig, hash->digest, hash->salt, hash->esalt, hash->hook_salt, hash->hash_info, input_buf, input_len);
if (parser_status == PARSER_OK)
{
hashes_cnt++;
}
else
{
event_log_warning (hashcat_ctx, "Hash '%s': %s", input_buf, strparser (parser_status));
}
}
}
}
hashes->hashes_cnt = hashes_cnt;
@ -1802,8 +1833,6 @@ void hashes_destroy (hashcat_ctx_t *hashcat_ctx)
hcfree (hashes->st_esalts_buf);
hcfree (hashes->st_hook_salts_buf);
hcfree (hashes->hashfile_hcdmp);
memset (hashes, 0, sizeof (hashes_t));
}

View File

@ -72,7 +72,7 @@ static int monitor (hashcat_ctx_t *hashcat_ctx)
restore_check = true;
}
if ((user_options->remove == true) && (hashes->hashlist_mode == HL_MODE_FILE))
if ((user_options->remove == true) && ((hashes->hashlist_mode == HL_MODE_FILE_PLAIN) || (hashes->hashlist_mode == HL_MODE_FILE_BINARY)))
{
remove_check = true;
}