1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-12-27 08:58:10 +00:00

fix HCFILE with potfile BUG and something else related to HCFILE wrong usage

This commit is contained in:
Gabriele Gristina 2019-07-02 18:27:36 +02:00
parent ea786f715f
commit 2db6dfcd4e
6 changed files with 46 additions and 87 deletions

View File

@ -27,8 +27,8 @@ typedef struct extra_info_combi
{ {
u64 pos; u64 pos;
HCFILE *base_fp; HCFILE base_fp;
HCFILE *combs_fp; HCFILE combs_fp;
u64 comb_pos_prev; u64 comb_pos_prev;
u64 comb_pos; u64 comb_pos;

View File

@ -1163,7 +1163,7 @@ typedef struct hc_device_param
char *scratch_buf; char *scratch_buf;
HCFILE *combs_fp; HCFILE combs_fp;
pw_t *combs_buf; pw_t *combs_buf;
void *hooks_buf; void *hooks_buf;
@ -1639,7 +1639,7 @@ typedef struct potfile_ctx
{ {
bool enabled; bool enabled;
FILE *fp; HCFILE fp;
char *filename; char *filename;
u8 *out_buf; // allocates [HCBUFSIZ_LARGE]; u8 *out_buf; // allocates [HCBUFSIZ_LARGE];

View File

@ -4377,7 +4377,7 @@ int run_cracker (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, co
device_param->kernel_params_buf32[31] = salt_buf->digests_cnt; device_param->kernel_params_buf32[31] = salt_buf->digests_cnt;
device_param->kernel_params_buf32[32] = salt_buf->digests_offset; device_param->kernel_params_buf32[32] = salt_buf->digests_offset;
HCFILE *combs_fp = device_param->combs_fp; HCFILE *combs_fp = &device_param->combs_fp;
if (user_options->slow_candidates == true) if (user_options->slow_candidates == true)
{ {

View File

@ -747,30 +747,26 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param)
combs_file = combinator_ctx->dict1; combs_file = combinator_ctx->dict1;
} }
HCFILE base_fp; extra_info_combi_t extra_info_combi;
if (hc_fopen (&base_fp, base_file, "rb") == false) memset (&extra_info_combi, 0, sizeof (extra_info_combi));
if (hc_fopen (&extra_info_combi.base_fp, base_file, "rb") == false)
{ {
event_log_error (hashcat_ctx, "%s: %s", base_file, strerror (errno)); event_log_error (hashcat_ctx, "%s: %s", base_file, strerror (errno));
return -1; return -1;
} }
HCFILE combs_fp; if (hc_fopen (&extra_info_combi.combs_fp, combs_file, "rb") == false)
if (hc_fopen (&combs_fp, combs_file, "rb") == false)
{ {
event_log_error (hashcat_ctx, "%s: %s", combs_file, strerror (errno)); event_log_error (hashcat_ctx, "%s: %s", combs_file, strerror (errno));
hc_fclose (&extra_info_combi.base_fp);
return -1; return -1;
} }
extra_info_combi_t extra_info_combi;
memset (&extra_info_combi, 0, sizeof (extra_info_combi));
extra_info_combi.base_fp = &base_fp;
extra_info_combi.combs_fp = &combs_fp;
extra_info_combi.scratch_buf = device_param->scratch_buf; extra_info_combi.scratch_buf = device_param->scratch_buf;
hashcat_ctx_t *hashcat_ctx_tmp = (hashcat_ctx_t *) hcmalloc (sizeof (hashcat_ctx_t)); hashcat_ctx_t *hashcat_ctx_tmp = (hashcat_ctx_t *) hcmalloc (sizeof (hashcat_ctx_t));
@ -783,12 +779,10 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param)
if (rc_wl_data_init == -1) if (rc_wl_data_init == -1)
{ {
hc_fclose (&combs_fp); hc_fclose (&extra_info_combi.base_fp);
hc_fclose (&extra_info_combi.combs_fp);
hc_fclose (&base_fp);
hcfree (hashcat_ctx_tmp->wl_data); hcfree (hashcat_ctx_tmp->wl_data);
hcfree (hashcat_ctx_tmp); hcfree (hashcat_ctx_tmp);
return -1; return -1;
@ -996,12 +990,10 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param)
if (CL_rc == -1) if (CL_rc == -1)
{ {
hc_fclose (&combs_fp); hc_fclose (&extra_info_combi.base_fp);
hc_fclose (&extra_info_combi.combs_fp);
hc_fclose (&base_fp);
hcfree (hashcat_ctx_tmp->wl_data); hcfree (hashcat_ctx_tmp->wl_data);
hcfree (hashcat_ctx_tmp); hcfree (hashcat_ctx_tmp);
return -1; return -1;
@ -1011,12 +1003,10 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param)
if (CL_rc == -1) if (CL_rc == -1)
{ {
hc_fclose (&combs_fp); hc_fclose (&extra_info_combi.base_fp);
hc_fclose (&extra_info_combi.combs_fp);
hc_fclose (&base_fp);
hcfree (hashcat_ctx_tmp->wl_data); hcfree (hashcat_ctx_tmp->wl_data);
hcfree (hashcat_ctx_tmp); hcfree (hashcat_ctx_tmp);
return -1; return -1;
@ -1058,14 +1048,12 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param)
if (words_fin == 0) break; if (words_fin == 0) break;
} }
hc_fclose (&combs_fp); hc_fclose (&extra_info_combi.base_fp);
hc_fclose (&extra_info_combi.combs_fp);
hc_fclose (&base_fp);
wl_data_destroy (hashcat_ctx_tmp); wl_data_destroy (hashcat_ctx_tmp);
hcfree (hashcat_ctx_tmp->wl_data); hcfree (hashcat_ctx_tmp->wl_data);
hcfree (hashcat_ctx_tmp); hcfree (hashcat_ctx_tmp);
} }
else if (attack_mode == ATTACK_MODE_BF) else if (attack_mode == ATTACK_MODE_BF)
@ -1322,16 +1310,12 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param)
{ {
char *dictfile = straight_ctx->dict; char *dictfile = straight_ctx->dict;
HCFILE combs_fp; if (hc_fopen (&device_param->combs_fp, dictfile, "rb") == false)
if (hc_fopen (&combs_fp, dictfile, "rb") == false)
{ {
event_log_error (hashcat_ctx, "%s: %s", dictfile, strerror (errno)); event_log_error (hashcat_ctx, "%s: %s", dictfile, strerror (errno));
return -1; return -1;
} }
device_param->combs_fp = &combs_fp;
} }
while (status_ctx->run_thread_level1 == true) while (status_ctx->run_thread_level1 == true)
@ -1388,31 +1372,23 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param)
{ {
const char *dictfilec = combinator_ctx->dict2; const char *dictfilec = combinator_ctx->dict2;
HCFILE combs_fp; if (hc_fopen (&device_param->combs_fp, dictfilec, "rb") == false)
if (hc_fopen (&combs_fp, dictfilec, "rb") == false)
{ {
event_log_error (hashcat_ctx, "%s: %s", combinator_ctx->dict2, strerror (errno)); event_log_error (hashcat_ctx, "%s: %s", combinator_ctx->dict2, strerror (errno));
return -1; return -1;
} }
device_param->combs_fp = &combs_fp;
} }
else if (combs_mode == COMBINATOR_MODE_BASE_RIGHT) else if (combs_mode == COMBINATOR_MODE_BASE_RIGHT)
{ {
const char *dictfilec = combinator_ctx->dict1; const char *dictfilec = combinator_ctx->dict1;
HCFILE combs_fp; if (hc_fopen (&device_param->combs_fp, dictfilec, "rb") == false)
if (hc_fopen (&combs_fp, dictfilec, "rb") == false)
{ {
event_log_error (hashcat_ctx, "%s: %s", dictfilec, strerror (errno)); event_log_error (hashcat_ctx, "%s: %s", dictfilec, strerror (errno));
return -1; return -1;
} }
device_param->combs_fp = &combs_fp;
} }
} }
@ -1435,7 +1411,7 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param)
if (rc_wl_data_init == -1) if (rc_wl_data_init == -1)
{ {
if (attack_mode == ATTACK_MODE_COMBI) hc_fclose (device_param->combs_fp); if (attack_mode == ATTACK_MODE_COMBI) hc_fclose (&device_param->combs_fp);
hc_fclose (&fp); hc_fclose (&fp);
@ -1567,7 +1543,7 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param)
if (CL_rc == -1) if (CL_rc == -1)
{ {
if (attack_mode == ATTACK_MODE_COMBI) hc_fclose (device_param->combs_fp); if (attack_mode == ATTACK_MODE_COMBI) hc_fclose (&device_param->combs_fp);
hc_fclose (&fp); hc_fclose (&fp);
@ -1582,7 +1558,7 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param)
if (CL_rc == -1) if (CL_rc == -1)
{ {
if (attack_mode == ATTACK_MODE_COMBI) hc_fclose (device_param->combs_fp); if (attack_mode == ATTACK_MODE_COMBI) hc_fclose (&device_param->combs_fp);
hc_fclose (&fp); hc_fclose (&fp);
@ -1638,7 +1614,7 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param)
if (words_fin == 0) break; if (words_fin == 0) break;
} }
if (attack_mode == ATTACK_MODE_COMBI) hc_fclose (device_param->combs_fp); if (attack_mode == ATTACK_MODE_COMBI) hc_fclose (&device_param->combs_fp);
hc_fclose (&fp); hc_fclose (&fp);

View File

@ -117,14 +117,14 @@ int potfile_init (hashcat_ctx_t *hashcat_ctx)
if (user_options->potfile_path == NULL) if (user_options->potfile_path == NULL)
{ {
potfile_ctx->fp = NULL; potfile_ctx->fp.pfp = NULL;
hc_asprintf (&potfile_ctx->filename, "%s/hashcat.potfile", folder_config->profile_dir); hc_asprintf (&potfile_ctx->filename, "%s/hashcat.potfile", folder_config->profile_dir);
} }
else else
{ {
potfile_ctx->filename = hcstrdup (user_options->potfile_path); potfile_ctx->filename = hcstrdup (user_options->potfile_path);
potfile_ctx->fp = NULL; potfile_ctx->fp.pfp = NULL;
} }
// starting from here, we should allocate some scratch buffer for later use // starting from here, we should allocate some scratch buffer for later use
@ -181,9 +181,7 @@ int potfile_read_open (hashcat_ctx_t *hashcat_ctx)
if (potfile_ctx->enabled == false) return 0; if (potfile_ctx->enabled == false) return 0;
potfile_ctx->fp = fopen (potfile_ctx->filename, "rb"); if (hc_fopen (&potfile_ctx->fp, potfile_ctx->filename, "rb") == false)
if (potfile_ctx->fp == NULL)
{ {
event_log_error (hashcat_ctx, "%s: %s", potfile_ctx->filename, strerror (errno)); event_log_error (hashcat_ctx, "%s: %s", potfile_ctx->filename, strerror (errno));
@ -202,9 +200,9 @@ void potfile_read_close (hashcat_ctx_t *hashcat_ctx)
if (hashconfig->potfile_disable == true) return; if (hashconfig->potfile_disable == true) return;
if (potfile_ctx->fp == NULL) return; if (potfile_ctx->fp.pfp == NULL) return;
fclose (potfile_ctx->fp); hc_fclose (&potfile_ctx->fp);
} }
int potfile_write_open (hashcat_ctx_t *hashcat_ctx) int potfile_write_open (hashcat_ctx_t *hashcat_ctx)
@ -213,17 +211,13 @@ int potfile_write_open (hashcat_ctx_t *hashcat_ctx)
if (potfile_ctx->enabled == false) return 0; if (potfile_ctx->enabled == false) return 0;
FILE *fp = fopen (potfile_ctx->filename, "ab"); if (hc_fopen (&potfile_ctx->fp, potfile_ctx->filename, "ab") == false)
if (fp == NULL)
{ {
event_log_error (hashcat_ctx, "%s: %s", potfile_ctx->filename, strerror (errno)); event_log_error (hashcat_ctx, "%s: %s", potfile_ctx->filename, strerror (errno));
return -1; return -1;
} }
potfile_ctx->fp = fp;
return 0; return 0;
} }
@ -236,14 +230,14 @@ void potfile_write_close (hashcat_ctx_t *hashcat_ctx)
if (hashconfig->potfile_disable == true) return; if (hashconfig->potfile_disable == true) return;
fclose (potfile_ctx->fp); hc_fclose (&potfile_ctx->fp);
} }
void potfile_write_append (hashcat_ctx_t *hashcat_ctx, const char *out_buf, const int out_len, u8 *plain_ptr, unsigned int plain_len) void potfile_write_append (hashcat_ctx_t *hashcat_ctx, const char *out_buf, const int out_len, u8 *plain_ptr, unsigned int plain_len)
{ {
const hashconfig_t *hashconfig = hashcat_ctx->hashconfig; const hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
const potfile_ctx_t *potfile_ctx = hashcat_ctx->potfile_ctx;
const user_options_t *user_options = hashcat_ctx->user_options; const user_options_t *user_options = hashcat_ctx->user_options;
potfile_ctx_t *potfile_ctx = hashcat_ctx->potfile_ctx;
if (potfile_ctx->enabled == false) return; if (potfile_ctx->enabled == false) return;
@ -292,18 +286,13 @@ void potfile_write_append (hashcat_ctx_t *hashcat_ctx, const char *out_buf, cons
tmp_buf[tmp_len] = 0; tmp_buf[tmp_len] = 0;
HCFILE fp; hc_lockfile (&potfile_ctx->fp);
fp.is_gzip = false;
fp.pfp = potfile_ctx->fp;
fp.fd = fileno (fp.pfp);
hc_lockfile (&fp); hc_fprintf (&potfile_ctx->fp, "%s" EOL, tmp_buf);
fprintf (potfile_ctx->fp, "%s" EOL, tmp_buf); hc_fflush (&potfile_ctx->fp);
fflush (potfile_ctx->fp); if (hc_unlockfile (&potfile_ctx->fp))
if (hc_unlockfile (&fp))
{ {
event_log_error (hashcat_ctx, "%s: Failed to unlock file.", potfile_ctx->filename); event_log_error (hashcat_ctx, "%s: Failed to unlock file.", potfile_ctx->filename);
} }
@ -380,7 +369,7 @@ int potfile_remove_parse (hashcat_ctx_t *hashcat_ctx)
const hashconfig_t *hashconfig = hashcat_ctx->hashconfig; const hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
const hashes_t *hashes = hashcat_ctx->hashes; const hashes_t *hashes = hashcat_ctx->hashes;
const module_ctx_t *module_ctx = hashcat_ctx->module_ctx; const module_ctx_t *module_ctx = hashcat_ctx->module_ctx;
const potfile_ctx_t *potfile_ctx = hashcat_ctx->potfile_ctx; potfile_ctx_t *potfile_ctx = hashcat_ctx->potfile_ctx;
if (potfile_ctx->enabled == false) return 0; if (potfile_ctx->enabled == false) return 0;
@ -530,15 +519,9 @@ int potfile_remove_parse (hashcat_ctx_t *hashcat_ctx)
char *line_buf = (char *) hcmalloc (HCBUFSIZ_LARGE); char *line_buf = (char *) hcmalloc (HCBUFSIZ_LARGE);
// workaround for new fgetl while (!hc_feof (&potfile_ctx->fp))
HCFILE fp;
fp.is_gzip = false;
fp.pfp = potfile_ctx->fp;
fp.fd = fileno (fp.pfp);
while (!feof (potfile_ctx->fp))
{ {
size_t line_len = fgetl (&fp, line_buf); size_t line_len = fgetl (&potfile_ctx->fp, line_buf);
if (line_len == 0) continue; if (line_len == 0) continue;

View File

@ -76,8 +76,8 @@ void slow_candidates_seek (hashcat_ctx_t *hashcat_ctx, void *extra_info, const u
{ {
extra_info_combi_t *extra_info_combi = (extra_info_combi_t *) extra_info; extra_info_combi_t *extra_info_combi = (extra_info_combi_t *) extra_info;
HCFILE *base_fp = extra_info_combi->base_fp; HCFILE *base_fp = &extra_info_combi->base_fp;
HCFILE *combs_fp = extra_info_combi->combs_fp; HCFILE *combs_fp = &extra_info_combi->combs_fp;
for (u64 i = cur; i < end; i++) for (u64 i = cur; i < end; i++)
{ {
@ -238,8 +238,8 @@ void slow_candidates_next (hashcat_ctx_t *hashcat_ctx, void *extra_info)
{ {
extra_info_combi_t *extra_info_combi = (extra_info_combi_t *) extra_info; extra_info_combi_t *extra_info_combi = (extra_info_combi_t *) extra_info;
HCFILE *base_fp = extra_info_combi->base_fp; HCFILE *base_fp = &extra_info_combi->base_fp;
HCFILE *combs_fp = extra_info_combi->combs_fp; HCFILE *combs_fp = &extra_info_combi->combs_fp;
if ((extra_info_combi->pos % combinator_ctx->combs_cnt) == 0) if ((extra_info_combi->pos % combinator_ctx->combs_cnt) == 0)
{ {