1
0
mirror of https://github.com/hashcat/hashcat.git synced 2025-07-04 22:02:36 +00:00

Parse maskfiles and escaped ?s properly

Replace the old reversal function with an improved one, that both respects custom charsets in mask files and escaped question marks
This commit is contained in:
PenguinKeeper7 2024-03-04 22:22:31 +00:00
parent 7c24f36db0
commit cbc3470642

View File

@ -1073,19 +1073,36 @@ static int mask_append_final (hashcat_ctx_t *hashcat_ctx, const char *mask)
} }
// ?l?u?d -> ?d?u?l // ?l?u?d -> ?d?u?l
static char* reverseMask (const char *mask) { static char* reverseMask (const char *mask, const char *prepend)
int length = strlen (mask); {
u32 maskLength = strlen (mask);
u32 prependLength = strlen (prepend);
char *tmp_buf = (char *) hcmalloc (256); char *tmp_buf = (char *) hcmalloc (256);
for (int i = length - 1, j = 0; i >= 0; i--) { u32 i = 0;
if (mask[i] == '\0')
continue; // Add prepend section to tmp_buf, avoiding reversal
if (i != 0 && mask[i - 1] == '?') { if (prependLength != 0)
tmp_buf[j++] = '?'; {
tmp_buf[j++] = mask[i]; for (i = 0; i < prependLength ; i++)
i--; {
} else { tmp_buf[i] = prepend[i];
tmp_buf[j++] = mask[i]; }
tmp_buf[i++] = ',';
}
for (u32 j = maskLength - 1; i <= maskLength - 1 ; i++)
{
if (mask[i] == '?' && mask[i + 1] != '\0')
{
tmp_buf[j--] = mask[i + 1];
tmp_buf[j--] = mask[i];
i++;
}
else
{
tmp_buf[j--] = mask[i];
} }
} }
@ -1130,14 +1147,21 @@ static int mask_append (hashcat_ctx_t *hashcat_ctx, const char *mask, const char
if (user_options->increment_inverse == true) if (user_options->increment_inverse == true)
{ {
if (mp_get_truncated_mask (hashcat_ctx, reverseMask (mask), strlen (mask), increment_len, mask_truncated_next) == -1) if (mp_get_truncated_mask (hashcat_ctx, reverseMask (mask, ""), strlen (mask), increment_len, mask_truncated_next) == -1)
{ {
hcfree (mask_truncated); hcfree (mask_truncated);
break; break;
} }
mask_truncated = reverseMask (mask_truncated); if (prepend)
{
mask_truncated = reverseMask (mask_truncated, prepend);
}
else
{
mask_truncated = reverseMask (mask_truncated, "");
}
} }
else else
{ {