Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 113 additions & 24 deletions src/rules.c
Original file line number Diff line number Diff line change
Expand Up @@ -1437,18 +1437,101 @@ char *rules_apply(char *word_in, char *rule, int split)
}
break;

/* Additional "single crack" mode rules */
case 'h': /*convert the entire password to lowercase hex */
{
char outbuf[RULE_WORD_SIZE * 2];
int i;
if (length * 2 >= RULE_WORD_SIZE)
break;
for (i = 0; i < length; i++)
sprintf(&outbuf[i * 2], "%02x", (unsigned char)in[i]);
strcpy(in, outbuf);
length *= 2;
}
break;

case 'H': /*convert the entire password to uppercase hex*/
{
char outbuf[RULE_WORD_SIZE * 2];
int i;
if (length * 2 >= RULE_WORD_SIZE)
break;
for (i = 0; i < length; i++)
sprintf(&outbuf[i * 2], "%02X", (unsigned char)in[i]);
strcpy(in, outbuf);
length *= 2;
}
break;

case 'B': /* add byte value of X at pos N, bytewise. Format: BNX */
{
unsigned int pos;
unsigned char val;
POSITION(pos)
VALUE(val)
if (pos < length)
{
in[pos] = (unsigned char)(in[pos] + val);
}
}
break;

case 'v':
if (hc_logic)
{
/* HC rule: insert char X every N chars */
unsigned int n, i, out_len = 0;
char value;
char *out;
POSITION(n)
VALUE(value)
if (!n)
break;
GET_OUT
for (i = 0; i < length; i++)
{
if (out_len >= RULE_WORD_SIZE - 1)
break;
out[out_len++] = in[i];
if (((i + 1) % n) == 0) {
if (out_len >= RULE_WORD_SIZE - 1)
break;
out[out_len++] = value;
}
}
out[out_len] = 0;
in = out;
length = out_len;
break;
}
else
{
/* original JtR rule */
char var;
int a, s; /* may be negative */
VALUE(var)
if (var < 'a' || var > 'k')
goto out_ERROR_POSITION;
rules_vars['l'] = length;
POSITION(a)
POSITION(s)
rules_vars[ARCH_INDEX(var)] = a - s; /* may be negative */
}
break;

/* Additional "single crack" mode rules */
case '1':
if (split < 0)
goto out_ERROR_UNALLOWED;
if (!split) REJECT
if (!split)
REJECT
if (which)
memcpy(buffer[2][STAGE],
in, length + 1);
in, length + 1);
else
strnzcpy(buffer[2][STAGE],
&word[split],
RULE_WORD_SIZE);
&word[split],
RULE_WORD_SIZE);
length = split;
if (length > RULE_WORD_SIZE - 1)
length = RULE_WORD_SIZE - 1;
Expand All @@ -1460,37 +1543,43 @@ char *rules_apply(char *word_in, char *rule, int split)
case '2':
if (split < 0)
goto out_ERROR_UNALLOWED;
if (!split) REJECT
if (which) {
if (!split)
REJECT
if (which)
{
memcpy(buffer[2][STAGE],
in, length + 1);
} else {
in, length + 1);
}
else
{
length = split;
if (length > RULE_WORD_SIZE - 1)
length = RULE_WORD_SIZE - 1;
strnzcpy(buffer[2][STAGE],
word, length + 1);
word, length + 1);
}
strnzcpy(in, &word[split], RULE_WORD_SIZE);
length = strlen(in);
which = 2;
break;

case '+':
if (hc_logic || !which) {
/* HC rule: increment character */
unsigned int x;
POSITION(x)
if (x < length)
++in[x];
break;
}
switch (which) {
case 1:
strcat(in, buffer[2][STAGE]);
break;
case '+':
if (hc_logic || !which)
{
/* HC rule: increment character */
unsigned int x;
POSITION(x)
if (x < length)
++in[x];
break;
}
switch (which)
{
case 1:
strcat(in, buffer[2][STAGE]);
break;

case 2:
case 2:
{
char *out;
GET_OUT
Expand Down