[GH-ISSUE #570] Add session save/restore for --regex mode #246

Closed
opened 2026-10-14 02:57:55 +07:00 by bsakaguchi · 10 comments
Owner

Originally created by @magnumripper on GitHub (Apr 19, 2014).
Original GitHub issue: https://github.com/openwall/john/issues/570

  • on its own
  • in combination with --wordlist
Originally created by @magnumripper on GitHub (Apr 19, 2014). Original GitHub issue: https://github.com/openwall/john/issues/570 - [ ] on its own - [x] in combination with --wordlist
bsakaguchi 2026-10-14 02:57:55 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@jfoug commented on GitHub (Apr 21, 2014):

  • in combination with --wordlist --rules
<!-- gh-comment-id:40931627 --> @jfoug commented on GitHub (Apr 21, 2014): - [x] in combination with --wordlist --rules
Author
Owner

@magnumripper commented on GitHub (May 2, 2014):

The two wordlist cases will likely work fine already, but with greater loss (ie. repeated effort after resume). For a complex regex it might be a whole lot of duplicate effort.

<!-- gh-comment-id:41997567 --> @magnumripper commented on GitHub (May 2, 2014): The two wordlist cases will likely work fine already, but with greater loss (ie. repeated effort after resume). For a complex regex it might be a whole lot of duplicate effort.
Author
Owner

@magnumripper commented on GitHub (May 25, 2014):

This is kind of high priority, not being able to resume is pretty nasty. But I don't have a clue how to code this. Jim, I bet you have?

<!-- gh-comment-id:44147268 --> @magnumripper commented on GitHub (May 25, 2014): This is kind of high priority, not being able to resume is pretty nasty. But I don't have a clue how to code this. Jim, I bet you have?
Author
Owner

@magnumripper commented on GitHub (May 25, 2014):

Added a warning in 1045c4d when used as a separate mode.

<!-- gh-comment-id:44147378 --> @magnumripper commented on GitHub (May 25, 2014): Added a warning in 1045c4d when used as a separate mode.
Author
Owner

@magnumripper commented on GitHub (Dec 4, 2014):

Since we have the warning in place, I'm moving this to later milestone.

<!-- gh-comment-id:65724958 --> @magnumripper commented on GitHub (Dec 4, 2014): Since we have the warning in place, I'm moving this to later milestone.
Author
Owner

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

I have been working on this, and it is NOT fun.

First, there are issues with rexgen save/resume. I am trying to work through all of those first. I 'think' I have the save/resume code in JtR working semi OK, I just need to fix rexgen (with as small as possible of a patch), and then remove a bunch of work around 'hacks' in JtR The hacks could not get things done, because there is a latent bug that I could not hack my way around.

<!-- gh-comment-id:194588137 --> @jfoug commented on GitHub (Mar 10, 2016): I have been working on this, and it is NOT fun. First, there are issues with rexgen save/resume. I am trying to work through all of those first. I 'think' I have the save/resume code in JtR working semi OK, I just need to fix rexgen (with as small as possible of a patch), and then remove a bunch of work around 'hacks' in JtR The hacks could not get things done, because there is a latent bug that I could not hack my way around.
Author
Owner

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

This CR was given to the rexgen page. I think there will be another before I am done.

https://github.com/teeshop/rexgen/issues/28

https://github.com/teeshop/rexgen/pull/29 (pull request)

NOTE, I can not incorporate my changes until the above issue is addressed. We use rexgen in hybrid mode 1 word at a time. For save/restore to work, we have to not create a new session for each word,but create the session 1 time, and then re-use it. But rexgen is in charge of reading words, AND there were real problems restarting a session with new words (until the above patch is done).

NOTE, there is also still a bug IN the resume. Here are examples:

001_88           (?)
001_98           (?)
001_09           (?)
001_19           (?)
192g 0:00:00:04 0.07% (ETA: 00:57:09) 39.99g/s 39.99p/s 39.99c/s 39.99C/s 001_29..002_32
Session aborted

$ OMP_NUM_THREADS=2 ../run/john -res=tst-x
Loaded 1 password hash (restore_tester [None])
Will run 2 OpenMP threads
Note: This format may emit false positives, so it will keep trying even after
finding a possible candidate.
Press 'q' or Ctrl-C to abort, almost any other key for status
192g 0:00:00:05 0.05% (ETA: 02:17:23) 38.40g/s 38.40p/s 38.40c/s 38.40C/s 001_20
001_20           (?)
001_30           (?)

the regex is \0[0-9][0-9] The 'proper' resume should be either 001_19 or 001_29 (my choice would be 001_19)

If you see where the session left off, when reloaded, it incremented BOTH of the sets (1 went to 2 and 9 went to restart or 0). So from this regex, we are missing 10 candidates (well, in the above example, we actually are re-doing 90 candidates.

This happens all the time, here we see how for this regex we miss 10 items:

001_16           (?)
001_26           (?)
001_36           (?)
001_46           (?)
001_56           (?)
256g 0:00:00:06 0.05% (ETA: 02:51:32) 42.66g/s 42.66p/s 42.66c/s 42.66C/s 001_66..001_79
Session aborted

$ OMP_NUM_THREADS=2 ../run/john -res=tst-x
Loaded 1 password hash (restore_tester [None])
Will run 2 OpenMP threads
Note: This format may emit false positives, so it will keep trying even after
finding a possible candidate.
Press 'q' or Ctrl-C to abort, almost any other key for status
256g 0:00:00:07 0.07% (ETA: 13:12:50) 36.57g/s 36.57p/s 36.57c/s 36.57C/s 001_67
001_67           (?)
001_77           (?)
001_87           (?)
001_97           (?)
001_08           (?)
001_18           (?)

I think what SHOULD happen is that if 001_56 is requested, that the restart data should return whatever data is needed so that 001_56 is the first thing returned after a restart, and then if the calling program knows that 001_56 was completed, it would call next() dropping the data. BUT if 001_56 was aborted during work, then 001_56 should be the item to restart from. Only the calling program would know that.

But I have not gotten that figure out yet. However, I do have rexgen fully incorporated into my VC environment (not an easy task), so possibly I can find a simple solution to this. This code is NOT easy to debug, by any stretch.

<!-- gh-comment-id:194942630 --> @jfoug commented on GitHub (Mar 10, 2016): This CR was given to the rexgen page. I think there will be another before I am done. https://github.com/teeshop/rexgen/issues/28 https://github.com/teeshop/rexgen/pull/29 (pull request) NOTE, I can not incorporate my changes until the above issue is addressed. We use rexgen in hybrid mode 1 word at a time. For save/restore to work, we have to not create a new session for each word,but create the session 1 time, and then re-use it. But rexgen is in charge of reading words, AND there were real problems restarting a session with new words (until the above patch is done). NOTE, there is also still a bug IN the resume. Here are examples: ``` 001_88 (?) 001_98 (?) 001_09 (?) 001_19 (?) 192g 0:00:00:04 0.07% (ETA: 00:57:09) 39.99g/s 39.99p/s 39.99c/s 39.99C/s 001_29..002_32 Session aborted $ OMP_NUM_THREADS=2 ../run/john -res=tst-x Loaded 1 password hash (restore_tester [None]) Will run 2 OpenMP threads Note: This format may emit false positives, so it will keep trying even after finding a possible candidate. Press 'q' or Ctrl-C to abort, almost any other key for status 192g 0:00:00:05 0.05% (ETA: 02:17:23) 38.40g/s 38.40p/s 38.40c/s 38.40C/s 001_20 001_20 (?) 001_30 (?) ``` the regex is \0[0-9][0-9] The 'proper' resume should be either 001_19 or 001_29 (my choice would be 001_19) If you see where the session left off, when reloaded, it incremented BOTH of the sets (1 went to 2 and 9 went to restart or 0). So from this regex, we are missing 10 candidates (well, in the above example, we actually are re-doing 90 candidates. This happens all the time, here we see how for this regex we miss 10 items: ``` 001_16 (?) 001_26 (?) 001_36 (?) 001_46 (?) 001_56 (?) 256g 0:00:00:06 0.05% (ETA: 02:51:32) 42.66g/s 42.66p/s 42.66c/s 42.66C/s 001_66..001_79 Session aborted $ OMP_NUM_THREADS=2 ../run/john -res=tst-x Loaded 1 password hash (restore_tester [None]) Will run 2 OpenMP threads Note: This format may emit false positives, so it will keep trying even after finding a possible candidate. Press 'q' or Ctrl-C to abort, almost any other key for status 256g 0:00:00:07 0.07% (ETA: 13:12:50) 36.57g/s 36.57p/s 36.57c/s 36.57C/s 001_67 001_67 (?) 001_77 (?) 001_87 (?) 001_97 (?) 001_08 (?) 001_18 (?) ``` I think what SHOULD happen is that if 001_56 is requested, that the restart data should return whatever data is needed so that 001_56 is the first thing returned after a restart, and then if the calling program knows that 001_56 was completed, it would call next() dropping the data. BUT if 001_56 was aborted during work, then 001_56 should be the item to restart from. Only the calling program would know that. But I have not gotten that figure out yet. However, I do have rexgen fully incorporated into my VC environment (not an easy task), so possibly I can find a simple solution to this. This code is NOT easy to debug, by any stretch.
Author
Owner

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

I have a work around now for the bug above.

Here is my changes:

        iter = c_regex_iterator(regex_ptr);

-       if (restore_str)
+       if (restore_str) {
+           c_iterator_next(iter);
            c_iterator_set_state(iter, restore_str);
+       }

I think what was wrong was I was using a newly created iterator, and the proper 'state' value of the iterator is not being saved. Only the data and children are being saved. BUT with a call to next(), it appears to properly resume.

From the iterator.h (Iterator base class), this is the data not being saved (and later restored). This actually SHOULD be a trivial thing to fix.

enum {
    resetted,
    usable,
    not_usable
  } state;
<!-- gh-comment-id:195003246 --> @jfoug commented on GitHub (Mar 10, 2016): I have a work around now for the bug above. Here is my changes: ``` diff iter = c_regex_iterator(regex_ptr); - if (restore_str) + if (restore_str) { + c_iterator_next(iter); c_iterator_set_state(iter, restore_str); + } ``` I think what was wrong was I was using a newly created iterator, and the proper 'state' value of the iterator is not being saved. Only the data and children are being saved. BUT with a call to next(), it appears to properly resume. From the iterator.h (Iterator base class), this is the data not being saved (and later restored). This actually SHOULD be a trivial thing to fix. ``` C enum { resetted, usable, not_usable } state; ```
Author
Owner

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

Ok I have everything found and fixed, and into the PR for rexgen.

github.com/jfoug/rexgen@43eb0b4a81

This required the version of rexgen to get bumped to 1.4.0 since this change DOES make the save format strings incompatible. The state value was added for each iterator record.

<!-- gh-comment-id:195041953 --> @jfoug commented on GitHub (Mar 10, 2016): Ok I have everything found and fixed, and into the PR for rexgen. https://github.com/jfoug/rexgen/commit/43eb0b4a8119530dea5d8a37a4b86071e79f32d8 This required the version of rexgen to get bumped to 1.4.0 since this change DOES make the save format strings incompatible. The state value was added for each iterator record.
Author
Owner

@jfoug commented on GitHub (Aug 8, 2016):

Completed with PR #2199

<!-- gh-comment-id:238280935 --> @jfoug commented on GitHub (Aug 8, 2016): Completed with PR #2199
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#246
No description provided.