1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-12-22 06:38:11 +00:00

Add new rule function '3' to switch the case of the first letter after occurrence N of char X

This commit is contained in:
Jens Steube 2021-08-01 00:04:10 +02:00
parent d4997d1255
commit f4e52ca533
8 changed files with 172 additions and 4 deletions

View File

@ -269,6 +269,35 @@ DECLSPEC int mangle_toggle_at (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p
return (len);
}
DECLSPEC int mangle_toggle_at_sep (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, u32 *buf, const int len)
{
if (len >= RP_PASSWORD_SIZE) return (len);
u8 occurence = 0;
u32 rem = 0;
for (int i = 0, idx = 0; i < len; i += 4, idx += 1)
{
const u32 t = buf[idx];
buf[idx] = t | generate_cmask (t);
u32 out = rem;
rem = 0;
if (((t >> 0) & 0xff) == p1) { if (occurence == p0) out = 0x0000ff00; occurence++; }
if (((t >> 8) & 0xff) == p1) { if (occurence == p0) out = 0x00ff0000; occurence++; }
if (((t >> 16) & 0xff) == p1) { if (occurence == p0) out = 0xff000000; occurence++; }
if (((t >> 24) & 0xff) == p1) { if (occurence == p0) rem = 0x000000ff; occurence++; }
buf[idx] = t ^ (generate_cmask (t) & out);
}
return (len);
}
DECLSPEC int mangle_reverse (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, u32 *buf, const int len)
{
for (int l = 0; l < len / 2; l++)
@ -725,6 +754,7 @@ DECLSPEC int apply_rule (const u32 name, MAYBE_UNUSED const u8 p0, MAYBE_UNUSED
case RULE_OP_MANGLE_UREST_LFIRST: out_len = mangle_urest_lfirst (p0, p1, buf, out_len); break;
case RULE_OP_MANGLE_TREST: out_len = mangle_trest (p0, p1, buf, out_len); break;
case RULE_OP_MANGLE_TOGGLE_AT: out_len = mangle_toggle_at (p0, p1, buf, out_len); break;
case RULE_OP_MANGLE_TOGGLE_AT_SEP: out_len = mangle_toggle_at_sep (p0, p1, buf, out_len); break;
case RULE_OP_MANGLE_REVERSE: out_len = mangle_reverse (p0, p1, buf, out_len); break;
case RULE_OP_MANGLE_DUPEWORD: out_len = mangle_dupeword (p0, p1, buf, out_len); break;
case RULE_OP_MANGLE_DUPEWORD_TIMES: out_len = mangle_dupeword_times (p0, p1, (u8 *) buf, out_len); break;

View File

@ -21,6 +21,7 @@
#define RULE_OP_MANGLE_UREST_LFIRST 'C'
#define RULE_OP_MANGLE_TREST 't'
#define RULE_OP_MANGLE_TOGGLE_AT 'T'
#define RULE_OP_MANGLE_TOGGLE_AT_SEP '3'
#define RULE_OP_MANGLE_REVERSE 'r'
#define RULE_OP_MANGLE_DUPEWORD 'd'
#define RULE_OP_MANGLE_DUPEWORD_TIMES 'p'
@ -83,6 +84,7 @@ DECLSPEC int mangle_urest (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, u
DECLSPEC int mangle_urest_lfirst (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, u32 *buf, const int len);
DECLSPEC int mangle_trest (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, u32 *buf, const int len);
DECLSPEC int mangle_toggle_at (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, u32 *buf, const int len);
DECLSPEC int mangle_toggle_at_sep (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, u32 *buf, const int len);
DECLSPEC int mangle_reverse (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, u32 *buf, const int len);
DECLSPEC int mangle_dupeword (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, u32 *buf, const int len);
DECLSPEC int mangle_dupeword_times (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, u8 *buf, const int len);

View File

@ -1163,6 +1163,82 @@ DECLSPEC u32 rule_op_mangle_toggle_at (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED c
return (in_len);
}
DECLSPEC u32 rule_op_mangle_toggle_at_sep (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 *buf0, MAYBE_UNUSED u32 *buf1, const u32 in_len)
{
if (in_len == 0) return in_len;
u32 r0 = search_on_register (buf0[0], p1);
u32 r1 = search_on_register (buf0[1], p1);
u32 r2 = search_on_register (buf0[2], p1);
u32 r3 = search_on_register (buf0[3], p1);
u32 r4 = search_on_register (buf1[0], p1);
u32 r5 = search_on_register (buf1[1], p1);
u32 r6 = search_on_register (buf1[2], p1);
u32 r7 = search_on_register (buf1[3], p1);
const u32 rn = (r0 << 0)
| (r1 << 4)
| (r2 << 8)
| (r3 << 12)
| (r4 << 16)
| (r5 << 20)
| (r6 << 24)
| (r7 << 28);
if (rn == 0) return in_len;
u32 occurence = 0;
u32 ro = 0;
#ifdef _unroll
#pragma unroll
#endif
for (int i = 0; i < 32; i++)
{
if ((rn >> i) & 1)
{
if (occurence == p0)
{
ro = 1 << i;
break;
}
occurence++;
}
}
r0 = (ro >> 0) & 15;
r1 = (ro >> 4) & 15;
r2 = (ro >> 8) & 15;
r3 = (ro >> 12) & 15;
r4 = (ro >> 16) & 15;
r5 = (ro >> 20) & 15;
r6 = (ro >> 24) & 15;
r7 = (ro >> 28) & 15;
r0 <<= 1;
r1 <<= 1; r1 |= r0 >> 4;
r2 <<= 1; r2 |= r1 >> 4;
r3 <<= 1; r3 |= r2 >> 4;
r4 <<= 1; r4 |= r3 >> 4;
r5 <<= 1; r5 |= r4 >> 4;
r6 <<= 1; r6 |= r5 >> 4;
r7 <<= 1; r7 |= r6 >> 4;
buf0[0] = toggle_on_register (buf0[0], r0);
buf0[1] = toggle_on_register (buf0[1], r1);
buf0[2] = toggle_on_register (buf0[2], r2);
buf0[3] = toggle_on_register (buf0[3], r3);
buf1[0] = toggle_on_register (buf1[0], r4);
buf1[1] = toggle_on_register (buf1[1], r5);
buf1[2] = toggle_on_register (buf1[2], r6);
buf1[3] = toggle_on_register (buf1[3], r7);
return in_len;
}
DECLSPEC u32 rule_op_mangle_reverse (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 *buf0, MAYBE_UNUSED u32 *buf1, const u32 in_len)
{
reverse_block_optimized (buf0, buf1, buf0, buf1, in_len);
@ -2285,6 +2361,7 @@ DECLSPEC u32 apply_rule_optimized (const u32 name, const u32 p0, const u32 p1, u
case RULE_OP_MANGLE_UREST_LFIRST: out_len = rule_op_mangle_urest_lfirst (p0, p1, buf0, buf1, out_len); break;
case RULE_OP_MANGLE_TREST: out_len = rule_op_mangle_trest (p0, p1, buf0, buf1, out_len); break;
case RULE_OP_MANGLE_TOGGLE_AT: out_len = rule_op_mangle_toggle_at (p0, p1, buf0, buf1, out_len); break;
case RULE_OP_MANGLE_TOGGLE_AT_SEP: out_len = rule_op_mangle_toggle_at_sep (p0, p1, buf0, buf1, out_len); break;
case RULE_OP_MANGLE_REVERSE: out_len = rule_op_mangle_reverse (p0, p1, buf0, buf1, out_len); break;
case RULE_OP_MANGLE_DUPEWORD: out_len = rule_op_mangle_dupeword (p0, p1, buf0, buf1, out_len); break;
case RULE_OP_MANGLE_DUPEWORD_TIMES: out_len = rule_op_mangle_dupeword_times (p0, p1, buf0, buf1, out_len); break;

View File

@ -21,6 +21,7 @@
#define RULE_OP_MANGLE_UREST_LFIRST 'C'
#define RULE_OP_MANGLE_TREST 't'
#define RULE_OP_MANGLE_TOGGLE_AT 'T'
#define RULE_OP_MANGLE_TOGGLE_AT_SEP '3'
#define RULE_OP_MANGLE_REVERSE 'r'
#define RULE_OP_MANGLE_DUPEWORD 'd'
#define RULE_OP_MANGLE_DUPEWORD_TIMES 'p'
@ -85,6 +86,7 @@ DECLSPEC u32 rule_op_mangle_lrest_ufirst (MAYBE_UNUSED const u32 p0, MAYBE_UNUSE
DECLSPEC u32 rule_op_mangle_urest_lfirst (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 *buf0, MAYBE_UNUSED u32 *buf1, const u32 in_len);
DECLSPEC u32 rule_op_mangle_trest (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 *buf0, MAYBE_UNUSED u32 *buf1, const u32 in_len);
DECLSPEC u32 rule_op_mangle_toggle_at (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 *buf0, MAYBE_UNUSED u32 *buf1, const u32 in_len);
DECLSPEC u32 rule_op_mangle_toggle_at_sep (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 *buf0, MAYBE_UNUSED u32 *buf1, const u32 in_len);
DECLSPEC u32 rule_op_mangle_reverse (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 *buf0, MAYBE_UNUSED u32 *buf1, const u32 in_len);
DECLSPEC u32 rule_op_mangle_dupeword (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 *buf0, MAYBE_UNUSED u32 *buf1, const u32 in_len);
DECLSPEC u32 rule_op_mangle_dupeword_times (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 *buf0, MAYBE_UNUSED u32 *buf1, const u32 in_len);

View File

@ -5,6 +5,7 @@
#define RULE_OP_MANGLE_UREST_LFIRST 'C' // upper case all chars, lower case 1st
#define RULE_OP_MANGLE_TREST 't' // switch the case of each char
#define RULE_OP_MANGLE_TOGGLE_AT 'T' // switch the case of each char on pos N
#define RULE_OP_MANGLE_TOGGLE_AT_SEP '3' // switch the case of the first letter after occurrence N of char X
#define RULE_OP_MANGLE_REVERSE 'r' // reverse word
#define RULE_OP_MANGLE_DUPEWORD 'd' // append word to itself
#define RULE_OP_MANGLE_DUPEWORD_TIMES 'p' // append word to itself N times

View File

@ -295,6 +295,7 @@ typedef enum rule_functions
RULE_OP_MANGLE_UREST_LFIRST = 'C',
RULE_OP_MANGLE_TREST = 't',
RULE_OP_MANGLE_TOGGLE_AT = 'T',
RULE_OP_MANGLE_TOGGLE_AT_SEP = '3',
RULE_OP_MANGLE_REVERSE = 'r',
RULE_OP_MANGLE_DUPEWORD = 'd',
RULE_OP_MANGLE_DUPEWORD_TIMES = 'p',

View File

@ -71,7 +71,8 @@ static const char grp_op_chr_chr[] =
static const char grp_op_pos_chr[] =
{
RULE_OP_MANGLE_INSERT,
RULE_OP_MANGLE_OVERSTRIKE
RULE_OP_MANGLE_OVERSTRIKE,
RULE_OP_MANGLE_TOGGLE_AT_SEP
};
static const char grp_op_pos_pos0[] =
@ -444,12 +445,18 @@ int cpu_rule_to_kernel_rule (char *rule_buf, u32 rule_len, kernel_rule_t *rule)
break;
case RULE_OP_MANGLE_TITLE:
SET_NAME (rule, rule_buf[rule_pos]);
SET_NAME (rule, rule_buf[rule_pos]);
break;
case RULE_OP_MANGLE_TITLE_SEP:
SET_NAME (rule, rule_buf[rule_pos]);
SET_P0 (rule, rule_buf[rule_pos]);
SET_NAME (rule, rule_buf[rule_pos]);
SET_P0 (rule, rule_buf[rule_pos]);
break;
case RULE_OP_MANGLE_TOGGLE_AT_SEP:
SET_NAME (rule, rule_buf[rule_pos]);
SET_P0_CONV (rule, rule_buf[rule_pos]);
SET_P1 (rule, rule_buf[rule_pos]);
break;
default:
@ -675,6 +682,12 @@ int kernel_rule_to_cpu_rule (char *rule_buf, kernel_rule_t *rule)
GET_P0 (rule);
break;
case RULE_OP_MANGLE_TOGGLE_AT_SEP:
rule_buf[rule_pos] = rule_cmd;
GET_P0_CONV (rule);
GET_P1 (rule);
break;
case 0:
if (rule_pos == 0) return -1;
return rule_pos - 1;

View File

@ -45,6 +45,41 @@ static void MANGLE_SWITCH (char *arr, const int l, const int r)
arr[l] = c;
}
static int mangle_toggle_at_sep (char arr[RP_PASSWORD_SIZE], int arr_len, char c, int upos)
{
int toggle_next = 0;
int occurrence = 0;
int pos;
for (pos = 0; pos < arr_len; pos++)
{
if (arr[pos] == c)
{
if (occurrence == upos)
{
toggle_next = 1;
}
else
{
occurrence++;
}
continue;
}
if (toggle_next == 1)
{
MANGLE_TOGGLE_AT (arr, pos);
break;
}
}
return (arr_len);
}
static int mangle_lrest (char arr[RP_PASSWORD_SIZE], int arr_len)
{
int pos;
@ -561,6 +596,13 @@ int _old_apply_rule (const char *rule, int rule_len, char in[RP_PASSWORD_SIZE],
if (upos < out_len) MANGLE_TOGGLE_AT (out, upos);
break;
case RULE_OP_MANGLE_TOGGLE_AT_SEP:
NEXT_RULEPOS (rule_pos);
NEXT_RPTOI (rule_new, rule_pos, upos);
NEXT_RULEPOS (rule_pos);
out_len = mangle_toggle_at_sep (out, out_len, rule_new[rule_pos], upos);
break;
case RULE_OP_MANGLE_REVERSE:
out_len = mangle_reverse (out, out_len);
break;