[GH-ISSUE #2817] Salt resume problem (potentially severe bug) #1804

Closed
opened 2026-10-15 04:24:50 +07:00 by bsakaguchi · 52 comments
Owner

Originally created by @magnumripper on GitHub (Oct 18, 2017).
Original GitHub issue: https://github.com/openwall/john/issues/2817

Originally assigned to: @jfoug on GitHub.

Since Jim added "salt resume" (which is basically an excellent thing but was never systematically tested), I believe we have the following problem:

Say we run some OpenCL format that happened to auto-tune to 2K keys per crypt and we have 500 salts loaded. After eg. 200 salts, we abort the job.

When resuming, the same format could just as well auto-tune to 4K keys per crypt (due to random variations). The salt-resume code will happily skip the first 200 salts that were "already processed" - but the problem is they all miss 2K candidates which will never be tested. Possible false negatives...

The same thing would happen at smaller scale if eg. running AVX and resuming on AVX2 or running OpenMP and bumping number of threads at resume.

What to do about this? Not sure. Perhaps we could store the active "keys per crypt" in the rec file, and check when resuming that it didn't increase. If it did, we can skip the salt-resuming and just start over from salt 0. As an attempt to avoid that, we might be able to instead ensure the very first batch runs with that same kpc.

Originally created by @magnumripper on GitHub (Oct 18, 2017). Original GitHub issue: https://github.com/openwall/john/issues/2817 Originally assigned to: @jfoug on GitHub. Since Jim added "salt resume" (which is basically an excellent thing but was never systematically tested), I believe we have the following problem: Say we run some OpenCL format that happened to auto-tune to 2K keys per crypt and we have 500 salts loaded. After eg. 200 salts, we abort the job. When resuming, the same format could just as well auto-tune to 4K keys per crypt (due to random variations). The salt-resume code will happily skip the first 200 salts that were "already processed" - but the problem is **they all miss 2K candidates** which will never be tested. Possible false negatives... The same thing would happen at smaller scale if eg. running AVX and resuming on AVX2 or running OpenMP and bumping number of threads at resume. What to do about this? Not sure. Perhaps we could store the active "keys per crypt" in the rec file, and check when resuming that it didn't increase. If it did, we can skip the salt-resuming and just start over from salt 0. As an attempt to avoid that, we might be able to instead ensure the very first batch runs with that same kpc.
bsakaguchi 2026-10-15 04:24:50 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@solardiz commented on GitHub (Nov 3, 2017):

This is tricky. I wasn't even aware we had gotten this functionality. I suppose its implementation already has to add storing of the current salt to the .rec file, so we could as well add storing of "keys per crypt".

Meanwhile, we could hide this functionality behind an experimental john.conf setting (with a comment stating so and documenting this known issue), and have it disabled by default. It's no good to have this bug in a tree that people actually use (we don't have a development tree now - we actually recommend that people use bleeding-jumbo - so we have to be responsible and not keep major known bugs like this exposed by default).

<!-- gh-comment-id:341676534 --> @solardiz commented on GitHub (Nov 3, 2017): This is tricky. I wasn't even aware we had gotten this functionality. I suppose its implementation already has to add storing of the current salt to the .rec file, so we could as well add storing of "keys per crypt". Meanwhile, we could hide this functionality behind an experimental `john.conf` setting (with a comment stating so and documenting this known issue), and have it disabled by default. It's no good to have this bug in a tree that people actually use (we don't have a development tree now - we actually recommend that people use bleeding-jumbo - so we have to be responsible and not keep major known bugs like this exposed by default).
Author
Owner

@jfoug commented on GitHub (Nov 6, 2017):

Perhaps we could store the active "keys per crypt" in the rec file, and check when resuming that it didn't increase. If it did, we can skip the salt-resuming and just start over from salt 0.

I hate to say it, but that is the only sane solution. The resume requires a STATE. Well, when the state is changed (whether by the user, or in this case by john itself), then the resume has to ignore some of its knowledge, reverting it to a safe level. In this case, we will simply have to start the salt resume off at 0, since it would be overly complex to try to back adjust just what is different in the saved 'state'.

This saved_salt logic is REALLY important when there are very VERY slow hashes with a lot of salts. Things like the AM dump. There were 30+ million salts, and just working 3 passwords forward (with BF_X2 properly being set to 3) it would take weeks. So without this salt save logic, if john ran for 10 days, shutdown and restarted, then the first 10 days of the resumed session would simply be replaying 100% done data, and never find anything. But in the exact same logic, but on items which the entire salt level runs in seconds (or even minutes), losing the initially done salts is a non-impact as far as resume is concerned. We just need to know a bit more state information to make an informed decision.

<!-- gh-comment-id:342031065 --> @jfoug commented on GitHub (Nov 6, 2017): > Perhaps we could store the active "keys per crypt" in the rec file, and check when resuming that it didn't increase. If it did, we can skip the salt-resuming and just start over from salt 0. I hate to say it, but that is the only sane solution. The resume requires a STATE. Well, when the state is changed (whether by the user, or in this case by john itself), then the resume has to ignore some of its knowledge, reverting it to a safe level. In this case, we will simply have to start the salt resume off at 0, since it would be overly complex to try to back adjust just what is different in the saved 'state'. This saved_salt logic is REALLY important when there are very VERY slow hashes with a lot of salts. Things like the AM dump. There were 30+ million salts, and just working 3 passwords forward (with BF_X2 properly being set to 3) it would take weeks. So without this salt save logic, if john ran for 10 days, shutdown and restarted, then the first 10 days of the resumed session would simply be replaying 100% done data, and never find anything. But in the exact same logic, but on items which the entire salt level runs in seconds (or even minutes), losing the initially done salts is a non-impact as far as resume is concerned. We just need to know a bit more state information to make an informed decision.
Author
Owner

@jfoug commented on GitHub (Nov 6, 2017):

@magnumripper Please try with these patches:

diff --git a/src/recovery.c b/src/recovery.c
index cd2b9d657..4544ddfc9 100644
--- a/src/recovery.c
+++ b/src/recovery.c
@@ -81,6 +81,8 @@ static void (*rec_save_mode)(FILE *file);
 static void (*rec_save_mode2)(FILE *file);
 static void (*rec_save_mode3)(FILE *file);

+extern int cracker_max_keys_per_crypt();
+
 static void rec_name_complete(void)
 {
        if (rec_name_completed)
@@ -275,7 +277,12 @@ static void save_salt_state()
                ++h;
        }
        *p = 0;
-       fprintf(rec_file, "slt-v1\n%s\n", md5_buf);
+       fprintf(rec_file, "slt-v2\n%s\n", md5_buf);
+       // bug found in original salt-restore.  if the cracks per loop value is NOT the same,
+       // then we end up skipping processing some data. So we save this value, and then
+       // when we resume IF this value is not the same, we ignore the salt resume, and just
+       // start from salt zero.
+       fprintf(rec_file, "%d\n", cracker_max_keys_per_crypt());
 }

 void rec_save(void)
@@ -606,16 +613,31 @@ void rec_restore_args(int lock)
        rec_restoring_now = 1;
 }

-static void restore_salt_state()
+static void restore_salt_state(int type)
 {
        char buf[34];
+       char buf2[48];
        static uint32_t hash[4];
        unsigned char *h = (unsigned char*)hash;
        int i;

        fgetl(buf, sizeof(buf), rec_file);
+       if (type == 2) {
+               fgetl(buf2, sizeof(buf2), rec_file);
+       }
        if (strlen(buf) != 32 || !ishex(buf))
                rec_format_error("multi-salt");
+       if (type == 2) {
+               // the first crack, we seek to the above salt, BUT only if we
+               // still have exactly same count of max_crypts_per  If the max
+               // changes, then we simply start over at salt#1 to avoid any
+               // salt records NOT being processed. properly.
+               status.resume_salt_crypts_per = strtoul(buf2, NULL, 10);
+       } else if (type == 1) {
+               // tells cracker to ignore the check, since this information was not
+               // available in v1 slt records
+               status.resume_salt_crypts_per = -1;
+       }
        for (i = 0; i < 16; ++i) {
                h[i] = atoi16[ARCH_INDEX(buf[i*2])] << 4;
                h[i] += atoi16[ARCH_INDEX(buf[i*2+1])];
@@ -652,7 +674,10 @@ void rec_restore_mode(int (*restore_mode)(FILE *file))
                }
 #endif
                if (!strcmp(buf, "slt-v1")) {
-                       restore_salt_state();
+                       restore_salt_state(1);
+               }
+               if (!strcmp(buf, "slt-v2")) {
+                       restore_salt_state(2);
                }
                fgetl(buf, sizeof(buf), rec_file);
        }
diff --git a/src/cracker.c b/src/cracker.c
index 63e876d00..9da6c3700 100644
--- a/src/cracker.c
+++ b/src/cracker.c
@@ -97,6 +97,10 @@ static int64 *crk_timestamps;
 static char crk_stdout_key[PLAINTEXT_BUFFER_SIZE];
 int64_t crk_pot_pos;

+// expose max_keys_per_crypt to the world (needed in recovery.c)
+int cracker_max_keys_per_crypt() {
+       return  crk_params.max_keys_per_crypt;
+}
 static void crk_dummy_set_salt(void *salt)
 {
 }
@@ -969,15 +973,18 @@ static int crk_salt_loop(void)
                struct db_salt *s = salt;

                status.resume_salt = 0; /* only resume the first time */
-               while (s) {
-                       if (s->salt_md5[0] == status.resume_salt_md5[0] &&
-                           !memcmp(s->salt_md5, status.resume_salt_md5, 16))
-                       {
-                               /* found it!! */
-                               salt = s;
-                               break;
+               if (status.resume_salt_crypts_per == -1 ||
+                       status.resume_salt_crypts_per == crk_params.max_keys_per_crypt) {
+                       while (s) {
+                               if (s->salt_md5[0] == status.resume_salt_md5[0] &&
+                                       !memcmp(s->salt_md5, status.resume_salt_md5, 16))
+                               {
+                                       /* found it!! */
+                                       salt = s;
+                                       break;
+                               }
+                               s = s->next;
                        }
-                       s = s->next;
                }
        }
        do {
diff --git a/src/status.h b/src/status.h
index c71b7ce31..3ceb0d8fb 100644
--- a/src/status.h
+++ b/src/status.h
@@ -43,6 +43,7 @@ struct status_main {
        int progress;
        int resume_salt;
        uint32_t *resume_salt_md5;
+       int resume_salt_crypts_per;
 };

 extern struct status_main status;
<!-- gh-comment-id:342146814 --> @jfoug commented on GitHub (Nov 6, 2017): @magnumripper Please try with these patches: ```diff diff --git a/src/recovery.c b/src/recovery.c index cd2b9d657..4544ddfc9 100644 --- a/src/recovery.c +++ b/src/recovery.c @@ -81,6 +81,8 @@ static void (*rec_save_mode)(FILE *file); static void (*rec_save_mode2)(FILE *file); static void (*rec_save_mode3)(FILE *file); +extern int cracker_max_keys_per_crypt(); + static void rec_name_complete(void) { if (rec_name_completed) @@ -275,7 +277,12 @@ static void save_salt_state() ++h; } *p = 0; - fprintf(rec_file, "slt-v1\n%s\n", md5_buf); + fprintf(rec_file, "slt-v2\n%s\n", md5_buf); + // bug found in original salt-restore. if the cracks per loop value is NOT the same, + // then we end up skipping processing some data. So we save this value, and then + // when we resume IF this value is not the same, we ignore the salt resume, and just + // start from salt zero. + fprintf(rec_file, "%d\n", cracker_max_keys_per_crypt()); } void rec_save(void) @@ -606,16 +613,31 @@ void rec_restore_args(int lock) rec_restoring_now = 1; } -static void restore_salt_state() +static void restore_salt_state(int type) { char buf[34]; + char buf2[48]; static uint32_t hash[4]; unsigned char *h = (unsigned char*)hash; int i; fgetl(buf, sizeof(buf), rec_file); + if (type == 2) { + fgetl(buf2, sizeof(buf2), rec_file); + } if (strlen(buf) != 32 || !ishex(buf)) rec_format_error("multi-salt"); + if (type == 2) { + // the first crack, we seek to the above salt, BUT only if we + // still have exactly same count of max_crypts_per If the max + // changes, then we simply start over at salt#1 to avoid any + // salt records NOT being processed. properly. + status.resume_salt_crypts_per = strtoul(buf2, NULL, 10); + } else if (type == 1) { + // tells cracker to ignore the check, since this information was not + // available in v1 slt records + status.resume_salt_crypts_per = -1; + } for (i = 0; i < 16; ++i) { h[i] = atoi16[ARCH_INDEX(buf[i*2])] << 4; h[i] += atoi16[ARCH_INDEX(buf[i*2+1])]; @@ -652,7 +674,10 @@ void rec_restore_mode(int (*restore_mode)(FILE *file)) } #endif if (!strcmp(buf, "slt-v1")) { - restore_salt_state(); + restore_salt_state(1); + } + if (!strcmp(buf, "slt-v2")) { + restore_salt_state(2); } fgetl(buf, sizeof(buf), rec_file); } ``` ```diff diff --git a/src/cracker.c b/src/cracker.c index 63e876d00..9da6c3700 100644 --- a/src/cracker.c +++ b/src/cracker.c @@ -97,6 +97,10 @@ static int64 *crk_timestamps; static char crk_stdout_key[PLAINTEXT_BUFFER_SIZE]; int64_t crk_pot_pos; +// expose max_keys_per_crypt to the world (needed in recovery.c) +int cracker_max_keys_per_crypt() { + return crk_params.max_keys_per_crypt; +} static void crk_dummy_set_salt(void *salt) { } @@ -969,15 +973,18 @@ static int crk_salt_loop(void) struct db_salt *s = salt; status.resume_salt = 0; /* only resume the first time */ - while (s) { - if (s->salt_md5[0] == status.resume_salt_md5[0] && - !memcmp(s->salt_md5, status.resume_salt_md5, 16)) - { - /* found it!! */ - salt = s; - break; + if (status.resume_salt_crypts_per == -1 || + status.resume_salt_crypts_per == crk_params.max_keys_per_crypt) { + while (s) { + if (s->salt_md5[0] == status.resume_salt_md5[0] && + !memcmp(s->salt_md5, status.resume_salt_md5, 16)) + { + /* found it!! */ + salt = s; + break; + } + s = s->next; } - s = s->next; } } do { ``` ```diff diff --git a/src/status.h b/src/status.h index c71b7ce31..3ceb0d8fb 100644 --- a/src/status.h +++ b/src/status.h @@ -43,6 +43,7 @@ struct status_main { int progress; int resume_salt; uint32_t *resume_salt_md5; + int resume_salt_crypts_per; }; extern struct status_main status; ```
Author
Owner

@jfoug commented on GitHub (Nov 6, 2017):

The above simply creates a v2 salt save record. It still processes any v1 salt record properly. It sets the status.resume_salt_crypts_pre to -1 for v1, and then within cracker, the -1 is used as a valid value. BUT on the v2 record, we store max cracks per (we had to expose this in cracker to be used in recovery.c), and then when we get to skipping salts, we ONLY perform that code if the max_keys_per_crypt is still the same as it was when the resume file was made. Easy peasy. NOTE, it would probably be smart to add a logging line here, listing that we wanted to skip salts, but that the runtime state was different.

It could be as simple as they used a different OMP value. Or like you stated, the auto tuning code set up the runtime environment differently. But in any way, in the code presented above, we start from 0.

Now, back looking AT the code, I am still not 100% sure that any values would not have been tested properly. the only 'issues' I see, is if the user re-ordered the input file, thus messing with order of the salts. but since we save the MD5 of the actual salt we left off, and simply move the salt pointer ahead in the list before actually USING them in the loop, are you 'sure' that there would have been data trials skipped???

<!-- gh-comment-id:342148426 --> @jfoug commented on GitHub (Nov 6, 2017): The above simply creates a v2 salt save record. It still processes any v1 salt record properly. It sets the status.resume_salt_crypts_pre to -1 for v1, and then within cracker, the -1 is used as a valid value. BUT on the v2 record, we store max cracks per (we had to expose this in cracker to be used in recovery.c), and then when we get to skipping salts, we ONLY perform that code if the max_keys_per_crypt is still the same as it was when the resume file was made. Easy peasy. NOTE, it would probably be smart to add a logging line here, listing that we wanted to skip salts, but that the runtime state was different. It could be as simple as they used a different OMP value. Or like you stated, the auto tuning code set up the runtime environment differently. But in any way, in the code presented above, we start from 0. Now, back looking AT the code, I am still not 100% sure that any values would not have been tested properly. the only 'issues' I see, is if the user re-ordered the input file, thus messing with order of the salts. but since we save the MD5 of the actual salt we left off, and simply move the salt pointer ahead in the list before actually USING them in the loop, are you 'sure' that there would have been data trials skipped???
Author
Owner

@frank-dittrich commented on GitHub (Nov 6, 2017):

we ONLY perform that code if the max_keys_per_crypt is still the same as it was when the resume file was made.

Wouldn't it be possible to skip salts if the new max_keys_per_crypt is smaller than the old one?

<!-- gh-comment-id:342184046 --> @frank-dittrich commented on GitHub (Nov 6, 2017): > we ONLY perform that code if the max_keys_per_crypt is still the same as it was when the resume file was made. Wouldn't it be possible to skip salts if the new max_keys_per_crypt is smaller than the old one?
Author
Owner

@jfoug commented on GitHub (Nov 6, 2017):

Missed one file needing patched, status.h (added it to the post above)

<!-- gh-comment-id:342191409 --> @jfoug commented on GitHub (Nov 6, 2017): Missed one file needing patched, status.h (added it to the post above)
Author
Owner

@magnumripper commented on GitHub (Nov 6, 2017):

Now, back looking AT the code, I am still not 100% sure that any values would not have been tested properly. the only 'issues' I see, is if the user re-ordered the input file, thus messing with order of the salts. but since we save the MD5 of the actual salt we left off, and simply move the salt pointer ahead in the list before actually USING them in the loop, are you 'sure' that there would have been data trials skipped???

I was, but right now (having forgotten some details) I am not. We should try to verify this to 100% certainity. It might even be that the problem occurs in the opposite situation (we resume with a lower KPC than we had). And/or it might actually be mode-dependant to some degree.

<!-- gh-comment-id:342229376 --> @magnumripper commented on GitHub (Nov 6, 2017): > Now, back looking AT the code, I am still not 100% sure that any values would not have been tested properly. the only 'issues' I see, is if the user re-ordered the input file, thus messing with order of the salts. but since we save the MD5 of the actual salt we left off, and simply move the salt pointer ahead in the list before actually USING them in the loop, are you 'sure' that there would have been data trials skipped??? I was, but right now (having forgotten some details) I am not. We should try to verify this to 100% certainity. It might even be that the problem occurs in the opposite situation (we resume with a lower KPC than we had). And/or it might actually be mode-dependant to some degree.
Author
Owner

@magnumripper commented on GitHub (Nov 6, 2017):

I have little time right now (perhaps next week) but I will try to verify (for SURE) what happens without your patch (and come up with a reproducible test case), and then have a look at it with the patch applied.

<!-- gh-comment-id:342230203 --> @magnumripper commented on GitHub (Nov 6, 2017): I have little time right now (perhaps next week) but I will try to verify (for SURE) what happens without your patch (and come up with a reproducible test case), and then have a look at it with the patch applied.
Author
Owner

@jfoug commented on GitHub (Nov 6, 2017):

I will see what I can do. I will draw up some sample files, then add some debugging (output salt and pw trial). Then run them, then run them using v1 salt resume (prioe to this change), then v2, etc, and make 'sure' we know exactly when this is happening. It is easy to do, just changing the OMP number threads should do it (I think). I can also run using a VC build (2x) bcrypt, and my 3x cygwin bcrypt builds. I am using bcrypt so it is slow enough I can easily get salt resume logic, but fast enough it finishes in a reasonable amount of time.

<!-- gh-comment-id:342235944 --> @jfoug commented on GitHub (Nov 6, 2017): I will see what I can do. I will draw up some sample files, then add some debugging (output salt and pw trial). Then run them, then run them using v1 salt resume (prioe to this change), then v2, etc, and make 'sure' we know exactly when this is happening. It is easy to do, just changing the OMP number threads should do it (I think). I can also run using a VC build (2x) bcrypt, and my 3x cygwin bcrypt builds. I am using bcrypt so it is slow enough I can easily get salt resume logic, but fast enough it finishes in a reasonable amount of time.
Author
Owner

@jfoug commented on GitHub (Nov 6, 2017):

But the way the salt resume works, I still am not 100% assured that there is a bug to start with. The salt resume simply does a normal resume (i.e. which password to start at), but in salt-resume, no the very first call to the crack block, the code will walk the salt list, looking for the last one processed (salt). IF (and only if) an exact match was found for salt (uses MD5 hashes of the salt, computed one time at load time).

It may be that we have to simply 'back up' the current max count of salt records (minus 1?) I will simply see if I can get enough debugging output to see just WTF actually happens. But I 'think' that by the way 'q' or ^c works, that the current block is completed, and then the resume block is computed, so I would expect that starting at the salt right after where we left off 'should' not cause any chance of a false negative.

<!-- gh-comment-id:342238101 --> @jfoug commented on GitHub (Nov 6, 2017): But the way the salt resume works, I still am not 100% assured that there is a bug to start with. The salt resume simply does a normal resume (i.e. which password to start at), but in salt-resume, no the very first call to the crack block, the code will walk the salt list, looking for the last one processed (salt). IF (and only if) an exact match was found for salt (uses MD5 hashes of the salt, computed one time at load time). It may be that we have to simply 'back up' the current max count of salt records (minus 1?) I will simply see if I can get enough debugging output to see just WTF actually happens. But I 'think' that by the way 'q' or ^c works, that the current block is completed, and then the resume block is computed, so I would expect that starting at the salt right after where we left off 'should' not cause any chance of a false negative.
Author
Owner

@jfoug commented on GitHub (Nov 6, 2017):

I am not able to replicate this. I have tried using bcrypt. I made changes so that the original salt string is stored in the salt also. Then within crypt_all, I perform a loop, print out the salt text string, followed by each password tried. I then built a file with 2500 unique passwords and 2500 unique salts, and ran it. Then re-ran, stopping many times. I then looked at the original debugging file and each of the partials. I looked to the bottom of each numbered partial, found that string. Then searched the original for that string, and then took the line right below it (as the EXPECTED) salt to see starting the next debug file. Each time, I see exactly what was expected.

NOTE, this is using v1 salt resume.

One notable thing I spotted, is that the resume always happens at the very end of a salt (after all passowrds are done) (using the 'q' or ^c). So this test may require waiting for the .rec file to be written, and then killing the file (hard kill, not a 'q'). I do not know. I will test a bit more later and see if I can get this to fail in any way. But all testing done to this point, makes it appear that things are working exactly as expected (for the v1 salt resume). It starts right off where it left off. Before this change, it would NOT resume the salts already done, and would instead replay the entire set of work done on the password set, thus when restarting, it would simply make john appear to hang, when it went through and rechecked all of the already completed salts.

I will try to find the AM data. I may have removed that a while back, so may need to find it somewhere again. That was really good data to test this out. Getting a million (or 10) slow bcrypt hashes, and then only being able to test a few passwords at a time efficiently really showed this bug. When I found it, I had run for about a week, the machine crashes, and then I restarted, and there was simply NO passwords cracked for about a week, then when they started to crack , they were cracking at about the exact rate they should have been. It ended up in this case that the resume was 100% starting over, and was no resume at all.

<!-- gh-comment-id:342305457 --> @jfoug commented on GitHub (Nov 6, 2017): I am not able to replicate this. I have tried using bcrypt. I made changes so that the original salt string is stored in the salt also. Then within crypt_all, I perform a loop, print out the salt text string, followed by each password tried. I then built a file with 2500 unique passwords and 2500 unique salts, and ran it. Then re-ran, stopping many times. I then looked at the original debugging file and each of the partials. I looked to the bottom of each numbered partial, found that string. Then searched the original for that string, and then took the line right below it (as the EXPECTED) salt to see starting the next debug file. Each time, I see exactly what was expected. NOTE, this is using v1 salt resume. One notable thing I spotted, is that the resume always happens at the very end of a salt (after all passowrds are done) (using the 'q' or ^c). So this test may require waiting for the .rec file to be written, and then killing the file (hard kill, not a 'q'). I do not know. I will test a bit more later and see if I can get this to fail in any way. But all testing done to this point, makes it appear that things are working exactly as expected (for the v1 salt resume). It starts right off where it left off. Before this change, it would NOT resume the salts already done, and would instead replay the entire set of work done on the password set, thus when restarting, it would simply make john appear to hang, when it went through and rechecked all of the already completed salts. I will try to find the AM data. I may have removed that a while back, so may need to find it somewhere again. That was really good data to test this out. Getting a million (or 10) slow bcrypt hashes, and then only being able to test a few passwords at a time efficiently really showed this bug. When I found it, I had run for about a week, the machine crashes, and then I restarted, and there was simply NO passwords cracked for about a week, then when they started to crack , they were cracking at about the exact rate they should have been. It ended up in this case that the resume was 100% starting over, and was no resume at all.
Author
Owner

@magnumripper commented on GitHub (Nov 6, 2017):

OK so let's just reason about this without any hard facts: What, exactly, is stored in the rec file? Say we have a wordlist with 00000...99999 in it, and we run with 500 salts and a KPC of 100. We load 100 candidates (that'd be 00000...00099) in set_key() and then we run crypt_all() with salt 0. Then salt 1 and crypt_all() again, and so on until salt 249, then we abort (soft).

What is now in the rec file? I'm sure the salt is OK, but what is stored in terms of candidates?

I had in mind that we'd have something like "candidates up to x are processed up to salt y". If that's it and we change the KPC, things will (or may) get out of hands.

I'll be VERY happy if we can prove I'm wrong, I'm just not sure (yet) we will.

<!-- gh-comment-id:342307732 --> @magnumripper commented on GitHub (Nov 6, 2017): OK so let's just reason about this without any hard facts: What, exactly, is stored in the rec file? Say we have a wordlist with 00000...99999 in it, and we run with 500 salts and a KPC of 100. We load 100 candidates (that'd be 00000...00099) in set_key() and then we run crypt_all() with salt 0. Then salt 1 and crypt_all() again, and so on until salt 249, then we abort (soft). What is now in the rec file? I'm sure the salt is OK, but what is stored in terms of candidates? I had in mind that we'd have something like "candidates up to x are processed up to salt y". If that's it and we change the KPC, things will (or may) get out of hands. I'll be VERY happy if we can prove I'm wrong, I'm just not sure (yet) we will.
Author
Owner

@magnumripper commented on GitHub (Nov 6, 2017):

"candidates up to x are processed up to salt y"

Note that this (given a rec file says this at all) implicitly says "all salts has processed all candidates up to (x - kpc) fully". So if we changed the KPC... what just happened?

<!-- gh-comment-id:342309184 --> @magnumripper commented on GitHub (Nov 6, 2017): > "candidates up to x are processed up to salt y" Note that this (given a rec file says this at all) implicitly says "all salts has processed all candidates up to (x - kpc) fully". So if we changed the KPC... what just happened?
Author
Owner

@jfoug commented on GitHub (Nov 6, 2017):

I do understand the bug, We have this:

passwords loaded 60001 to 62000 stopped processing after salt xxxxxxx Then upon resume, we restore to the 'right' password, but this time, we reload 4k password (600001 to 64000), then we seek to salt xxxxxxx (somewhere in the middle of the salts). However, all prior salts (from aaaaaaa to xxxxxxx do not get passwords 62001 to 64000 tested. But for the life of me, I can not seem to find a way to test this. I have tried different OMP thread counts, etc. Nothing seems lost, but I do understand the reasoning behind this bug, and that we 'should' be missing data. I just need to find a good way to trigger this problem, so that I know if/when it happens that the changes I am proposing will solve the problem (and hopefully do so without displaying the huge problem of doing mountains of work in 100% infertile ground, i.e. work already done, which itself is a very bad thing also.

<!-- gh-comment-id:342309501 --> @jfoug commented on GitHub (Nov 6, 2017): I do understand the bug, We have this: passwords loaded 60001 to 62000 stopped processing after salt xxxxxxx Then upon resume, we restore to the 'right' password, but this time, we reload 4k password (600001 to 64000), then we seek to salt xxxxxxx (somewhere in the middle of the salts). However, all prior salts (from aaaaaaa to xxxxxxx do not get passwords 62001 to 64000 tested. But for the life of me, I can not seem to find a way to test this. I have tried different OMP thread counts, etc. Nothing seems lost, but I do understand the reasoning behind this bug, and that we 'should' be missing data. I just need to find a good way to trigger this problem, so that I know if/when it happens that the changes I am proposing will solve the problem (and hopefully do so without displaying the huge problem of doing mountains of work in 100% infertile ground, i.e. work already done, which itself is a very bad thing also.
Author
Owner

@magnumripper commented on GitHub (Nov 6, 2017):

Right! Great you get my idea. Perhaps in the end I'm wrong, and that'd be sweet. I'm just very frightened by this very scenario.

Again, the question is "what is actually stored in terms of candidates when we abort"?

<!-- gh-comment-id:342310093 --> @magnumripper commented on GitHub (Nov 6, 2017): Right! Great you get my idea. Perhaps in the end I'm wrong, and that'd be sweet. I'm just very frightened by this very scenario. Again, the question is "what is actually stored in terms of **candidates** when we abort"?
Author
Owner

@jfoug commented on GitHub (Nov 6, 2017):

I'll be VERY happy if we can prove I'm wrong, I'm just not sure (yet) we will.

I am not sure you are wrong either. But so far, the thing starts out 'exactly' where a full blown run would have, If I concatented all of the partial runs (just the debugging output), it was 100% identical to the full run. Even switching OMP threads. The only difference was the higher OMP count had more 'garbage' at the start of the file (debugging output for the test vectors). But that was 100% expected.

NOTE, when talking about this, I see 100% exactly the same as you were, that we should be missing a TON of candidate trials. But the debugging does not show this. NOTE, this was with 'graceful' shutdowns, not with an arbitrary .rec file being stored, and then the app crashing. I simply hit 'q' then resumed, appending the stderr output to a new file each time, so I could compare results when done.

It is VERY likely that I simply am not using input data that will trigger the bug listed here. Like I said, I would like to test with a know huge monster (way 50k salts from AM) I have simply created some moderately slow BCRYPT using pass_gen. But for the life of me, I have not gotten invalid results so far.

<!-- gh-comment-id:342311027 --> @jfoug commented on GitHub (Nov 6, 2017): > I'll be VERY happy if we can prove I'm wrong, I'm just not sure (yet) we will. I am not sure you are wrong either. But so far, the thing starts out 'exactly' where a full blown run would have, If I concatented all of the partial runs (just the debugging output), it was 100% identical to the full run. Even switching OMP threads. The only difference was the higher OMP count had more 'garbage' at the start of the file (debugging output for the test vectors). But that was 100% expected. NOTE, when talking about this, I see 100% exactly the same as you were, that we should be missing a TON of candidate trials. But the debugging does not show this. NOTE, this was with 'graceful' shutdowns, not with an arbitrary .rec file being stored, and then the app crashing. I simply hit 'q' then resumed, appending the stderr output to a new file each time, so I could compare results when done. It is VERY likely that I simply am not using input data that will trigger the bug listed here. Like I said, I would like to test with a know huge monster (way 50k salts from AM) I have simply created some moderately slow BCRYPT using pass_gen. But for the life of me, I have not gotten invalid results so far.
Author
Owner

@magnumripper commented on GitHub (Nov 6, 2017):

Trying to get a grip, let's go to extremes. We run some raw OpenCL format doing a 1M candidates per batch. We load 1M candidates (the very first million). We run half of the salts and then we abort. I think what is now stored is we're still at position "0" and we did half of the salts.

So upon resuming (but now with a wee 8 candidates per batch, just for extremes), we're still at "0" but only load 8 in a batch. And then we resume half-way into the salts. This should actually not be a problem (except we are re-doing work).

OK, so far so good. What if we went from KPC 8 to KPC 1M?

We load 8 candidates (the very first 8), we run half of the salts, we abort. Rec file says we're at "0" and through half of the salts. Upon resuming, we load 1M candidates instead, and jump over half of the salts. OK, here's where the problem is. I think this was my original reasoning. We now load 1M candidates instead of 8, but we skip half of the salts even though they were only tested with a wee 8 candidates and not 1M candidates.

<!-- gh-comment-id:342311726 --> @magnumripper commented on GitHub (Nov 6, 2017): Trying to get a grip, let's go to extremes. We run some raw OpenCL format doing a 1M candidates per batch. We load 1M candidates (the very first million). We run half of the salts and then we abort. I think what is now stored is we're still at position "0" and we did half of the salts. So upon resuming (but now with a wee 8 candidates per batch, just for extremes), we're still at "0" but only load 8 in a batch. And then we resume half-way into the salts. This should actually not be a problem (except we are re-doing work). OK, so far so good. What if we went from KPC 8 to KPC 1M? We load 8 candidates (the very first 8), we run half of the salts, we abort. Rec file says we're at "0" and through half of the salts. Upon resuming, we load 1M candidates instead, and jump over half of the salts. OK, here's where the problem is. I think this was my original reasoning. We now load 1M candidates instead of 8, but we skip half of the salts even though they were only tested with a wee 8 candidates and not 1M candidates.
Author
Owner

@jfoug commented on GitHub (Nov 6, 2017):

Ok, what is stored:

  1. normal resume file. This seeks to password 62001 (or whatever)
  2. an extra restore block. This is the salt block.

What is stored in the salt block is the MD5 of the salt we just finished. So what happens is when we go into salt_crack_loop (in cracker.c), it gets the 'salt' pointer (i.e the list of salts). These do match order when you rerun the same file. If the user edits the input file, then all bets are off (i.e. the state is NOT what we expect). There is special code and if this is the FIRST call to salt_crack_loop, and there was a salt-md5 stored, then the code knows to move the salt pointer. It simply searched the salt linked list, checking the md5 checksums (created at salt loading time). IF it finds an exact match, then it changes the salt pointer to start from here (i.e. skipping the prior salts, and only doing salts from that point on).

So, here could be some problems.. 1. the stored salt may ALWAYS be the last salt in the list (in my testing). In that case, it would do no tests, and simply go to the next passwords. 2. the stored salt may always be the FIRST salt in the salt list. In that case, the fill list of salts is tested with the new password set. Other than those 2 possibilities, I just can not see how we are testing all possible salt-password pairs that we 'should' be. I will check to see if any of these situations are happening. But like I said, I can literally take the salt-pw pairs from a complete full run, and take the salt-pw pairs from multiple runs, and concatenate those file, and have 100% identical salt-pw files, showing that 100% of the expected salt-pw were tested, and not a single extra one was tested.

So either my expected test conditions are not valid for showing this bug, OR due to other factors (like when / how john makes the .rec files), this is not really a bug even though it REALLY appears to be.

I am out for now. Got a lot of other real stuff to do for now.

<!-- gh-comment-id:342313920 --> @jfoug commented on GitHub (Nov 6, 2017): Ok, what is stored: 1. normal resume file. This seeks to password 62001 (or whatever) 2. an extra restore block. This is the salt block. What is stored in the salt block is the MD5 of the salt we just finished. So what happens is when we go into salt_crack_loop (in cracker.c), it gets the 'salt' pointer (i.e the list of salts). These do match order when you rerun the same file. If the user edits the input file, then all bets are off (i.e. the state is NOT what we expect). There is special code and if this is the FIRST call to salt_crack_loop, and there was a salt-md5 stored, then the code knows to move the salt pointer. It simply searched the salt linked list, checking the md5 checksums (created at salt loading time). IF it finds an exact match, then it changes the salt pointer to start from here (i.e. skipping the prior salts, and only doing salts from that point on). So, here could be some problems.. 1. the stored salt may ALWAYS be the last salt in the list (in my testing). In that case, it would do no tests, and simply go to the next passwords. 2. the stored salt may always be the FIRST salt in the salt list. In that case, the fill list of salts is tested with the new password set. Other than those 2 possibilities, I just can not see how we are testing all possible salt-password pairs that we 'should' be. I will check to see if any of these situations are happening. But like I said, I can literally take the salt-pw pairs from a complete full run, and take the salt-pw pairs from multiple runs, and concatenate those file, and have 100% identical salt-pw files, showing that 100% of the expected salt-pw were tested, and not a single extra one was tested. So either my expected test conditions are not valid for showing this bug, OR due to other factors (like when / how john makes the .rec files), this is not really a bug even though it REALLY appears to be. I am out for now. Got a lot of other real stuff to do for now.
Author
Owner

@jfoug commented on GitHub (Nov 6, 2017):

sorry wrong button

<!-- gh-comment-id:342314026 --> @jfoug commented on GitHub (Nov 6, 2017): sorry wrong button
Author
Owner

@jfoug commented on GitHub (Nov 6, 2017):

I think what is now stored is we're still at position "0" and we did half of the salts.

I am not sure john will allow us to exit in this way. That is why I am wondering if this bug will ONLY show up on a TRUE crash resume ? I will look deeper when I have time.

<!-- gh-comment-id:342314666 --> @jfoug commented on GitHub (Nov 6, 2017): > I think what is now stored is we're still at position "0" and we did half of the salts. I am not sure john will allow us to exit in this way. That is why I am wondering if this bug will ONLY show up on a TRUE crash resume ? I will look deeper when I have time.
Author
Owner

@magnumripper commented on GitHub (Nov 6, 2017):

I think what is now stored is we're still at position "0" and we did half of the salts.

I am not sure john will allow us to exit in this way.

Yet I'm pretty sure that IS a normal resume. The rec file stores the position of the last word that is fully tested (with all salts) as well as the salt that was tested with the last batch (note the discrepancy - this is the bug!). If we load the first batch and then abort after half of the salts, the position will still be "zero" or "start of wordlist".

As long as we resume with same KPC, we will seek to zero, re-load the first x words, skip y salts and everything will be fine and dandy. Nothing missed, nothing re-done.

If we resume with 2x KPC, we will seek to zero, re-load the first eg. 2x words, skip y salts and boom, we missed stuff. To be precise the real miss actually happens once we have processed all the remaining salts. John will now write to the recovery file that we did 2x words with all salts. But we didn't.

<!-- gh-comment-id:342316733 --> @magnumripper commented on GitHub (Nov 6, 2017): >> I think what is now stored is we're still at position "0" and we did half of the salts. > > I am not sure john will allow us to exit in this way. Yet I'm pretty sure that IS a normal resume. The rec file stores the position of the last word *that is fully tested* (with all salts) as well as the salt that was *tested with the last batch* (note the discrepancy - this is the bug!). If we load the first batch and then abort after half of the salts, the position will still be "zero" or "start of wordlist". As long as we resume with same KPC, we will seek to zero, re-load the first *x* words, skip *y* salts and everything will be fine and dandy. Nothing missed, nothing re-done. If we resume with 2x KPC, we will seek to zero, re-load the first eg. *2x* words, skip *y* salts and boom, we missed stuff. To be precise the real miss actually happens once we have processed all the remaining salts. John will now write to the recovery file that we did *2x* words with *all* salts. But we didn't.
Author
Owner

@jfoug commented on GitHub (Nov 7, 2017):

Ok, I have validated that this bug DOES happen (I was concerned about not seeing it). I built some input files in a specific manner, to make sure it would happen it it could. Well, here are the results (and re-running against the .pot file made no the 2nd run did find the other 20 or so missed passwords

$ wc full-run
 234544  704935 7053381 full-run

User@User-PC /c/JtR/bleed0/tst
$ wc part*-run
   3855   12522  124933 part0-run
  37654  113141 1136747 part1-run
   4204   12639  128671 part2-run
 174602  523825 5240401 part3-run
 220315  662127 6630752 total

So now I can replicate it. I can start to put code together to make sure that we do not MISS anything, and try to write it so that we have as few redundant tests being done. IT may actually be best to try to run the very first batch using KPC at equal (or less) than what was in the .rec file (but only the first), then from that run forward, use the KPC native to the run. Then I would not have to restart at salt #1, but could continue forward, But that first set of passwords 'might' not be fully optimal, but only that first run.

This testing was done by simply varying OMP_NUM_THREADS (1 2 8 16), and resuming the session.

<!-- gh-comment-id:342563791 --> @jfoug commented on GitHub (Nov 7, 2017): Ok, I have validated that this bug DOES happen (I was concerned about not seeing it). I built some input files in a specific manner, to make sure it would happen it it could. Well, here are the results (and re-running against the .pot file made no the 2nd run did find the other 20 or so missed passwords ``` $ wc full-run 234544 704935 7053381 full-run User@User-PC /c/JtR/bleed0/tst $ wc part*-run 3855 12522 124933 part0-run 37654 113141 1136747 part1-run 4204 12639 128671 part2-run 174602 523825 5240401 part3-run 220315 662127 6630752 total ``` So now I can replicate it. I can start to put code together to make sure that we do not MISS anything, and try to write it so that we have as few redundant tests being done. IT may actually be best to try to run the very first batch using KPC at equal (or less) than what was in the .rec file (but only the first), then from that run forward, use the KPC native to the run. Then I would not have to restart at salt #1, but could continue forward, But that first set of passwords 'might' not be fully optimal, but only that first run. This testing was done by simply varying OMP_NUM_THREADS (1 2 8 16), and resuming the session.
Author
Owner

@jfoug commented on GitHub (Nov 7, 2017):

I will first simply switch over to v2 salt logic that I wrote (ignore salt resume if the KPC changes). Once I am sure that code fixes things, I will see if I can change the first leg of work to use a possibly reduced KPC. Then If both methods work, I will see which method is better than the other. But I think it will end up being that there are times which one method will be better, but other times when the other method is better.

Ok, first test. The code listed above (v2 salt restore). Things worked fine. Running a full session finds 120 passwords, resuming finds the same 120 passwords. There was noticeable delays at resume time, before passwords started to show up, since we were re-running already partly worked data (when we expanded the KPC). Here are the counts of salt-passwords tested:

$ wc full-run
 234375  704412 7047269 full-run

$ wc part-?-run
   1884    6594   64684 part-0-run
  13584   42000  418336 part-1-run
   6024   18072  180720 part-2-run
  20784   62352  624061 part-3-run
  14304   42912  430908 part-4-run
   5664   16992  169920 part-5-run
 197427  592281 5927145 part-6-run
 259671  781203 7815774 total

So the counts done on the restart were higher, using this method (the re-run of already tested data). But in the end all passwords were cracked, and the bug pointed out here is handled.

I will work at the reduced KPC on first loop on restart, and see how that works. It should not show any noticeable delay kicking out the first passwords after resume. BUT that first block of code may be sub optimal, since it is not full.

<!-- gh-comment-id:342607840 --> @jfoug commented on GitHub (Nov 7, 2017): I will first simply switch over to v2 salt logic that I wrote (ignore salt resume if the KPC changes). Once I am sure that code fixes things, I will see if I can change the first leg of work to use a possibly reduced KPC. Then If both methods work, I will see which method is better than the other. But I think it will end up being that there are times which one method will be better, but other times when the other method is better. Ok, first test. The code listed above (v2 salt restore). Things worked fine. Running a full session finds 120 passwords, resuming finds the same 120 passwords. There was noticeable delays at resume time, before passwords started to show up, since we were re-running already partly worked data (when we expanded the KPC). Here are the counts of salt-passwords tested: ``` $ wc full-run 234375 704412 7047269 full-run $ wc part-?-run 1884 6594 64684 part-0-run 13584 42000 418336 part-1-run 6024 18072 180720 part-2-run 20784 62352 624061 part-3-run 14304 42912 430908 part-4-run 5664 16992 169920 part-5-run 197427 592281 5927145 part-6-run 259671 781203 7815774 total ``` So the counts done on the restart were higher, using this method (the re-run of already tested data). But in the end all passwords were cracked, and the bug pointed out here is handled. I will work at the reduced KPC on first loop on restart, and see how that works. It should not show any noticeable delay kicking out the first passwords after resume. BUT that first block of code may be sub optimal, since it is not full.
Author
Owner

@jfoug commented on GitHub (Nov 7, 2017):

Note to self. We also need to make sure that the ET is properly handled (either method we settle on using)

<!-- gh-comment-id:342608644 --> @jfoug commented on GitHub (Nov 7, 2017): Note to self. We also need to make sure that the ET is properly handled (either method we settle on using)
Author
Owner

@jfoug commented on GitHub (Nov 7, 2017):

Ok, doing reduced KPC on first resume run was pretty easy also. In this model, you do NOT see any delay for the first crack, since there is no work being redone. The downside is that the first salt loop will be run with the same count as what was in the resume file (if we have more KPC now), but on all the remaining salt_loop calls, we will be at full KCP

$ wc full-run
 234375  704412 7047269 full-run

User@User-PC /c/JtR/bleed0/tst
$ wc part_*
   2256    7332   72568 part_0-run
   1500    4875   48250 part_1-run
  12192   36924  368817 part_2-run
  31656   94968  951990 part_3-run
 186650  559950 5602020 part_4-run
 234254  704049 7043645 total

Note, there are a few missing tests in the resume with this method. I need to check why. It looks like either we are starting the salt after where we should be or something. BUT I do like this 'feel' of this method better. It does not have the large delays the other restore does. Appearance to the end users do matter ;) If they have been seeing a couple cracks per minute, resume, and then do not see ANYTHING output for several hours, they will think something is wrong, even it it is not and simply john working around this bug. But if done by lowering the KPC on the first loop, if they were seeing cracks every couple minutes, then they should start seeing cracks shortly after starting.

here is cracker.c (the other patches shown earlier in this post are still valid). This would not be a complete patch here. I simply commented out the if statement in the salt_loop. If we go with this method, that if statement simply would not exist, and the original salt_crack_loop would be used.

--- a/src/cracker.c
+++ b/src/cracker.c
@@ -97,6 +97,10 @@ static int64 *crk_timestamps;
 static char crk_stdout_key[PLAINTEXT_BUFFER_SIZE];
 int64_t crk_pot_pos;

+// expose max_keys_per_crypt to the world (needed in recovery.c)
+int cracker_max_keys_per_crypt() {
+       return  crk_params.max_keys_per_crypt;
+}
 static void crk_dummy_set_salt(void *salt)
 {
 }
@@ -969,15 +973,19 @@ static int crk_salt_loop(void)
                struct db_salt *s = salt;

                status.resume_salt = 0; /* only resume the first time */
-               while (s) {
-                       if (s->salt_md5[0] == status.resume_salt_md5[0] &&
-                           !memcmp(s->salt_md5, status.resume_salt_md5, 16))
-                       {
-                               /* found it!! */
-                               salt = s;
-                               break;
+//             if ((status.resume_salt_crypts_per == -1 ||
+//                     status.resume_salt_crypts_per == crk_params.max_keys_per_crypt))
+               {
+                       while (s) {
+                               if (s->salt_md5[0] == status.resume_salt_md5[0] &&
+                                       !memcmp(s->salt_md5, status.resume_salt_md5, 16))
+                               {
+                                       /* found it!! */
+                                       salt = s;
+                                       break;
+                               }
+                               s = s->next;
                        }
-                       s = s->next;
                }
        }
        do {
@@ -1035,13 +1043,16 @@ static int crk_salt_loop(void)

 int crk_process_key(char *key)
 {
+       int max_keys = crk_params.max_keys_per_crypt;
+       if (status.resume_salt && status.resume_salt_crypts_per > 0 && status.resume_salt_crypts_per < max_keys)
+               max_keys = status.resume_salt_crypts_per;
        if (crk_db->loaded) {
                if (crk_key_index == 0)
                        crk_methods.clear_keys();

                crk_methods.set_key(key, crk_key_index++);

-               if (crk_key_index >= crk_params.max_keys_per_crypt ||
+               if (crk_key_index >= max_keys ||
                    (options.force_maxkeys &&
                     crk_key_index >= options.force_maxkeys))
                        return crk_salt_loop();
<!-- gh-comment-id:342620476 --> @jfoug commented on GitHub (Nov 7, 2017): Ok, doing reduced KPC on first resume run was pretty easy also. In this model, you do NOT see any delay for the first crack, since there is no work being redone. The downside is that the first salt loop will be run with the same count as what was in the resume file (if we have more KPC now), but on all the remaining salt_loop calls, we will be at full KCP ``` $ wc full-run 234375 704412 7047269 full-run User@User-PC /c/JtR/bleed0/tst $ wc part_* 2256 7332 72568 part_0-run 1500 4875 48250 part_1-run 12192 36924 368817 part_2-run 31656 94968 951990 part_3-run 186650 559950 5602020 part_4-run 234254 704049 7043645 total ``` Note, there are a few missing tests in the resume with this method. I need to check why. It looks like either we are starting the salt after where we should be or something. BUT I do like this 'feel' of this method better. It does not have the large delays the other restore does. Appearance to the end users do matter ;) If they have been seeing a couple cracks per minute, resume, and then do not see ANYTHING output for several hours, they will think something is wrong, even it it is not and simply john working around this bug. But if done by lowering the KPC on the first loop, if they were seeing cracks every couple minutes, then they should start seeing cracks shortly after starting. here is cracker.c (the other patches shown earlier in this post are still valid). This would not be a complete patch here. I simply commented out the if statement in the salt_loop. If we go with this method, that if statement simply would not exist, and the original salt_crack_loop would be used. ```diff --- a/src/cracker.c +++ b/src/cracker.c @@ -97,6 +97,10 @@ static int64 *crk_timestamps; static char crk_stdout_key[PLAINTEXT_BUFFER_SIZE]; int64_t crk_pot_pos; +// expose max_keys_per_crypt to the world (needed in recovery.c) +int cracker_max_keys_per_crypt() { + return crk_params.max_keys_per_crypt; +} static void crk_dummy_set_salt(void *salt) { } @@ -969,15 +973,19 @@ static int crk_salt_loop(void) struct db_salt *s = salt; status.resume_salt = 0; /* only resume the first time */ - while (s) { - if (s->salt_md5[0] == status.resume_salt_md5[0] && - !memcmp(s->salt_md5, status.resume_salt_md5, 16)) - { - /* found it!! */ - salt = s; - break; +// if ((status.resume_salt_crypts_per == -1 || +// status.resume_salt_crypts_per == crk_params.max_keys_per_crypt)) + { + while (s) { + if (s->salt_md5[0] == status.resume_salt_md5[0] && + !memcmp(s->salt_md5, status.resume_salt_md5, 16)) + { + /* found it!! */ + salt = s; + break; + } + s = s->next; } - s = s->next; } } do { @@ -1035,13 +1043,16 @@ static int crk_salt_loop(void) int crk_process_key(char *key) { + int max_keys = crk_params.max_keys_per_crypt; + if (status.resume_salt && status.resume_salt_crypts_per > 0 && status.resume_salt_crypts_per < max_keys) + max_keys = status.resume_salt_crypts_per; if (crk_db->loaded) { if (crk_key_index == 0) crk_methods.clear_keys(); crk_methods.set_key(key, crk_key_index++); - if (crk_key_index >= crk_params.max_keys_per_crypt || + if (crk_key_index >= max_keys || (options.force_maxkeys && crk_key_index >= options.force_maxkeys)) return crk_salt_loop(); ```
Author
Owner

@jfoug commented on GitHub (Nov 7, 2017):

Digging deeper, there may be no issues at all (counts not matching), on the last method (the reduced KPC). It looks like salts may have been removed at different times based upon method. I think I will re-run the tests where I have no passwords in the input file that crack anything. Then we will see if the counts match. But right now, even with the unexpected count mismatch, I think the code is correct.

<!-- gh-comment-id:342623711 --> @jfoug commented on GitHub (Nov 7, 2017): Digging deeper, there may be no issues at all (counts not matching), on the last method (the reduced KPC). It looks like salts may have been removed at different times based upon method. I think I will re-run the tests where I have no passwords in the input file that crack anything. Then we will see if the counts match. But right now, even with the unexpected count mismatch, I think the code is correct.
Author
Owner

@jfoug commented on GitHub (Nov 7, 2017):

Also, we may be able to put the computation of max_keys (it would have to be global or static), and only do that in the

  if (crk_key_index==0) {}

block of code (i.e. so we do not have to preform that computation every salt/pw pair. But I will not do that unless @magnum thinks it is the right place to move that code.

<!-- gh-comment-id:342624877 --> @jfoug commented on GitHub (Nov 7, 2017): Also, we may be able to put the computation of max_keys (it would have to be global or static), and only do that in the ```C if (crk_key_index==0) {} ``` block of code (i.e. so we do not have to preform that computation every salt/pw pair. But I will not do that unless @magnum thinks it is the right place to move that code.
Author
Owner

@magnumripper commented on GitHub (Nov 7, 2017):

Excellent! I have little time now and haven't looked much at your latest diffs, but here's some thoughts from yesterday & today:

  • When we see a v1-only salt tag, I think we should put safety first and start over from scratch. At least for OpenCL - and probably for others too (unless KPC == 1 on resume, that case is always safe).
  • We need to test and/or dry-run Single mode separately and carefully, because that one is special. I think KPC may vary a lot in that mode.
<!-- gh-comment-id:342637855 --> @magnumripper commented on GitHub (Nov 7, 2017): Excellent! I have little time now and haven't looked much at your latest diffs, but here's some thoughts from yesterday & today: * When we see a v1-only salt tag, I think we should put safety first and start over from scratch. At least for OpenCL - and probably for others too (unless KPC == 1 on resume, that case is always safe). * We need to test and/or dry-run Single mode separately and carefully, because that one is special. I think KPC may vary a lot in that mode.
Author
Owner

@jfoug commented on GitHub (Nov 7, 2017):

Ok, I feel good now. The new method finds the exact same salt-pw list. It did have a few duplicates. I think there were dupes when I shut things down before the first run block completed, and then started it again with a different OMP level. BUT i the end, all salt-pw pairs were processed

$ wc full-x-run
 290004  870012 9570132 full-x-run

$ wc part-x*
  22272   66816  734976 part-x0-run
   6792   20376  224136 part-x1-run
  17292   51876  570636 part-x2-run
  31008   93024 1023264 part-x3-run
 213900  641700 7058700 part-x4-run
 291264  873792 9611712 total                     (Note, count a bit high here)

$ cat part-x* | sort > p

$ cat p | uniq | wc
 290004  870012 9570132   (after uniq, the count matches exactly)
<!-- gh-comment-id:342638164 --> @jfoug commented on GitHub (Nov 7, 2017): Ok, I feel good now. The new method finds the exact same salt-pw list. It did have a few duplicates. I think there were dupes when I shut things down before the first run block completed, and then started it again with a different OMP level. BUT i the end, all salt-pw pairs were processed ``` $ wc full-x-run 290004 870012 9570132 full-x-run $ wc part-x* 22272 66816 734976 part-x0-run 6792 20376 224136 part-x1-run 17292 51876 570636 part-x2-run 31008 93024 1023264 part-x3-run 213900 641700 7058700 part-x4-run 291264 873792 9611712 total (Note, count a bit high here) $ cat part-x* | sort > p $ cat p | uniq | wc 290004 870012 9570132 (after uniq, the count matches exactly) ```
Author
Owner

@magnumripper commented on GitHub (Nov 7, 2017):

  • We need to test and/or dry-run Single mode separately and carefully, because that one is special. I think KPC may vary a lot in that mode.

Actually, if we feel any uncertainity about Single mode we could simply disable salt resume for it. Since it runs so totally different, I'm pretty sure there's little penalty on resume anyway (and when there is, it's for other reasons than the normal "many slow salts" case). @solardiz does this make sense?

<!-- gh-comment-id:342639241 --> @magnumripper commented on GitHub (Nov 7, 2017): > * We need to test and/or dry-run Single mode separately and carefully, because that one is special. I think KPC may vary a lot in that mode. Actually, if we feel any uncertainity about Single mode we could simply disable salt resume for it. Since it runs so totally different, I'm pretty sure there's little penalty on resume anyway (and when there is, it's for other reasons than the normal "many slow salts" case). @solardiz does this make sense?
Author
Owner

@jfoug commented on GitHub (Nov 7, 2017):

When we see a v1-only salt tag

This will remove any salt-resume for older john. Yes, we can easily add that. I already know it is v1, since there is a -1 in there for the prior run KPC. This is a trivial change.

We need to test and/or dry-run Single mode

I will have to think about how to test this one. It may be that my method of detection (code changes to crypt_all for bcrypt will work just fine. The code I inserted is this:

	{ 
		int i;
		for (i = 0; i < count; ++i)
			fprintf (stderr, "bf_crack: %s %s\n", saved_salt.saltorig, saved_key[i]);
	}

If that code is all that is need, I should be able to test single mode. NOTE, I am not 100% sure how this will play out in single mode. Is the call to the salt_loop function even used??

<!-- gh-comment-id:342640720 --> @jfoug commented on GitHub (Nov 7, 2017): > When we see a v1-only salt tag This will remove any salt-resume for older john. Yes, we can easily add that. I already know it is v1, since there is a -1 in there for the prior run KPC. This is a trivial change. > We need to test and/or dry-run Single mode I will have to think about how to test this one. It may be that my method of detection (code changes to crypt_all for bcrypt will work just fine. The code I inserted is this: ```C { int i; for (i = 0; i < count; ++i) fprintf (stderr, "bf_crack: %s %s\n", saved_salt.saltorig, saved_key[i]); } ``` If that code is all that is need, I should be able to test single mode. NOTE, I am not 100% sure how this will play out in single mode. Is the call to the salt_loop function even used??
Author
Owner

@magnumripper commented on GitHub (Nov 7, 2017):

NOTE, I am not 100% sure how this will play out in single mode. Is the call to the salt_loop function even used??

Me neither. No, I think it's not - Single mode runs very very differently than anything else seen in any cracker I know of.

<!-- gh-comment-id:342641248 --> @magnumripper commented on GitHub (Nov 7, 2017): > NOTE, I am not 100% sure how this will play out in single mode. Is the call to the salt_loop function even used?? Me neither. No, I think it's not - Single mode runs very very differently than anything else seen in any cracker I know of.
Author
Owner

@jfoug commented on GitHub (Nov 7, 2017):

I think the only time salt resume would raise its head, is if there were multiple same salts (I could be wrong). I think the single mode works on each hash independently. Now, there MAY be issues when the single mode does the 'replay of cracked passwords. But I will assure you, there IS serious problems on resume there. The single mode is wholly based upon built up facts happening during the run. We have no way at all (currently) to save the entire state needed to properly resume single mode anyway.

<!-- gh-comment-id:342641568 --> @jfoug commented on GitHub (Nov 7, 2017): I think the only time salt resume would raise its head, is if there were multiple same salts (I could be wrong). I think the single mode works on each hash independently. Now, there MAY be issues when the single mode does the 'replay of cracked passwords. But I will assure you, there IS serious problems on resume there. The single mode is wholly based upon built up facts happening during the run. We have no way at all (currently) to save the entire state needed to properly resume single mode anyway.
Author
Owner

@jfoug commented on GitHub (Nov 7, 2017):

The only real 'resume' in single mode, is to know that we have worked up to hash #x in single mode. The 'extras' done likely are not getting restored properly.

Single is SOOOO powerful, but difficult to add recovery code to.

<!-- gh-comment-id:342642062 --> @jfoug commented on GitHub (Nov 7, 2017): The only real 'resume' in single mode, is to know that we have worked up to hash #x in single mode. The 'extras' done likely are not getting restored properly. Single is SOOOO powerful, but difficult to add recovery code to.
Author
Owner

@jfoug commented on GitHub (Nov 7, 2017):

Ok, I will do this:

  1. use the reduced KPC logic (on first salt loop).
  2. the salt will be skipped forward to the salt left off at on prior run.
  3. if restoring from v1 salt, it will not use the KPC reduction, and also not use the skip fwd in the salts. (i.e. neuter the salt resume logic for any existing v1 salt resume files).
  4. the salt resume block will be the v2 type. Contains the MD5 of the salt, and the existing KPC at the end of the run (and of course the v2 tag).

I will look a bit at single mode, just to make sure this salt resume does not impact a resume, prior to checking the above code in.

But yes, this certainly was a bug. Both corrective methods worked around the bug, but I think the reduced KPC is the better 'fix' to allow keeping the salt resume logic.

<!-- gh-comment-id:342643678 --> @jfoug commented on GitHub (Nov 7, 2017): Ok, I will do this: 1. use the reduced KPC logic (on first salt loop). 2. the salt will be skipped forward to the salt left off at on prior run. 3. if restoring from v1 salt, it will not use the KPC reduction, and also not use the skip fwd in the salts. (i.e. neuter the salt resume logic for any existing v1 salt resume files). 4. the salt resume block will be the v2 type. Contains the MD5 of the salt, and the existing KPC at the end of the run (and of course the v2 tag). I will look a bit at single mode, just to make sure this salt resume does not impact a resume, prior to checking the above code in. But yes, this certainly was a bug. Both corrective methods worked around the bug, but I think the reduced KPC is the better 'fix' to allow keeping the salt resume logic.
Author
Owner

@magnumripper commented on GitHub (Nov 7, 2017):

Yeah, keeping salt resume with varying KPC is awesome. In case of OpenCL, it will normally not even mean any significant speed drop for the first run with "reduced" KPC. Very effective. Really good stuff.

<!-- gh-comment-id:342645070 --> @magnumripper commented on GitHub (Nov 7, 2017): Yeah, keeping salt resume with varying KPC is awesome. In case of OpenCL, it will normally not even mean any significant speed drop for the first run with "reduced" KPC. Very effective. Really good stuff.
Author
Owner

@magnumripper commented on GitHub (Nov 7, 2017):

I think it's something along these lines, very simplified.

Normal crack:

foreach (rule) {
    foreach (word) {
        apply_rule();
        set_key() {
        if (full batch) {
            foreach (salt) {
                set_salt();
                crypt_all();
            }
        }
    }
}

Single mode:

foreach (rule) {
    foreach (salt) {
        foreach (salt-specific candidate) {
            apply_rule();
            set_key();
            if (full batch) {
                set_salt();
                crypt_all();
            }
        }
    }
}

This is not quite it, but it shows the huge difference. @solardiz can you describe it better?

<!-- gh-comment-id:342648225 --> @magnumripper commented on GitHub (Nov 7, 2017): I think it's something along these lines, very simplified. Normal crack: ```c foreach (rule) { foreach (word) { apply_rule(); set_key() { if (full batch) { foreach (salt) { set_salt(); crypt_all(); } } } } ``` Single mode: ```c foreach (rule) { foreach (salt) { foreach (salt-specific candidate) { apply_rule(); set_key(); if (full batch) { set_salt(); crypt_all(); } } } } ``` This is not quite it, but it shows the huge difference. @solardiz can you describe it better?
Author
Owner

@jfoug commented on GitHub (Nov 7, 2017):

That code (if improved to be correct), is VERY VERY helpful. Thanks for simplifying things. there is some logic to 'create;' the salt-specific candidate word somewhere. I think that happens before the apply_rule() block, while at the same time, the 'normal' code it happens within wordlist at load time. So it may be more like:

single mode:

foreach (rule) {
    foreach (salt) {
        foreach (salt-specific candidate) {
           build_local_words();
           foreach(local_word) {
              apply_rule();
              set_key();
              if (full batch) {
                  set_salt();
                  crypt_all();
               }
            }
        }
    }
}
<!-- gh-comment-id:342650296 --> @jfoug commented on GitHub (Nov 7, 2017): That code (if improved to be correct), is VERY VERY helpful. Thanks for simplifying things. there is some logic to 'create;' the salt-specific candidate word somewhere. I think that happens before the apply_rule() block, while at the same time, the 'normal' code it happens within wordlist at load time. So it may be more like: single mode: ```c foreach (rule) { foreach (salt) { foreach (salt-specific candidate) { build_local_words(); foreach(local_word) { apply_rule(); set_key(); if (full batch) { set_salt(); crypt_all(); } } } } } ```
Author
Owner

@jfoug commented on GitHub (Nov 7, 2017):

NOTE, I do not remember if the build-local-words was done within the runtime loop, or done at load time (I think it was at load time, IIRC). But I do think there was a foreach(local_word) loop missing before the apply_rule tag.

If @solardiz would correct this, and also using this format, show how the replay of found cracks plays into the single mode. But simple pseudo docs like this would be fantastic to take the mystery for me out of single mode (and would make great additions to the github wiki)

<!-- gh-comment-id:342650987 --> @jfoug commented on GitHub (Nov 7, 2017): NOTE, I do not remember if the build-local-words was done within the runtime loop, or done at load time (I think it was at load time, IIRC). But I do think there was a foreach(local_word) loop missing before the apply_rule tag. If @solardiz would correct this, and also using this format, show how the replay of found cracks plays into the single mode. But simple pseudo docs like this would be fantastic to take the mystery for me out of single mode (and would make great additions to the github wiki)
Author
Owner

@magnumripper commented on GitHub (Nov 7, 2017):

It's at load-time. Each salt has a list (a list.c list) with candidates made from login and gecos fields (and others) as well as pairing of them and other combinations (like initials).

So instead of a wordlist for all salts, we have a wordlist per salt.

<!-- gh-comment-id:342651458 --> @magnumripper commented on GitHub (Nov 7, 2017): It's at load-time. Each salt has a list (a `list.c` list) with candidates made from login and gecos fields (and others) as well as pairing of them and other combinations (like initials). So instead of a wordlist for all salts, we have a wordlist per salt.
Author
Owner

@magnumripper commented on GitHub (Nov 7, 2017):

Actually it's more like this (I think). Each salt has a buffer that can hold KPC:

foreach (rule) {
    foreach (salt) {
        foreach (salt-specific candidate) {
            apply_rule();
            add_to_salt's_buffer(word);
            if (salt's buffer has a full batch) {
                foreach (buffer)
                    set_key();
                set_salt();
                crypt_all();
            }
        }
    }
}
<!-- gh-comment-id:342652469 --> @magnumripper commented on GitHub (Nov 7, 2017): Actually it's more like this (I think). Each salt has a buffer that can hold KPC: ```c foreach (rule) { foreach (salt) { foreach (salt-specific candidate) { apply_rule(); add_to_salt's_buffer(word); if (salt's buffer has a full batch) { foreach (buffer) set_key(); set_salt(); crypt_all(); } } } } ```
Author
Owner

@jfoug commented on GitHub (Nov 8, 2017):

So, when a crack happens, the code simply spins through all buffers, and calls the

add_to_buffer(cracked_word)

to each salt's buffer?

Also, is your

foreach (salt-specific candidate)

code where we get the gecos split words for each user?

<!-- gh-comment-id:342665265 --> @jfoug commented on GitHub (Nov 8, 2017): So, when a crack happens, the code simply spins through all buffers, and calls the ```c add_to_buffer(cracked_word) ``` to each salt's buffer? Also, is your ```c foreach (salt-specific candidate) ``` code where we get the gecos split words for each user?
Author
Owner

@magnumripper commented on GitHub (Nov 8, 2017):

So, when a crack happens, the code simply spins through all buffers, and calls the

add_to_buffer(cracked_word)

to each salt's buffer?

Either that, or it's a global list. Either way, I have absouletly no idea just how THAT part would resume (even in core John). Should be easily found if we follow the code for SingleRetestGuessed.

Also, is your

foreach (salt-specific candidate)

code where we get the gecos split words for each user?

IIRC all that happens during loading. But pre-made word pairs (the ones that work even with --single=none) are possibly made closer to the inner loops.

<!-- gh-comment-id:342668399 --> @magnumripper commented on GitHub (Nov 8, 2017): > So, when a crack happens, the code simply spins through all buffers, and calls the > ```c > add_to_buffer(cracked_word) > ``` > to each salt's buffer? Either that, or it's a global list. Either way, I have absouletly no idea just how THAT part would resume (even in core John). Should be easily found if we follow the code for `SingleRetestGuessed`. > Also, is your > ```c > foreach (salt-specific candidate) > ``` > code where we get the gecos split words for each user? IIRC all that happens during loading. But pre-made word pairs (the ones that work even with `--single=none`) are possibly made closer to the inner loops.
Author
Owner

@magnumripper commented on GitHub (Nov 8, 2017):

Note that we have a per-salt candidates list (that is static and populated while loading), and a per-salt buffer for next batch of keys for crypt_all for that salt. They are two separate things.

<!-- gh-comment-id:342668715 --> @magnumripper commented on GitHub (Nov 8, 2017): Note that we have a per-salt candidates list (that is static and populated while loading), and a per-salt buffer for next batch of keys for crypt_all for that salt. They are two separate things.
Author
Owner

@jfoug commented on GitHub (Nov 8, 2017):

I have absouletly no idea just how THAT part would resume (even in core John)

It does not resume well. Try it. Get a decent set of data which single will crack about 25%, but that takes an hour or so to run. Run it to completion. Then run it again, but to a different .pot file. Break every 10 minutes, resuming. What you will get in the end will not be the same .pot file. It will still crack a lot, but not all that would have been cracked.

For single mode, it is best to really let it run to completion. IMHO, the default for single should NOT re-insert the cracked candidates (at least in jumbo). what should happen, is single should work to quickly run all the gecos data against the proper hashes. THEN, when completed with single, re-run john in loopback mode, with better rules than the single. Doing this is quite a bit faster (especially for single), and it ends up finding more values than auto retest in single mode. Some of this some depends upon the speed of the hash, but more importantly, if you plan on running john in loopback mode at some point. IF that is the plan, then the retest within single is wasted time (or the retest of these values when doing the loopback is wasted time). Just my $0.02 worth of usage insite.

<!-- gh-comment-id:342796887 --> @jfoug commented on GitHub (Nov 8, 2017): > I have absouletly no idea just how THAT part would resume (even in core John) It does not resume well. Try it. Get a decent set of data which single will crack about 25%, but that takes an hour or so to run. Run it to completion. Then run it again, but to a different .pot file. Break every 10 minutes, resuming. What you will get in the end will not be the same .pot file. It will still crack a lot, but not all that would have been cracked. For single mode, it is best to really let it run to completion. IMHO, the default for single should NOT re-insert the cracked candidates (at least in jumbo). what should happen, is single should work to quickly run all the gecos data against the proper hashes. THEN, when completed with single, re-run john in loopback mode, with better rules than the single. Doing this is quite a bit faster (especially for single), and it ends up finding more values than auto retest in single mode. Some of this some depends upon the speed of the hash, but more importantly, if you plan on running john in loopback mode at some point. IF that is the plan, then the retest within single is wasted time (or the retest of these values when doing the loopback is wasted time). Just my $0.02 worth of usage insite.
Author
Owner

@ghost commented on GitHub (Nov 9, 2017):

I'm trying to demonstrate a situation where JtR restore logic seems to stop to try the next new candidates.

  1. adjust to 2 - 4 p/s (on super -> OMP_THREAD_LIMIT=1)
  2. run ../run/john -mask=?w?d?d -w=bitcoin_restart_rules_tst.dic bitcoin_restart_rules_tst.in -form=bitcoin -max-run=20
  3. notice the Loaded a total of 2000 password hashes with 2000 different salts versus:
../run/john -mask=?w?d?d -w=bitcoin_restart_rules_tst.dic --stdout
[...]
2000p 0:00:00:00 100,00% (2017-11-09 05:32) 40000p/s 11112977
  1. notice it cracks some stuff in the beginning. In 1:1 keys versus cracks it is expected. But:

CI: stuck on 5%:

81g 0:00:00:20 5.00% (ETA: 00:06:34) 4.045g/s 3.996p/s 8133c/s 8133C/s 11111016..11111046
88g 0:00:00:41 5.00% (ETA: 00:13:34) 2.146g/s 3.902p/s 7937c/s 7937C/s 11111016..11111046
94g 0:00:01:02 5.00% (ETA: 00:20:34) 1.516g/s 4.000p/s 7875c/s 7875C/s 11111066..11111087
94g 0:00:01:23 5.00% (ETA: 00:27:34) 1.132g/s 4.048p/s 7841c/s 7841C/s 11111066..11111087
94g 0:00:01:44 5.00% (ETA: 00:34:34) 0.9038g/s 4.000p/s 7826c/s 7826C/s 11111016..11111046
94g 0:00:02:05 5.00% (ETA: 00:41:34) 0.7520g/s 4.032p/s 7815c/s 7815C/s 11111066..11111087
[...]
94g 0:00:40:56 5.00% (ETA: 13:38:50) 0.03827g/s 4.065p/s 7753c/s 7753C/s 11111066..11111087

Super: stuck on 10%:

52g 0:00:00:20 5.00% (ETA: 04:23:44) 2.578g/s 0p/s 4769c/s 4769C/s 11111011..11111035
Continuing session.  Cmd line: ../run/john -res=tst- 2>&1
94g 0:00:00:41 10.00% (ETA: 04:24:04) 2.292g/s 1.560p/s 4686c/s 4686C/s 11111095..11111142
Continuing session.  Cmd line: ../run/john -res=tst- 2>&1
94g 0:00:01:02 10.00% (ETA: 04:27:44) 1.516g/s 2.064p/s 4650c/s 4650C/s 11111095..11111142
Continuing session.  Cmd line: ../run/john -res=tst- 2>&1
94g 0:00:01:23 10.00% (ETA: 04:31:24) 1.132g/s 2.313p/s 4633c/s 4633C/s 11111095..11111142
Continuing session.  Cmd line: ../run/john -res=tst- 2>&1
94g 0:00:01:44 5.00% (ETA: 04:52:24) 0.9038g/s 1.846p/s 4623c/s 4623C/s 11111011..11111035
Continuing session.  Cmd line: ../run/john -res=tst- 2>&1
108g 0:00:02:05 10.00% (ETA: 04:38:44) 0.8640g/s 2.048p/s 4613c/s 4613C/s 11111095..11111142
Continuing session.  Cmd line: ../run/john -res=tst- 2>&1
108g 0:00:02:26 10.00% (ETA: 04:42:23) 0.7397g/s 2.191p/s 4608c/s 4608C/s 11111095..11111142
Continuing session.  Cmd line: ../run/john -res=tst- 2>&1
108g 0:00:02:47 10.00% (ETA: 04:46:03) 0.6467g/s 2.299p/s 4604c/s 4604C/s 11111095..11111142
Continuing session.  Cmd line: ../run/john -res=tst- 2>&1
108g 0:00:03:08 10.00% (ETA: 04:49:43) 0.5744g/s 2.382p/s 4602c/s 4602C/s 11111095..11111142
Continuing session.  Cmd line: ../run/john -res=tst- 2>&1
108g 0:00:03:29 5.00% (ETA: 05:28:13) 0.5167g/s 2.143p/s 4600c/s 4600C/s 11111011..11111035
Continuing session.  Cmd line: ../run/john -res=tst- 2>&1
108g 0:00:03:50 10.00% (ETA: 04:57:03) 0.4695g/s 2.226p/s 4598c/s 4598C/s 11111095..11111142
Continuing session.  Cmd line: ../run/john -res=tst- 2>&1
108g 0:00:04:11 10.00% (ETA: 05:00:43) 0.4302g/s 2.294p/s 4597c/s 4597C/s 11111095..11111142
Continuing session.  Cmd line: ../run/john -res=tst- 2>&1
108g 0:00:04:32 10.00% (ETA: 05:04:23) 0.3970g/s 2.352p/s 4596c/s 4596C/s 11111095..11111142
Continuing session.  Cmd line: ../run/john -res=tst- 2>&1
108g 0:00:04:53 10.00% (ETA: 05:08:03) 0.3686g/s 2.402p/s 4593c/s 4593C/s 11111095..11111142
Continuing session.  Cmd line: ../run/john -res=tst- 2>&1
108g 0:00:05:14 5.00% (ETA: 06:04:02) 0.3439g/s 2.242p/s 4593c/s 4593C/s 11111011..11111035
Continuing session.  Cmd line: ../run/john -res=tst- 2>&1
108g 0:00:05:35 10.00% (ETA: 05:15:22) 0.3223g/s 2.292p/s 4592c/s 4592C/s 11111095..11111142
Continuing session.  Cmd line: ../run/john -res=tst- 2>&1
108g 0:00:05:56 10.00% (ETA: 05:19:02) 0.3033g/s 2.337p/s 4591c/s 4591C/s 11111095..11111142
Continuing session.  Cmd line: ../run/john -res=tst- 2>&1
108g 0:00:06:17 10.00% (ETA: 05:22:42) 0.2864g/s 2.376p/s 4590c/s 4590C/s 11111095..11111142
Continuing session.  Cmd line: ../run/john -res=tst- 2>&1
108g 0:00:06:38 5.00% (ETA: 06:32:42) 0.2713g/s 2.251p/s 4589c/s 4589C/s 11111011..11111035
Continuing session.  Cmd line: ../run/john -res=tst- 2>&1
118g 0:00:06:59 10.00% (ETA: 05:30:02) 0.2816g/s 2.291p/s 4589c/s 4589C/s 11111095..11111142
Continuing session.  Cmd line: ../run/john -res=tst- 2>&1
118g 0:00:07:20 10.00% (ETA: 05:33:42) 0.2681g/s 2.327p/s 4588c/s 4588C/s 11111095..11111142
Continuing session.  Cmd line: ../run/john -res=tst- 2>&1
[...]
118g 0:00:59:29 5.00% (ETA: 00:34:41) 0.03306g/s 2.402p/s 4560c/s 4560C/s 11111011..11111035
Continuing session.  Cmd line: ../run/john -res=tst- 2>&1
118g 0:00:59:50 10.00% (ETA: 14:43:31) 0.03286g/s 2.406p/s 4560c/s 4560C/s 11111095..11111142
Continuing session.  Cmd line: ../run/john -res=tst- 2>&1

  • 1 hour and nothing? > Running at +2p/s!
<!-- gh-comment-id:343032046 --> @ghost commented on GitHub (Nov 9, 2017): I'm trying to demonstrate a situation where JtR restore logic seems to stop to try the next new candidates. 1. adjust to 2 - 4 p/s (on super -> `OMP_THREAD_LIMIT=1`) 2. run ```../run/john -mask=?w?d?d -w=bitcoin_restart_rules_tst.dic bitcoin_restart_rules_tst.in -form=bitcoin -max-run=20``` 3. notice the `Loaded a total of 2000 password hashes with 2000 different salts` versus: ``` ../run/john -mask=?w?d?d -w=bitcoin_restart_rules_tst.dic --stdout [...] 2000p 0:00:00:00 100,00% (2017-11-09 05:32) 40000p/s 11112977 ``` 4. notice it cracks some stuff in the beginning. In 1:1 keys versus cracks it is expected. But: CI: stuck on 5%: ``` 81g 0:00:00:20 5.00% (ETA: 00:06:34) 4.045g/s 3.996p/s 8133c/s 8133C/s 11111016..11111046 88g 0:00:00:41 5.00% (ETA: 00:13:34) 2.146g/s 3.902p/s 7937c/s 7937C/s 11111016..11111046 94g 0:00:01:02 5.00% (ETA: 00:20:34) 1.516g/s 4.000p/s 7875c/s 7875C/s 11111066..11111087 94g 0:00:01:23 5.00% (ETA: 00:27:34) 1.132g/s 4.048p/s 7841c/s 7841C/s 11111066..11111087 94g 0:00:01:44 5.00% (ETA: 00:34:34) 0.9038g/s 4.000p/s 7826c/s 7826C/s 11111016..11111046 94g 0:00:02:05 5.00% (ETA: 00:41:34) 0.7520g/s 4.032p/s 7815c/s 7815C/s 11111066..11111087 [...] 94g 0:00:40:56 5.00% (ETA: 13:38:50) 0.03827g/s 4.065p/s 7753c/s 7753C/s 11111066..11111087 ``` Super: stuck on 10%: ``` 52g 0:00:00:20 5.00% (ETA: 04:23:44) 2.578g/s 0p/s 4769c/s 4769C/s 11111011..11111035 Continuing session. Cmd line: ../run/john -res=tst- 2>&1 94g 0:00:00:41 10.00% (ETA: 04:24:04) 2.292g/s 1.560p/s 4686c/s 4686C/s 11111095..11111142 Continuing session. Cmd line: ../run/john -res=tst- 2>&1 94g 0:00:01:02 10.00% (ETA: 04:27:44) 1.516g/s 2.064p/s 4650c/s 4650C/s 11111095..11111142 Continuing session. Cmd line: ../run/john -res=tst- 2>&1 94g 0:00:01:23 10.00% (ETA: 04:31:24) 1.132g/s 2.313p/s 4633c/s 4633C/s 11111095..11111142 Continuing session. Cmd line: ../run/john -res=tst- 2>&1 94g 0:00:01:44 5.00% (ETA: 04:52:24) 0.9038g/s 1.846p/s 4623c/s 4623C/s 11111011..11111035 Continuing session. Cmd line: ../run/john -res=tst- 2>&1 108g 0:00:02:05 10.00% (ETA: 04:38:44) 0.8640g/s 2.048p/s 4613c/s 4613C/s 11111095..11111142 Continuing session. Cmd line: ../run/john -res=tst- 2>&1 108g 0:00:02:26 10.00% (ETA: 04:42:23) 0.7397g/s 2.191p/s 4608c/s 4608C/s 11111095..11111142 Continuing session. Cmd line: ../run/john -res=tst- 2>&1 108g 0:00:02:47 10.00% (ETA: 04:46:03) 0.6467g/s 2.299p/s 4604c/s 4604C/s 11111095..11111142 Continuing session. Cmd line: ../run/john -res=tst- 2>&1 108g 0:00:03:08 10.00% (ETA: 04:49:43) 0.5744g/s 2.382p/s 4602c/s 4602C/s 11111095..11111142 Continuing session. Cmd line: ../run/john -res=tst- 2>&1 108g 0:00:03:29 5.00% (ETA: 05:28:13) 0.5167g/s 2.143p/s 4600c/s 4600C/s 11111011..11111035 Continuing session. Cmd line: ../run/john -res=tst- 2>&1 108g 0:00:03:50 10.00% (ETA: 04:57:03) 0.4695g/s 2.226p/s 4598c/s 4598C/s 11111095..11111142 Continuing session. Cmd line: ../run/john -res=tst- 2>&1 108g 0:00:04:11 10.00% (ETA: 05:00:43) 0.4302g/s 2.294p/s 4597c/s 4597C/s 11111095..11111142 Continuing session. Cmd line: ../run/john -res=tst- 2>&1 108g 0:00:04:32 10.00% (ETA: 05:04:23) 0.3970g/s 2.352p/s 4596c/s 4596C/s 11111095..11111142 Continuing session. Cmd line: ../run/john -res=tst- 2>&1 108g 0:00:04:53 10.00% (ETA: 05:08:03) 0.3686g/s 2.402p/s 4593c/s 4593C/s 11111095..11111142 Continuing session. Cmd line: ../run/john -res=tst- 2>&1 108g 0:00:05:14 5.00% (ETA: 06:04:02) 0.3439g/s 2.242p/s 4593c/s 4593C/s 11111011..11111035 Continuing session. Cmd line: ../run/john -res=tst- 2>&1 108g 0:00:05:35 10.00% (ETA: 05:15:22) 0.3223g/s 2.292p/s 4592c/s 4592C/s 11111095..11111142 Continuing session. Cmd line: ../run/john -res=tst- 2>&1 108g 0:00:05:56 10.00% (ETA: 05:19:02) 0.3033g/s 2.337p/s 4591c/s 4591C/s 11111095..11111142 Continuing session. Cmd line: ../run/john -res=tst- 2>&1 108g 0:00:06:17 10.00% (ETA: 05:22:42) 0.2864g/s 2.376p/s 4590c/s 4590C/s 11111095..11111142 Continuing session. Cmd line: ../run/john -res=tst- 2>&1 108g 0:00:06:38 5.00% (ETA: 06:32:42) 0.2713g/s 2.251p/s 4589c/s 4589C/s 11111011..11111035 Continuing session. Cmd line: ../run/john -res=tst- 2>&1 118g 0:00:06:59 10.00% (ETA: 05:30:02) 0.2816g/s 2.291p/s 4589c/s 4589C/s 11111095..11111142 Continuing session. Cmd line: ../run/john -res=tst- 2>&1 118g 0:00:07:20 10.00% (ETA: 05:33:42) 0.2681g/s 2.327p/s 4588c/s 4588C/s 11111095..11111142 Continuing session. Cmd line: ../run/john -res=tst- 2>&1 [...] 118g 0:00:59:29 5.00% (ETA: 00:34:41) 0.03306g/s 2.402p/s 4560c/s 4560C/s 11111011..11111035 Continuing session. Cmd line: ../run/john -res=tst- 2>&1 118g 0:00:59:50 10.00% (ETA: 14:43:31) 0.03286g/s 2.406p/s 4560c/s 4560C/s 11111095..11111142 Continuing session. Cmd line: ../run/john -res=tst- 2>&1 ``` **** * 1 hour and nothing? > Running at +2p/s!
Author
Owner

@magnumripper commented on GitHub (Nov 9, 2017):

In some cases -max-run=20 will be too short for any real work to actually happen in a run. Perhaps -max-run=60 will be free of this problem?

<!-- gh-comment-id:343064861 --> @magnumripper commented on GitHub (Nov 9, 2017): In some cases `-max-run=20` will be too short for any real work to actually happen in a run. Perhaps `-max-run=60` will be free of this problem?
Author
Owner

@jfoug commented on GitHub (Nov 9, 2017):

I'm trying to demonstrate a situation where JtR restore logic seems to stop to try the next new candidates.

This I believe is the exact same type situation which first pushed me to implement the salt-resume code. When the run is against VERY slow candidates, and with a lot of salts, then ETA does not move at all, until the entire block of salts is done for the KPC passwords selected. When I was working on the AM stuff, I was seeing times of several weeks (months??) before the loop completed and the ETA changed. Any session save during that time frame would start then entire block of passwords over at the start of the salts. Simply unacceptable.

now, for the ETA screen being 'stuck'. I think that is an open issue (at least it was 2 years ago). It is all based upon when the computation for that is done, and now we are starting to see these spectacularly slow dumps of many hashes. Years ago, a hash which you could only do a couple thousand cracks per second was considered slow (like md5crypt). Now there are salted hashes which take nearly a second. When you get a large dump of them, john has some design items which cause it to appear hung. I am not sure just how much of that we 'want' to fix since we also do not want to harm super fast hashes either (which is often what a cracker gets reviews over). UNLESS we make changes to list that this hash is a fast, medium, slow, or SUPER SLOW hash, and handle things slightly differently for each. For a super slow hash, updating ETA after every crypt_all may make sense, it does not slow down the run at all. BUT for a fast hash, that would greatly impact speed.

NOTE, this may be the wrong location to chit chat about this.

<!-- gh-comment-id:343127765 --> @jfoug commented on GitHub (Nov 9, 2017): > I'm trying to demonstrate a situation where JtR restore logic seems to stop to try the next new candidates. This I believe is the exact same type situation which first pushed me to implement the salt-resume code. When the run is against VERY slow candidates, and with a lot of salts, then ETA does not move at all, until the entire block of salts is done for the KPC passwords selected. When I was working on the AM stuff, I was seeing times of several weeks (months??) before the loop completed and the ETA changed. Any session save during that time frame would start then entire block of passwords over at the start of the salts. Simply unacceptable. now, for the ETA screen being 'stuck'. I think that is an open issue (at least it was 2 years ago). It is all based upon when the computation for that is done, and now we are starting to see these spectacularly slow dumps of many hashes. Years ago, a hash which you could only do a couple thousand cracks per second was considered slow (like md5crypt). Now there are salted hashes which take nearly a second. When you get a large dump of them, john has some design items which cause it to appear hung. I am not sure just how much of that we 'want' to fix since we also do not want to harm super fast hashes either (which is often what a cracker gets reviews over). UNLESS we make changes to list that this hash is a fast, medium, slow, or SUPER SLOW hash, and handle things slightly differently for each. For a super slow hash, updating ETA after every crypt_all may make sense, it does not slow down the run at all. BUT for a fast hash, that would greatly impact speed. NOTE, this may be the wrong location to chit chat about this.
Author
Owner

@ghost commented on GitHub (Nov 9, 2017):

In some cases -max-run=20 will be too short for any real work to actually happen in a run. Perhaps -max-run=60 will be free of this problem?

I'm afraid I am going to have to disagree. The same crack session using a pure mask [1] finishes in a couple of minutes. It can crack 100+ hashes per run.

  1. ok, hybrid restore might be worse by nature.
  2. but, so much worse?

I'll be running the "hybrid" mode to find out how long does it take.

[1]

../run/john  -mask=1111[12]?d?d?d  bitcoin_restart_rules_tst.in -max-run=20
<!-- gh-comment-id:343161332 --> @ghost commented on GitHub (Nov 9, 2017): > In some cases `-max-run=20` will be too short for any real work to actually happen in a run. Perhaps `-max-run=60` will be free of this problem? I'm afraid I am going to have to disagree. The same crack session using a pure mask [1] finishes in a couple of minutes. It can crack 100+ hashes per run. 1. ok, hybrid restore might be worse by nature. 2. but, so much worse? I'll be running the "hybrid" mode to find out how long does it take. [1] ``` ../run/john -mask=1111[12]?d?d?d bitcoin_restart_rules_tst.in -max-run=20 ```
Author
Owner

@solardiz commented on GitHub (Nov 9, 2017):

Good job figuring out the single mode!

So, when a crack happens, the code simply spins through all buffers, and calls the add_to_buffer(cracked_word) to each salt's buffer?

Exactly. And there's also a check whether the buffer is full, where some very limited recursion may occur.

And yes, interrupting and resuming the single mode doesn't produce the exact same results because of those recracks. And yes, they make less sense when someone experienced uses jumbo, but they still do make sense when someone inexperienced does and the hash isn't terribly slow along with large salt count. I don't oppose us changing the default, though.

What Jim says about marking hashes as fast or slow, etc. makes sense to me. We could have this affect various things, but for anything that would result in different passwords (not) getting cracked we should inform the user ("Notice: ..." messages?) In many cases, the slowness will also vary a lot by the tunable costs, which makes things a lot trickier. So maybe base runtime decisions on actual measured c/s and/or p/s rates, where relevant? Can't use these before even starting a cracking mode, though - let alone in the loader.

<!-- gh-comment-id:343258421 --> @solardiz commented on GitHub (Nov 9, 2017): Good job figuring out the single mode! > So, when a crack happens, the code simply spins through all buffers, and calls the add_to_buffer(cracked_word) to each salt's buffer? Exactly. And there's also a check whether the buffer is full, where some very limited recursion may occur. And yes, interrupting and resuming the single mode doesn't produce the exact same results because of those recracks. And yes, they make less sense when someone experienced uses jumbo, but they still do make sense when someone inexperienced does and the hash isn't terribly slow along with large salt count. I don't oppose us changing the default, though. What Jim says about marking hashes as fast or slow, etc. makes sense to me. We could have this affect various things, but for anything that would result in different passwords (not) getting cracked we should inform the user ("Notice: ..." messages?) In many cases, the slowness will also vary a lot by the tunable costs, which makes things a lot trickier. So maybe base runtime decisions on actual measured c/s and/or p/s rates, where relevant? Can't use these before even starting a cracking mode, though - let alone in the loader.
Author
Owner

@jfoug commented on GitHub (Nov 9, 2017):

Can't use these before even starting a cracking mode,

But since a ST is done prior to starting, we could do a bit of a ST (a couple seconds), and then use the c/s p/s rates. Then it would allow setting what 'is' a fast, what is a 'slow' in the john.conf file. Like you mention, if tuning is done, it can change a hash from slow to medium. the same format running on a AVX512 vs running on something that is forced to use oSSL CTX models can be an order of magnitude or more different in speed. So getting 3 'buckets' (fast, medium, slow), and then determining at runtime just what we have, would provide more information for changes in the runtime behavior.

there certainly are times when the play-back found in single is really the wrong default. In the VERY slow AM format, it simply meant that a single mode run would take decades (possibly centuries), vs weeks. It really was that big of a difference. Yup, at the end, there would be a lot more passwords hacked, BUT that end never would have gotten here. It was first noticed, when I was getting 4 to 10 cracks per minute, and then after a while, that just appeared to stop. Yes, there would be a couple hundred cracks per day, but not much more. It was at a point where there were millions of 'full' by salt buffers, and no more single data was being tested. It happened when 1000's of salt-buffers filled up, and had to be satisfied prior to more single data being dropped off in salt buffers.

This would certainly not be the only area where super fast vs super slow processing could be looked at differently. Certainly, things like computation of ETA is another very ripe area, where there is great need to different logic. I bet there are numerous other parts of john, where the runtime characteristics could be variable based upon type of data, giving the user better end results, OR better 'smoother' running and usability.

<!-- gh-comment-id:343263640 --> @jfoug commented on GitHub (Nov 9, 2017): > Can't use these before even starting a cracking mode, But since a ST is done prior to starting, we could do a bit of a ST (a couple seconds), and then use the c/s p/s rates. Then it would allow setting what 'is' a fast, what is a 'slow' in the john.conf file. Like you mention, if tuning is done, it can change a hash from slow to medium. the same format running on a AVX512 vs running on something that is forced to use oSSL CTX models can be an order of magnitude or more different in speed. So getting 3 'buckets' (fast, medium, slow), and then determining at runtime just what we have, would provide more information for changes in the runtime behavior. there certainly are times when the play-back found in single is really the wrong default. In the VERY slow AM format, it simply meant that a single mode run would take decades (possibly centuries), vs weeks. It really was that big of a difference. Yup, at the end, there would be a lot more passwords hacked, BUT that end never would have gotten here. It was first noticed, when I was getting 4 to 10 cracks per minute, and then after a while, that just appeared to stop. Yes, there would be a couple hundred cracks per day, but not much more. It was at a point where there were millions of 'full' by salt buffers, and no more single data was being tested. It happened when 1000's of salt-buffers filled up, and had to be satisfied prior to more single data being dropped off in salt buffers. This would certainly not be the only area where super fast vs super slow processing could be looked at differently. Certainly, things like computation of ETA is another very ripe area, where there is great need to different logic. I bet there are numerous other parts of john, where the runtime characteristics could be variable based upon type of data, giving the user better end results, OR better 'smoother' running and usability.
Author
Owner

@ghost commented on GitHub (Nov 9, 2017):

Back to the stuck on restore

  • 4 hours and nothing: zero new cracks;
  • so hybrid (the mask part) needs to restart over and over again when JtR quits (by design); [1]
  • BUT, the salt saved in rec keeps changing;
  • so, it should finish a batch of "keys" sooner or later (or not?); Sooner than later;

In some cases -max-run=20 will be too short for any real work to actually happen in a run. Perhaps -max-run=60 will be free of this problem?

Since I can't find a bug, I'll do this.


[1] with KPC = 64 and 8k c/s (C/s), mask should finish one set and move to another. That said, thinking about a 1M bitcoin hashes, the --restore will be a problem even for a real prospective run.

<!-- gh-comment-id:343291801 --> @ghost commented on GitHub (Nov 9, 2017): Back to the **stuck on restore** * 4 hours and nothing: zero new cracks; * so hybrid (the mask part) needs to restart over and over again when JtR quits (by design); [1] * BUT, the salt saved in rec keeps changing; * so, it should finish a batch of "keys" sooner or later (or not?); Sooner than later; > In some cases -max-run=20 will be too short for any real work to actually happen in a run. Perhaps -max-run=60 will be free of this problem? Since I can't find a bug, I'll do this. **** [1] with KPC = 64 and 8k c/s (C/s), mask should finish one set and move to another. That said, thinking about a 1M bitcoin hashes, the `--restore` will be a problem even for a real prospective run.
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#1804
No description provided.