mirror of
https://github.com/openwall/john.git
synced 2026-12-03 18:45:21 +07:00
[GH-ISSUE #2072] New external 'hybrid' mode that allows work to be done similar to rules #1390
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#1390
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 (Mar 3, 2016).
Original GitHub issue: https://github.com/openwall/john/issues/2072
Outstanding issues:
github.com/jfoug/ExternalHybrid@1b7d8a2dceb64645fgithub.com/jfoug/ExternalHybrid@4453eb71bbRight now, we have 'filter', which can change the current word or cause that word to be ignored.
We also have 'generate' mode. In this mode, the external script builds the dictionary.
Why not add a 3rd mode, 'wordlist' or 'hybrid' mode. In this mode, I think we only need to add 2 builtins functions: next() and new()
new() is used as a hook for the external script to grab word[] data. Whatever has happened prior to this has produced the next candidate. new returns the count of values we will produce for this candidate (it can be zero).
next() iterates and when complete word[] is the next candidate value.
Within restore, we will need to be given the count of how many candidate FROM the current word were run. Also, restore needs the original base word (what was sent to the original new() function).
What do others think?
NOTE, if this capability is already there, then I am sorry, but I do not think it is. YES, we do have rules. YES we do have regex. BUT I do see a TON of usefulness in this request.
I have added this also as a core. I think we do this first in jumbo, BUT Solar may also want this in core, so if so, we will have to revert and use core changes. I have also not taken this to john-users, just in case there already is this capability that I am unaware of.
@jfoug commented on GitHub (Mar 3, 2016):
Here would be the reference external script
@jfoug commented on GitHub (Mar 3, 2016):
So right now, what I see these requirements:
@magnumripper commented on GitHub (Mar 3, 2016):
There might be modes where you can't know (or it's very expensive to calculate) the count beforehand. So an alternative could be that you call
new("baseword")and get either a candidate or NULL. If you got a candidate, you callnext()for a new candidate and keep doing so until that function returns NULL.@jfoug commented on GitHub (Mar 3, 2016):
I thought about that, but then thing about resume. Resume would have to be handled (might have to be) outside of external. For resume, jtr would have to set the word, then call next X number of times.
But tracking total and total_done, allows a extern to simply work.
YES, it is a bit harder. If it is 'too' hard for a format to know this, then at resume time, it would simply start over on this word. It could then set tot_candi to -1, meaning it does not know how many. Is that a viable option?
NOTE, this may be pretty easy to add. I do not know the code at all, but I think this is like a filter, BUT calls next until it bails before getting next word.
@jfoug commented on GitHub (Mar 3, 2016):
@magnumripper overall, what do you think of this 'idea' ? It literally just popped into my head about a 2 hours ago, when I realized that external could not be used in this way.
@jfoug commented on GitHub (Mar 3, 2016):
@magnumripper question......
When I am within the extern_hybrid_crack loop, do you think I should copy the baseword into a working buffer, and simply call next on the same buffer over and over, or should I strcpy the original word into the buffer before each call to next()
I 'think' copying one time would be best, but I can see benefits for both 'ways'..
@jfoug commented on GitHub (Mar 3, 2016):
@magnumripper I should not have to deal with nodes at all in this generator, correct? The parent generator would handle the node handling, OR should we handle them here in this generator also ??
@jfoug commented on GitHub (Mar 3, 2016):
Nope, I think I will have to deal with proper node handling in my function.
Well, I have it working already!!!!! (cept the node stuff). Soon, I will get the node stuff done, then test some more, and then get things checked in. This is cool, and was actually pretty easy.
@jfoug commented on GitHub (Mar 3, 2016):
Here is an initial 'look' that actually runs. Plug in the external script I did above, and bam, you have $[0-9]$[0-9] working!!!
@jfoug commented on GitHub (Mar 3, 2016):
Seeing that I am 'learning' external/compiler as I go, I am not 100% sure about the requirements of int_word and ext_word. I think I have them, but I may be doing more work than I need to. I will keep working on this, and hopefully tonite, we will have a new mode.
Then I might put out a request for comment on john-users (lol), or simply just list that there is a new external mode.
@jfoug commented on GitHub (Mar 4, 2016):
I think I have it for resume logic (and I have an 'ah-ha' moment for rexgen resume also).
I will use the 1 var ext_cur_candi 'hybrid' global variable. Used in this way.
in ext_new() if the script can easily count totals on a pre-word basis, it sets this to the number for this word. If it can not, it sets it to -1.
in the run, external_hybrid_crack() keeps track of the count of words returned for this word. Upon shutdown, both the 'total' and this current value are store in rec file.
before resume is called, external.c sets 'hybrid' global to be the current count (i.e. resume value).
Within resume() if the script can deal with it, it uses the hybrid value to recompute it's state, AND sets the hybrid value to the total number of candidates for this word (not number left, BUT total as if it were starting from scratch). If the script can not deal with resuming like this (i.e. too hard, or otherwise), it should do nothing, or not be defined at all.
Then within external.c's ext_resume() function, it checks hybrid after the script returns. If it is set to the proper total (remember, resume has that value also), then external.c will set a static int hybrid_resume to -1. If the value of ext_hybrid is still the same, OR not the proper max count, then this static hybrid_resume will be set to the stored current value.
Then within the crack loop, if that static hybrid_resume is set to -1, we do NOT call ext_new() since the ext_resume() has set the state properly for this word, and set hybrid_resume to 0. If hybrid_resume is > 0, then after we call ext_new(), we call ext_next() hybrid_resume times, and set hybrid_resume to 0.
;That should handle resume! I think I can do the same thing for rexgen. Just keep a counter, store it off, and then upon restart, simply do the next() logic that many times, dropping the words. Easy-peasy.
Now I just have to figure out how to work with the .rec files, lol.
@magnumripper commented on GitHub (Mar 4, 2016):
Our state is mostly just our last word, right? So I think we should not reset it. Besides, it eats performance.
@magnumripper commented on GitHub (Mar 4, 2016):
Good stuff. Commit to a topic branch so we can try it out!
@magnumripper commented on GitHub (Mar 4, 2016):
Not sure about node/fork stuff. It's more efficient putting that logic prior to hybrid ext (so different nodes simply uses different base words) - but OTOH some words may generate 0 candidates and others millions of them (theoretically). KISS for now.
@magnumripper commented on GitHub (Mar 4, 2016):
This is better than nothing but may take ages. So if we can do it faster, using some more state than just last word used, we should. At least for rexgen.
@jfoug commented on GitHub (Mar 4, 2016):
For rexgen the save/restore is easy. Rexgen (IIRC) has it's own save/restore code. We just have to get the context, save it off in the rec file, and then get it from the rec file and pass it back into rexgen. Should be a piece of cake. So what I said about a naive back-walk for rexgen is not needed.
But I am leaving that ability 'open' on external. Yes, it is MUCH better, if a script will know how many candidates are generated by the input word, and be able to easily restart given the original word, and the count. Possibly, we may want to do original word, count AND the last 'current-word', and allow the script to figure it out. I think we still need to allow the script to say it does not know how to resume, so just call the next() function that many times doing nothing with the words until caught up. There can be functions which are semi-one-way, where there really is no resume, and no way of knowing how many candidates there will be, until the hashing type function returns the completion result. Take for instance some modular type function. You simply remember the first value generated. Then when you generate it again, your are done (cycle reached). But does that happen after 2 candidates or 2 million? Without running it you do not know. So in that case, the script would simply have to tell Now, if we could call next() within restore() function in the script, then the script itself could self-iterate. BUT (at least at this time), compiler.c can not handle a function calling another function (would that be something we would want???)
@jfoug commented on GitHub (Mar 5, 2016):
Here is the first draft. Save/resume is there, but I am not 100% sure everything is right there. That was not the most simple 'hook'.
I forked bleeding, and put the changes into this fork, since this is a pretty encompassing change.
github.com/jfoug/ExternalHybrid@70c1cf7c85Things still outstanding
@frank-dittrich commented on GitHub (Mar 5, 2016):
Behavior when mixing --wordlist (or --incremental or --markov) with such an external mode and --mask (or --regex) needs to be discussed.
Should --mask / --regex be used on the candidates generated by --external, or vice versa?
Should the user be able to decide that sequence of "stacked" modes? If yes, how can this be implemented?
@jfoug commented on GitHub (Mar 6, 2016):
It looks like the hybrids should not do node splitting. It looks like it should be handled by the parent.
Here was a test
This generated an input file of 409600 candidates and a dictionary file of 4096 input words. These perfectly match. for each input word, appending 2 digits is the input file. Input is in dummy format.
When I ran a build where I had a simple modular node splitter in there, and ran with -fork=4, it appears that only 1/4 of the candidates were cracked? I then tested with a simple rule against the wordlist, and all 409k were cracked. When I removed the modular node code from external hybrid, then the hybrid code worked as expected, where each thread properly ran and each thread was given every 4th word and then did full processing on that word.
I need to test other base modes (like Markov, mask, pp to make sure they are ok), but it may be that hybrid's do not need to worry about node splitting.
Markov test:
in the above test, if I tried to add node logic to the hybrid-extern, then each fork node only handled 1/4 of the candidates.
So I think -fork=x work is done. It must be ignored, and the 'parent' word generator does the splitting. Each candidate word given to a external hybrid will not be given to any other thread, so that script has to generate ALL data for that word.
@jfoug commented on GitHub (Mar 6, 2016):
Note, currently, -markov does not allow rules. What is our reason to disallow rules? Yes, I realize most times, markov is stand alone. But what about targeted audits where you know many of the password patterns are leet or something like that. markov can bring many wordlike words into play, but it will not help in that situation. But rules (or better yet, this new hybrid-external) could allow these new word-like words to be tested with leet modifications run on top of them.
But for -fork, it is the same thing, each node gets only 1/4 of the data if we try to do node logic inside the external
@jfoug commented on GitHub (Mar 6, 2016):
I created a new format (it will live in unused) that is built specifically for testing restore of john. This format only has 1 valid hash:
$restore_tester$validSo that is the only line needed on the input side. Then every password tested will be cracked ;) It also has a nano-sleep in the crypt_all loop, so that it works like a slow format. It is unsalted. I am not 100% sure we need to test salted for resume, if unsalted is 'proven' to be correct, but I will listen to others if they think it is needed.github.com/jfoug/ExternalHybrid@15f7fdf6ef@jfoug commented on GitHub (Mar 6, 2016):
Ok, I found some behavior that I was not aware of. Not 100% sure how to handle this in hybrid-ext.
Here is a run, that I hit ^c pretty early on. Notice it ends with 000_95 and should expect the next word to be 000_96.
Now, the ext-v1 record is this.
So upon resume, the first word generated is 001_11 ?? Well, what this is, is 16 words further along than what we really want!?!? So it appears that within cracker, if a session is aborted, then the last block of data is NOT checked for cracked passwords?
Now, I have a couple questions.
@jfoug commented on GitHub (Mar 6, 2016):
I am adding the restore_tester format to bleeding. It is turning up strange behavior all over the place,, and I think it will really help getting these issues addressed. Seeing problems pretty much all over the place (like rules, etc), where the restart is not at where things left off, but many data is re-done.
@magnumripper commented on GitHub (Mar 7, 2016):
You need to support the UTF-32 flag too. It's trivial, just look for the existing use of it.
@magnumripper commented on GitHub (Mar 7, 2016):
Here's a test for your new code.
This dumb filter will simply mute every third word. After that, we should get the fourth and so on but the version I tested (this one) didn't.
@jfoug commented on GitHub (Mar 7, 2016):
That would be up to the script writer. In the simple example, I do not care about utf-32. But it should be usable for anyone writing a script that needs to handle that. (or am I not understanding what you are saying)
@jfoug commented on GitHub (Mar 7, 2016):
Was this the results you saw in the filter?
@jfoug commented on GitHub (Mar 7, 2016):
github.com/jfoug/ExternalHybrid@0b1f0a7cc9I believe that fixes the problem with filter you mentioned.
@jfoug commented on GitHub (Mar 7, 2016):
I just thought of a wonderful external-hybrid script.
'keyboard_smart'
This would be the normal keyboard script, BUT the input words to the script will be of this format:
S-m-M
S is the starting string. So, it could just be the letter 'q'
m is min length
M is max length.
So an input file with
q-8-12
a-8-12
1-8-12
k-8-12
would only do keyboard work for the letters q, a, 1 and k from length 8 to 12.
Keyboard is a very powerful external, BUT about 75-80% of the run is over areas that are very sparse in 'real' passwords. Being able to specify specific 'hot' ranges, allows running keyboard to work more like incremental. incremental is 'just' brute force (if run to completion), but it puts the best data first (or early on). But now with external-hybrid, we can do the same thing for keyboard.
@jfoug commented on GitHub (Mar 7, 2016):
@magnumripper please look over patch :
github.com/jfoug/ExternalHybrid@1b7d8a2dcewhich hopefully correctly deals with utf32 flag.@magnumripper commented on GitHub (Mar 8, 2016):
Yeah it looks right, I'll test it a bit.
@jfoug commented on GitHub (Mar 8, 2016):
There were several things busted in the patch above. This corrects those problems. BUT I am not 100% sure how to test the utf32 stuff, so I am not 100% sure I have everything as it should be.
github.com/jfoug/ExternalHybrid@3c8167c73b@magnumripper commented on GitHub (Mar 8, 2016):
I can't see why you had to merge it so soon but anyways, here's some notes from my testing. Most of them are very minor and/or trivial to fix.
ext_word[0] = int_word[0];restore after filter rejection is not (always) valid for UTF-32. Better saveext_word[0]off before filter, and restore that very integer afterwards.char word[1024]at all, isn't that just a redundant copy of int_word? If we do need it, I guess it shouldn't be 1024 but PLAINTEXT_BUFFER_SIZE.Also, the case where hybrid filter ends up just going through f_filter() and not to some downstream mode (like mask) can be optimized if we care: We can get rid of unneeded conversions back and forth between char and int (UTF-32 or not). To do so you need to stop calling
ext_filter()and instead callc_execute_fast(f_filter);with a little surrounding support code. BTW I have a pending patch for ext_filter() vs. UTF-32 (which isn't handled now - this is a bug regardless of the new hybrid mode). Edit this was applied ase14b768.@jfoug commented on GitHub (Mar 8, 2016):
Partly because I have other things which depend upon some of the foundations added by this change.
Yes, I knew it still had worts, BUT everything is working mostly, and there should be no legacy issues. Also, until new scripts are written the code is just sitting there.
@jfoug commented on GitHub (Mar 8, 2016):
Your first 2 bullet points should be handled here.
ee5c0d8I am not 100% sure about your 3rd one (the reject if > --max-len=10). Does it reject? I thought it just truncated. We should check other modes of input because I really think there are others which truncate and not skip overlong words.
@magnumripper commented on GitHub (Mar 8, 2016):
--max-len has (I think) always been about rejection, not truncation. At the time the --max-len option was introduced, the format's max length was always truncating so they served (or could serve) slightly different purposes. If you find --max-len merely truncating, it's a bug.
Since a few months (
3701702af), even the format's max-length (as well as --stdout=N) is rejecting unless format has FMT_TRUNC flag. This was proposed by Solar, and it was indeed a good idea.@magnumripper commented on GitHub (Mar 8, 2016):
And BTW when I tested the new mode, --max-length=10 neither truncated nor rejected!
@magnumripper commented on GitHub (Mar 8, 2016):
Here's an example of correct rejection vs. truncation
The --stdout=N works like a FMT_TRUNC format with max length of N. The reason the figure drops a little is because of rejected successive dupes after truncation. The --max-len=3 case results in much fewer candidates because it actually rejects the longer candidates right away.
@magnumripper commented on GitHub (Mar 8, 2016):
I see several problems with external maxlen, it was buggy even before this hybrid mode. Will fix tomorrow.
@magnumripper commented on GitHub (Mar 9, 2016):
Some fixes in
e649f8bbut the real -max-len reject stuff really needs to be in the user code because it gets really hairy with some combinations of encodings. For example, you can run./john -stdout -max-len=16 -ext:repeats32and get strings up to length 16 characters even though they are up to 64 bytes in UTF-8...