Fixed custom char parsing code in maskfiles in --increment mode: Custom charset wasn't used

pull/933/head
jsteube 8 years ago
parent 72599fd109
commit 767ad440b2

@ -13,7 +13,8 @@
- Fixed infinite loop when using --loopback in case all hashes have been cracked - Fixed infinite loop when using --loopback in case all hashes have been cracked
- Fixed double fclose() using AMDGPU-Pro on sysfs compatible platform: Leading to segfault - Fixed double fclose() using AMDGPU-Pro on sysfs compatible platform: Leading to segfault
- Fixed kernel loops in leading to slower performance in --increment mode - Fixed kernel loops in --increment mode leading to slower performance
- Fixed custom char parsing code in maskfiles in --increment mode: Custom charset wasn't used
- Removed access to readlink() on FreeBSD: Causes problem building hashcat - Removed access to readlink() on FreeBSD: Causes problem building hashcat
## ##

@ -927,7 +927,7 @@ static int mask_append_final (hashcat_ctx_t *hashcat_ctx, const char *mask)
return 0; return 0;
} }
static int mask_append (hashcat_ctx_t *hashcat_ctx, const char *mask) static int mask_append (hashcat_ctx_t *hashcat_ctx, const char *mask, const char *prepend)
{ {
hashconfig_t *hashconfig = hashcat_ctx->hashconfig; hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
user_options_t *user_options = hashcat_ctx->user_options; user_options_t *user_options = hashcat_ctx->user_options;
@ -950,7 +950,16 @@ static int mask_append (hashcat_ctx_t *hashcat_ctx, const char *mask)
{ {
char *mask_truncated = (char *) hcmalloc (256); char *mask_truncated = (char *) hcmalloc (256);
const int rc_truncated_mask = mp_get_truncated_mask (hashcat_ctx, mask, strlen (mask), increment_len, mask_truncated); char *mask_truncated_next = mask_truncated;
if (prepend)
{
// this happens with maskfiles only
mask_truncated_next += snprintf (mask_truncated, 256, "%s,", prepend);
}
const int rc_truncated_mask = mp_get_truncated_mask (hashcat_ctx, mask, strlen (mask), increment_len, mask_truncated_next);
if (rc_truncated_mask == -1) break; if (rc_truncated_mask == -1) break;
@ -985,6 +994,34 @@ u32 mp_get_length (const char *mask)
return len; return len;
} }
static char *mask_ctx_parse_maskfile_find_mask (char *line_buf, int line_len)
{
char *mask_buf = line_buf;
bool escaped = false;
for (int i = 0; i < line_len; i++)
{
if (escaped == true)
{
escaped = false;
}
else
{
if (line_buf[i] == '\\')
{
escaped = true;
}
else if (line_buf[i] == ',')
{
mask_buf = line_buf + i + 1;
}
}
}
return mask_buf;
}
int mask_ctx_update_loop (hashcat_ctx_t *hashcat_ctx) int mask_ctx_update_loop (hashcat_ctx_t *hashcat_ctx)
{ {
combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx; combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx;
@ -1188,7 +1225,7 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx)
if (hc_stat (arg, &file_stat) == -1) if (hc_stat (arg, &file_stat) == -1)
{ {
const int rc = mask_append (hashcat_ctx, arg); const int rc = mask_append (hashcat_ctx, arg, NULL);
if (rc == -1) return -1; if (rc == -1) return -1;
} }
@ -1228,7 +1265,20 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx)
if (line_buf[0] == '#') continue; if (line_buf[0] == '#') continue;
const int rc = mask_append (hashcat_ctx, line_buf); 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) if (rc == -1)
{ {
@ -1255,7 +1305,7 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx)
{ {
const char *mask = DEF_MASK; const char *mask = DEF_MASK;
const int rc = mask_append (hashcat_ctx, mask); const int rc = mask_append (hashcat_ctx, mask, NULL);
if (rc == -1) return -1; if (rc == -1) return -1;
} }
@ -1264,7 +1314,7 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx)
{ {
const char *mask = hashconfig_benchmark_mask (hashcat_ctx); const char *mask = hashconfig_benchmark_mask (hashcat_ctx);
const int rc = mask_append (hashcat_ctx, mask); const int rc = mask_append (hashcat_ctx, mask, NULL);
if (rc == -1) return -1; if (rc == -1) return -1;
} }
@ -1281,7 +1331,7 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx)
if (hc_stat (arg, &file_stat) == -1) if (hc_stat (arg, &file_stat) == -1)
{ {
const int rc = mask_append (hashcat_ctx, arg); const int rc = mask_append (hashcat_ctx, arg, NULL);
if (rc == -1) return -1; if (rc == -1) return -1;
} }
@ -1310,7 +1360,20 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx)
if (line_buf[0] == '#') continue; if (line_buf[0] == '#') continue;
const int rc = mask_append (hashcat_ctx, line_buf); 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) if (rc == -1)
{ {
@ -1344,7 +1407,7 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx)
if (hc_stat (arg, &file_stat) == -1) if (hc_stat (arg, &file_stat) == -1)
{ {
const int rc = mask_append (hashcat_ctx, arg); const int rc = mask_append (hashcat_ctx, arg, NULL);
if (rc == -1) return -1; if (rc == -1) return -1;
} }
@ -1373,7 +1436,20 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx)
if (line_buf[0] == '#') continue; if (line_buf[0] == '#') continue;
const int rc = mask_append (hashcat_ctx, line_buf); 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) if (rc == -1)
{ {
@ -1443,13 +1519,15 @@ int mask_ctx_parse_maskfile (hashcat_ctx_t *hashcat_ctx)
if (mask_ctx->mask_from_file == false) return 0; if (mask_ctx->mask_from_file == false) return 0;
mf_t *mfs = mask_ctx->mfs; mf_t *mfs_buf = mask_ctx->mfs;
mfs_buf[0].mf_len = 0;
mfs_buf[1].mf_len = 0;
mfs_buf[2].mf_len = 0;
mfs_buf[3].mf_len = 0;
mfs_buf[4].mf_len = 0;
mfs[0].mf_len = 0; int mfs_cnt = 0;
mfs[1].mf_len = 0;
mfs[2].mf_len = 0;
mfs[3].mf_len = 0;
mfs[4].mf_len = 0;
char *mask_buf = mask_ctx->mask; char *mask_buf = mask_ctx->mask;
@ -1457,11 +1535,9 @@ int mask_ctx_parse_maskfile (hashcat_ctx_t *hashcat_ctx)
bool escaped = false; bool escaped = false;
int mf_cnt = 0;
for (int i = 0; i < mask_len; i++) for (int i = 0; i < mask_len; i++)
{ {
mf_t *mf = mfs + mf_cnt; mf_t *mf = mfs_buf + mfs_cnt;
if (escaped == true) if (escaped == true)
{ {
@ -1481,9 +1557,9 @@ int mask_ctx_parse_maskfile (hashcat_ctx_t *hashcat_ctx)
{ {
mf->mf_buf[mf->mf_len] = 0; mf->mf_buf[mf->mf_len] = 0;
mf_cnt++; mfs_cnt++;
if (mf_cnt >= MAX_MFS) if (mfs_cnt == MAX_MFS)
{ {
event_log_error (hashcat_ctx, "Invalid line '%s' in maskfile", mask_buf); event_log_error (hashcat_ctx, "Invalid line '%s' in maskfile", mask_buf);
@ -1499,41 +1575,41 @@ int mask_ctx_parse_maskfile (hashcat_ctx_t *hashcat_ctx)
} }
} }
mf_t *mf = mfs + mf_cnt; mf_t *mf = mfs_buf + mfs_cnt;
mf->mf_buf[mf->mf_len] = 0; mf->mf_buf[mf->mf_len] = 0;
for (int i = 0; i < mf_cnt; i++) for (int i = 0; i < mfs_cnt; i++)
{ {
switch (i) switch (i)
{ {
case 0: case 0:
user_options->custom_charset_1 = mfs[0].mf_buf; user_options->custom_charset_1 = mfs_buf[0].mf_buf;
mp_reset_usr (mask_ctx->mp_usr, 0); mp_reset_usr (mask_ctx->mp_usr, 0);
mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_1, 0); mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_1, 0);
break; break;
case 1: case 1:
user_options->custom_charset_2 = mfs[1].mf_buf; user_options->custom_charset_2 = mfs_buf[1].mf_buf;
mp_reset_usr (mask_ctx->mp_usr, 1); mp_reset_usr (mask_ctx->mp_usr, 1);
mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_2, 1); mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_2, 1);
break; break;
case 2: case 2:
user_options->custom_charset_3 = mfs[2].mf_buf; user_options->custom_charset_3 = mfs_buf[2].mf_buf;
mp_reset_usr (mask_ctx->mp_usr, 2); mp_reset_usr (mask_ctx->mp_usr, 2);
mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_3, 2); mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_3, 2);
break; break;
case 3: case 3:
user_options->custom_charset_4 = mfs[3].mf_buf; user_options->custom_charset_4 = mfs_buf[3].mf_buf;
mp_reset_usr (mask_ctx->mp_usr, 3); mp_reset_usr (mask_ctx->mp_usr, 3);
mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_4, 3); mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_4, 3);
break; break;
} }
} }
mask_ctx->mask = mfs[mf_cnt].mf_buf; mask_ctx->mask = mfs_buf[mfs_cnt].mf_buf;
return 0; return 0;
} }

Loading…
Cancel
Save