mirror of
https://github.com/openwall/john.git
synced 2026-12-03 18:45:21 +07:00
[GH-ISSUE #2122] Rule on Rule stacking #1417
Labels
No labels
bug
core branch
documentation
enhancement
enhancement
fixed - pending verify
fuzz bug
good first issue
invalid
invalid
maintenance/cleanup
new cracking mode
new format
new tool
non-trivial
notes/external issues
portability
question
RFC / discussion
testing
WONTFIX
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
openwall/john#1417
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @jfoug on GitHub (Apr 17, 2016).
Original GitHub issue: https://github.com/openwall/john/issues/2122
Called 'multi-rule' in hash-cat. This seems pretty easy to add. I would think we would stack like this:
this would produce: -rules=rule1+rule2+rule3 (note the command line syntax is not set in stone, just something I typed on the fly)
But I could see 'other' ideas on how to stack this (like having
a$-$1 then c$-$1 etc@jfoug commented on GitHub (Apr 18, 2016):
Note, it would be a smart thing to do some analysis of rules also for this (and even for just standard rules). I have been seeing some crap like this, when analyzing some of the hashcat rule sets (first TONS of dupes, but then some no-op things). The 'easiest' way was if there was some cannonzation function.
@magnumripper commented on GitHub (Apr 18, 2016):
See also #745
@jfoug commented on GitHub (Apr 18, 2016):
You want me to close this one, and move these messages to the prior?
@jfoug commented on GitHub (Apr 18, 2016):
I think one of the hardest things, is to remove duplicates when we start stacking rules, I have been working on some new code (for rules work), and a couple things I have been working on may help in this.
One is rules cannonization (hard). But this actually can improve runtime (by reducing rules AND by allowing some rules to optimize themselves in the code), AND this also can find dupes. The nice thing about cannonization, is that you can also frequently optimize. So $1$2$3$4 can become 1 rule Az"1234" (just 1 rule), and $1^4$2^3$3^2$4^1 or $1$2$3$4^4^3^2^1 or ^4^3^2^1$1$2$3$4 can all become A0"1234"Az"1234" which shows they are the same, and reduces 8 to 2
One is backfinding a rule (or many rules) targeting single mostly, based upon found found word, and input word(s). This is also a good way to find dupes, when the finding code is checked against all rules, and not just the first that cracks the word. It is also really good at finding THE good rules out of an ocean of rules that work.
One is dupe finding in a targetted manner.
There is only one program I am actually writing (it will be a symlink to john, likely called rulez). But I am also doing some other prototyping in some simple code and perl scripts.
@jfoug commented on GitHub (Apr 18, 2016):
How about this for 'syntax' ?
-rule=r1+r2+r3
-rule=r1&r2&r3
-rule=r1&+r2&+r3
-rule=r1^r2 (not showing all 3) NOTE, in this case it is not useful, but for many rule sets it 'could' be useful mixing order.
There could probably be other operators. - would come to mind, and be VERY useful.
Minus would be -rules=r2-r1 This would run using r2 rules, but removing all r1 rules found from r2 i.e. -rules=r1 was already done.
Ok, I know this is a bit,but hell, if we are going to do this, then why not do it right, and allow it to be more useful (and more optimal) to the end user.
@jfoug commented on GitHub (Apr 18, 2016):
here is a good example of dupes (I have many, but here is another)
In this case, we can normalize by:
So canonizing the above rule(s) would be
The hard part of canonizing, is to find the 'rules', and then parsing and handing adjustment of the data. It gets more tricky when more and more rules and their interplay with each other are put together.
The other way I am dup looking, is by using the rules themselves, looking for identical end results, then grouping rules that produce identical, and continuing to feed them different data (rotating letters, varying lengths, etc), to weed out the ones that are not really duplicate. This probably is not a valid way to do things at run time. This would be offline optimization work on existing rule sets.
Some examples of 'dupe' rules, but which only run testing may show are things like:
This could be 'argued' (inaccurately), that these are not dupes, since the 2nd one will output the original candidate for words less than 6 bytes. But I would disagree, and state that they are dupes. Now, the 3rd/4th ones, are ONLY a dupe with the first if word is > 6 bytes. Other than that, in JtR mode, it will add a 'b' char to the input word. But they are 100% duplicate to each other, and would be very hard to tell apart from each other.
@frank-dittrich commented on GitHub (Apr 18, 2016):
The etc is important here. There are other commands which have to be considered ({, }, ], d, r, f, ...).
Future releases might add even more of such commands, So, instead of "blacklisting" commands which don't allow shuffling the o commands, you'd need to define a whitelist of commands which allow such shuffling.
Not sure whether this will be worth it.
@jfoug commented on GitHub (Apr 18, 2016):
It may not be 'worth' it, but if/when we start stacking rules, having ability to quickly get as close as we can to a canonized rule allows removal of duplicates.
If you stack 3 or 4 rule sets (or even 2 big ones), and allow 2 way many to many stacking there are literally millions of rules that get generated, and a huge percentage of these are likely to produce identical results. If these can not be trimmed down, then the end performance is only a tiny fraction of what it should be.
Now, trying to get things 100%, I do not think that is worth the time involved. Rules are HARD. Without generating a pure interpretive environment, it is really hard to always know that 2 things are identical. But there are many things which CAN be normalized and done some fairly easily, and lots of dupes can get removed.
Things like:
and finding as many of these 'easy' canonizations, ends up finding MANY dupes, AND also optimizes. This work is actually pretty easy, and then it could simply be expanded as additional 'safe/easy' canonization rules are added. Some of the rule sets appearing are very 'good', but are not great because of a relatively high volume of duplicate rules. When we allow "rule x rule" logic, that problem will be exponentially worse.
@frank-dittrich commented on GitHub (Apr 18, 2016):
Unless the character after $ or ^ is ". Then you have to pick another character to enclose that string.
Just removing plain duplicate rules would be a worthwhile first step.
AFAIK, currently, the preprocessor would remove duplicate
But it will still produce duplicate $[0-9] for this:
Or was there any recent change in jumbo I missed?
@jfoug commented on GitHub (Apr 18, 2016):
Nope, I think rpp will remove these (I think). It is done with rules_remove_dups() at load time.
I see many rule sets which have 123k, end up with 121k when loaded. It is this dup removal. There are dupe lines like:
that will get removed. This is done after the apply_rules call which converts the first into the same string as the 2nd. So in your case, there would be 95 rules, and then 10 more dupes, then during rule loading, those 10 are thrown away (I am pretty sure, but not 100% certain).
@jfoug commented on GitHub (Apr 19, 2016):
This 'rule-x-rule' may be better done as a offline script (for the time being). I will see if I can whip up a POC, it should not be too hard.
@jfoug commented on GitHub (Apr 19, 2016):
Well, here is config.c functions converted to Perl, just a bit simpler, lol. This jtrconf.pm module will be placed into run, and then we can easily make scripts to load and process john's configuration. (Not bad for 130 or so lines, lol)
@magnumripper commented on GitHub (Apr 19, 2016):
Not really, just consider it. Fixing either may close both - or not, depending on what we end up doing and planning.
@jfoug commented on GitHub (Apr 20, 2016):
there is still work to be done on the script. stacking wordlist on wordlist gives lots of lines that fail. Things like this are not happy in rpp:
The 2nd -c is triggering a 'invalid length'. That may be a bug in my HC logic also, I have not checked. But this is easy to work around. All I need is to unique the - rules, and then probably pack them up against the start of the rule. But after fixing things like this, stacking wordlist on wordlist is 'working'. I am finding a couple of words, but it's pretty slow. Yes, there are MUCH better rule sets to stack, and things will likely work better (I am trying o1 and a num appender and it is working, BUT that rule can be done with a 1 liner using the RPP)
@magnumripper commented on GitHub (Aug 14, 2016):
Perhaps we should do this at a smarter level, using 2 (or n) rule contexts (and rpp contexts). That should work perfectly but may not be the very fastest solution.
@magnumripper commented on GitHub (Dec 14, 2018):
5be3ed49Stacked rules. New option
--rules-stack=(SECTION[,..]|:rule[;..])adds a second pass of rules, applied after normal processing.Example:
--single --rules-stack=ShiftTogglewill run single mode's normal rules fully through the first (no-op) rule in the toggle ruleset. Only then will the latter set move on to its second rule, the main rules are rewinded, and so on.In all other cases, eg.
--wordlist --rules --rules-stack=ShiftToggle, the stacked rules (ShiftToggle in this case) will do a full pass before the base rule moves to its second rule.This option also works fine with ALL modes that normally don't support rules at all, eg.
--mask=password?d?d?d --rules-stack=shifttogglealthough that will disable any GPU-side mask accleration.You can even use
--wordlist --rules-stack=SomeRulewithout using any base rule. The difference is in how it iterates: Normal--ruleswill run all words through the first rule before moving the second rule, while--rules-stackwill apply all rules to the first word before moving on to the second word from the list.My plan was doing a PR for the above commit but I accidentally pushed it to main branch. No biggie, it got past the bots and I tested it a lot already over last week. Beware of teething problems though.
This new functionality has no extra resume support so if the 2nd ruleset is huge, resuming may re-do a good deal of work before catching up. OTOH it shouldn't miss anything (that would be worse).
A known problem (by design) is the stacked rules are applied LAST, so they are applied after external mode and/or filter too. Shouldn't be a problem as long as you know it (perhaps a warning notice should be printed when used with external filters). Also, if used with a GPU-side mask capable format, the internal mask generation will be disabled, no way to work around that really. Though I think with some work I can make it work with hybrid mask - as of now it doesn't.