-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
--rules-stack broken (now fixed but may still need some TLC) #5722
Comments
Reverting d265b3c repairs it. |
Happens with PRINCE mode too (indeed any mode). |
This hack repairs it (just to narrow down where the problem is): +++ b/src/rules.c
@@ -1863,8 +1863,11 @@ char *rules_process_stack_all(char *key, rule_stack *ctx)
rules_stacked_after = 0;
while (ctx->rule) {
- if ((word = rules_apply(key, ctx->rule->data, -1)))
+ static char last[99];
+ if ((word = rules_apply(key, ctx->rule->data, -1)) && strcmp(word, last)) {
+ strcpy(last, word);
return word;
+ }
if ((ctx->rule = ctx->rule->next)) {
rules_stacked_number++;
if (!stack_rules_mute) |
So somehow |
I'll look into it right away |
Thank you! I'm sorry I didn't test this feature before merging - I should have, as it was obviously touched by the changes. |
This almost works: +++ b/src/rules.c
@@ -1863,9 +1863,11 @@ char *rules_process_stack_all(char *key, rule_stack *ctx)
rules_stacked_after = 0;
while (ctx->rule) {
- if ((word = rules_apply(key, ctx->rule->data, -1)))
+ char *rule = ctx->rule->data;
+ ctx->rule = ctx->rule->next;
+ if ((word = rules_apply(key, rule, -1)))
return word;
- if ((ctx->rule = ctx->rule->next)) {
+ if (ctx->rule) {
rules_stacked_number++;
if (!stack_rules_mute)
log_event("+ Stacked Rule #%u: '%.100s' accepted", but doesn't terminate when it should:
|
This may actually be correct (passes my test): +++ b/src/rules.c
@@ -1852,25 +1852,19 @@ char *rules_process_stack_all(char *key, rule_stack *ctx)
{
char *word;
- if (!ctx->rule) {
+ if (!ctx->rule && !rules_stacked_number)
ctx->rule = ctx->stack_rule->head;
- rules_stacked_number = 0;
- if (!stack_rules_mute)
- log_event("+ Stacked Rule #%u: '%.100s' accepted",
- rules_stacked_number + 1, ctx->rule->data);
- }
rules_stacked_after = 0;
while (ctx->rule) {
- if ((word = rules_apply(key, ctx->rule->data, -1)))
+ char *rule = ctx->rule->data;
+ rules_stacked_number++;
+ if (!stack_rules_mute)
+ log_event("+ Stacked Rule #%u: '%.100s' accepted", rules_stacked_number, rule);
+ ctx->rule = ctx->rule->next;
+ if ((word = rules_apply(key, rule, -1)))
return word;
- if ((ctx->rule = ctx->rule->next)) {
- rules_stacked_number++;
- if (!stack_rules_mute)
- log_event("+ Stacked Rule #%u: '%.100s' accepted",
- rules_stacked_number + 1, ctx->rule->data);
- }
}
rules_stacked_after = !!(options.flags & (FLG_RULES_CHK | FLG_SINGLE_CHK | FLG_BATCH_CHK)); Edit: correct the logged rule number. It's also simpler code than we had before. But it relies on two things:
|
Also seem to have found a bug we had before, where single mode would log stacked rule number 1 twice. Fix: +++ b/src/rules.c
@@ -1831,9 +1831,9 @@ char *rules_process_stack(char *key, rule_stack *ctx)
if (!ctx->rule) {
ctx->rule = ctx->stack_rule->head;
- rules_stacked_number = 0;
+ rules_stacked_number = 1;
log_event("+ Stacked Rule #%u: '%.100s' accepted",
- rules_stacked_number + 1, ctx->rule->data);
+ rules_stacked_number, ctx->rule->data);
}
rules_stacked_after = 0; |
…ssion Apparently --rules-stack was b0rken all the time, relying on the dupe suppression to proceed to next rule. This musy have been ineffective. Closes openwall#5722
I came up with this diff --git a/src/rules.c b/src/rules.c
index 5ea260326..78509e546 100644
--- a/src/rules.c
+++ b/src/rules.c
@@ -1858,6 +1858,13 @@ char *rules_process_stack_all(char *key, rule_stack *ctx)
if (!stack_rules_mute)
log_event("+ Stacked Rule #%u: '%.100s' accepted",
rules_stacked_number + 1, ctx->rule->data);
+ } else {
+ if ((ctx->rule = ctx->rule->next)) {
+ rules_stacked_number++;
+ if (!stack_rules_mute)
+ log_event("+ Stacked Rule #%u: '%.100s' accepted",
+ rules_stacked_number + 1, ctx->rule->data);
+ }
}
rules_stacked_after = 0; |
This was b0rken all the time - it must have produced one consecutive dupe for each call. Not very effective. |
This is certainly a less invasive change. If it works, let's get it in first, and then think of my code cleanup ideas. Thank you! |
Fixing this may expose something else, as |
Apparently --rules-stack was b0rken all the time, relying on the dupe suppression to proceed to next rule. This musy have been ineffective. Closes openwall#5722
At least |
Apparently --rules-stack was b0rken all the time, relying on the dupe suppression to proceed to next rule. This must have been ineffective. Closes openwall#5722
Added a PR. My code is very likely to just restore functionality to what it was (actually way better than it was) so I think we can merge it as a quick fix. Meanwhile I'll try to wrap my head around your version. |
It did pass my test as posted in here, but it failed with actual stacking on top of normal rules. So it's not ready. |
This passes my current tests: diff --git a/src/cracker.c b/src/cracker.c
index da2c9fc5c..a7db9c7f0 100644
--- a/src/cracker.c
+++ b/src/cracker.c
@@ -1234,6 +1234,7 @@ static int process_key_stack_rules(char *key)
int ret = 0;
char *word;
+ rules_stacked_number = 0;
while ((word = rules_process_stack_all(key, &crk_rule_stack)))
if ((ret = crk_direct_process_key(word)))
break;
diff --git a/src/rules.c b/src/rules.c
index 5ea260326..e1378616f 100644
--- a/src/rules.c
+++ b/src/rules.c
@@ -1831,9 +1831,9 @@ char *rules_process_stack(char *key, rule_stack *ctx)
if (!ctx->rule) {
ctx->rule = ctx->stack_rule->head;
- rules_stacked_number = 0;
+ rules_stacked_number = 1;
log_event("+ Stacked Rule #%u: '%.100s' accepted",
- rules_stacked_number + 1, ctx->rule->data);
+ rules_stacked_number, ctx->rule->data);
}
rules_stacked_after = 0;
@@ -1852,25 +1852,19 @@ char *rules_process_stack_all(char *key, rule_stack *ctx)
{
char *word;
- if (!ctx->rule) {
+ if (!ctx->rule && !rules_stacked_number)
ctx->rule = ctx->stack_rule->head;
- rules_stacked_number = 0;
- if (!stack_rules_mute)
- log_event("+ Stacked Rule #%u: '%.100s' accepted",
- rules_stacked_number + 1, ctx->rule->data);
- }
rules_stacked_after = 0;
while (ctx->rule) {
- if ((word = rules_apply(key, ctx->rule->data, -1)))
+ char *rule = ctx->rule->data;
+ rules_stacked_number++;
+ if (!stack_rules_mute)
+ log_event("+ Stacked Rule #%u: '%.100s' accepted", rules_stacked_number, rule);
+ ctx->rule = ctx->rule->next;
+ if ((word = rules_apply(key, rule, -1)))
return word;
- if ((ctx->rule = ctx->rule->next)) {
- rules_stacked_number++;
- if (!stack_rules_mute)
- log_event("+ Stacked Rule #%u: '%.100s' accepted",
- rules_stacked_number + 1, ctx->rule->data);
- }
}
rules_stacked_after = !!(options.flags & (FLG_RULES_CHK | FLG_SINGLE_CHK | FLG_BATCH_CHK));
diff --git a/src/single.c b/src/single.c
index 4568cf60e..7652604eb 100644
--- a/src/single.c
+++ b/src/single.c
@@ -74,12 +74,12 @@ static int restore_rule_number(void)
if (options.rule_stack) {
single_rule_stack.rule = single_rule_stack.stack_rule->head;
- rules_stacked_number = 0;
+ rules_stacked_number = 1;
while (rules_stacked_number < rec_rule[1])
if (!rules_advance_stack(&single_rule_stack, 1))
return 1;
log_event("+ Stacked Rule #%u: '%.100s' accepted",
- rules_stacked_number + 1, single_rule_stack.rule->data);
+ rules_stacked_number, single_rule_stack.rule->data);
}
return 0; |
That looks right to me |
There's room for optimization here, as we check |
I'm unsure about the changes to |
Yes, need more review/testing of zero- vs. one-based, especially as it relates to |
Why isn't |
We'd end up going over the rules again, infinitely. |
Oh, could use |
Not sure I understand. The stacked rules are supposed to rewind for each and every candidate. The old code had no such check. |
The old code returned with |
Apparently --rules-stack was b0rken all the time, relying on the dupe suppression to proceed to next rule. This must have been ineffective. Closes openwall#5722
Reopening for considering better code |
We also should not forget to fix "bug we had before, where single mode would log stacked rule number 1 twice". |
Maybe I'm too tired but this sounds backwards to me /*
* Advance stacked rules. We iterate main rules first and only then we
* advance the stacked rules (and rewind the main rules). Repeat until
* main rules are done with the last stacked rule.
*/
int rules_advance_stack(rule_stack *ctx, int quiet) The actual operation is we iterate over all stacked rules, then advance the main rules (if any) and rewind the stacked ones. |
This is also weird /*
* Return next word from stacked rules, calling rules_advance_stack() as
* necessary. Once there's no rules left in stack, return NULL-
*/
extern char *rules_process_stack_all(char *key, rule_stack *ctx); The actual code does not call |
I actually thought of unifying this. I'm not sure we need |
Anyway, I'm done with this for right now - can't afford to unexpectedly spend a lot of time on it. |
Just drop a couple of redundant log_event and move the last one so it covers all three See openwall#5722
Just drop a couple of redundant log_event and move the last one so it covers all three See openwall#5722
I had time to test this further today and it seems 100% OK. Added an innocent cleanup in #5725, also well tested. That PR also contains a log call just before session end, that says how many candidates were processed. Good to have with verifications like this one. |
Just drop a couple of redundant log_event and move the last one so it covers all three. See openwall#5722
Just drop a couple of redundant log_event and move the last one so it covers all three. See openwall#5722
Just drop a couple of redundant log_event and move the last one so it covers all three. See #5722
Opened #5729 for this. The fix I had posted in here was on top of my other changes here, which we didn't merge, and it may create other issues. So we'll need to come up with a different fix. We also need to choose what we fix first - simplify and optimize the code, or fix this bug. |
In fact, we may want to remove a level - move the logic directly into |
Looks like we (perhaps I) broke it in the recent week. Before recent changes:
Now:
The text was updated successfully, but these errors were encountered: