[GH-ISSUE #2099] external hybrid mode needs 'pushed' fix_state handling #1405

Open
opened 2026-10-15 04:15:41 +07:00 by bsakaguchi · 38 comments
Owner

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:

  1. ext_hybrid_fix_state was not being called as frequently as it should have been or in the right place
  2. wordlist's 'fix state' was being called too early, when the word was not yet complete, and in the case of an interruption, the 'restore' would resume at the next word, not the current one, skipping all the remaining permutations of hybrid external on that word.

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

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: 1. ext_hybrid_fix_state was not being called as frequently as it should have been or in the right place 2. wordlist's 'fix state' was being called too early, when the word was not yet complete, and in the case of an interruption, the 'restore' would resume at the _next_ word, not the current one, skipping all the remaining permutations of hybrid external on that word. 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](https://github.com/magnumripper/JohnTheRipper/files/189052/p.patch.txt) [hybridleet.zip](https://github.com/magnumripper/JohnTheRipper/files/189050/hybridleet.zip)
Author
Owner

@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.

<!-- gh-comment-id:201135182 --> @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.
Author
Owner

@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:

> john --stdout --wordlist=c:\temp\p.dic --external=Hybrid_example
_00
__01
___02
____03
_____04
______05
_______06
________07
_________08
__________09
___________10
____________11
_____________12
______________13
_______________14
________________15
_________________16
__________________17
___________________18
____________________19
_____________________20
______________________21
_______________________22
________________________23
_________________________24
__________________________25
___________________________26
____________________________27
_____________________________28
______________________________29
_______________________________30
________________________________31
_________________________________32
__________________________________33
___________________________________34
____________________________________35
_____________________________________36
______________________________________37
_______________________________________38
________________________________________39
_________________________________________40
__________________________________________41
___________________________________________42
____________________________________________43
_____________________________________________44
______________________________________________45
_______________________________________________46
________________________________________________47
_________________________________________________48
__________________________________________________49
___________________________________________________50
____________________________________________________51
_____________________________________________________52
______________________________________________________53
_______________________________________________________54
________________________________________________________55
_________________________________________________________56
__________________________________________________________57
___________________________________________________________58
____________________________________________________________59
_____________________________________________________________60
______________________________________________________________61
_______________________________________________________________62
________________________________________________________________63
_________________________________________________________________64
__________________________________________________________________65
___________________________________________________________________66
____________________________________________________________________67
_____________________________________________________________________68
______________________________________________________________________69
_______________________________________________________________________70
________________________________________________________________________71
_________________________________________________________________________72
__________________________________________________________________________73
___________________________________________________________________________74
____________________________________________________________________________75
_____________________________________________________________________________76
______________________________________________________________________________77
_______________________________________________________________________________78
________________________________________________________________________________79
_________________________________________________________________________________80
__________________________________________________________________________________81
___________________________________________________________________________________82
____________________________________________________________________________________83
_____________________________________________________________________________________84
______________________________________________________________________________________85
_______________________________________________________________________________________86
________________________________________________________________________________________87
_________________________________________________________________________________________88
__________________________________________________________________________________________89
___________________________________________________________________________________________90
____________________________________________________________________________________________91
_____________________________________________________________________________________________92
______________________________________________________________________________________________93
_______________________________________________________________________________________________94
________________________________________________________________________________________________95
_________________________________________________________________________________________________96
__________________________________________________________________________________________________97
___________________________________________________________________________________________________98
____________________________________________________________________________________________________99

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:

> john --stdout --wordlist=c:\temp\p.dic --external=Hybrid_example
smithsonian_00
smithsonian__01
smithsonian___02
smithsonian____03
smithsonian_____04
smithsonian______05
smithsonian_______06
smithsonian________07
smithsonian_________08
smithsonian__________09
smithsonian___________10
smithsonian____________11
smithsonian_____________12
smithsonian______________13
smithsonian_______________14
smithsonian________________15
smithsonian_________________16
smithsonian__________________17
smithsonian___________________18
smithsonian____________________19
smithsonian_____________________20
smithsonian______________________21
smithsonian_______________________22
smithsonian________________________23
smithsonian_________________________24
smithsonian__________________________25
smithsonian___________________________26
smithsonian____________________________27
smithsonian_____________________________28
smithsonian______________________________29
smithsonian_______________________________30
smithsonian________________________________31
smithsonian_________________________________32
smithsonian__________________________________33
smithsonian___________________________________34
smithsonian____________________________________35
smithsonian_____________________________________36
smithsonian______________________________________37
smithsonian_______________________________________38
smithsonian________________________________________39
smithsonian_________________________________________40
smithsonian__________________________________________41
smithsonian___________________________________________42
smithsonian____________________________________________43
smithsonian_____________________________________________44
smithsonian______________________________________________45
smithsonian_______________________________________________46
smithsonian________________________________________________47
smithsonian_________________________________________________48
smithsonian__________________________________________________49

> john --restore
smithsonian___________________________________________________50
smithsonian____________________________________________________51
smithsonian_____________________________________________________52
smithsonian______________________________________________________53
smithsonian_______________________________________________________54
smithsonian________________________________________________________55
smithsonian_________________________________________________________56
smithsonian__________________________________________________________57
smithsonian___________________________________________________________58
smithsonian____________________________________________________________59
smithsonian_____________________________________________________________60
smithsonian______________________________________________________________61
smithsonian_______________________________________________________________62
smithsonian________________________________________________________________63
smithsonian_________________________________________________________________64
smithsonian__________________________________________________________________65
smithsonian___________________________________________________________________66
smithsonian____________________________________________________________________67
smithsonian_____________________________________________________________________68
smithsonian______________________________________________________________________69
smithsonian_______________________________________________________________________70
smithsonian________________________________________________________________________71
smithsonian_________________________________________________________________________72
smithsonian__________________________________________________________________________73
smithsonian___________________________________________________________________________74
smithsonian____________________________________________________________________________75
smithsonian_____________________________________________________________________________76
smithsonian______________________________________________________________________________77
smithsonian_______________________________________________________________________________78
smithsonian________________________________________________________________________________79
smithsonian_________________________________________________________________________________80
smithsonian__________________________________________________________________________________81
smithsonian___________________________________________________________________________________82
smithsonian____________________________________________________________________________________83
smithsonian_____________________________________________________________________________________84
smithsonian______________________________________________________________________________________85
smithsonian_______________________________________________________________________________________86
smithsonian________________________________________________________________________________________87
smithsonian_________________________________________________________________________________________88
smithsonian__________________________________________________________________________________________89
smithsonian___________________________________________________________________________________________90
smithsonian____________________________________________________________________________________________91
smithsonian_____________________________________________________________________________________________92
smithsonian______________________________________________________________________________________________93
smithsonian_______________________________________________________________________________________________94
smithsonian________________________________________________________________________________________________95
smithsonian_________________________________________________________________________________________________96
smithsonian__________________________________________________________________________________________________97
smithsonian___________________________________________________________________________________________________98
smithsonian____________________________________________________________________________________________________99
<!-- gh-comment-id:201135813 --> @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: ``` > john --stdout --wordlist=c:\temp\p.dic --external=Hybrid_example _00 __01 ___02 ____03 _____04 ______05 _______06 ________07 _________08 __________09 ___________10 ____________11 _____________12 ______________13 _______________14 ________________15 _________________16 __________________17 ___________________18 ____________________19 _____________________20 ______________________21 _______________________22 ________________________23 _________________________24 __________________________25 ___________________________26 ____________________________27 _____________________________28 ______________________________29 _______________________________30 ________________________________31 _________________________________32 __________________________________33 ___________________________________34 ____________________________________35 _____________________________________36 ______________________________________37 _______________________________________38 ________________________________________39 _________________________________________40 __________________________________________41 ___________________________________________42 ____________________________________________43 _____________________________________________44 ______________________________________________45 _______________________________________________46 ________________________________________________47 _________________________________________________48 __________________________________________________49 ___________________________________________________50 ____________________________________________________51 _____________________________________________________52 ______________________________________________________53 _______________________________________________________54 ________________________________________________________55 _________________________________________________________56 __________________________________________________________57 ___________________________________________________________58 ____________________________________________________________59 _____________________________________________________________60 ______________________________________________________________61 _______________________________________________________________62 ________________________________________________________________63 _________________________________________________________________64 __________________________________________________________________65 ___________________________________________________________________66 ____________________________________________________________________67 _____________________________________________________________________68 ______________________________________________________________________69 _______________________________________________________________________70 ________________________________________________________________________71 _________________________________________________________________________72 __________________________________________________________________________73 ___________________________________________________________________________74 ____________________________________________________________________________75 _____________________________________________________________________________76 ______________________________________________________________________________77 _______________________________________________________________________________78 ________________________________________________________________________________79 _________________________________________________________________________________80 __________________________________________________________________________________81 ___________________________________________________________________________________82 ____________________________________________________________________________________83 _____________________________________________________________________________________84 ______________________________________________________________________________________85 _______________________________________________________________________________________86 ________________________________________________________________________________________87 _________________________________________________________________________________________88 __________________________________________________________________________________________89 ___________________________________________________________________________________________90 ____________________________________________________________________________________________91 _____________________________________________________________________________________________92 ______________________________________________________________________________________________93 _______________________________________________________________________________________________94 ________________________________________________________________________________________________95 _________________________________________________________________________________________________96 __________________________________________________________________________________________________97 ___________________________________________________________________________________________________98 ____________________________________________________________________________________________________99 ``` 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: ``` > john --stdout --wordlist=c:\temp\p.dic --external=Hybrid_example smithsonian_00 smithsonian__01 smithsonian___02 smithsonian____03 smithsonian_____04 smithsonian______05 smithsonian_______06 smithsonian________07 smithsonian_________08 smithsonian__________09 smithsonian___________10 smithsonian____________11 smithsonian_____________12 smithsonian______________13 smithsonian_______________14 smithsonian________________15 smithsonian_________________16 smithsonian__________________17 smithsonian___________________18 smithsonian____________________19 smithsonian_____________________20 smithsonian______________________21 smithsonian_______________________22 smithsonian________________________23 smithsonian_________________________24 smithsonian__________________________25 smithsonian___________________________26 smithsonian____________________________27 smithsonian_____________________________28 smithsonian______________________________29 smithsonian_______________________________30 smithsonian________________________________31 smithsonian_________________________________32 smithsonian__________________________________33 smithsonian___________________________________34 smithsonian____________________________________35 smithsonian_____________________________________36 smithsonian______________________________________37 smithsonian_______________________________________38 smithsonian________________________________________39 smithsonian_________________________________________40 smithsonian__________________________________________41 smithsonian___________________________________________42 smithsonian____________________________________________43 smithsonian_____________________________________________44 smithsonian______________________________________________45 smithsonian_______________________________________________46 smithsonian________________________________________________47 smithsonian_________________________________________________48 smithsonian__________________________________________________49 > john --restore smithsonian___________________________________________________50 smithsonian____________________________________________________51 smithsonian_____________________________________________________52 smithsonian______________________________________________________53 smithsonian_______________________________________________________54 smithsonian________________________________________________________55 smithsonian_________________________________________________________56 smithsonian__________________________________________________________57 smithsonian___________________________________________________________58 smithsonian____________________________________________________________59 smithsonian_____________________________________________________________60 smithsonian______________________________________________________________61 smithsonian_______________________________________________________________62 smithsonian________________________________________________________________63 smithsonian_________________________________________________________________64 smithsonian__________________________________________________________________65 smithsonian___________________________________________________________________66 smithsonian____________________________________________________________________67 smithsonian_____________________________________________________________________68 smithsonian______________________________________________________________________69 smithsonian_______________________________________________________________________70 smithsonian________________________________________________________________________71 smithsonian_________________________________________________________________________72 smithsonian__________________________________________________________________________73 smithsonian___________________________________________________________________________74 smithsonian____________________________________________________________________________75 smithsonian_____________________________________________________________________________76 smithsonian______________________________________________________________________________77 smithsonian_______________________________________________________________________________78 smithsonian________________________________________________________________________________79 smithsonian_________________________________________________________________________________80 smithsonian__________________________________________________________________________________81 smithsonian___________________________________________________________________________________82 smithsonian____________________________________________________________________________________83 smithsonian_____________________________________________________________________________________84 smithsonian______________________________________________________________________________________85 smithsonian_______________________________________________________________________________________86 smithsonian________________________________________________________________________________________87 smithsonian_________________________________________________________________________________________88 smithsonian__________________________________________________________________________________________89 smithsonian___________________________________________________________________________________________90 smithsonian____________________________________________________________________________________________91 smithsonian_____________________________________________________________________________________________92 smithsonian______________________________________________________________________________________________93 smithsonian_______________________________________________________________________________________________94 smithsonian________________________________________________________________________________________________95 smithsonian_________________________________________________________________________________________________96 smithsonian__________________________________________________________________________________________________97 smithsonian___________________________________________________________________________________________________98 smithsonian____________________________________________________________________________________________________99 ```
Author
Owner

@crioux commented on GitHub (Mar 25, 2016):

And yea, the l33t generator i wrote looks like this:

smithsonian
Smithsonian
$mithsonian
5mithsonian
smIthsonian
SmIthsonian
$mIthsonian
5mIthsonian
sm1thsonian
Sm1thsonian
$m1thsonian
5m1thsonian
sm!thsonian
Sm!thsonian
$m!thsonian
5m!thsonian
smiThsonian
SmiThsonian
$miThsonian
5miThsonian
smIThsonian
SmIThsonian
$mIThsonian
5mIThsonian
sm1Thsonian
Sm1Thsonian
$m1Thsonian
5m1Thsonian
sm!Thsonian
Sm!Thsonian
$m!Thsonian
5m!Thsonian
smi+hsonian
Smi+hsonian
$mi+hsonian
5mi+hsonian
smI+hsonian
SmI+hsonian
$mI+hsonian
5mI+hsonian
sm1+hsonian
Sm1+hsonian
$m1+hsonian
5m1+hsonian
sm!+hsonian
Sm!+hsonian
$m!+hsonian
5m!+hsonian
smi7hsonian
Smi7hsonian
$mi7hsonian
5mi7hsonian
smI7hsonian
SmI7hsonian
$mI7hsonian
5mI7hsonian
sm17hsonian
Sm17hsonian
$m17hsonian
5m17hsonian
sm!7hsonian
Sm!7hsonian
$m!7hsonian
5m!7hsonian
smitHsonian
SmitHsonian
$mitHsonian
5mitHsonian
smItHsonian
SmItHsonian
$mItHsonian
5mItHsonian
sm1tHsonian
Sm1tHsonian
$m1tHsonian
5m1tHsonian
sm!tHsonian
Sm!tHsonian
$m!tHsonian
5m!tHsonian
smiTHsonian
SmiTHsonian
$miTHsonian
5miTHsonian
smITHsonian
SmITHsonian
$mITHsonian
5mITHsonian
sm1THsonian
Sm1THsonian
$m1THsonian
5m1THsonian
sm!THsonian
Sm!THsonian
$m!THsonian
5m!THsonian
smi+Hsonian
Smi+Hsonian
$mi+Hsonian
5mi+Hsonian
smI+Hsonian
SmI+Hsonian
$mI+Hsonian
5mI+Hsonian
sm1+Hsonian
Sm1+Hsonian
$m1+Hsonian
5m1+Hsonian
sm!+Hsonian
Sm!+Hsonian
$m!+Hsonian
5m!+Hsonian
smi7Hsonian
Smi7Hsonian
$mi7Hsonian
5mi7Hsonian
smI7Hsonian
SmI7Hsonian
$mI7Hsonian
5mI7Hsonian
sm17Hsonian
Sm17Hsonian
$m17Hsonian
5m17Hsonian
sm!7Hsonian
Sm!7Hsonian
$m!7Hsonian
5m!7Hsonian
smit#sonian
Smit#sonian

etc etc for the rest of the permutations.

<!-- gh-comment-id:201137599 --> @crioux commented on GitHub (Mar 25, 2016): And yea, the l33t generator i wrote looks like this: ``` smithsonian Smithsonian $mithsonian 5mithsonian smIthsonian SmIthsonian $mIthsonian 5mIthsonian sm1thsonian Sm1thsonian $m1thsonian 5m1thsonian sm!thsonian Sm!thsonian $m!thsonian 5m!thsonian smiThsonian SmiThsonian $miThsonian 5miThsonian smIThsonian SmIThsonian $mIThsonian 5mIThsonian sm1Thsonian Sm1Thsonian $m1Thsonian 5m1Thsonian sm!Thsonian Sm!Thsonian $m!Thsonian 5m!Thsonian smi+hsonian Smi+hsonian $mi+hsonian 5mi+hsonian smI+hsonian SmI+hsonian $mI+hsonian 5mI+hsonian sm1+hsonian Sm1+hsonian $m1+hsonian 5m1+hsonian sm!+hsonian Sm!+hsonian $m!+hsonian 5m!+hsonian smi7hsonian Smi7hsonian $mi7hsonian 5mi7hsonian smI7hsonian SmI7hsonian $mI7hsonian 5mI7hsonian sm17hsonian Sm17hsonian $m17hsonian 5m17hsonian sm!7hsonian Sm!7hsonian $m!7hsonian 5m!7hsonian smitHsonian SmitHsonian $mitHsonian 5mitHsonian smItHsonian SmItHsonian $mItHsonian 5mItHsonian sm1tHsonian Sm1tHsonian $m1tHsonian 5m1tHsonian sm!tHsonian Sm!tHsonian $m!tHsonian 5m!tHsonian smiTHsonian SmiTHsonian $miTHsonian 5miTHsonian smITHsonian SmITHsonian $mITHsonian 5mITHsonian sm1THsonian Sm1THsonian $m1THsonian 5m1THsonian sm!THsonian Sm!THsonian $m!THsonian 5m!THsonian smi+Hsonian Smi+Hsonian $mi+Hsonian 5mi+Hsonian smI+Hsonian SmI+Hsonian $mI+Hsonian 5mI+Hsonian sm1+Hsonian Sm1+Hsonian $m1+Hsonian 5m1+Hsonian sm!+Hsonian Sm!+Hsonian $m!+Hsonian 5m!+Hsonian smi7Hsonian Smi7Hsonian $mi7Hsonian 5mi7Hsonian smI7Hsonian SmI7Hsonian $mI7Hsonian 5mI7Hsonian sm17Hsonian Sm17Hsonian $m17Hsonian 5m17Hsonian sm!7Hsonian Sm!7Hsonian $m!7Hsonian 5m!7Hsonian smit#sonian Smit#sonian ``` etc etc for the rest of the permutations.
Author
Owner

@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).

<!-- gh-comment-id:201139877 --> @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).
Author
Owner

@jfoug commented on GitHub (Mar 27, 2016):

This patch is closer but still not right.

$ ../run/john -ext=hybrid_example -w=tst-.dic tst-x.in
password_00      (?)
password__01     (?)
password___02    (?)
password____03   (?)
password_____04  (?)
password______05 (?)
password_______06 (?)
password________07 (?)
password_________08 (?)
password__________09 (?)
password___________10 (?)
password____________11 (?)
password_____________12 (?)
password______________13 (?)
password_______________14 (?)
password________________15 (?)
password_________________16 (?)
password__________________17 (?)
password___________________18 (?)
password____________________19 (?)
password_____________________20 (?)
password______________________21 (?)
password_______________________22 (?)
password________________________23 (?)
password_________________________24 (?)
password__________________________25 (?)
password___________________________26 (?)
password____________________________27 (?)
password_____________________________28 (?)
password______________________________29 (?)
password_______________________________30 (?)
password________________________________31 (?)
password_________________________________32 (?)
password__________________________________33 (?)
password___________________________________34 (?)
password____________________________________35 (?)
$ ../run/john -rest
password_____________________________________36 (?)
password______________________________________37 (?)
password_______________________________________38 (?)
password________________________________________39 (?)
password_________________________________________40 (?)
password__________________________________________41 (?)
password___________________________________________42 (?)
password____________________________________________43 (?)
password_____________________________________________44 (?)
password______________________________________________45 (?)
password_______________________________________________46 (?)
password________________________________________________47 (?)
password_________________________________________________48 (?)
password__________________________________________________49 (?)
password___________________________________________________50 (?)
$ ../run/john -rest
password_____________________________________36 (?)
password______________________________________37 (?)
password_______________________________________38 (?)
password________________________________________39 (?)
password_________________________________________40 (?)
password__________________________________________41 (?)
password___________________________________________42 (?)
password____________________________________________43 (?)
password_____________________________________________44 (?)
password______________________________________________45 (?)
password_______________________________________________46 (?)
password________________________________________________47 (?)
password_________________________________________________48 (?)
password__________________________________________________49 (?)
password___________________________________________________50 (?)

So yes, it did restore, but did not save a .rec file properly after restore.

<!-- gh-comment-id:202128473 --> @jfoug commented on GitHub (Mar 27, 2016): This patch is closer but still not right. ``` $ ../run/john -ext=hybrid_example -w=tst-.dic tst-x.in password_00 (?) password__01 (?) password___02 (?) password____03 (?) password_____04 (?) password______05 (?) password_______06 (?) password________07 (?) password_________08 (?) password__________09 (?) password___________10 (?) password____________11 (?) password_____________12 (?) password______________13 (?) password_______________14 (?) password________________15 (?) password_________________16 (?) password__________________17 (?) password___________________18 (?) password____________________19 (?) password_____________________20 (?) password______________________21 (?) password_______________________22 (?) password________________________23 (?) password_________________________24 (?) password__________________________25 (?) password___________________________26 (?) password____________________________27 (?) password_____________________________28 (?) password______________________________29 (?) password_______________________________30 (?) password________________________________31 (?) password_________________________________32 (?) password__________________________________33 (?) password___________________________________34 (?) password____________________________________35 (?) $ ../run/john -rest password_____________________________________36 (?) password______________________________________37 (?) password_______________________________________38 (?) password________________________________________39 (?) password_________________________________________40 (?) password__________________________________________41 (?) password___________________________________________42 (?) password____________________________________________43 (?) password_____________________________________________44 (?) password______________________________________________45 (?) password_______________________________________________46 (?) password________________________________________________47 (?) password_________________________________________________48 (?) password__________________________________________________49 (?) password___________________________________________________50 (?) $ ../run/john -rest password_____________________________________36 (?) password______________________________________37 (?) password_______________________________________38 (?) password________________________________________39 (?) password_________________________________________40 (?) password__________________________________________41 (?) password___________________________________________42 (?) password____________________________________________43 (?) password_____________________________________________44 (?) password______________________________________________45 (?) password_______________________________________________46 (?) password________________________________________________47 (?) password_________________________________________________48 (?) password__________________________________________________49 (?) password___________________________________________________50 (?) ``` So yes, it did restore, but did not save a .rec file properly after restore.
Author
Owner

@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?

diff --git a/src/external.c b/src/external.c
index e7e3a9d..0c2c9be 100644
--- a/src/external.c
+++ b/src/external.c
@@ -584,28 +600,46 @@ void do_external_crack(struct db_main *db)
  * then each word will only be sent to ONE thread. Thus that thread has
  * to process ALL candidates that the external script will build
  */
+
+
+extern void(*crk_fix_state)(void);

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.

<!-- gh-comment-id:202129446 --> @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? ``` diff diff --git a/src/external.c b/src/external.c index e7e3a9d..0c2c9be 100644 --- a/src/external.c +++ b/src/external.c @@ -584,28 +600,46 @@ void do_external_crack(struct db_main *db) * then each word will only be sent to ONE thread. Thus that thread has * to process ALL candidates that the external script will build */ + + +extern void(*crk_fix_state)(void); ``` 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.
Author
Owner

@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:

        if (rec_restored) {
            ext_hybrid_resume = hybrid_resume;
            if (!hybrid_resume)
                do_load = 0;
        }

to this

        if (rec_restored) {
            ++ext_hybrid_resume;
            if (!hybrid_resume)
                do_load = 0;
        }
<!-- gh-comment-id:202142079 --> @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: ``` c if (rec_restored) { ext_hybrid_resume = hybrid_resume; if (!hybrid_resume) do_load = 0; } ``` to this ``` if (rec_restored) { ++ext_hybrid_resume; if (!hybrid_resume) do_load = 0; } ```
Author
Owner

@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.

<!-- gh-comment-id:202200923 --> @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.
Author
Owner

@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.

<!-- gh-comment-id:202204720 --> @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.
Author
Owner

@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:

        /* gets the next word */
        ++ext_hybrid_resume;
        c_execute_fast(f_next);

        //xxx
        static int x = 0;
        if (x == 30)
        {
            fflush(stdout);
            rec_save();
            DebugBreak();
        }
        x++;

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:

john -rest
Incorrect crash recovery file: ▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌

Not sure why yet, will review.

<!-- gh-comment-id:202211078 --> @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: ``` /* gets the next word */ ++ext_hybrid_resume; c_execute_fast(f_next); //xxx static int x = 0; if (x == 30) { fflush(stdout); rec_save(); DebugBreak(); } x++; ``` 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: > john -rest > Incorrect crash recovery file: ▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌ Not sure why yet, will review.
Author
Owner

@crioux commented on GitHub (Mar 28, 2016):

This is the john.rec file at the point where it craps out

REC4
6
--stdout
--wordlist=c:\temp\p.dic
--external=hybrid_example
--input-encoding=UTF-8
--internal-codepage=UTF-8
4
0
0
0
0
0
0
7c
0
0
0
100
0
0
0
0
ext-v1
23 100 10
114 117 98 98 101 114 100 117 99 107  110
<!-- gh-comment-id:202211660 --> @crioux commented on GitHub (Mar 28, 2016): This is the john.rec file at the point where it craps out ``` REC4 6 --stdout --wordlist=c:\temp\p.dic --external=hybrid_example --input-encoding=UTF-8 --internal-codepage=UTF-8 4 0 0 0 0 0 0 7c 0 0 0 100 0 0 0 0 ext-v1 23 100 10 114 117 98 98 101 114 100 117 99 107 110 ```
Author
Owner

@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:

diff --git a/src/recovery.c b/src/recovery.c
index b9cbc19..f17bc80 100644
--- a/src/recovery.c
+++ b/src/recovery.c
@@ -389,6 +389,8 @@ void rec_save(void)
        if (fflush(rec_file)) pexit("fflush");
 #ifndef _MSC_VER
        if (ftruncate(rec_fd, size)) pexit("ftruncate");
+#else
+       if (_chsize(rec_fd, size)) pexit("ftruncate");
 #endif
 #if HAVE_WINDOWS_H==0
        if (!options.fork && fsync(rec_fd))
<!-- gh-comment-id:202217423 --> @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: ``` diff --git a/src/recovery.c b/src/recovery.c index b9cbc19..f17bc80 100644 --- a/src/recovery.c +++ b/src/recovery.c @@ -389,6 +389,8 @@ void rec_save(void) if (fflush(rec_file)) pexit("fflush"); #ifndef _MSC_VER if (ftruncate(rec_fd, size)) pexit("ftruncate"); +#else + if (_chsize(rec_fd, size)) pexit("ftruncate"); #endif #if HAVE_WINDOWS_H==0 if (!options.fork && fsync(rec_fd)) ```
Author
Owner

@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.

<!-- gh-comment-id:202217500 --> @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.
Author
Owner

@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

<!-- gh-comment-id:202220721 --> @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
Author
Owner

@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.

<!-- gh-comment-id:202223025 --> @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.
Author
Owner

@jfoug commented on GitHub (Mar 28, 2016):

Can you test out these changes within your DLL ?

diff --git a/src/recovery.c b/src/recovery.c
index b9cbc19..95cdcae 100644
--- a/src/recovery.c
+++ b/src/recovery.c
@@ -274,11 +274,6 @@ void rec_save(void)
        if (!rec_file) return;

        if (fseek(rec_file, 0, SEEK_SET)) pexit("fseek");
-#ifdef _MSC_VER
-       if (_write(fileno(rec_file), "", 0)) pexit("ftruncate");
-#elif __CYGWIN__
-       if (ftruncate(rec_fd, 0)) pexit("ftruncate");
-#endif

        save_format = !options.format && rec_db->loaded;

@@ -389,8 +384,12 @@ void rec_save(void)
        if (fflush(rec_file)) pexit("fflush");
 #ifndef _MSC_VER
        if (ftruncate(rec_fd, size)) pexit("ftruncate");
+#else
+       if (_chsize(rec_fd, size)) pexit("ftruncate");
 #endif
-#if HAVE_WINDOWS_H==0
+#if defined (_MSC_VER) || defined (__MINGW__)
+       _close(_dup(rec_fd));
+#else
        if (!options.fork && fsync(rec_fd))
                pexit("fsync");
 #endif

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.

<!-- gh-comment-id:202241846 --> @jfoug commented on GitHub (Mar 28, 2016): Can you test out these changes within your DLL ? ``` diff diff --git a/src/recovery.c b/src/recovery.c index b9cbc19..95cdcae 100644 --- a/src/recovery.c +++ b/src/recovery.c @@ -274,11 +274,6 @@ void rec_save(void) if (!rec_file) return; if (fseek(rec_file, 0, SEEK_SET)) pexit("fseek"); -#ifdef _MSC_VER - if (_write(fileno(rec_file), "", 0)) pexit("ftruncate"); -#elif __CYGWIN__ - if (ftruncate(rec_fd, 0)) pexit("ftruncate"); -#endif save_format = !options.format && rec_db->loaded; @@ -389,8 +384,12 @@ void rec_save(void) if (fflush(rec_file)) pexit("fflush"); #ifndef _MSC_VER if (ftruncate(rec_fd, size)) pexit("ftruncate"); +#else + if (_chsize(rec_fd, size)) pexit("ftruncate"); #endif -#if HAVE_WINDOWS_H==0 +#if defined (_MSC_VER) || defined (__MINGW__) + _close(_dup(rec_fd)); +#else if (!options.fork && fsync(rec_fd)) pexit("fsync"); #endif ``` 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.
Author
Owner

@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.

<!-- gh-comment-id:202242721 --> @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.
Author
Owner

@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

<!-- gh-comment-id:202259067 --> @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](https://github.com/magnumripper/JohnTheRipper/files/191452/fix_state.diff.txt)
Author
Owner

@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.

<!-- gh-comment-id:202260210 --> @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.
Author
Owner

@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.

<!-- gh-comment-id:202278223 --> @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.
Author
Owner

@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:

  1. save_state_hybrid did not add a trailing newline (probably cosmetic)
  2. the hybrid restore code in external expected that the string of the last cracked base word was going to be the last thing in the .rec file, which in the case of a mask stacked it's not.

for example this:

john -stdout -wordlist=c:\temp\p.dic -external=hybrid_example -mask=?l?w?u

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.

diff --git a/src/external.c b/src/external.c
index 058b2a3..51eef42 100644
--- a/src/external.c
+++ b/src/external.c
@@ -387,6 +387,7 @@ static void save_state_hybrid(FILE *file)
                hybrid_actual_completed_total, (unsigned)strlen((char*)ptr));
        while (*ptr)
                fprintf(file, "%d ", (int)*ptr++);
+       fprintf(file, "\n");
 }

 static int restore_state(FILE *file)
@@ -439,11 +440,16 @@ int ext_restore_state_hybrid(const char *sig, FILE *file)
                                        break;
                                return 1;
                        }
-                       if (++count >= PLAINTEXT_BUFFER_SIZE) return 1;
-               } while ((*internal++ = *external++ = *cp++ = c));
+                       if (++count >= PLAINTEXT_BUFFER_SIZE)
+                               return 1;
+
+                       *internal++ = *external++ = *cp++ = c;
+               } while ((c != 0) && (cnt != count));
+
                *internal = 0;
                *external = 0;
-               if (cnt != count) return 1;
+               if (cnt != count)
+                       return 1;
                if (ext_utf32)
                        enc_to_utf32((UTF32*)ext_word, PLAINTEXT_BUFFER_SIZE,
                                     (UTF8*)int_word, strlen(int_word));
<!-- gh-comment-id:202485054 --> @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: 1. save_state_hybrid did not add a trailing newline (probably cosmetic) 2. the hybrid restore code in external expected that the string of the last cracked base word was going to be the last thing in the .rec file, which in the case of a mask stacked it's not. for example this: ``` john -stdout -wordlist=c:\temp\p.dic -external=hybrid_example -mask=?l?w?u ``` 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. ``` diff --git a/src/external.c b/src/external.c index 058b2a3..51eef42 100644 --- a/src/external.c +++ b/src/external.c @@ -387,6 +387,7 @@ static void save_state_hybrid(FILE *file) hybrid_actual_completed_total, (unsigned)strlen((char*)ptr)); while (*ptr) fprintf(file, "%d ", (int)*ptr++); + fprintf(file, "\n"); } static int restore_state(FILE *file) @@ -439,11 +440,16 @@ int ext_restore_state_hybrid(const char *sig, FILE *file) break; return 1; } - if (++count >= PLAINTEXT_BUFFER_SIZE) return 1; - } while ((*internal++ = *external++ = *cp++ = c)); + if (++count >= PLAINTEXT_BUFFER_SIZE) + return 1; + + *internal++ = *external++ = *cp++ = c; + } while ((c != 0) && (cnt != count)); + *internal = 0; *external = 0; - if (cnt != count) return 1; + if (cnt != count) + return 1; if (ext_utf32) enc_to_utf32((UTF32*)ext_word, PLAINTEXT_BUFFER_SIZE, (UTF8*)int_word, strlen(int_word)); ```
Author
Owner

@jfoug commented on GitHub (Mar 28, 2016):

Notes:

  1. save_state_hybrid did not add a trailing newline (probably cosmetic)

I made somewhat same change last nite: github.com/magnumripper/JohnTheRipper@476f044ffd

Looks like in your restore_state (external), you miss the chomp ;)

<!-- gh-comment-id:202496308 --> @jfoug commented on GitHub (Mar 28, 2016): > Notes: > 1. save_state_hybrid did not add a trailing newline (probably cosmetic) I made somewhat same change last nite: https://github.com/magnumripper/JohnTheRipper/commit/476f044ffde91125b93ee087724b96a49fb9d053 Looks like in your restore_state (external), you miss the chomp ;)
Author
Owner

@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.

<!-- gh-comment-id:202502701 --> @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.
Author
Owner

@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.

<!-- gh-comment-id:202504630 --> @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.
Author
Owner

@magnumripper commented on GitHub (Mar 30, 2016):

I probably have no time to look closely at this until friday, at best.

<!-- gh-comment-id:203249908 --> @magnumripper commented on GitHub (Mar 30, 2016): I probably have no time to look closely at this until friday, at best.
Author
Owner

@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.

<!-- gh-comment-id:203253821 --> @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.
Author
Owner

@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.

<!-- gh-comment-id:205035941 --> @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.
Author
Owner

@jfoug commented on GitHub (Apr 3, 2016):

Issues from here: L0phtCrack/jtrdll@bcbee16 now addressed ba18f89

<!-- gh-comment-id:205039628 --> @jfoug commented on GitHub (Apr 3, 2016): Issues from here: L0phtCrack/jtrdll@bcbee16 now addressed ba18f89
Author
Owner

@jfoug commented on GitHub (Apr 3, 2016):

github.com/L0phtCrack/jtrdll@20a4986 has been tweaked to comply with core style, and is now located in it's own branch: https://github.com/magnumripper/JohnTheRipper/tree/resume-fixes

That 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).

<!-- gh-comment-id:205064751 --> @jfoug commented on GitHub (Apr 3, 2016): https://github.com/L0phtCrack/jtrdll/commit/20a4986 has been tweaked to comply with core style, and is now located in it's own branch: https://github.com/magnumripper/JohnTheRipper/tree/resume-fixes That 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).
Author
Owner

@jfoug commented on GitHub (Apr 12, 2016):

PR #2114, so that the branch has some destination. BUT more testing will be needed.

<!-- gh-comment-id:208972385 --> @jfoug commented on GitHub (Apr 12, 2016): PR #2114, so that the branch has some destination. BUT more testing will be needed.
Author
Owner

@magnumripper commented on GitHub (Aug 24, 2016):

@crioux I committed your HybridLeet mode to Jumbo.

<!-- gh-comment-id:242125219 --> @magnumripper commented on GitHub (Aug 24, 2016): @crioux I committed your HybridLeet mode to Jumbo.
Author
Owner

@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:

# create test file
$ ../run/john -stdout -inc:digits -max-len=3 | ../run/pass_gen.pl --count=1111 md5crypt > md5.in

# start a job
$ rm -f test.pot && ../run/john -pot:test.pot md5.in -form:md5crypt -inc:digits -min-len=0 -max-len=3 -mask:?w?d -max-run=2

# resume until done
$ while true ; do ../run/john -res && break ; sleep 1 ; done

This ends up with missed candidates.

<!-- gh-comment-id:255652312 --> @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: ``` # create test file $ ../run/john -stdout -inc:digits -max-len=3 | ../run/pass_gen.pl --count=1111 md5crypt > md5.in # start a job $ rm -f test.pot && ../run/john -pot:test.pot md5.in -form:md5crypt -inc:digits -min-len=0 -max-len=3 -mask:?w?d -max-run=2 # resume until done $ while true ; do ../run/john -res && break ; sleep 1 ; done ``` This ends up with missed candidates.
Author
Owner

@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.

<!-- gh-comment-id:255915801 --> @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.
Author
Owner

@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.

<!-- gh-comment-id:256071084 --> @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.
Author
Owner

@crioux commented on GitHub (Oct 25, 2016):

Session stopped (max run-time reached)
Loaded 1110 password hashes with 1011 different salts (md5crypt, crypt(3) $1$ [MD5 256/256 AVX2 8x3])
Remaining 937 password hashes with 856 different salts
Detected avx2 instruction set
173g 0:00:06:09 N/A 0.4688g/s 7.934p/s 8101c/s 8849C/s 000
173g 0:00:06:11 N/A 0.4663g/s 7.956p/s 8123c/s 8873C/s 088..016
Session stopped (max run-time reached)
Loaded 1110 password hashes with 1011 different salts (md5crypt, crypt(3) $1$ [MD5 256/256 AVX2 8x3])
Remaining 937 password hashes with 856 different salts
Detected avx2 instruction set
173g 0:00:06:12 N/A 0.4650g/s 7.935p/s 8102c/s 8850C/s 008
173g 0:00:06:14 N/A 0.4625g/s 7.957p/s 8124c/s 8874C/s 087..062
Session stopped (max run-time reached)
Loaded 1110 password hashes with 1011 different salts (md5crypt, crypt(3) $1$ [MD5 256/256 AVX2 8x3])
Remaining 937 password hashes with 856 different salts
Detected avx2 instruction set
173g 0:00:06:15 N/A 0.4613g/s 7.936p/s 8102c/s 8850C/s 007
173g 0:00:06:17 N/A 0.4588g/s 7.957p/s 8124c/s 8874C/s 093..065
Session stopped (max run-time reached)
Loaded 1110 password hashes with 1011 different salts (md5crypt, crypt(3) $1$ [MD5 256/256 AVX2 8x3])
Remaining 937 password hashes with 856 different salts
Detected avx2 instruction set
173g 0:00:06:18 N/A 0.4576g/s 7.936p/s 8103c/s 8851C/s 003
173g 0:00:06:20 N/A 0.4552g/s 7.957p/s 8125c/s 8874C/s 084..061
Session stopped (max run-time reached)
Loaded 1110 password hashes with 1011 different salts (md5crypt, crypt(3) $1$ [MD5 256/256 AVX2 8x3])
Remaining 937 password hashes with 856 different salts
Detected avx2 instruction set
173g 0:00:06:21 N/A 0.4540g/s 7.937p/s 8103c/s 8851C/s 004
173g 0:00:06:23 N/A 0.4516g/s 7.958p/s 8125c/s 8875C/s 090..069
Session stopped (max run-time reached)
Loaded 1110 password hashes with 1011 different salts (md5crypt, crypt(3) $1$ [MD5 256/256 AVX2 8x3])
Remaining 937 password hashes with 856 different salts
Detected avx2 instruction set
173g 0:00:06:24 N/A 0.4505g/s 7.937p/s 8104c/s 8852C/s 000
173g 0:00:06:26 N/A 0.4481g/s 7.958p/s 8125c/s 8875C/s 088..016
Session stopped (max run-time reached)
Loaded 1110 password hashes with 1011 different salts (md5crypt, crypt(3) $1$ [MD5 256/256 AVX2 8x3])
Remaining 937 password hashes with 856 different salts
Detected avx2 instruction set
173g 0:00:06:27 N/A 0.4470g/s 7.937p/s 8104c/s 8852C/s 008
173g 0:00:06:29 N/A 0.4447g/s 7.958p/s 8126c/s 8875C/s 087..062
Session stopped (max run-time reached)
<!-- gh-comment-id:256071278 --> @crioux commented on GitHub (Oct 25, 2016): ``` Session stopped (max run-time reached) Loaded 1110 password hashes with 1011 different salts (md5crypt, crypt(3) $1$ [MD5 256/256 AVX2 8x3]) Remaining 937 password hashes with 856 different salts Detected avx2 instruction set 173g 0:00:06:09 N/A 0.4688g/s 7.934p/s 8101c/s 8849C/s 000 173g 0:00:06:11 N/A 0.4663g/s 7.956p/s 8123c/s 8873C/s 088..016 Session stopped (max run-time reached) Loaded 1110 password hashes with 1011 different salts (md5crypt, crypt(3) $1$ [MD5 256/256 AVX2 8x3]) Remaining 937 password hashes with 856 different salts Detected avx2 instruction set 173g 0:00:06:12 N/A 0.4650g/s 7.935p/s 8102c/s 8850C/s 008 173g 0:00:06:14 N/A 0.4625g/s 7.957p/s 8124c/s 8874C/s 087..062 Session stopped (max run-time reached) Loaded 1110 password hashes with 1011 different salts (md5crypt, crypt(3) $1$ [MD5 256/256 AVX2 8x3]) Remaining 937 password hashes with 856 different salts Detected avx2 instruction set 173g 0:00:06:15 N/A 0.4613g/s 7.936p/s 8102c/s 8850C/s 007 173g 0:00:06:17 N/A 0.4588g/s 7.957p/s 8124c/s 8874C/s 093..065 Session stopped (max run-time reached) Loaded 1110 password hashes with 1011 different salts (md5crypt, crypt(3) $1$ [MD5 256/256 AVX2 8x3]) Remaining 937 password hashes with 856 different salts Detected avx2 instruction set 173g 0:00:06:18 N/A 0.4576g/s 7.936p/s 8103c/s 8851C/s 003 173g 0:00:06:20 N/A 0.4552g/s 7.957p/s 8125c/s 8874C/s 084..061 Session stopped (max run-time reached) Loaded 1110 password hashes with 1011 different salts (md5crypt, crypt(3) $1$ [MD5 256/256 AVX2 8x3]) Remaining 937 password hashes with 856 different salts Detected avx2 instruction set 173g 0:00:06:21 N/A 0.4540g/s 7.937p/s 8103c/s 8851C/s 004 173g 0:00:06:23 N/A 0.4516g/s 7.958p/s 8125c/s 8875C/s 090..069 Session stopped (max run-time reached) Loaded 1110 password hashes with 1011 different salts (md5crypt, crypt(3) $1$ [MD5 256/256 AVX2 8x3]) Remaining 937 password hashes with 856 different salts Detected avx2 instruction set 173g 0:00:06:24 N/A 0.4505g/s 7.937p/s 8104c/s 8852C/s 000 173g 0:00:06:26 N/A 0.4481g/s 7.958p/s 8125c/s 8875C/s 088..016 Session stopped (max run-time reached) Loaded 1110 password hashes with 1011 different salts (md5crypt, crypt(3) $1$ [MD5 256/256 AVX2 8x3]) Remaining 937 password hashes with 856 different salts Detected avx2 instruction set 173g 0:00:06:27 N/A 0.4470g/s 7.937p/s 8104c/s 8852C/s 008 173g 0:00:06:29 N/A 0.4447g/s 7.958p/s 8126c/s 8875C/s 087..062 Session stopped (max run-time reached) ```
Author
Owner

@crioux commented on GitHub (Oct 25, 2016):

(maybe i'm just reading the status output wrong too)

<!-- gh-comment-id:256071582 --> @crioux commented on GitHub (Oct 25, 2016): (maybe i'm just reading the status output wrong too)
Author
Owner

@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.

<!-- gh-comment-id:256097873 --> @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.
Author
Owner

@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.

<!-- gh-comment-id:256109968 --> @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.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
openwall/john#1405
No description provided.