mirror of
https://github.com/openwall/john.git
synced 2026-12-03 18:45:21 +07:00
[GH-ISSUE #2099] external hybrid mode needs 'pushed' fix_state handling #1405
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#1405
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 @crioux on GitHub (Mar 25, 2016).
Original GitHub issue: https://github.com/openwall/john/issues/2099
when doing hybrid external on top of wordlist, the 'fix state' logic called by crk_process_key was calling the crk_fix_state from wordlist.c, not the ext_hybrid_fix_state. This had two bad effects:
I have attached a patch, and as a bonus, attached a hybrid 'leet' mode word rotator for your cracking pleasure. (i needed it for lc7, so here you go.)
p.patch.txt
hybridleet.zip
@jfoug commented on GitHub (Mar 25, 2016):
When this resumes, does it properly continue with only the permutations that should be left on the current items? Getting these inter-restore methods restoring properly is not trivial, and some of the hooking locations were not properly 'there'. The inner-resume code in the multi-salts has also been a challenge. I will look at this code shortly.
Yes, I thought one of the first externals that would go, would be a 'super' leet generator. There is only so much that can be done with rules, and there is quite a bit of overhead in the rules, since only a singular mask will work, and many words will simply be filtered out. But in an external mode, you can easily build your permutation logic 1 time for a word, and then each iteration is very fast, morphing to the next word, changing only a byte or 2 most times.
All sorts of fun could be done with that mode. Case permuations, permutation of changes.
So things like basketball could be b4$KeT6a1! pretty easily, BUT doing that in rulez would SUCK, and would be very slow. Permutations like that before hybrid external were pretty beyond what could be done inside of john, and required an external script, and redirection.
@crioux commented on GitHub (Mar 25, 2016):
The code that is committed does not do this properly. It also does not properly take the base_word into consideration. When I created a dictionary file with one word (smithsonian), and used the following command line, I got the following output, which was missing the actual word:
because logic for 'do load' did not consider the first word to be something that needed to be put into ext_word. Once I fixed that, I realized that the restore logic wasn't working either, due to the calls to ext_hybrid_fix_state being missing. To test this, i hardcoded jtr to segfault out after 50 iterations of hybrid on the first word and then I restored the resulting .rec file, to ensure that this code does the right thing. Here's the output on my system with the one-word dictionary:
@crioux commented on GitHub (Mar 25, 2016):
And yea, the l33t generator i wrote looks like this:
etc etc for the rest of the permutations.
@jfoug commented on GitHub (Mar 25, 2016):
One thing that may help in testing this type stuff, is a format that has been placed into the ./src/unused directory. Is is called restor_tester_fmt_plug.c Is is just a simple format, that every word given to it is properly cracked. The format simply delays a short time between words (to allow a 'q' or ^c) to be issued.
That way, you can know what you SHOULD be seeing, and make sure that the ending .pot file contains the right words, in order, with no gaps, and with no overlap.
It was done after the external hybrid (which I thought was working).
@jfoug commented on GitHub (Mar 27, 2016):
This patch is closer but still not right.
So yes, it did restore, but did not save a .rec file properly after restore.
@jfoug commented on GitHub (Mar 27, 2016):
Also, is the patch missing 16 lines? Have you made other edits to external.c that are not listed here?
The part I am talking about is line 584 in original, line 600 in the new version. I do not see any 16 lines added.
@jfoug commented on GitHub (Mar 27, 2016):
Ok, I think I found the problem. @crioux please make this change to your code, do your testing, and make sure you think it is fixed. The problem appeared to be that we were clearing out the resume counter that would be stored back to the .rec file. The ++ is needed, so that after the first restore (which worked fine), subsequent restores were off by 1. I not sure why, but without it the first restore after a real start would restore properly, but then every restore after that would replay the first word. The += 1 fixes that, if only done when the code detects the restore. I tried to do this in the ext_restore_state_hybrid() function, but if done there, I was missing a record on the first restore (i.e. the first restore would be 1 too 'deep'). After that the others worked. However the += 1 change I have in the code above, handles all cases of restore I have tossed at it. But I would like to see how it works with other external-hybrid scripts and you seem to have done some (finding this bug in the first place).
In your code, Change this:
to this
@crioux commented on GitHub (Mar 28, 2016):
Yea, my bad. I removed stuff from the patch manually. Sorry if that messed you up.
If you want to see my original, it's on my jtrdll fork, but that has a lot of very specific edits well that dont have a place today in mainline JtR (github.com/l0phtcrack/jtrdll). I will incorporate this edit and let you know how it goes, but the logic is sound.
@jfoug commented on GitHub (Mar 28, 2016):
I am pretty sure you will find the same problem I was seeing, prior to the change I made. No, I was pretty comfy with your patch, but due to seeing problems still, I was just not sure that there was not something missing that you had done. But after finding that problem, I will assure you, it needs fixed.
That was my original coding, you just left it alone. Yes, the first resume was happy as could be BUT if there was a 2nd resume while STILL in the same word of the external run, then the subsequent restore was NOT starting off in the right place.
I just want to have another set of eyes look at it, since the resume logic is pretty subtle. It does not take too much for it to be very wrong.
@crioux commented on GitHub (Mar 28, 2016):
I was able to get it to do a weird thing. I'm not sure if it's just me or not.
Try creating a dictionary with two words in it. (i used 'smithsonian' and 'rubberduck')
Have it abort after 30 rounds of external. I ran with this edit:
Unless you're on windows, that won't work exactly, but invoking a sigint at that point should suffice.
I ran with: john -stdout -wordlist=c:\temp\p.dic -external=hybrid_example
That gave me:
smithsonian 00 through 30
Then ran with : john -rest
That gave me
smithsonian 31 through 61
Then again and got
smithsonian 62 through 92
Then again and got
smithsonian 93 through 99, rubberduck 00 through 23
THEN AGAIN i got THIS:
Not sure why yet, will review.
@crioux commented on GitHub (Mar 28, 2016):
This is the john.rec file at the point where it craps out
@crioux commented on GitHub (Mar 28, 2016):
This is a windows only bug
the last '110' in that .rec file should not be there because it is left over from a previous .rec file that was overwritten. The unix version of jtr does an ftruncate, but there is not one there for MSVC.
I fixed it on my fork with this:
@crioux commented on GitHub (Mar 28, 2016):
Anywhere you see ftruncate special-casing for MSC_VER , you can use _chsize instead.
Anyway, your edits and this last one by me, make it so my test cases all passs.
@jfoug commented on GitHub (Mar 28, 2016):
This is WONDERFUL news. Especially the #ifdef for cygwin, doing the ftruncate to 0 bytes (early on in rec_save), as was the _write(0) for mscv. I think BOTH of those are problems.
I have been fighting with a bug in cygwin. I get restore files that are full of null bytes (proper size, just all nulls). It happens randomly, and seems to happen in -fork running. This is something to look at here. I have been pulling hair out trying to find a likely problem I have chased about 3 red herrings so far, but this one looks promising. I will look for other areas where _chsize can be used, and possibly do a #define against ftruncate, if it has the same behavior
@jfoug commented on GitHub (Mar 28, 2016):
I am going to commit what is in external.c I will spend a bit more time looking at the side effects to the external.c changes. I think the cygwin truncate to 0, and the VC write of 0 bytes to start of the file (at the top of rec_save) will be removed. I think they are nothing but problems. Obviously, it is NOT truncating the file for vc, and I am hoping this is the recovery file corruption problem I am seeing in cygwin.
Once I get a better feel that the changes to recovery.c are right, I will check them in also.
I will leave this issue open for now, since until the recovery.c is updated, your VC builds still have issues.
@jfoug commented on GitHub (Mar 28, 2016):
Can you test out these changes within your DLL ?
The close(dup(fn)) is an old trick I know of that forces the directory entry to be updated (in case of power outages).
Btw, you are not able to run fork under vc, correct? I have never tried but I think the system call is not there anyway.
@crioux commented on GitHub (Mar 28, 2016):
Spoke too soon. The whole fix_state logic seems really complex. I see what you mean @jfoug.
Now, with the changes I've made there is a problem where resuming starts over from the beginning of the wordlist, because wordlist_hybrid_fix_state gets called but fix_state never does, hence the rec file still says line 0 of the wordlist.
I have a fix coming I think but it's a pretty sweeping change of the fix_state logic that will require someone to review it. I will post a patch here, and reference my jtrdll commit as well once i have it tested. there's a simpler way to arrange all of this stuff i think such that it's harder to break it.
@crioux commented on GitHub (Mar 28, 2016):
Okay, this is a hairy patch, but the logic is basically this: if you're chaining through to a 'hybrid' crack, the thing that's being chained to should preserve the 'crk_fix_state' and then restore it upon exit.
This should probably be handled by a specific piece of code that encapsulates this functionality in cracker.c, but for now, I've done it this way to keep from changing things too drastically (hah!)
Specifically, the 'save_fix_state/restore_fix_state' logic should only be written once, and in cracker.c alongside the other code that cares about crk_fix_state().
Anyway, this does away with some of the complexity around when to call fix_state, and reduces the amount of random hybrid_fix_state type calls all over the code in random inconsistent places.
I made the appropriate changes to the 'regex' and 'prince' cracking modes as well, but i have no way of testing those as they are not being used in my environment, so consider that part of the code untested. 'But It Should Work Or Something (tm)'.
Attached, my jtrdll fork has this committed on commit 20a4986.
fix_state.diff.txt
@crioux commented on GitHub (Mar 28, 2016):
Also, the thing chaining through, should call its own fix_state() after each call to the chained mode. so if you are in wordlist, and call do_mask_crack, when it returns, call fix_state. That's it. If you're in mask, and you chain to do_hybrid_external_crack, when it returns, call mask_fix_state (or whatever you have as the current fix_state for where you are, whatever you initialized crk_fix_state to at that point in the code. (yes, all of those calls should probably just be calls to crk_fix_state() rather than each individual fix_state function), anyway that's the idea.
@crioux commented on GitHub (Mar 28, 2016):
So yea, that patch still needs some work. Eh, I'm working on it. Will let you know when it passes all my tests. But it's the right idea i think. Off for the night, more tomorrow.
@crioux commented on GitHub (Mar 28, 2016):
Okay, patch seems to be working better now. Now this patch (commit L0phtCrack/jtrdll@bcbee16 on jtrdll fork) and the one before it (commit L0phtCrack/jtrdll@20a4986) are ready for review by anyone that cares to do so :)
Notes:
for example this:
was adding extra characters to the end of that string from the mask save state. So i reworked the loop to use the 'count' to ensure that it doesn't read past the end of the string and now things are working swimmingly.
@jfoug commented on GitHub (Mar 28, 2016):
I made somewhat same change last nite:
github.com/magnumripper/JohnTheRipper@476f044ffdLooks like in your restore_state (external), you miss the chomp ;)
@jfoug commented on GitHub (Mar 28, 2016):
I have tossed off a email to @magnumripper to also look at this patch, since it IS pretty deep into code, and since up to this point, most of the extra hooks added for the 'hybrid' type save/restore was done by him (I think).
I do think we really do need to better 'unify' how the save/restore logic works, so that we can show that it is working for all possible combinations of stacked hybrid work.
Like I mentioned earlier, this code is NOT trivial to work with, and or to get right. But I am hopeful that it can be simplified/unified to work the same way for all types.
@jfoug commented on GitHub (Mar 28, 2016):
NOTE, there is some pretty huge changes which are also in the works, that I have done for multi-salt resuming. I will certainly have to see how some of this plays with those changes.
I actually think quite a bit of what you have here, IS stuff that I am also doing within that multi-salt PR that has been working on.
@magnumripper commented on GitHub (Mar 30, 2016):
I probably have no time to look closely at this until friday, at best.
@jfoug commented on GitHub (Mar 30, 2016):
I understand. I also have not looked to deeply at this change. NOTE, I need to do some comparisons with what is done in these patches, vs what I found that I had to do to make multi-salt restore work. Likely there is a little of both changes that need to be put together, and merged into a single save/restore logic change.
@jfoug commented on GitHub (Apr 3, 2016):
Now that 2087 is merged, I am going to look at what parts of this patch are still relevant, and which need to be placed into bleeding jtr code.
@jfoug commented on GitHub (Apr 3, 2016):
Issues from here: L0phtCrack/jtrdll@bcbee16 now addressed
ba18f89@jfoug commented on GitHub (Apr 3, 2016):
github.com/L0phtCrack/jtrdll@20a4986has been tweaked to comply with core style, and is now located in it's own branch: https://github.com/magnumripper/JohnTheRipper/tree/resume-fixesThat branch has the multi-salt code also. I have not started testing on that branch, it is just code placed there (by hand, so hopefully it is the same as on the jtrdll tree).
@jfoug commented on GitHub (Apr 12, 2016):
PR #2114, so that the branch has some destination. BUT more testing will be needed.
@magnumripper commented on GitHub (Aug 24, 2016):
@crioux I committed your HybridLeet mode to Jumbo.
@magnumripper commented on GitHub (Oct 24, 2016):
@crioux #2114 and then (rebased) #2308 contains your patch but they introduce resume bugs. Are you sure your jtrdll branch resumes correctly?
Example:
This ends up with missed candidates.
@crioux commented on GitHub (Oct 25, 2016):
It worked for me the last time I looked at it. I will try your test there and see what I get.
@crioux commented on GitHub (Oct 25, 2016):
Okay, I am seeing some missed candidates. How many missed candidates are you seeing on your test? For whatever reason I'm only getting 173 out of 1111 candidates with that test, and if i remove the break, I am getting a bunch of the same candidates found every second that have already been found, which doesnt make much sense to me.
@crioux commented on GitHub (Oct 25, 2016):
@crioux commented on GitHub (Oct 25, 2016):
(maybe i'm just reading the status output wrong too)
@magnumripper commented on GitHub (Oct 25, 2016):
Your initial run cracks 173, the resumed runs crack nothing. Removing the break makes no sense, it's there to stop the loop once the session is complete. A "max run time reached" will return false while a complete run will return true and thus break.
@crioux commented on GitHub (Oct 25, 2016):
Yea, i get that. My jtrexe build doesn't do the return code the same way as john.exe does, so the break wasn't ever stopping the loop. Anyway, I'll let you know what I find when I get to this later today.