mirror of
https://github.com/openwall/john.git
synced 2026-12-03 18:45:21 +07:00
[GH-ISSUE #998] Implement "unrule" #600
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#600
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 @magnumripper on GitHub (Jan 5, 2015).
Original GitHub issue: https://github.com/openwall/john/issues/998
Brainstorming...
Say you had a utility you could run like this:
Goal: Produce the smallest possible wordlist that will still cover 100% of rockyou.txt when run with --rules=jumbo
One thing that makes this project interesting is we can actually start out pretty rough (even just supporting a single rule) and best-effort and improve it over time. Even if not perfect it will never be a bad thing.
I initially thought this would be a perl script - but then we'd need to port a whole lot of code to perl for reading config files and include directives, and pre-processing rules. And possibly even support those encoding options.
@magnumripper commented on GitHub (Jan 8, 2015):
Found this http://hashcat.net/forum/thread-1305.html
@jfoug commented on GitHub (Jan 8, 2015):
I really think this is something that could be done in perl. The rules themselves are not that complex, and would work wonderful in perl (just like I put the dynamic 'language' into pass_gen.pl). It would be no where near as fast as rule processing in JtR (it would likely be a recursive decent parser), BUT speed is not what we are looking for.
This might be a fun project to greater improve my Perl.
Now, the tr-sed 1 liner from epixiop is a wonderful pre-screening tool. We would assume that stripping out that crap would often be a good step to find many base words. Should it always be done, hard to say. If for instance, your rules did not have the 1337 rulez, then that is not good. Same thing for removing things like 143345password$ => password (or passwords) IF your rules do not have append of 6 numbers.
Now, if it would be better to pre-process a wordlist, or to build a 'proper' unruler to simply run rules in reverse order to find minimal valids.
I guess, what we should do, is to do some of these BY hand, talking them out. Algorithms will fall out of talk like that.
@magnumripper commented on GitHub (Jan 8, 2015):
Making it "perfect" for an exact set of rules is probably a very complex task though.
Say we start with this wordlist
Say we un-rule "capitalize" and change it to
Then we un-rule "append three digits" and drop the dupe so we end up with
This looks good. But the problem is that running this with those two rules will produce this:
So we never produce the original
Password123because we never apply both rules at once.@jfoug commented on GitHub (Jan 8, 2015):
It has to be done 1 rule at a time (in current john compat mode).
You really need to have this: 1 starting word list, and mimimized word list for each rule.
So here, original list is:
Password
Password123
The unrule list for append 3 digits is:
Password
The unrule list for capitialize is
password
password123
As you see, the Capitalize rule does not come into play. We have found a smaller wordlist from just the append-3num.
@magnumripper commented on GitHub (Jan 8, 2015):
So we should finally look at both lists and somehow produce either
or
@magnumripper commented on GitHub (Jan 8, 2015):
And given 4,000,000 rules after PP, how would we write that!?
@jfoug commented on GitHub (Jan 8, 2015):
by handing pp inline, and not 'creating' pseudo rules from the pre-processor.
If the rule is:
$[0-9]$[0-9]$[0-9]
we do not have to create 1000 separate rules. we simply write code that handles this.
Keep in mind, that 'really' is 1 rule, and to properly 'unrule' it, you should treat all 1000 separate rules as being the 'same' rule.
Thus,
password123
password234
password456
would simply generate a single
password
hash. If we had 1000 'separate' rules, then that would not help us out. Everything that happens within the macro rule, should be taken into account, not just each micro-rule part.
@magnumripper commented on GitHub (Jan 8, 2015):
I mean if we are to keep a list from each unrule to process later, we'll have 4M lists...
But perhaps my example is bad. Given an original wordlist of
After processing "Capitalize" we could definitely drop "Password" for good.
And after processing "append3" (with no "memory" of the previous operation except our one list is shorter now) we could definitely change the words with numbers in the end to not have them.
And this re-inserts "Password". So after dropping dupes we'd end up with
This is doable and it will produce all original words.
@jfoug commented on GitHub (Jan 8, 2015):
This is getting uglier and uglier. There are some really ugly things to take into account:
s?CY
@X
@?CY
Note, that we have no way to 'undo' that, in any 1 to 1 manner. What we would need to do for each of these, is to attempt to find words which would satisfy the purge/replacement, BUT still satisfy as many as possible OTHER words.
Many of the rules are easy to 'undo'. They are all 1 to 1, and done if a very specific order. Some of these purge / replacements may end up being close to show stoppers.
@magnumripper commented on GitHub (Jan 8, 2015):
So s?CY is "replace all chars of class ?C with Y" and @X is "purge all X"
I see no problem. The quest is not really to undo anything. The quest is to remove all words from the initial wordlist that will be produced by some other word + rule.
The result from original rockyou.txt + rules will produce a whole lot of dupes. I think after processing, we'll have a much shorter rockyou2.txt, that will still produce all the original words with rules applied, and more (eg. an original word of password123 may now be password + any tree digits).
@magnumripper commented on GitHub (Jan 8, 2015):
Maybe this is ambigous - and I'm not 100% sure what we want. It's either "original without rules is 100% covered with new list + rules" or "original + rules is a subset of new list + rules" and I think the latter is a superset of the former.
@magnumripper commented on GitHub (Jan 8, 2015):
I think we need to stick with "original without rules is 100% covered with new list + rules" or this will be hairy.
@magnumripper commented on GitHub (Jan 8, 2015):
This is still not it. If we proceed to process a rule "append 'ord' to the end" we would end up like this
But this will never produce "password123" or "Password456"
@jfoug commented on GitHub (Jan 8, 2015):
Ok, here is an algorithm (note, typing on the fly)
Ok, what find_best() does, is find the highest number of multiple words within the current word list that will be replaced by a single word, having that single word run through the rules. So something like password password1 password2 ... password9 would return 9 for Az,[0-9], since 10 words would be replaced by the single input password.
Then the RemoveWords() would return the proper 'base' word (which is added to the @newwords array, and all of the words would be removed from the @words array. In this case the word 'password' should probably also be removed, even though it did not satisfy the "Az,[0-9]," rule, the base word was contained within the output wordlist proper. Also, nCnt would be reduced by 10 for this 'hit'.
In this algorithm, we look for the 'best' hit, remove that word (based upon the rule), then look for the remaining 'best' hit based upon the words that are still left.
This ALMOST CERTAILY is not an optimal algorithm, but I assure you, it is valid, AND will exit when complete. There are only so many words in the @words array. As long as we can make that list smaller we continue. Once we can no longer make it smaller, we exit, and print both the replacement words, and whatever was left over. That should be a complete replacement set.
@jfoug commented on GitHub (Jan 8, 2015):
Ok, using the above algorithm, (very brain dead method, yes I know). I also created a hard coded specific 'simple' rule to check.
I created code for this rule:
A simple lower case. I have done NO optimizations. My code simply loads the rockyou.txt file like this:
my @words = <IN>;That takes 45s by itself and consumes a boat load of memory.My main loop is then this:
This takes right at 2 minutes to run. It returns 34 and password. If I grep -i -w password and cut 'only' pure password stuff, I get 34, so the count done by hash is working just fine
But it is probably WAY too slow (to satisfy usability in the original algorithm), and uses a shit load of memory.
NOTE, this rule 'could' be improved, and could removed a boat load of items. If we ran this 1 time, and then removed all words with > X number of reductions, and set X to 10, then 1 run and we remove quite a few.
I added this code (to count number where more than 10 were removed by lc), and here is results:
and here were the results:
@jfoug commented on GitHub (Jan 8, 2015):
Now again, "l" is not the 'best' rule, but I wanted to start there, since it is pretty much the easiest and quickest type of rule. But even here, 719 removals out of 14.34 million is pretty minor. However, this rule is O(n) in complexity. 1 word output for every one word input (well, less than this, since rejection rules will reject many from the wordlist). So this one is a pretty fast rule. It will run as fast or faster (close to it) as running the wordlist with no rules.
One other 'fun' thing, is that the rule rejections have to almost be done later on. So we will probably have to un-run the rule mangling, and only then, check to see if the rejection rules are satisfied.
@magnumripper commented on GitHub (Jan 8, 2015):
Could you not use (ie. remove) all of
keys(%map)after one run, instead of just the best hit? I'm not sure I follow.@magnumripper commented on GitHub (Jan 8, 2015):
I think I meant all of
keys(%map)that has a value larger than 1...@magnumripper commented on GitHub (Jan 8, 2015):
It took only 40s on my laptop.
Why limit to 10? I get a total of 513143 possible removals using this code (after yours)
I had the
contains_classthing commented out though.@magnumripper commented on GitHub (Jan 8, 2015):
Adding contains_class() decreased it to 493062 (and it took 57s)
@jfoug commented on GitHub (Jan 8, 2015):
What we are looking for is finding 'base' words, in the proper order, that each word replaces the most original words from the wordlist based upon 'some' rule. So to do that (in an ideal manner), we would use an algorithm like I first mentioned, which is to fine the BEST overall word (against all rules), and add that word to our 'new' set of words, removing all of the words which that rule would have found. Then repeat the same steps. Now, the repeat really 'could' be improved a lot. We could re-compute data for each rule, by simply removing the words. So after the initial load, we find that adding the word 'password' removed 250000 lines, based upon rule X, then we remove all 250000 of those 'final wordlist' words, and update each of the rule sets, undoing those 250k words. Then the next best word is rockyou. Say some specific rule and that base-word removes 63500 original words that are still left. We then remove those 63500 words, and recompute all the rules removing these words.
New thought. When we 'find' a base-word, we should then run that base-word through EVERY rule, and remove all found words for that base word. So take password. Then simply play that word back through the wordlist, using every rule and whatever words are still left, removing each of them.
That would be a pretty big speedup. We know probably 1000 (or 2500) GOOD base words. We could play each of those original 'known' good base-words through each rule, and remove those items out of the original list, so that instead of loading 14.34 million words, we only load 3 or 4 million of them. That is a pretty huge improvement. I will look at something like that first. This really is a O(N^3) or possibly a O(N^4) problem. Reducing the size of input greatly improves this problem.
@jfoug commented on GitHub (Jan 8, 2015):
The time may be limited upon memory (also the perl). I am using cygwin, and I ASSURE you, it is slow. I also only have 8GB on this box. More memory would almost certainly run quite a bit faster.
@jfoug commented on GitHub (Jan 8, 2015):
Side thought.
creates a quick 'input' file. (980mb). This took about a minute to create.
Then
This took about 20s to load but only 10s to run.
It only found 756521 hashes however (5%). I was expecting MUCH more than this to be removed.
@magnumripper commented on GitHub (Jan 8, 2015):
Cracking 750K/5% of a real password database using a 3546 line wordlist is a feat. Also, the real database had lots and lots of dupe passwords so it would be a LOT more than that.
@jfoug commented on GitHub (Jan 8, 2015):
Ok, I am not 100% sure things are working properly, but it 'could' be due to other words being in password.lst file.
This data was generated from -rules:jumbo using password.lst
This was a complete new run, using 'just' the line "password" in a input file:
@jfoug commented on GitHub (Jan 8, 2015):
Yes, I know, the data that I am using is greatly reduced, since the duplication has been removed. This is rockyou 'unique' words. But I did expect a higher success with the -rules:jumbo AND a high quality wordlist.
@magnumripper commented on GitHub (Jan 8, 2015):
Try -rules:all and see how much better it gets...
@frank-dittrich commented on GitHub (Jan 8, 2015):
And "unrule" password.lst first!
@jfoug commented on GitHub (Jan 9, 2015):
Here is a 'new' better baseword sorted list:
run epixoip baseword 1-liner:
cat rockyou.dic | tr A-Z a-z | sed 's/^[^a-z]//g; s/[^a-z]$//g; y/112345677890@$!#/ilzeasbzvbgoasih/; s/[^a-z]//g; /^$/d' >basewords
sort it by count:
LC_ALL='C' sort < basewords | LC_ALL='C' uniq -c -d | sort -n -r > basewords.cnt
head -7830 basewords.cnt | awk '{print $2;}' > bestbase.lst
7830 was all lines with 100 or more 'base' words.
Now I will run with THIS file, and see how things go (both jumbo, and then all rules), and follow up.
@jfoug commented on GitHub (Jan 9, 2015):
So here, we have 10% processed with -rules:jumbo and the top 7800 'base' words. This shows that the 3500 words in 'password.lst' is very strong, since it was general words, and not specifically FROM the RU list. These 7800, were specially built data right from the RU data.
@magnumripper commented on GitHub (Jan 9, 2015):
Here's rockyou with original dupes
That's over 28% of the passwords using a 3500 line wordlist. Pure awsomeness!
And using -rules=all
This took it past 33%. Solar's wordlist is amazing. Add -loopback for even more cracks without actually adding any new data. I can't test this, it will take a month using -rules=all but it cracked yet another 3.5 million passwords (counting dupes, it was 1 million unique ones) in three minutes which took the total crack rate over 44%. This is almost unbelievably good.
@magnumripper commented on GitHub (Jan 9, 2015):
For -rules=jumbo it's much faster though. Starting with the 28% cracked with -w -rules=jumbo from above and running loopback:
...we got over 50% of the passwords in no time using a 3500 line wordlist. Amazing!
@magnumripper commented on GitHub (Jan 16, 2015):
I added a perl script that does it the "epixoip way" plus removes dupes and outputs sorted by count. It's a very good start.