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
65 changes: 65 additions & 0 deletions src/rules.c
Original file line number Diff line number Diff line change
Expand Up @@ -1424,7 +1424,35 @@ char *rules_apply(char *word_in, char *rule, int split)
break;

case 'v': /* assign value to numeric variable */
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)
Expand All @@ -1437,6 +1465,43 @@ char *rules_apply(char *word_in, char *rule, int split)
}
break;

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]);
Comment on lines +1485 to +1488
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first line here (and same for 'h') aborts without converting a single letter to hex. I'm not saying it's wrong (we don't have a spec that detailed) and I don't care - I think RULE_WORD_SIZE is pretty large. Just mentioning it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also don't think it's a problem, if it's acceptable now should it be merged?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe @solardiz wants to look at this first, I'm not sure. I'm not 100% sure of the cryptic rules.c macros such as GET_OUT, and I haven't had time to delve into it yet. It's unfortunate we have so very long delay in merging stuff right now.

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;

/* Additional "single crack" mode rules */
case '1':
if (split < 0)
Expand Down