[GH-ISSUE #2072] New external 'hybrid' mode that allows work to be done similar to rules #1390

Closed
opened 2026-10-14 03:47:11 +07:00 by bsakaguchi · 40 comments
Owner

Originally created by @jfoug on GitHub (Mar 3, 2016).
Original GitHub issue: https://github.com/openwall/john/issues/2072

Outstanding issues:

Right now, we have 'filter', which can change the current word or cause that word to be ignored.

We also have 'generate' mode. In this mode, the external script builds the dictionary.

Why not add a 3rd mode, 'wordlist' or 'hybrid' mode. In this mode, I think we only need to add 2 builtins functions: next() and new()

new() is used as a hook for the external script to grab word[] data. Whatever has happened prior to this has produced the next candidate. new returns the count of values we will produce for this candidate (it can be zero).

next() iterates and when complete word[] is the next candidate value.

Within restore, we will need to be given the count of how many candidate FROM the current word were run. Also, restore needs the original base word (what was sent to the original new() function).

What do others think?

NOTE, if this capability is already there, then I am sorry, but I do not think it is. YES, we do have rules. YES we do have regex. BUT I do see a TON of usefulness in this request.

I have added this also as a core. I think we do this first in jumbo, BUT Solar may also want this in core, so if so, we will have to revert and use core changes. I have also not taken this to john-users, just in case there already is this capability that I am unaware of.

Originally created by @jfoug on GitHub (Mar 3, 2016). Original GitHub issue: https://github.com/openwall/john/issues/2072 Outstanding issues: - [x] utf-32 flag https://github.com/jfoug/ExternalHybrid/commit/1b7d8a2dce15c9791ce4e415195c884d1ca650d9 - [x] node support (trivial, I just have not gotten it done) - [x] testing of restore. b64645f - [x] dox (boo....) https://github.com/jfoug/ExternalHybrid/commit/4453eb71bb666353a7dccae0c2f5b8924f2cae72 - [ ] daisy chaining of hybrid modes. ( discussion ) Right now, we have 'filter', which can change the current word or cause that word to be ignored. We also have 'generate' mode. In this mode, the external script builds the dictionary. Why not add a 3rd mode, 'wordlist' or 'hybrid' mode. In this mode, I think we only need to add 2 builtins functions: next() and new() new() is used as a hook for the external script to grab word[] data. Whatever has happened prior to this has produced the next candidate. new returns the count of values we will produce for this candidate (it can be zero). next() iterates and when complete word[] is the next candidate value. Within restore, we will need to be given the count of how many candidate FROM the current word were run. Also, restore needs the original base word (what was sent to the original new() function). What do others think? NOTE, if this capability is already there, then I am sorry, but I do not think it is. YES, we do have rules. YES we do have regex. BUT I do see a TON of usefulness in this request. I have added this also as a core. I think we do this first in jumbo, BUT Solar may also want this in core, so if so, we will have to revert and use core changes. I have also not taken this to john-users, just in case there already is this capability that I am unaware of.
Author
Owner

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

Here would be the reference external script

# Reference example hybrid-mode external. same as jtr-rule: $[0-9]$[0-9]
[List.External:Wordlist_example]
/* static vars for the script */
int cnt, length, total;

void init()
{
    total = 100;  /* this is a VERY simple example */
}

/* new word */
void new()
{
    /* get the word length) */
    length = 0;
    while (word[length++]) ;

    /*
     * If this was a more complex script, we would compute total candidates
     * at this location, if we can. If we can not compute total candidates
     * then it is likely we can not resume 'easily', so if that is the
     * case, we would simply set hybrid_total to -1, or do nothing, since
     * do_external_hybrid_crack() sets it to -1 before calling this function.
     */
     hybrid_total = total;

    /* Reset or counter for THIS word. */
    cnt = 0;

    /*
     * word will be too long to be used, or too short to be used. If so
     * then set hybrid_total to 0 and this entire word will be skipped.
     */
    if (req_minlen > length - 2 || req_maxlen < length + 2)
        hybrid_total = 0;
}

void next()
{
    /* in this simple script, if cnt is 100, this word is DONE */
    if (cnt == 100)
    {
        word[0] = 0;
        return;
    }

    /* set word[] to the next candidate */
    word[length  ] = '0' + cnt / 10;
    word[length+1] = '0' + cnt % 10;
    word[length+2] = 0;
    ++cnt;
}

/* Called when restoring an interrupted session */
void restore()
{
    /* Import the word back. really 'length' is the only thing we need. */
    length = 0;
    while (word[length++]) ;

    /* for this simple script, simply setting cnt resumes */
    cnt = hybrid_current;

    /* tell john that we have properly 'resumed', by setting a 'proper' total */
    hybrid_total = total;
}
<!-- gh-comment-id:191902508 --> @jfoug commented on GitHub (Mar 3, 2016): Here would be the reference external script ``` C # Reference example hybrid-mode external. same as jtr-rule: $[0-9]$[0-9] [List.External:Wordlist_example] /* static vars for the script */ int cnt, length, total; void init() { total = 100; /* this is a VERY simple example */ } /* new word */ void new() { /* get the word length) */ length = 0; while (word[length++]) ; /* * If this was a more complex script, we would compute total candidates * at this location, if we can. If we can not compute total candidates * then it is likely we can not resume 'easily', so if that is the * case, we would simply set hybrid_total to -1, or do nothing, since * do_external_hybrid_crack() sets it to -1 before calling this function. */ hybrid_total = total; /* Reset or counter for THIS word. */ cnt = 0; /* * word will be too long to be used, or too short to be used. If so * then set hybrid_total to 0 and this entire word will be skipped. */ if (req_minlen > length - 2 || req_maxlen < length + 2) hybrid_total = 0; } void next() { /* in this simple script, if cnt is 100, this word is DONE */ if (cnt == 100) { word[0] = 0; return; } /* set word[] to the next candidate */ word[length ] = '0' + cnt / 10; word[length+1] = '0' + cnt % 10; word[length+2] = 0; ++cnt; } /* Called when restoring an interrupted session */ void restore() { /* Import the word back. really 'length' is the only thing we need. */ length = 0; while (word[length++]) ; /* for this simple script, simply setting cnt resumes */ cnt = hybrid_current; /* tell john that we have properly 'resumed', by setting a 'proper' total */ hybrid_total = total; } ```
Author
Owner

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

So right now, what I see these requirements:

  1. 2 new hook functions: new() and next()
  2. 2 external variables: tot_candi and cur_candi
<!-- gh-comment-id:191903728 --> @jfoug commented on GitHub (Mar 3, 2016): So right now, what I see these requirements: 1. 2 new hook functions: new() and next() 2. 2 external variables: tot_candi and cur_candi
Author
Owner

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

There might be modes where you can't know (or it's very expensive to calculate) the count beforehand. So an alternative could be that you call new("baseword") and get either a candidate or NULL. If you got a candidate, you call next() for a new candidate and keep doing so until that function returns NULL.

<!-- gh-comment-id:191929669 --> @magnumripper commented on GitHub (Mar 3, 2016): There might be modes where you can't know (or it's very expensive to calculate) the count beforehand. So an alternative could be that you call `new("baseword")` and get either a candidate or NULL. If you got a candidate, you call `next()` for a new candidate and keep doing so until that function returns NULL.
Author
Owner

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

I thought about that, but then thing about resume. Resume would have to be handled (might have to be) outside of external. For resume, jtr would have to set the word, then call next X number of times.

But tracking total and total_done, allows a extern to simply work.

YES, it is a bit harder. If it is 'too' hard for a format to know this, then at resume time, it would simply start over on this word. It could then set tot_candi to -1, meaning it does not know how many. Is that a viable option?

NOTE, this may be pretty easy to add. I do not know the code at all, but I think this is like a filter, BUT calls next until it bails before getting next word.

<!-- gh-comment-id:191932771 --> @jfoug commented on GitHub (Mar 3, 2016): I thought about that, but then thing about resume. Resume would have to be handled (might have to be) outside of external. For resume, jtr would have to set the word, then call next X number of times. But tracking total and total_done, allows a extern to simply work. YES, it is a bit harder. If it is 'too' hard for a format to know this, then at resume time, it would simply start over on this word. It could then set tot_candi to -1, meaning it does not know how many. Is that a viable option? NOTE, this may be pretty easy to add. I do not know the code at all, but I think this is like a filter, BUT calls next until it bails before getting next word.
Author
Owner

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

@magnumripper overall, what do you think of this 'idea' ? It literally just popped into my head about a 2 hours ago, when I realized that external could not be used in this way.

<!-- gh-comment-id:191932944 --> @jfoug commented on GitHub (Mar 3, 2016): @magnumripper overall, what do you think of this 'idea' ? It literally just popped into my head about a 2 hours ago, when I realized that external could not be used in this way.
Author
Owner

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

@magnumripper question......

When I am within the extern_hybrid_crack loop, do you think I should copy the baseword into a working buffer, and simply call next on the same buffer over and over, or should I strcpy the original word into the buffer before each call to next()

I 'think' copying one time would be best, but I can see benefits for both 'ways'..

<!-- gh-comment-id:191978357 --> @jfoug commented on GitHub (Mar 3, 2016): @magnumripper question...... When I am within the extern_hybrid_crack loop, do you think I should copy the baseword into a working buffer, and simply call next on the same buffer over and over, or should I strcpy the original word into the buffer before each call to next() I 'think' copying one time would be best, but I can see benefits for both 'ways'..
Author
Owner

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

@magnumripper I should not have to deal with nodes at all in this generator, correct? The parent generator would handle the node handling, OR should we handle them here in this generator also ??

<!-- gh-comment-id:191989643 --> @jfoug commented on GitHub (Mar 3, 2016): @magnumripper I should not have to deal with nodes at all in this generator, correct? The parent generator would handle the node handling, OR should we handle them here in this generator also ??
Author
Owner

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

Nope, I think I will have to deal with proper node handling in my function.

Well, I have it working already!!!!! (cept the node stuff). Soon, I will get the node stuff done, then test some more, and then get things checked in. This is cool, and was actually pretty easy.

<!-- gh-comment-id:192002792 --> @jfoug commented on GitHub (Mar 3, 2016): Nope, I think I will have to deal with proper node handling in my function. Well, I have it working already!!!!! (cept the node stuff). Soon, I will get the node stuff done, then test some more, and then get things checked in. This is cool, and was actually pretty easy.
Author
Owner

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

Here is an initial 'look' that actually runs. Plug in the external script I did above, and bam, you have $[0-9]$[0-9] working!!!

--- src/external.c  Mon Jan 19 16:26:32 1970
+++ src/external.c  Mon Jan 19 16:26:32 1970
@@ -55,7 +55,7 @@
 static char *ext_mode;

 static c_int ext_word[PLAINTEXT_BUFFER_SIZE];
-c_int ext_abort, ext_status, ext_cipher_limit, ext_minlen, ext_maxlen;
+c_int ext_abort, ext_status, ext_cipher_limit, ext_minlen, ext_maxlen, ext_cur_candi, ext_tot_candi;
 c_int ext_time, ext_utf32, ext_target_utf8;

 static struct c_ident ext_ident_status = {
@@ -106,13 +106,27 @@
    &ext_time
 };

-static struct c_ident ext_globals = {
+static struct c_ident ext_ident_tot_candi = {
    &ext_ident_time,
+   "tot_candi",
+   &ext_tot_candi
+};
+
+static struct c_ident ext_ident_cur_candi = {
+   &ext_ident_tot_candi,
+   "cur_candi",
+   &ext_cur_candi
+};
+
+static struct c_ident ext_globals = {
+   &ext_ident_cur_candi,
    "word",
    ext_word
 };

 static void *f_generate;
+void *f_new = NULL;
+void *f_next = NULL;
 void *f_filter = NULL;

 static struct cfg_list *ext_source;
@@ -224,6 +238,9 @@

    f_generate = c_lookup("generate");
    f_filter = c_lookup("filter");
+   f_new = c_lookup("new");
+   f_next = c_lookup("next");
+

    if ((ext_flags & EXT_REQ_GENERATE) && !f_generate) {
        if (john_main_process)
@@ -243,6 +260,10 @@
                        "Warning: external mode '%s' can't be"
                        " resumed if aborted\n", mode);
    }
+   /* in 'filter' mode, it may be a filter run, OR a hybrid run */
+   if ((ext_flags & EXT_REQ_FILTER) && f_next && f_new) {
+       ; // this one is 'ok'.  A wordlist mode CAN run with next() and new()
+   } else
    if ((ext_flags & EXT_REQ_FILTER) && !f_filter) {
        if (john_main_process)
            fprintf(stderr,
@@ -474,3 +495,62 @@
    crk_done();
    rec_done(event_abort);
 }
+
+
+int do_external_hybrid_crack(struct db_main *db, const char *base_word) {
+   char word[1024];
+   static int first = 1;
+   int retval = 0;
+   int max_len = db->format->params.plaintext_length;
+   unsigned char *internal, *cp;
+   c_int *external;
+
+
+// log_event("Proceeding with external hybrid mode: %.25s on word %.50s", ext_mode, base_word);
+
+   if (first) {
+       /* whatever init needs done */
+//     c_execute_fast(f_init);
+       first = 0;
+   }
+// strcpy(word, base_word);
+
+   internal = (unsigned char *)int_word;
+   external = ext_word;
+   cp = (unsigned char*)base_word;
+   while (*cp)
+       *internal++ = *external++ = *cp++;
+   *internal = 0;
+   *external = 0;
+
+   c_execute_fast(f_new);
+   c_execute_fast(f_next);
+   while (ext_word[0]) {
+       //strcpy(word, base_word);
+
+       cp = (unsigned char*)word;
+       internal = (unsigned char *)int_word;
+       external = ext_word;
+       while (*external)
+           *cp++ = *internal++ = *external++;
+       *internal = 0;
+       *cp = 0;
+
+       if (options.mask) {
+           if (do_mask_crack(word)) {
+               retval = 1;
+               goto out;
+           }
+       } else if (ext_filter((char*)word)) {
+           word[max_len] = 0;
+           if (crk_process_key((char *)word)) {
+               retval = 1;
+               goto out;
+           }
+       }
+       c_execute_fast(f_next);
+   }
+out:;
+   return retval;
+}
+
--- src/external.h  Mon Jan 19 16:26:32 1970
+++ src/external.h  Mon Jan 19 16:26:32 1970
@@ -29,7 +29,7 @@

 extern unsigned int ext_flags;

-extern c_int ext_abort, ext_status;
+extern c_int ext_abort, ext_status, ext_cur_candi, ext_tot_candi;

 /*
  * Defined for use in the ext_filter() macro, below.
@@ -37,6 +37,16 @@
 extern void *f_filter;

 /*
+ * Defined for use in the ext_next() macro, below.
+ */
+extern void *f_next;
+
+/*
+ * Defined for use in the ext_new() macro, below.
+ */
+extern void *f_new;
+
+/*
  * Returns true if the external mode has function()
  * Used for list=ext-filter and list=ext-mode
  */
@@ -62,5 +72,10 @@
  * Runs the external mode cracker.
  */
 extern void do_external_crack(struct db_main *db);
+
+/*
+ * Runs the Regular expression cracker in hybrid mode
+ */
+extern int do_external_hybrid_crack(struct db_main *db, const char *base_word);

 #endif
--- src/inc.c   Mon Jan 19 16:26:32 1970
+++ src/inc.c   Mon Jan 19 16:26:32 1970
@@ -413,6 +413,11 @@
        inc_hybrid_fix_state();
    } else
 #endif
+   if (f_new) {
+       if (do_external_hybrid_crack(db, key))
+           return 1;
+       inc_hybrid_fix_state();
+   } else
    if (options.mask) {
        if (do_mask_crack(key))
            return 1;
@@ -823,6 +828,11 @@
                inc_hybrid_fix_state();
            } else
 #endif
+           if (f_new) {
+               if (!skip && do_external_hybrid_crack(db, fmt_null_key))
+                   break;
+               inc_hybrid_fix_state();
+           } else
            if (options.mask) {
                if (!skip && do_mask_crack(fmt_null_key))
                    break;
--- src/mkv.c   Mon Jan 19 16:26:32 1970
+++ src/mkv.c   Mon Jan 19 16:26:32 1970
@@ -105,6 +105,11 @@
                mkv_hybrid_fix_state();
            } else
 #endif
+           if (f_new) {
+               if (do_external_hybrid_crack(db, pass))
+                   return 1;
+               mkv_hybrid_fix_state();
+           } else
            if (options.mask) {
                if (do_mask_crack(pass))
                    return 1;
@@ -166,6 +171,11 @@
                mkv_hybrid_fix_state();
            } else
 #endif
+           if (f_new) {
+               if (do_external_hybrid_crack(db, pass))
+                   return 1;
+               mkv_hybrid_fix_state();
+           } else
            if (options.mask) {
                if (do_mask_crack(pass))
                    return 1;
@@ -201,6 +211,11 @@
                mkv_hybrid_fix_state();
            } else
 #endif
+           if (f_new) {
+               if (do_external_hybrid_crack(db, pass))
+                   return 1;
+               mkv_hybrid_fix_state();
+           } else
            if (options.mask) {
                if (do_mask_crack(pass))
                    return 1;
@@ -252,6 +267,11 @@
                    mkv_hybrid_fix_state();
                } else
 #endif
+               if (f_new) {
+                   if (do_external_hybrid_crack(db, pass))
+                       return 1;
+                   mkv_hybrid_fix_state();
+               } else
                if (options.mask) {
                    if (do_mask_crack(pass))
                        return 1;
@@ -284,6 +304,11 @@
                mkv_hybrid_fix_state();
            } else
 #endif
+           if (f_new) {
+               if (do_external_hybrid_crack(db, pass))
+                   return 1;
+               mkv_hybrid_fix_state();
+           } else
            if (options.mask) {
                if (do_mask_crack(pass))
                    return 1;
--- src/pp.c    Mon Jan 19 16:26:32 1970
+++ src/pp.c    Mon Jan 19 16:26:32 1970
@@ -2233,6 +2233,11 @@
                 pp_hybrid_fix_state();
               } else
 #endif
+                   if (f_new) {
+                if (do_external_hybrid_crack(db, pw_buf))
+                  break;
+                       pp_hybrid_fix_state();
+                   } else
               if (options.mask) {
                 if ((jtr_done = do_mask_crack(pw_buf)))
                   break;
@@ -2261,6 +2266,11 @@
                     pp_hybrid_fix_state();
                   } else
 #endif
+                       if (f_new) {
+                    if (do_external_hybrid_crack(db, word))
+                      break;
+                           pp_hybrid_fix_state();
+                       } else
                   if (options.mask) {
                     if ((jtr_done = do_mask_crack(word)))
                       break;
--- src/wordlist.c  Mon Jan 19 16:26:32 1970
+++ src/wordlist.c  Mon Jan 19 16:26:32 1970
@@ -1193,6 +1193,17 @@
                    wordlist_hybrid_fix_state();
                } else
 #endif
+               if (f_new) {
+                   if (do_external_hybrid_crack(db, word))
+                   {
+                       rule = NULL;
+                       rules = 0;
+                       pipe_input = 0;
+                       do_lmloop = 0;
+                       break;
+                   }
+                   wordlist_hybrid_fix_state();
+               } else
                if (options.mask) {
                    if (do_mask_crack(word)) {
                        rule = NULL;
@@ -1250,6 +1261,16 @@
                    wordlist_hybrid_fix_state();
                } else
 #endif
+               if (f_new) {
+                   if (do_external_hybrid_crack(db, word))
+                   {
+                       rule = NULL;
+                       rules = 0;
+                       pipe_input = 0;
+                       break;
+                   }
+                   wordlist_hybrid_fix_state();
+               } else
                if (options.mask) {
                    if (do_mask_crack(word)) {
                        rule = NULL;
@@ -1314,6 +1335,16 @@
                        wordlist_hybrid_fix_state();
                    } else
 #endif
+                   if (f_new) {
+                       if (do_external_hybrid_crack(db, word))
+                       {
+                           rule = NULL;
+                           rules = 0;
+                           pipe_input = 0;
+                           break;
+                       }
+                       wordlist_hybrid_fix_state();
+                   } else
                    if (options.mask) {
                        if (do_mask_crack(word)) {
                            rule = NULL;
<!-- gh-comment-id:192005370 --> @jfoug commented on GitHub (Mar 3, 2016): Here is an initial 'look' that actually runs. Plug in the external script I did above, and bam, you have $[0-9]$[0-9] working!!! ``` patch --- src/external.c Mon Jan 19 16:26:32 1970 +++ src/external.c Mon Jan 19 16:26:32 1970 @@ -55,7 +55,7 @@ static char *ext_mode; static c_int ext_word[PLAINTEXT_BUFFER_SIZE]; -c_int ext_abort, ext_status, ext_cipher_limit, ext_minlen, ext_maxlen; +c_int ext_abort, ext_status, ext_cipher_limit, ext_minlen, ext_maxlen, ext_cur_candi, ext_tot_candi; c_int ext_time, ext_utf32, ext_target_utf8; static struct c_ident ext_ident_status = { @@ -106,13 +106,27 @@ &ext_time }; -static struct c_ident ext_globals = { +static struct c_ident ext_ident_tot_candi = { &ext_ident_time, + "tot_candi", + &ext_tot_candi +}; + +static struct c_ident ext_ident_cur_candi = { + &ext_ident_tot_candi, + "cur_candi", + &ext_cur_candi +}; + +static struct c_ident ext_globals = { + &ext_ident_cur_candi, "word", ext_word }; static void *f_generate; +void *f_new = NULL; +void *f_next = NULL; void *f_filter = NULL; static struct cfg_list *ext_source; @@ -224,6 +238,9 @@ f_generate = c_lookup("generate"); f_filter = c_lookup("filter"); + f_new = c_lookup("new"); + f_next = c_lookup("next"); + if ((ext_flags & EXT_REQ_GENERATE) && !f_generate) { if (john_main_process) @@ -243,6 +260,10 @@ "Warning: external mode '%s' can't be" " resumed if aborted\n", mode); } + /* in 'filter' mode, it may be a filter run, OR a hybrid run */ + if ((ext_flags & EXT_REQ_FILTER) && f_next && f_new) { + ; // this one is 'ok'. A wordlist mode CAN run with next() and new() + } else if ((ext_flags & EXT_REQ_FILTER) && !f_filter) { if (john_main_process) fprintf(stderr, @@ -474,3 +495,62 @@ crk_done(); rec_done(event_abort); } + + +int do_external_hybrid_crack(struct db_main *db, const char *base_word) { + char word[1024]; + static int first = 1; + int retval = 0; + int max_len = db->format->params.plaintext_length; + unsigned char *internal, *cp; + c_int *external; + + +// log_event("Proceeding with external hybrid mode: %.25s on word %.50s", ext_mode, base_word); + + if (first) { + /* whatever init needs done */ +// c_execute_fast(f_init); + first = 0; + } +// strcpy(word, base_word); + + internal = (unsigned char *)int_word; + external = ext_word; + cp = (unsigned char*)base_word; + while (*cp) + *internal++ = *external++ = *cp++; + *internal = 0; + *external = 0; + + c_execute_fast(f_new); + c_execute_fast(f_next); + while (ext_word[0]) { + //strcpy(word, base_word); + + cp = (unsigned char*)word; + internal = (unsigned char *)int_word; + external = ext_word; + while (*external) + *cp++ = *internal++ = *external++; + *internal = 0; + *cp = 0; + + if (options.mask) { + if (do_mask_crack(word)) { + retval = 1; + goto out; + } + } else if (ext_filter((char*)word)) { + word[max_len] = 0; + if (crk_process_key((char *)word)) { + retval = 1; + goto out; + } + } + c_execute_fast(f_next); + } +out:; + return retval; +} + --- src/external.h Mon Jan 19 16:26:32 1970 +++ src/external.h Mon Jan 19 16:26:32 1970 @@ -29,7 +29,7 @@ extern unsigned int ext_flags; -extern c_int ext_abort, ext_status; +extern c_int ext_abort, ext_status, ext_cur_candi, ext_tot_candi; /* * Defined for use in the ext_filter() macro, below. @@ -37,6 +37,16 @@ extern void *f_filter; /* + * Defined for use in the ext_next() macro, below. + */ +extern void *f_next; + +/* + * Defined for use in the ext_new() macro, below. + */ +extern void *f_new; + +/* * Returns true if the external mode has function() * Used for list=ext-filter and list=ext-mode */ @@ -62,5 +72,10 @@ * Runs the external mode cracker. */ extern void do_external_crack(struct db_main *db); + +/* + * Runs the Regular expression cracker in hybrid mode + */ +extern int do_external_hybrid_crack(struct db_main *db, const char *base_word); #endif --- src/inc.c Mon Jan 19 16:26:32 1970 +++ src/inc.c Mon Jan 19 16:26:32 1970 @@ -413,6 +413,11 @@ inc_hybrid_fix_state(); } else #endif + if (f_new) { + if (do_external_hybrid_crack(db, key)) + return 1; + inc_hybrid_fix_state(); + } else if (options.mask) { if (do_mask_crack(key)) return 1; @@ -823,6 +828,11 @@ inc_hybrid_fix_state(); } else #endif + if (f_new) { + if (!skip && do_external_hybrid_crack(db, fmt_null_key)) + break; + inc_hybrid_fix_state(); + } else if (options.mask) { if (!skip && do_mask_crack(fmt_null_key)) break; --- src/mkv.c Mon Jan 19 16:26:32 1970 +++ src/mkv.c Mon Jan 19 16:26:32 1970 @@ -105,6 +105,11 @@ mkv_hybrid_fix_state(); } else #endif + if (f_new) { + if (do_external_hybrid_crack(db, pass)) + return 1; + mkv_hybrid_fix_state(); + } else if (options.mask) { if (do_mask_crack(pass)) return 1; @@ -166,6 +171,11 @@ mkv_hybrid_fix_state(); } else #endif + if (f_new) { + if (do_external_hybrid_crack(db, pass)) + return 1; + mkv_hybrid_fix_state(); + } else if (options.mask) { if (do_mask_crack(pass)) return 1; @@ -201,6 +211,11 @@ mkv_hybrid_fix_state(); } else #endif + if (f_new) { + if (do_external_hybrid_crack(db, pass)) + return 1; + mkv_hybrid_fix_state(); + } else if (options.mask) { if (do_mask_crack(pass)) return 1; @@ -252,6 +267,11 @@ mkv_hybrid_fix_state(); } else #endif + if (f_new) { + if (do_external_hybrid_crack(db, pass)) + return 1; + mkv_hybrid_fix_state(); + } else if (options.mask) { if (do_mask_crack(pass)) return 1; @@ -284,6 +304,11 @@ mkv_hybrid_fix_state(); } else #endif + if (f_new) { + if (do_external_hybrid_crack(db, pass)) + return 1; + mkv_hybrid_fix_state(); + } else if (options.mask) { if (do_mask_crack(pass)) return 1; --- src/pp.c Mon Jan 19 16:26:32 1970 +++ src/pp.c Mon Jan 19 16:26:32 1970 @@ -2233,6 +2233,11 @@ pp_hybrid_fix_state(); } else #endif + if (f_new) { + if (do_external_hybrid_crack(db, pw_buf)) + break; + pp_hybrid_fix_state(); + } else if (options.mask) { if ((jtr_done = do_mask_crack(pw_buf))) break; @@ -2261,6 +2266,11 @@ pp_hybrid_fix_state(); } else #endif + if (f_new) { + if (do_external_hybrid_crack(db, word)) + break; + pp_hybrid_fix_state(); + } else if (options.mask) { if ((jtr_done = do_mask_crack(word))) break; --- src/wordlist.c Mon Jan 19 16:26:32 1970 +++ src/wordlist.c Mon Jan 19 16:26:32 1970 @@ -1193,6 +1193,17 @@ wordlist_hybrid_fix_state(); } else #endif + if (f_new) { + if (do_external_hybrid_crack(db, word)) + { + rule = NULL; + rules = 0; + pipe_input = 0; + do_lmloop = 0; + break; + } + wordlist_hybrid_fix_state(); + } else if (options.mask) { if (do_mask_crack(word)) { rule = NULL; @@ -1250,6 +1261,16 @@ wordlist_hybrid_fix_state(); } else #endif + if (f_new) { + if (do_external_hybrid_crack(db, word)) + { + rule = NULL; + rules = 0; + pipe_input = 0; + break; + } + wordlist_hybrid_fix_state(); + } else if (options.mask) { if (do_mask_crack(word)) { rule = NULL; @@ -1314,6 +1335,16 @@ wordlist_hybrid_fix_state(); } else #endif + if (f_new) { + if (do_external_hybrid_crack(db, word)) + { + rule = NULL; + rules = 0; + pipe_input = 0; + break; + } + wordlist_hybrid_fix_state(); + } else if (options.mask) { if (do_mask_crack(word)) { rule = NULL; ```
Author
Owner

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

Seeing that I am 'learning' external/compiler as I go, I am not 100% sure about the requirements of int_word and ext_word. I think I have them, but I may be doing more work than I need to. I will keep working on this, and hopefully tonite, we will have a new mode.

Then I might put out a request for comment on john-users (lol), or simply just list that there is a new external mode.

<!-- gh-comment-id:192006497 --> @jfoug commented on GitHub (Mar 3, 2016): Seeing that I am 'learning' external/compiler as I go, I am not 100% sure about the requirements of int_word and ext_word. I think I have them, but I may be doing more work than I need to. I will keep working on this, and hopefully tonite, we will have a new mode. Then I might put out a request for comment on john-users (lol), or simply just list that there is a new external mode.
Author
Owner

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

I think I have it for resume logic (and I have an 'ah-ha' moment for rexgen resume also).

I will use the 1 var ext_cur_candi 'hybrid' global variable. Used in this way.

in ext_new() if the script can easily count totals on a pre-word basis, it sets this to the number for this word. If it can not, it sets it to -1.

in the run, external_hybrid_crack() keeps track of the count of words returned for this word. Upon shutdown, both the 'total' and this current value are store in rec file.

before resume is called, external.c sets 'hybrid' global to be the current count (i.e. resume value).

Within resume() if the script can deal with it, it uses the hybrid value to recompute it's state, AND sets the hybrid value to the total number of candidates for this word (not number left, BUT total as if it were starting from scratch). If the script can not deal with resuming like this (i.e. too hard, or otherwise), it should do nothing, or not be defined at all.

Then within external.c's ext_resume() function, it checks hybrid after the script returns. If it is set to the proper total (remember, resume has that value also), then external.c will set a static int hybrid_resume to -1. If the value of ext_hybrid is still the same, OR not the proper max count, then this static hybrid_resume will be set to the stored current value.

Then within the crack loop, if that static hybrid_resume is set to -1, we do NOT call ext_new() since the ext_resume() has set the state properly for this word, and set hybrid_resume to 0. If hybrid_resume is > 0, then after we call ext_new(), we call ext_next() hybrid_resume times, and set hybrid_resume to 0.

;That should handle resume! I think I can do the same thing for rexgen. Just keep a counter, store it off, and then upon restart, simply do the next() logic that many times, dropping the words. Easy-peasy.

Now I just have to figure out how to work with the .rec files, lol.

<!-- gh-comment-id:192050158 --> @jfoug commented on GitHub (Mar 4, 2016): I think I have it for resume logic (and I have an 'ah-ha' moment for rexgen resume also). I will use the 1 var ext_cur_candi 'hybrid' global variable. Used in this way. in ext_new() if the script can easily count totals on a pre-word basis, it sets this to the number for this word. If it can not, it sets it to -1. in the run, external_hybrid_crack() keeps track of the count of words returned for this word. Upon shutdown, both the 'total' and this current value are store in rec file. before resume is called, external.c sets 'hybrid' global to be the current count (i.e. resume value). Within resume() if the script can deal with it, it uses the hybrid value to recompute it's state, AND sets the hybrid value to the total number of candidates for this word (not number left, BUT total as if it were starting from scratch). If the script can not deal with resuming like this (i.e. too hard, or otherwise), it should do nothing, or not be defined at all. Then within external.c's ext_resume() function, it checks hybrid after the script returns. If it is set to the proper total (remember, resume has that value also), then external.c will set a static int hybrid_resume to -1. If the value of ext_hybrid is still the same, OR not the proper max count, then this static hybrid_resume will be set to the stored current value. Then within the crack loop, if that static hybrid_resume is set to -1, we do NOT call ext_new() since the ext_resume() has set the state properly for this word, and set hybrid_resume to 0. If hybrid_resume is > 0, then after we call ext_new(), we call ext_next() hybrid_resume times, and set hybrid_resume to 0. ;That should handle resume! I think I can do the same thing for rexgen. Just keep a counter, store it off, and then upon restart, simply do the next() logic that many times, dropping the words. Easy-peasy. Now I just have to figure out how to work with the .rec files, lol.
Author
Owner

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

When I am within the extern_hybrid_crack loop, do you think I should copy the baseword into a working buffer, and simply call next on the same buffer over and over, or should I strcpy the original word into the buffer before each call to next()

Our state is mostly just our last word, right? So I think we should not reset it. Besides, it eats performance.

<!-- gh-comment-id:192144628 --> @magnumripper commented on GitHub (Mar 4, 2016): > When I am within the extern_hybrid_crack loop, do you think I should copy the baseword into a working buffer, and simply call next on the same buffer over and over, or should I strcpy the original word into the buffer before each call to next() Our state is mostly just our last word, right? So I think we should not reset it. Besides, it eats performance.
Author
Owner

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

Good stuff. Commit to a topic branch so we can try it out!

<!-- gh-comment-id:192144829 --> @magnumripper commented on GitHub (Mar 4, 2016): Good stuff. Commit to a topic branch so we can try it out!
Author
Owner

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

Not sure about node/fork stuff. It's more efficient putting that logic prior to hybrid ext (so different nodes simply uses different base words) - but OTOH some words may generate 0 candidates and others millions of them (theoretically). KISS for now.

<!-- gh-comment-id:192145772 --> @magnumripper commented on GitHub (Mar 4, 2016): Not sure about node/fork stuff. It's more efficient putting that logic prior to hybrid ext (so different nodes simply uses different base words) - but OTOH some words may generate 0 candidates and others millions of them (theoretically). KISS for now.
Author
Owner

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

That should handle resume! I think I can do the same thing for rexgen. Just keep a counter, store it off, and then upon restart, simply do the next() logic that many times, dropping the words. Easy-peasy.

This is better than nothing but may take ages. So if we can do it faster, using some more state than just last word used, we should. At least for rexgen.

<!-- gh-comment-id:192151652 --> @magnumripper commented on GitHub (Mar 4, 2016): > That should handle resume! I think I can do the same thing for rexgen. Just keep a counter, store it off, and then upon restart, simply do the next() logic that many times, dropping the words. Easy-peasy. This is better than nothing but may take ages. So if we can do it faster, using some more state than just last word used, we should. At least for rexgen.
Author
Owner

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

For rexgen the save/restore is easy. Rexgen (IIRC) has it's own save/restore code. We just have to get the context, save it off in the rec file, and then get it from the rec file and pass it back into rexgen. Should be a piece of cake. So what I said about a naive back-walk for rexgen is not needed.

But I am leaving that ability 'open' on external. Yes, it is MUCH better, if a script will know how many candidates are generated by the input word, and be able to easily restart given the original word, and the count. Possibly, we may want to do original word, count AND the last 'current-word', and allow the script to figure it out. I think we still need to allow the script to say it does not know how to resume, so just call the next() function that many times doing nothing with the words until caught up. There can be functions which are semi-one-way, where there really is no resume, and no way of knowing how many candidates there will be, until the hashing type function returns the completion result. Take for instance some modular type function. You simply remember the first value generated. Then when you generate it again, your are done (cycle reached). But does that happen after 2 candidates or 2 million? Without running it you do not know. So in that case, the script would simply have to tell Now, if we could call next() within restore() function in the script, then the script itself could self-iterate. BUT (at least at this time), compiler.c can not handle a function calling another function (would that be something we would want???)

<!-- gh-comment-id:192333332 --> @jfoug commented on GitHub (Mar 4, 2016): For rexgen the save/restore is easy. Rexgen (IIRC) has it's own save/restore code. We just have to get the context, save it off in the rec file, and then get it from the rec file and pass it back into rexgen. Should be a piece of cake. So what I said about a naive back-walk for rexgen is not needed. But I am leaving that ability 'open' on external. Yes, it is MUCH better, if a script will know how many candidates are generated by the input word, and be able to easily restart given the original word, and the count. Possibly, we may want to do original word, count AND the last 'current-word', and allow the script to figure it out. I think we still need to allow the script to say it does not know how to resume, so just call the next() function that many times doing nothing with the words until caught up. There can be functions which are semi-one-way, where there really is no resume, and no way of knowing how many candidates there will be, until the hashing type function returns the completion result. Take for instance some modular type function. You simply remember the first value generated. Then when you generate it again, your are done (cycle reached). But does that happen after 2 candidates or 2 million? Without running it you do not know. So in that case, the script would simply have to tell Now, if we could call next() within restore() function in the script, then the script itself could self-iterate. BUT (at least at this time), compiler.c can not handle a function calling another function (would that be something we would want???)
Author
Owner

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

Here is the first draft. Save/resume is there, but I am not 100% sure everything is right there. That was not the most simple 'hook'.

I forked bleeding, and put the changes into this fork, since this is a pretty encompassing change.

github.com/jfoug/ExternalHybrid@70c1cf7c85

Things still outstanding

  1. node support (trivial, I just have not gotten it done)
  2. testing of restore.
  3. should not operate in -stdin mode (note much harder than -rules, since we have 3 'types' of externals).
  4. dox (boo....)
  5. add restore code to rexgen (since the basic hooks for hybrid stuff is there now).
<!-- gh-comment-id:192700393 --> @jfoug commented on GitHub (Mar 5, 2016): Here is the first draft. Save/resume is there, but I am not 100% sure everything is right there. That was not the most simple 'hook'. I forked bleeding, and put the changes into this fork, since this is a pretty encompassing change. https://github.com/jfoug/ExternalHybrid/commit/70c1cf7c85613c2351c89373a83b9dd96b37cdd3 Things still outstanding 1. node support (trivial, I just have not gotten it done) 2. testing of restore. 3. should not operate in -stdin mode (note much harder than -rules, since we have 3 'types' of externals). 4. dox (boo....) 5. add restore code to rexgen (since the basic hooks for hybrid stuff is there now).
Author
Owner

@frank-dittrich commented on GitHub (Mar 5, 2016):

Behavior when mixing --wordlist (or --incremental or --markov) with such an external mode and --mask (or --regex) needs to be discussed.
Should --mask / --regex be used on the candidates generated by --external, or vice versa?
Should the user be able to decide that sequence of "stacked" modes? If yes, how can this be implemented?

<!-- gh-comment-id:192701295 --> @frank-dittrich commented on GitHub (Mar 5, 2016): Behavior when mixing --wordlist (or --incremental or --markov) with such an external mode and --mask (or --regex) needs to be discussed. Should --mask / --regex be used on the candidates generated by --external, or vice versa? Should the user be able to decide that sequence of "stacked" modes? If yes, how can this be implemented?
Author
Owner

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

It looks like the hybrids should not do node splitting. It looks like it should be handled by the parent.

Here was a test

perl -e 'for($i=0;$i<4096;$i++){for($x=0;$x<100;$x++){$s=sprintf("%03x_%02d",$i,$x);printf("%s:\$dummy\$",$s);for($a=0;$a<6;$a++){printf("%02x",ord(substr($s,$a,1)));}printf("\n");}}' > test.in
perl -e 'for($i=0;$i<4096;$i++){printf("%03x_\n",$i);}' > test.dic

This generated an input file of 409600 candidates and a dictionary file of 4096 input words. These perfectly match. for each input word, appending 2 digits is the input file. Input is in dummy format.

When I ran a build where I had a simple modular node splitter in there, and ran with -fork=4, it appears that only 1/4 of the candidates were cracked? I then tested with a simple rule against the wordlist, and all 409k were cracked. When I removed the modular node code from external hybrid, then the hybrid code worked as expected, where each thread properly ran and each thread was given every 4th word and then did full processing on that word.

I need to test other base modes (like Markov, mask, pp to make sure they are ok), but it may be that hybrid's do not need to worry about node splitting.

Markov test:

$ ../run/john -markov:90 -stdout > markov.dic
Press 'q' or Ctrl-C to abort, almost any other key for status
MKV start (stats=$JOHN/stats, lvl=90 len=12 pwd=3593)
3592p 0:00:00:00 99.69% (ETA: 19:16:10) 79822p/s &

$ perl -e 'foreach $s(<>){chomp($s);for($x=0;$x<100;$x++){printf("%s%02d:\$dummy\$",$s,$x);for($i=0;$i<length($s);++$i){printf("%02x",ord(substr($s,$i,1)));}printf("3%d3%d\n",$x/10,$x%10);}}' < markov.dic > markov.in
$ wc markov.in
 359200  359200 8501700 markov.in

in the above test, if I tried to add node logic to the hybrid-extern, then each fork node only handled 1/4 of the candidates.

So I think -fork=x work is done. It must be ignored, and the 'parent' word generator does the splitting. Each candidate word given to a external hybrid will not be given to any other thread, so that script has to generate ALL data for that word.

<!-- gh-comment-id:192773534 --> @jfoug commented on GitHub (Mar 6, 2016): It looks like the hybrids should not do node splitting. It looks like it should be handled by the parent. Here was a test ``` sh perl -e 'for($i=0;$i<4096;$i++){for($x=0;$x<100;$x++){$s=sprintf("%03x_%02d",$i,$x);printf("%s:\$dummy\$",$s);for($a=0;$a<6;$a++){printf("%02x",ord(substr($s,$a,1)));}printf("\n");}}' > test.in perl -e 'for($i=0;$i<4096;$i++){printf("%03x_\n",$i);}' > test.dic ``` This generated an input file of 409600 candidates and a dictionary file of 4096 input words. These perfectly match. for each input word, appending 2 digits is the input file. Input is in dummy format. When I ran a build where I had a simple modular node splitter in there, and ran with -fork=4, it appears that only 1/4 of the candidates were cracked? I then tested with a simple rule against the wordlist, and all 409k were cracked. When I removed the modular node code from external hybrid, then the hybrid code worked as expected, where each thread properly ran and each thread was given every 4th word and then did full processing on that word. I need to test other base modes (like Markov, mask, pp to make sure they are ok), but it may be that hybrid's do not need to worry about node splitting. Markov test: ``` sh $ ../run/john -markov:90 -stdout > markov.dic Press 'q' or Ctrl-C to abort, almost any other key for status MKV start (stats=$JOHN/stats, lvl=90 len=12 pwd=3593) 3592p 0:00:00:00 99.69% (ETA: 19:16:10) 79822p/s & $ perl -e 'foreach $s(<>){chomp($s);for($x=0;$x<100;$x++){printf("%s%02d:\$dummy\$",$s,$x);for($i=0;$i<length($s);++$i){printf("%02x",ord(substr($s,$i,1)));}printf("3%d3%d\n",$x/10,$x%10);}}' < markov.dic > markov.in $ wc markov.in 359200 359200 8501700 markov.in ``` in the above test, if I tried to add node logic to the hybrid-extern, then each fork node only handled 1/4 of the candidates. So I think -fork=x work is done. It must be ignored, and the 'parent' word generator does the splitting. Each candidate word given to a external hybrid will not be given to any other thread, so that script has to generate ALL data for that word.
Author
Owner

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

Note, currently, -markov does not allow rules. What is our reason to disallow rules? Yes, I realize most times, markov is stand alone. But what about targeted audits where you know many of the password patterns are leet or something like that. markov can bring many wordlike words into play, but it will not help in that situation. But rules (or better yet, this new hybrid-external) could allow these new word-like words to be tested with leet modifications run on top of them.

But for -fork, it is the same thing, each node gets only 1/4 of the data if we try to do node logic inside the external

<!-- gh-comment-id:192780609 --> @jfoug commented on GitHub (Mar 6, 2016): Note, currently, -markov does not allow rules. What is our reason to disallow rules? Yes, I realize most times, markov is stand alone. But what about targeted audits where you know many of the password patterns are leet or something like that. markov can bring many wordlike words into play, but it will not help in that situation. But rules (or better yet, this new hybrid-external) could allow these new word-like words to be tested with leet modifications run on top of them. But for -fork, it is the same thing, each node gets only 1/4 of the data if we try to do node logic inside the external
Author
Owner

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

I created a new format (it will live in unused) that is built specifically for testing restore of john. This format only has 1 valid hash: $restore_tester$valid So that is the only line needed on the input side. Then every password tested will be cracked ;) It also has a nano-sleep in the crypt_all loop, so that it works like a slow format. It is unsalted. I am not 100% sure we need to test salted for resume, if unsalted is 'proven' to be correct, but I will listen to others if they think it is needed.

github.com/jfoug/ExternalHybrid@15f7fdf6ef

<!-- gh-comment-id:192945577 --> @jfoug commented on GitHub (Mar 6, 2016): I created a new format (it will live in unused) that is built specifically for testing restore of john. This format only has 1 valid hash: `$restore_tester$valid` So that is the only line needed on the input side. Then every password tested will be cracked ;) It also has a nano-sleep in the crypt_all loop, so that it works like a slow format. It is unsalted. I am not 100% sure we need to test salted for resume, if unsalted is 'proven' to be correct, but I will listen to others if they think it is needed. https://github.com/jfoug/ExternalHybrid/commit/15f7fdf6efac125bef1c9d50d167c525f1d46890
Author
Owner

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

Ok, I found some behavior that I was not aware of. Not 100% sure how to handle this in hybrid-ext.

Here is a run, that I hit ^c pretty early on. Notice it ends with 000_95 and should expect the next word to be 000_96.

...
000_92           (?)
000_93           (?)
000_94           (?)
000_95           (?)
96g 0:00:00:00 0.05% (ETA: 12:15:26) 159.2g/s 159.2p/s 159.2c/s 159.2C/s 000_96..001_11
Session aborted

Now, the ext-v1 record is this.

$ cat tst-x.rec
....
ext-v1
11 0
001_

So upon resume, the first word generated is 001_11 ?? Well, what this is, is 16 words further along than what we really want!?!? So it appears that within cracker, if a session is aborted, then the last block of data is NOT checked for cracked passwords?

Now, I have a couple questions.

  1. if this was done from the pause file, do we miss anything (I guess my new restore_tester should help here)).
  2. if this is correct behavior, then how in my ext-hybrid do I know that I need to restart at the 'start' of this block, not at the end ? I guess I could handle this by simply setting my resume vars to be what they properly at the 'start' of a run, but this seems strange.
<!-- gh-comment-id:192954481 --> @jfoug commented on GitHub (Mar 6, 2016): Ok, I found some behavior that I was not aware of. Not 100% sure how to handle this in hybrid-ext. Here is a run, that I hit ^c pretty early on. Notice it ends with 000_95 and should expect the next word to be 000_96. ``` ... 000_92 (?) 000_93 (?) 000_94 (?) 000_95 (?) 96g 0:00:00:00 0.05% (ETA: 12:15:26) 159.2g/s 159.2p/s 159.2c/s 159.2C/s 000_96..001_11 Session aborted ``` Now, the ext-v1 record is this. ``` $ cat tst-x.rec .... ext-v1 11 0 001_ ``` So upon resume, the first word generated is 001_11 ?? Well, what this is, is 16 words further along than what we really want!?!? So it appears that within cracker, if a session is aborted, then the last block of data is NOT checked for cracked passwords? Now, I have a couple questions. 1. if this was done from the pause file, do we miss anything (I guess my new restore_tester should help here)). 2. if this is correct behavior, then how in my ext-hybrid do I know that I need to restart at the 'start' of this block, not at the end ? I guess I could handle this by simply setting my resume vars to be what they properly at the 'start' of a run, but this seems strange.
Author
Owner

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

I am adding the restore_tester format to bleeding. It is turning up strange behavior all over the place,, and I think it will really help getting these issues addressed. Seeing problems pretty much all over the place (like rules, etc), where the restart is not at where things left off, but many data is re-done.

<!-- gh-comment-id:192959949 --> @jfoug commented on GitHub (Mar 6, 2016): I am adding the restore_tester format to bleeding. It is turning up strange behavior all over the place,, and I think it will really help getting these issues addressed. Seeing problems pretty much all over the place (like rules, etc), where the restart is not at where things left off, but many data is re-done.
Author
Owner

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

You need to support the UTF-32 flag too. It's trivial, just look for the existing use of it.

<!-- gh-comment-id:193131297 --> @magnumripper commented on GitHub (Mar 7, 2016): You need to support the UTF-32 flag too. It's trivial, just look for the existing use of it.
Author
Owner

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

Here's a test for your new code.

void filter()
{
    if (cnt % 3 == 0)
        word = 0;
}

This dumb filter will simply mute every third word. After that, we should get the fourth and so on but the version I tested (this one) didn't.

<!-- gh-comment-id:193131688 --> @magnumripper commented on GitHub (Mar 7, 2016): Here's a test for your new code. ``` void filter() { if (cnt % 3 == 0) word = 0; } ``` This dumb filter will simply mute every third word. After that, we should get the fourth and so on but the version I tested ([this one](https://github.com/magnumripper/JohnTheRipper/issues/2072#issuecomment-192005370)) didn't.
Author
Owner

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

You need to support the UTF-32 flag too. It's trivial, just look for the existing use of it.

That would be up to the script writer. In the simple example, I do not care about utf-32. But it should be usable for anyone writing a script that needs to handle that. (or am I not understanding what you are saying)

<!-- gh-comment-id:193255717 --> @jfoug commented on GitHub (Mar 7, 2016): > You need to support the UTF-32 flag too. It's trivial, just look for the existing use of it. That would be up to the script writer. In the simple example, I do not care about utf-32. But it should be usable for anyone writing a script that needs to handle that. (or am I not understanding what you are saying)
Author
Owner

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

Was this the results you saw in the filter?

....
ffc_00
ffc_01
ffd_00
ffd_01
ffe_00
ffe_01
fff_00
fff_01
<!-- gh-comment-id:193258250 --> @jfoug commented on GitHub (Mar 7, 2016): Was this the results you saw in the filter? ``` .... ffc_00 ffc_01 ffd_00 ffd_01 ffe_00 ffe_01 fff_00 fff_01 ```
Author
Owner

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

github.com/jfoug/ExternalHybrid@0b1f0a7cc9

I believe that fixes the problem with filter you mentioned.

<!-- gh-comment-id:193268419 --> @jfoug commented on GitHub (Mar 7, 2016): https://github.com/jfoug/ExternalHybrid/commit/0b1f0a7cc9ea362dfaf67d50f35b37c58ca82e68 I believe that fixes the problem with filter you mentioned.
Author
Owner

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

I just thought of a wonderful external-hybrid script.

'keyboard_smart'

This would be the normal keyboard script, BUT the input words to the script will be of this format:

S-m-M

S is the starting string. So, it could just be the letter 'q'

m is min length

M is max length.

So an input file with

q-8-12
a-8-12
1-8-12
k-8-12

would only do keyboard work for the letters q, a, 1 and k from length 8 to 12.

Keyboard is a very powerful external, BUT about 75-80% of the run is over areas that are very sparse in 'real' passwords. Being able to specify specific 'hot' ranges, allows running keyboard to work more like incremental. incremental is 'just' brute force (if run to completion), but it puts the best data first (or early on). But now with external-hybrid, we can do the same thing for keyboard.

<!-- gh-comment-id:193317003 --> @jfoug commented on GitHub (Mar 7, 2016): I just thought of a wonderful external-hybrid script. 'keyboard_smart' This would be the normal keyboard script, BUT the input words to the script will be of this format: S-m-M S is the starting string. So, it could just be the letter 'q' m is min length M is max length. So an input file with q-8-12 a-8-12 1-8-12 k-8-12 would only do keyboard work for the letters q, a, 1 and k from length 8 to 12. Keyboard is a very powerful external, BUT about 75-80% of the run is over areas that are very sparse in 'real' passwords. Being able to specify specific 'hot' ranges, allows running keyboard to work more like incremental. incremental is 'just' brute force (if run to completion), but it puts the best data first (or early on). But now with external-hybrid, we can do the same thing for keyboard.
Author
Owner

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

@magnumripper please look over patch : github.com/jfoug/ExternalHybrid@1b7d8a2dce which hopefully correctly deals with utf32 flag.

<!-- gh-comment-id:193501055 --> @jfoug commented on GitHub (Mar 7, 2016): @magnumripper please look over patch : https://github.com/jfoug/ExternalHybrid/commit/1b7d8a2dce15c9791ce4e415195c884d1ca650d9 which hopefully correctly deals with utf32 flag.
Author
Owner

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

Yeah it looks right, I'll test it a bit.

<!-- gh-comment-id:193628348 --> @magnumripper commented on GitHub (Mar 8, 2016): Yeah it looks right, I'll test it a bit.
Author
Owner

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

There were several things busted in the patch above. This corrects those problems. BUT I am not 100% sure how to test the utf32 stuff, so I am not 100% sure I have everything as it should be.

github.com/jfoug/ExternalHybrid@3c8167c73b

<!-- gh-comment-id:193634121 --> @jfoug commented on GitHub (Mar 8, 2016): There were several things busted in the patch above. This corrects those problems. BUT I am not 100% sure how to test the utf32 stuff, so I am not 100% sure I have everything as it should be. https://github.com/jfoug/ExternalHybrid/commit/3c8167c73b84d1baa09124a9860b0bc1e182d380
Author
Owner

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

I can't see why you had to merge it so soon but anyways, here's some notes from my testing. Most of them are very minor and/or trivial to fix.

  • The ext_word[0] = int_word[0]; restore after filter rejection is not (always) valid for UTF-32. Better save ext_word[0] off before filter, and restore that very integer afterwards.
  • Do we really need the char word[1024] at all, isn't that just a redundant copy of int_word? If we do need it, I guess it shouldn't be 1024 but PLAINTEXT_BUFFER_SIZE.
  • Max length is ignored. If using "--stdout=10" the candidates should be truncated at 10 (and they are) but if using "--max-len=10" they should be rejected instead. This might actually just need a fix in the user code (conf file). If we want to enforce it with some code in external.c we probably need to add it for old-style f_generate too.

Also, the case where hybrid filter ends up just going through f_filter() and not to some downstream mode (like mask) can be optimized if we care: We can get rid of unneeded conversions back and forth between char and int (UTF-32 or not). To do so you need to stop calling ext_filter() and instead call c_execute_fast(f_filter); with a little surrounding support code. BTW I have a pending patch for ext_filter() vs. UTF-32 (which isn't handled now - this is a bug regardless of the new hybrid mode). Edit this was applied as e14b768.

<!-- gh-comment-id:193939335 --> @magnumripper commented on GitHub (Mar 8, 2016): I can't see why you had to merge it so soon but anyways, here's some notes from my testing. Most of them are very minor and/or trivial to fix. - The `ext_word[0] = int_word[0];` restore after filter rejection is not (always) valid for UTF-32. Better save `ext_word[0]` off before filter, and restore that very integer afterwards. - Do we really need the `char word[1024]` at all, isn't that just a redundant copy of int_word? If we do need it, I guess it shouldn't be 1024 but PLAINTEXT_BUFFER_SIZE. - Max length is ignored. If using "--stdout=10" the candidates should be truncated at 10 (and they are) but if using "--max-len=10" they should be rejected instead. This might actually just need a fix in the user code (conf file). If we want to enforce it with some code in external.c we probably need to add it for old-style f_generate too. Also, the case where hybrid filter ends up just going through f_filter() and not to some downstream mode (like mask) can be optimized if we care: We can get rid of unneeded conversions back and forth between char and int (UTF-32 or not). To do so you need to stop calling `ext_filter()` and instead call `c_execute_fast(f_filter);` with a little surrounding support code. BTW I have a pending patch for ext_filter() vs. UTF-32 (which isn't handled now - this is a bug regardless of the new hybrid mode). **Edit** this was applied as e14b768.
Author
Owner

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

I can't see why you had to merge it so soon but anyways

Partly because I have other things which depend upon some of the foundations added by this change.

Yes, I knew it still had worts, BUT everything is working mostly, and there should be no legacy issues. Also, until new scripts are written the code is just sitting there.

<!-- gh-comment-id:193944535 --> @jfoug commented on GitHub (Mar 8, 2016): > I can't see why you had to merge it so soon but anyways Partly because I have other things which depend upon some of the foundations added by this change. Yes, I knew it still had worts, BUT everything is working mostly, and there should be no legacy issues. Also, until new scripts are written the code is just sitting there.
Author
Owner

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

Your first 2 bullet points should be handled here. ee5c0d8

I am not 100% sure about your 3rd one (the reject if > --max-len=10). Does it reject? I thought it just truncated. We should check other modes of input because I really think there are others which truncate and not skip overlong words.

<!-- gh-comment-id:193953750 --> @jfoug commented on GitHub (Mar 8, 2016): Your first 2 bullet points should be handled here. ee5c0d8 I am not 100% sure about your 3rd one (the reject if > --max-len=10). Does it reject? I thought it just truncated. We should check other modes of input because I really think there are others which truncate and not skip overlong words.
Author
Owner

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

--max-len has (I think) always been about rejection, not truncation. At the time the --max-len option was introduced, the format's max length was always truncating so they served (or could serve) slightly different purposes. If you find --max-len merely truncating, it's a bug.

Since a few months (3701702af), even the format's max-length (as well as --stdout=N) is rejecting unless format has FMT_TRUNC flag. This was proposed by Solar, and it was indeed a good idea.

<!-- gh-comment-id:193961796 --> @magnumripper commented on GitHub (Mar 8, 2016): --max-len has (I think) always been about rejection, not truncation. At the time the --max-len option was introduced, the format's max length was always truncating so they served (or could serve) slightly different purposes. If you find --max-len merely truncating, it's a bug. Since a few months (3701702af), even the format's max-length (as well as --stdout=N) is rejecting unless format has FMT_TRUNC flag. This was proposed by Solar, and it was indeed a good idea.
Author
Owner

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

And BTW when I tested the new mode, --max-length=10 neither truncated nor rejected!

<!-- gh-comment-id:193965107 --> @magnumripper commented on GitHub (Mar 8, 2016): And BTW when I tested the new mode, --max-length=10 neither truncated nor rejected!
Author
Owner

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

Here's an example of correct rejection vs. truncation

$ ../run/john -w -stdout -v:1
3546p 0:00:00:00 100.00% (2016-03-08 23:54) 354600p/s sss

$ ../run/john -w -stdout=3 -v:1
2999p 0:00:00:00 100.00% (2016-03-08 23:55) 299900p/s sss

$ ../run/john -w -stdout -max-len=3 -v:1
84p 0:00:00:00 100.00% (2016-03-08 23:55) 4200p/s sss

The --stdout=N works like a FMT_TRUNC format with max length of N. The reason the figure drops a little is because of rejected successive dupes after truncation. The --max-len=3 case results in much fewer candidates because it actually rejects the longer candidates right away.

<!-- gh-comment-id:194006695 --> @magnumripper commented on GitHub (Mar 8, 2016): Here's an example of correct rejection vs. truncation ``` $ ../run/john -w -stdout -v:1 3546p 0:00:00:00 100.00% (2016-03-08 23:54) 354600p/s sss $ ../run/john -w -stdout=3 -v:1 2999p 0:00:00:00 100.00% (2016-03-08 23:55) 299900p/s sss $ ../run/john -w -stdout -max-len=3 -v:1 84p 0:00:00:00 100.00% (2016-03-08 23:55) 4200p/s sss ``` The --stdout=N works like a FMT_TRUNC format with max length of N. The reason the figure drops a little is because of rejected successive dupes after truncation. The --max-len=3 case results in much fewer candidates because it actually rejects the longer candidates right away.
Author
Owner

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

I see several problems with external maxlen, it was buggy even before this hybrid mode. Will fix tomorrow.

<!-- gh-comment-id:194020394 --> @magnumripper commented on GitHub (Mar 8, 2016): I see several problems with external maxlen, it was buggy even before this hybrid mode. Will fix tomorrow.
Author
Owner

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

Some fixes in e649f8b but the real -max-len reject stuff really needs to be in the user code because it gets really hairy with some combinations of encodings. For example, you can run ./john -stdout -max-len=16 -ext:repeats32 and get strings up to length 16 characters even though they are up to 64 bytes in UTF-8...

<!-- gh-comment-id:194062756 --> @magnumripper commented on GitHub (Mar 9, 2016): Some fixes in e649f8b but the real -max-len reject stuff really needs to be in the user code because it gets really hairy with some combinations of encodings. For example, you can run `./john -stdout -max-len=16 -ext:repeats32` and get strings up to length 16 _characters_ even though they are up to 64 _bytes_ in UTF-8...
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#1390
No description provided.