Skip to content

Commit

Permalink
Parse maskfiles and escaped ?s properly
Browse files Browse the repository at this point in the history
Replace the old reversal function with an improved one, that both respects custom charsets in mask files and escaped question marks
  • Loading branch information
PenguinKeeper7 committed Mar 4, 2024
1 parent 7c24f36 commit cbc3470
Showing 1 changed file with 42 additions and 18 deletions.
60 changes: 42 additions & 18 deletions src/mpsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1073,23 +1073,40 @@ static int mask_append_final (hashcat_ctx_t *hashcat_ctx, const char *mask)
}

// ?l?u?d -> ?d?u?l
static char* reverseMask (const char *mask) {
int length = strlen (mask);
char *tmp_buf = (char *) hcmalloc (256);

for (int i = length - 1, j = 0; i >= 0; i--) {
if (mask[i] == '\0')
continue;
if (i != 0 && mask[i - 1] == '?') {
tmp_buf[j++] = '?';
tmp_buf[j++] = mask[i];
i--;
} else {
tmp_buf[j++] = mask[i];
}
}
static char* reverseMask (const char *mask, const char *prepend)
{
u32 maskLength = strlen (mask);
u32 prependLength = strlen (prepend);

char *tmp_buf = (char *) hcmalloc (256);

return tmp_buf;
u32 i = 0;

// Add prepend section to tmp_buf, avoiding reversal
if (prependLength != 0)
{
for (i = 0; i < prependLength ; i++)
{
tmp_buf[i] = prepend[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];
}
}

return tmp_buf;
}

static int mask_append (hashcat_ctx_t *hashcat_ctx, const char *mask, const char *prepend)
Expand Down Expand Up @@ -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 (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);

break;
}

mask_truncated = reverseMask (mask_truncated);
if (prepend)
{
mask_truncated = reverseMask (mask_truncated, prepend);
}
else
{
mask_truncated = reverseMask (mask_truncated, "");
}
}
else
{
Expand Down

0 comments on commit cbc3470

Please sign in to comment.