1
0
mirror of https://github.com/hashcat/hashcat.git synced 2025-01-04 21:01:07 +00:00

Gracefully handle corrupt .gz archives

This commit is contained in:
PenguinKeeper7 2024-12-10 07:57:41 +00:00
parent 6716447dfc
commit 3617df2f25
4 changed files with 121 additions and 4 deletions

View File

@ -96,6 +96,16 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx)
return -1;
}
if (rc1 == -2)
{
event_log_error (hashcat_ctx, "Error reading wordlist: %s", dictfile1);
hc_fclose (&fp1);
hc_fclose (&fp2);
return -1;
}
if (words1_cnt == 0)
{
event_log_error (hashcat_ctx, "%s: empty file.", dictfile1);
@ -122,6 +132,13 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx)
return -1;
}
if (rc2 == -2)
{
event_log_error (hashcat_ctx, "Error reading wordlist: %s", dictfile2);
return -1;
}
if (words2_cnt == 0)
{
event_log_error (hashcat_ctx, "%s: empty file.", dictfile2);
@ -199,6 +216,16 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx)
return -1;
}
if (rc1 == -2)
{
event_log_error (hashcat_ctx, "Error reading wordlist: %s", dictfile1);
hc_fclose (&fp1);
hc_fclose (&fp2);
return -1;
}
if (words1_cnt == 0)
{
event_log_error (hashcat_ctx, "%s: empty file.", dictfile1);
@ -225,6 +252,13 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx)
return -1;
}
if (rc2 == -2)
{
event_log_error (hashcat_ctx, "Error reading wordlist: %s", dictfile2);
return -1;
}
if (words2_cnt == 0)
{
event_log_error (hashcat_ctx, "%s: empty file.", dictfile2);
@ -330,6 +364,16 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx)
return -1;
}
if (rc1 == -2)
{
event_log_error (hashcat_ctx, "Error reading wordlist: %s", dictfile1);
hc_fclose (&fp1);
hc_fclose (&fp2);
return -1;
}
if (words1_cnt == 0)
{
event_log_error (hashcat_ctx, "%s: empty file.", dictfile1);
@ -356,6 +400,13 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx)
return -1;
}
if (rc2 == -2)
{
event_log_error (hashcat_ctx, "Error reading wordlist: %s", dictfile2);
return -1;
}
if (words2_cnt == 0)
{
event_log_error (hashcat_ctx, "%s: empty file.", dictfile2);
@ -412,6 +463,13 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx)
return -1;
}
if (rc == -2)
{
event_log_error (hashcat_ctx, "Error reading wordlist: %s", dictfile);
return -1;
}
combinator_ctx->combs_cnt = words_cnt;
combinator_ctx->combs_mode = COMBINATOR_MODE_BASE_LEFT;
}

View File

@ -410,6 +410,17 @@ size_t hc_fread (void *ptr, size_t size, size_t nmemb, HCFILE *fp)
else if (fp->gfp)
{
n = gzfread (ptr, size, nmemb, fp->gfp);
// Double check to make sure that it successfully read 0 bytes instead of erroring
if (n == 0)
{
int errnum;
gzerror (fp->gfp, &errnum);
if (errnum != Z_OK)
{
return (size_t) -1;
}
}
}
else if (fp->ufp)
{

View File

@ -91,6 +91,13 @@ int straight_ctx_update_loop (hashcat_ctx_t *hashcat_ctx)
return -1;
}
if (rc == -2)
{
event_log_error (hashcat_ctx, "Error reading wordlist: %s", straight_ctx->dict);
return -1;
}
if (status_ctx->words_cnt == 0)
{
logfile_sub_msg ("STOP");
@ -125,6 +132,13 @@ int straight_ctx_update_loop (hashcat_ctx_t *hashcat_ctx)
return -1;
}
if (rc == -2)
{
event_log_error (hashcat_ctx, "Error reading wordlist: %s", combinator_ctx->dict1);
return -1;
}
}
else if (combinator_ctx->combs_mode == COMBINATOR_MODE_BASE_RIGHT)
{
@ -147,6 +161,13 @@ int straight_ctx_update_loop (hashcat_ctx_t *hashcat_ctx)
return -1;
}
if (rc == -2)
{
event_log_error (hashcat_ctx, "Error reading wordlist: %s", combinator_ctx->dict2);
return -1;
}
}
if (status_ctx->words_cnt == 0)
@ -194,6 +215,13 @@ int straight_ctx_update_loop (hashcat_ctx_t *hashcat_ctx)
return -1;
}
if (rc == -2)
{
event_log_error (hashcat_ctx, "Error reading wordlist: %s", straight_ctx->dict);
return -1;
}
if (status_ctx->words_cnt == 0)
{
logfile_sub_msg ("STOP");
@ -234,6 +262,13 @@ int straight_ctx_update_loop (hashcat_ctx_t *hashcat_ctx)
return -1;
}
if (rc == -2)
{
event_log_error (hashcat_ctx, "Error reading wordlist: %s", straight_ctx->dict);
return -1;
}
if ((status_ctx->words_cnt / straight_ctx->kernel_rules_cnt) != hashes->salts_cnt)
{
event_log_error (hashcat_ctx, "Number of words in wordlist '%s' is not in sync with number of unique salts", straight_ctx->dict);

View File

@ -60,6 +60,11 @@ int load_segment (hashcat_ctx_t *hashcat_ctx, HCFILE *fp)
wl_data->cnt = hc_fread (wl_data->buf, 1, wl_data->incr - 1000, fp);
if (wl_data->cnt == (size_t) -1)
{
return -1;
}
wl_data->buf[wl_data->cnt] = 0;
if (wl_data->cnt == 0) return 0;
@ -339,7 +344,12 @@ void get_next_word (hashcat_ctx_t *hashcat_ctx, HCFILE *fp, char **out_buf, u32
return;
}
load_segment (hashcat_ctx, fp);
if (load_segment (hashcat_ctx, fp) == -1)
{
event_log_error (hashcat_ctx, "Error reading file!\n");
return;
}
get_next_word (hashcat_ctx, fp, out_buf, out_len);
}
@ -559,9 +569,12 @@ int count_words (hashcat_ctx_t *hashcat_ctx, HCFILE *fp, const char *dictfile, u
u64 cnt2 = 0;
while (!hc_feof (fp))
{
load_segment (hashcat_ctx, fp);
{
if (load_segment (hashcat_ctx, fp) == -1)
{
return -2;
}
comp += wl_data->cnt;
u64 i = 0;