[GH-ISSUE #2108] Enhance --single mode to also use --extern:case and or -extern:leet #1411

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

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

I think this could be a great win, for the -single mode cracking. Not sure how easy it would be to do, but I would think it could be done.

Originally created by @jfoug on GitHub (Apr 3, 2016). Original GitHub issue: https://github.com/openwall/john/issues/2108 I think this could be a great win, for the -single mode cracking. Not sure how easy it would be to do, but I would think it could be done.
Author
Owner

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

I have seen many cases like this:

deeznuts2:d33znuts
Homerj:hom3rj
billy:b111y1

Single currently does not get these, but it would be very trivial to do so, if we could call the external hybrid scripts.

<!-- gh-comment-id:205012292 --> @jfoug commented on GitHub (Apr 3, 2016): I have seen many cases like this: deeznuts2:d33znuts Homerj:hom3rj billy:b111y1 Single currently does not get these, but it would be very trivial to do so, if we could call the external hybrid scripts.
Author
Owner

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

Doesn't single mode support external hybrid? It definitely should. It does support external filters, right?

I recall that neither me nor Sayantan could figure out how to stack mask upon Single mode. That too would definitely be a win. A thing like -single -mask:?w20?d?d would add years to the login name etc.

<!-- gh-comment-id:205182364 --> @magnumripper commented on GitHub (Apr 4, 2016): Doesn't single mode support external hybrid? It definitely should. It does support external filters, right? I recall that neither me nor Sayantan could figure out how to stack mask upon Single mode. That too would definitely be a win. A thing like `-single -mask:?w20?d?d` would add years to the login name etc.
Author
Owner

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

You can certainly put --single:leet on the command line with single, but it does not do anything.

Digging 'deeper', I think we can easily hook both mask, extern (or anything we want) into single mode, with almost no change to single. To do this, we simply hook them in the loader.c ldr_init_words() function. That is the function which chops up login, home and gecos fields into words.

NOTE, to do this, a user would also have to bump the total number of words to use (SingleWordsPairMax = x) quite a bit. Hooking here, simply provides single with a lot more candidate words. Also, restore would be TRIVIAL. There is no restore at all for the mask/ext_leet/ext_case, etc. They simply build the same words next time load happens.

NOTE, single restore sux, and there likely is nothing we can really do to fix it, since there is SOOOOO much state information that may be almost impossible to save/restore.

<!-- gh-comment-id:205426756 --> @jfoug commented on GitHub (Apr 4, 2016): You can certainly put --single:leet on the command line with single, but it does not do anything. Digging 'deeper', I think we can easily hook both mask, extern (or anything we want) into single mode, with almost no change to single. To do this, we simply hook them in the loader.c ldr_init_words() function. That is the function which chops up login, home and gecos fields into words. NOTE, to do this, a user would also have to bump the total number of words to use (SingleWordsPairMax = x) quite a bit. Hooking here, simply provides single with a lot more candidate words. Also, restore would be TRIVIAL. There is no restore at all for the mask/ext_leet/ext_case, etc. They simply build the same words next time load happens. NOTE, single restore sux, and there likely is nothing we can really do to fix it, since there is SOOOOO much state information that may be almost impossible to save/restore.
Author
Owner

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

This is how I see 'hooking' into loader.c NOTE, this is just pseudo code

$ git diff loader.c
diff --git a/src/loader.c b/src/loader.c
index 0b44dd1..0803ab5 100644
--- a/src/loader.c
+++ b/src/loader.c
@@ -797,6 +797,8 @@ static void ldr_split_string(struct list_main *dst, char *src)
 static struct list_main *ldr_init_words(char *login, char *gecos, char *home)
 {
        struct list_main *words;
+       struct  list_entry *tmp;
+       int i, start_cnt;
        char *pos;

        list_init(&words);
@@ -812,6 +814,18 @@ static struct list_main *ldr_init_words(char *login, char *gecos, char *home)
        if ((pos = strrchr(home, '/')) && pos[1])
                list_add_unique(words, ldr_conv(&pos[1]));

+
+       start_cnt = words->count;
+       tmp = words->head;
+       for (i = 0; i < start_cnt; ++i) {
+               char *word = ldr_mangle_start(tmp->data);
+               while (word) {
+                       list_add_unique(words, word);
+                       word = ldr_mangle_next();
+               }
+               tmp = tmp->next;
+       }
+
        return words;
 }

the mangle_start() and mangle_next() are simply pseudo code for whatever word modification function is being used (hybrid-something). So rexgen, extern, mask, even pp (I think), could be hooked into the ldr_mangle_start()/next() functions.

<!-- gh-comment-id:205439721 --> @jfoug commented on GitHub (Apr 4, 2016): This is how I see 'hooking' into loader.c NOTE, this is just pseudo code ``` diff $ git diff loader.c diff --git a/src/loader.c b/src/loader.c index 0b44dd1..0803ab5 100644 --- a/src/loader.c +++ b/src/loader.c @@ -797,6 +797,8 @@ static void ldr_split_string(struct list_main *dst, char *src) static struct list_main *ldr_init_words(char *login, char *gecos, char *home) { struct list_main *words; + struct list_entry *tmp; + int i, start_cnt; char *pos; list_init(&words); @@ -812,6 +814,18 @@ static struct list_main *ldr_init_words(char *login, char *gecos, char *home) if ((pos = strrchr(home, '/')) && pos[1]) list_add_unique(words, ldr_conv(&pos[1])); + + start_cnt = words->count; + tmp = words->head; + for (i = 0; i < start_cnt; ++i) { + char *word = ldr_mangle_start(tmp->data); + while (word) { + list_add_unique(words, word); + word = ldr_mangle_next(); + } + tmp = tmp->next; + } + return words; } ``` the mangle_start() and mangle_next() are simply pseudo code for whatever word modification function is being used (hybrid-something). So rexgen, extern, mask, even pp (I think), could be hooked into the ldr_mangle_start()/next() functions.
Author
Owner

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

A thing like -single -mask:?w20?d?d would add years to the login name etc.

single rules already do this, but I know what you mean about being able to use mask.

Actually, if stacking like this, then the SingleWordMaxPairs should be very high, and single-rules should likely be redone to avoid certain things (like any rules doing things like l, u, c if something like -extern:case were used).

<!-- gh-comment-id:205442062 --> @jfoug commented on GitHub (Apr 4, 2016): > A thing like -single -mask:?w20?d?d would add years to the login name etc. single rules already do this, but I know what you mean about being able to use mask. Actually, if stacking like this, then the SingleWordMaxPairs should be very high, and single-rules should likely be redone to avoid certain things (like any rules doing things like l, u, c if something like -extern:case were used).
Author
Owner

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

This is the hackish insert of any external-hybrid stacked script, into single. this 'does' run

>>>> Code Updated <<<<

diff --git a/run/john.conf b/run/john.conf
index 915b04e..ae99762 100644
--- a/run/john.conf
+++ b/run/john.conf
@@ -119,6 +119,23 @@ SingleWordsPairMax = 6
 # with all other salts.
 #SingleRetestGuessed = N

+# If we 'stack' on single (using extern, mask, etc), then this is how many of
+# of the words (from SingleWordsPairMax) that we will use. NOTE, if there are
+# more than 1 words already from SingleWordsPairMax, then we do NOT stack from
+# the first word. The first 'word' will be a packing of words 2 and 3, so we
+# simply skip that one (the rules can rebuild it later).
+SingleStackedMaxPair=3
+
+# This is the max words which will be created from 'each' word when we stack.
+SingleStackedMaxEach=256
+
+# In single stacked mode, we can either Ltrim and Rtrim digits from each word
+# before we stack them, OR leave them alone. By default we do the trim, but if
+# this is set to N, then we leave them.  If a word is pure digits, then it will
+# be skipped (if this is Y), and that word will NOT count against the
+# SingleStackedMaxPair count.
+SingleStackedTrimDigits=Y
+
 # Protect the restore files (*.rec) from being overwritten. The default
 # mode is "Disabled". This mode will provide no protection, but has been
 # the default mode in JtR forever, so to not change behavior, that mode

diff --git a/src/external.c b/src/external.c
index 9d8b26d..c7b0594 100644
--- a/src/external.c
+++ b/src/external.c
@@ -597,6 +597,39 @@ void restore_fix_state(void)
        crk_fix_state = saved_crk_fix_state;
 }

+char *external_hybrid_next() {
+       char *internal;
+       c_int *external;
+       c_execute_fast(f_next);
+       if (ext_word[0]) {
+               if (ext_utf32) {
+                       utf32_to_enc((UTF8*)int_word, maxlen, (UTF32*)ext_word);
+               } else {
+                       internal = (char *)int_word;
+                       external = ext_word;
+                       while (*external)
+                               *internal++ = *external++;
+                       *internal = 0;
+               }
+               return int_word;
+       }
+       return 0;
+}
+
+char *external_hybrid_start(const char *base_word) {
+       char *cp, *internal;
+       c_int *external;
+       strcpy(int_hybrid_base_word, base_word);
+       cp = (char*)base_word;
+       internal = (char *)int_word;
+       external = ext_word;
+       while (*cp)
+               *internal++ = *external++ = *cp++;
+       *internal = 0;
+       *external = 0;
+       c_execute_fast(f_new);
+       return external_hybrid_next();
+}

 int do_external_hybrid_crack(struct db_main *db, const char *base_word) {
        static int first=1;
diff --git a/src/list.c b/src/list.c
index 4ac55c8..22ef115 100644
--- a/src/list.c
+++ b/src/list.c
@@ -59,16 +59,17 @@ void list_add_multi(struct list_main *list, char *data)
        } while (comma);
 }

-void list_add_unique(struct list_main *list, char *data)
+int list_add_unique(struct list_main *list, char *data)
 {
        struct list_entry *current;

        if ((current = list->head))
        do {
-               if (!strcmp(current->data, data)) return;
+               if (!strcmp(current->data, data)) return 0;
        } while ((current = current->next));

        list_add(list, data);
+       return 1;
 }

 #if 0
diff --git a/src/list.h b/src/list.h
index dc806ee..aa06534 100644
--- a/src/list.h
+++ b/src/list.h
@@ -56,9 +56,10 @@ extern void list_add_multi(struct list_main *list, char *data);

 /*
  * Adds an entry to the list checking for dupes.  This is slow, and should
- * only be used on tiny lists.
+ * only be used on tiny lists.  Return 0 if word is not added (i.e. dupe)
+ * returns 1 if word was not there, and is now added.
  */
-extern void list_add_unique(struct list_main *list, char *data);
+extern int list_add_unique(struct list_main *list, char *data);

 #if 0
 /*
diff --git a/src/loader.c b/src/loader.c
index 0b44dd1..d983122 100644
--- a/src/loader.c
+++ b/src/loader.c
@@ -43,6 +43,7 @@
 #include "john.h"
 #include "cracker.h"
 #include "config.h"
+#include "external.h"
 #include "logger.h" /* Beware: log_init() happens after most functions here */
 #include "base64_convert.h"
 #include "memdbg.h"
@@ -794,10 +795,59 @@ static void ldr_split_string(struct list_main *dst, char *src)
        } while (c && dst->count < LDR_WORDS_MAX);
 }

+static char *ldr_mangle_start(char *word) {
+       static int hybrid_extern = -1;
+       extern char *external_hybrid_start(const char *base_word);
+
+
+       if (options.flags & FLG_EXTERNAL_CHK && hybrid_extern) {
+               if (hybrid_extern == -1) {
+                       if (ext_has_function(options.external, "new") &&
+                           ext_has_function(options.external, "next")) {
+                               if (ext_has_function(options.external, "init"))
+                                       c_execute(c_lookup("init"));
+                               printf ("Using external script stacking with [List.External:%s] script\n", options.external);
+                       } else {
+                               printf ("ERROR, could not use [List.External:%s] external script (not a hybrid script)\n", options.external);
+                               hybrid_extern = 0;
+                               return 0;
+                       }
+                       hybrid_extern = 1;
+               }
+               return external_hybrid_start(word);
+       }
+       return 0;
+}
+
+static char *ldr_mangle_next() {
+       if (options.flags & FLG_EXTERNAL_CHK) {
+               extern char *external_hybrid_next();
+               return external_hybrid_next();
+       }
+       return 0;
+}
+
+/* Optinally strips leading and trailing digits */
+static void DeNum(char *Buf, char *in, int digit_trim)
+{
+       if (digit_trim)
+               while (*in >= '0' && *in <= '9') ++in;
+       strnzcpy(Buf, in, 128);
+       if (!Buf[0]) return;
+       if (digit_trim) {
+               in = &Buf[strlen(Buf)-1];
+               while (in >= Buf && *in >= '0' && *in <= '9')
+                       *in-- = 0;
+       }
+}
+
 static struct list_main *ldr_init_words(char *login, char *gecos, char *home)
 {
        struct list_main *words;
-       char *pos;
+       struct  list_entry *tmp;
+       int i, start_cnt, til, max_per, max, words_for_this, digit_trim;
+       char *pos, *word;
+       char Buf[128];

        list_init(&words);

@@ -812,6 +862,54 @@ static struct list_main *ldr_init_words(char *login, char *gecos, char *home)
        if ((pos = strrchr(home, '/')) && pos[1])
                list_add_unique(words, ldr_conv(&pos[1]));

+       if (!words->count)
+               return words;
+
+       /* now run any stacked mode to build new words adding them to out list */
+       word = ldr_mangle_start(Buf);
+       if (!word)
+               return words;
+
+       max = cfg_get_int(SECTION_OPTIONS, NULL, "SingleStackedMaxPair");
+       if (max == -1)
+               max = 3;
+       max_per = cfg_get_int(SECTION_OPTIONS, NULL, "SingleStackedMaxEach");
+       if (max_per == -1)
+               max_per = 256;
+       digit_trim = cfg_get_bool(SECTION_OPTIONS, NULL, "SingleStackedTrimDigits", 1);
+
+       start_cnt = words->count;
+       tmp = words->head;
+       i = 0;
+       if (start_cnt > 1) {
+               i = 1;
+               tmp = tmp->next;
+       }
+       DeNum(Buf, tmp->data, digit_trim);
+       while (*Buf == 0 && i < start_cnt) {
+               ++i;
+               tmp = tmp->next;
+               DeNum(Buf, tmp->data, digit_trim);
+       }
+       for (words_for_this=0; i < start_cnt && max; words_for_this=0, ++i, --max) {
+               while (word) {
+                       if (list_add_unique(words, word))
+                               ++words_for_this;
+                       if (words_for_this == max_per)
+                               break;
+                       word = ldr_mangle_next();
+               }
+               tmp = tmp->next;
+               DeNum(Buf, tmp->data, digit_trim);
+               while (*Buf == 0 && i < start_cnt) {
+                       ++i;
+                       ++til;
+                       tmp = tmp->next;
+                       DeNum(Buf, tmp->data, digit_trim);
+               }
+               word = ldr_mangle_start(Buf);
+       }
+
        return words;
 }

Note, if running extern:leet, I had to set the max number of words to 5. Well, I may not have 'had' to set it that low, but 3^5 is 243, and there could be 2 words with this many words, if the user was assas.sassa etc where there were at least 2 words in the name, and the first 5 matched letters were either a or s.

NOTE, in the interim, I have also seen that -single:l33t does somewhat the same thing.

<!-- gh-comment-id:205517507 --> @jfoug commented on GitHub (Apr 4, 2016): This is the hackish insert of any external-hybrid stacked script, into single. this 'does' run `>>>> Code Updated <<<<` ``` diff diff --git a/run/john.conf b/run/john.conf index 915b04e..ae99762 100644 --- a/run/john.conf +++ b/run/john.conf @@ -119,6 +119,23 @@ SingleWordsPairMax = 6 # with all other salts. #SingleRetestGuessed = N +# If we 'stack' on single (using extern, mask, etc), then this is how many of +# of the words (from SingleWordsPairMax) that we will use. NOTE, if there are +# more than 1 words already from SingleWordsPairMax, then we do NOT stack from +# the first word. The first 'word' will be a packing of words 2 and 3, so we +# simply skip that one (the rules can rebuild it later). +SingleStackedMaxPair=3 + +# This is the max words which will be created from 'each' word when we stack. +SingleStackedMaxEach=256 + +# In single stacked mode, we can either Ltrim and Rtrim digits from each word +# before we stack them, OR leave them alone. By default we do the trim, but if +# this is set to N, then we leave them. If a word is pure digits, then it will +# be skipped (if this is Y), and that word will NOT count against the +# SingleStackedMaxPair count. +SingleStackedTrimDigits=Y + # Protect the restore files (*.rec) from being overwritten. The default # mode is "Disabled". This mode will provide no protection, but has been # the default mode in JtR forever, so to not change behavior, that mode diff --git a/src/external.c b/src/external.c index 9d8b26d..c7b0594 100644 --- a/src/external.c +++ b/src/external.c @@ -597,6 +597,39 @@ void restore_fix_state(void) crk_fix_state = saved_crk_fix_state; } +char *external_hybrid_next() { + char *internal; + c_int *external; + c_execute_fast(f_next); + if (ext_word[0]) { + if (ext_utf32) { + utf32_to_enc((UTF8*)int_word, maxlen, (UTF32*)ext_word); + } else { + internal = (char *)int_word; + external = ext_word; + while (*external) + *internal++ = *external++; + *internal = 0; + } + return int_word; + } + return 0; +} + +char *external_hybrid_start(const char *base_word) { + char *cp, *internal; + c_int *external; + strcpy(int_hybrid_base_word, base_word); + cp = (char*)base_word; + internal = (char *)int_word; + external = ext_word; + while (*cp) + *internal++ = *external++ = *cp++; + *internal = 0; + *external = 0; + c_execute_fast(f_new); + return external_hybrid_next(); +} int do_external_hybrid_crack(struct db_main *db, const char *base_word) { static int first=1; diff --git a/src/list.c b/src/list.c index 4ac55c8..22ef115 100644 --- a/src/list.c +++ b/src/list.c @@ -59,16 +59,17 @@ void list_add_multi(struct list_main *list, char *data) } while (comma); } -void list_add_unique(struct list_main *list, char *data) +int list_add_unique(struct list_main *list, char *data) { struct list_entry *current; if ((current = list->head)) do { - if (!strcmp(current->data, data)) return; + if (!strcmp(current->data, data)) return 0; } while ((current = current->next)); list_add(list, data); + return 1; } #if 0 diff --git a/src/list.h b/src/list.h index dc806ee..aa06534 100644 --- a/src/list.h +++ b/src/list.h @@ -56,9 +56,10 @@ extern void list_add_multi(struct list_main *list, char *data); /* * Adds an entry to the list checking for dupes. This is slow, and should - * only be used on tiny lists. + * only be used on tiny lists. Return 0 if word is not added (i.e. dupe) + * returns 1 if word was not there, and is now added. */ -extern void list_add_unique(struct list_main *list, char *data); +extern int list_add_unique(struct list_main *list, char *data); #if 0 /* diff --git a/src/loader.c b/src/loader.c index 0b44dd1..d983122 100644 --- a/src/loader.c +++ b/src/loader.c @@ -43,6 +43,7 @@ #include "john.h" #include "cracker.h" #include "config.h" +#include "external.h" #include "logger.h" /* Beware: log_init() happens after most functions here */ #include "base64_convert.h" #include "memdbg.h" @@ -794,10 +795,59 @@ static void ldr_split_string(struct list_main *dst, char *src) } while (c && dst->count < LDR_WORDS_MAX); } +static char *ldr_mangle_start(char *word) { + static int hybrid_extern = -1; + extern char *external_hybrid_start(const char *base_word); + + + if (options.flags & FLG_EXTERNAL_CHK && hybrid_extern) { + if (hybrid_extern == -1) { + if (ext_has_function(options.external, "new") && + ext_has_function(options.external, "next")) { + if (ext_has_function(options.external, "init")) + c_execute(c_lookup("init")); + printf ("Using external script stacking with [List.External:%s] script\n", options.external); + } else { + printf ("ERROR, could not use [List.External:%s] external script (not a hybrid script)\n", options.external); + hybrid_extern = 0; + return 0; + } + hybrid_extern = 1; + } + return external_hybrid_start(word); + } + return 0; +} + +static char *ldr_mangle_next() { + if (options.flags & FLG_EXTERNAL_CHK) { + extern char *external_hybrid_next(); + return external_hybrid_next(); + } + return 0; +} + +/* Optinally strips leading and trailing digits */ +static void DeNum(char *Buf, char *in, int digit_trim) +{ + if (digit_trim) + while (*in >= '0' && *in <= '9') ++in; + strnzcpy(Buf, in, 128); + if (!Buf[0]) return; + if (digit_trim) { + in = &Buf[strlen(Buf)-1]; + while (in >= Buf && *in >= '0' && *in <= '9') + *in-- = 0; + } +} + static struct list_main *ldr_init_words(char *login, char *gecos, char *home) { struct list_main *words; - char *pos; + struct list_entry *tmp; + int i, start_cnt, til, max_per, max, words_for_this, digit_trim; + char *pos, *word; + char Buf[128]; list_init(&words); @@ -812,6 +862,54 @@ static struct list_main *ldr_init_words(char *login, char *gecos, char *home) if ((pos = strrchr(home, '/')) && pos[1]) list_add_unique(words, ldr_conv(&pos[1])); + if (!words->count) + return words; + + /* now run any stacked mode to build new words adding them to out list */ + word = ldr_mangle_start(Buf); + if (!word) + return words; + + max = cfg_get_int(SECTION_OPTIONS, NULL, "SingleStackedMaxPair"); + if (max == -1) + max = 3; + max_per = cfg_get_int(SECTION_OPTIONS, NULL, "SingleStackedMaxEach"); + if (max_per == -1) + max_per = 256; + digit_trim = cfg_get_bool(SECTION_OPTIONS, NULL, "SingleStackedTrimDigits", 1); + + start_cnt = words->count; + tmp = words->head; + i = 0; + if (start_cnt > 1) { + i = 1; + tmp = tmp->next; + } + DeNum(Buf, tmp->data, digit_trim); + while (*Buf == 0 && i < start_cnt) { + ++i; + tmp = tmp->next; + DeNum(Buf, tmp->data, digit_trim); + } + for (words_for_this=0; i < start_cnt && max; words_for_this=0, ++i, --max) { + while (word) { + if (list_add_unique(words, word)) + ++words_for_this; + if (words_for_this == max_per) + break; + word = ldr_mangle_next(); + } + tmp = tmp->next; + DeNum(Buf, tmp->data, digit_trim); + while (*Buf == 0 && i < start_cnt) { + ++i; + ++til; + tmp = tmp->next; + DeNum(Buf, tmp->data, digit_trim); + } + word = ldr_mangle_start(Buf); + } + return words; } ``` Note, if running extern:leet, I had to set the max number of words to 5. Well, I may not have 'had' to set it that low, but 3^5 is 243, and there could be 2 words with this many words, if the user was assas.sassa etc where there were at least 2 words in the name, and the first 5 matched letters were either a or s. NOTE, in the interim, I have also seen that -single:l33t does somewhat the same thing.
Author
Owner

@frank-dittrich commented on GitHub (Apr 4, 2016):

Digging 'deeper', I think we can easily hook both mask, extern (or anything we want) into single mode, with almost no change to single. To do this, we simply hook them in the loader.c ldr_init_words() function. That is the function which chops up login, home and gecos fields into words.

I think that's a very good idea.

NOTE, to do this, a user would also have to bump the total number of words to use (SingleWordsPairMax = x) quite a bit.

But users would certainly prefer if SingleWordsPairMax wouln't need to be adjusted according to the mask you want to use or according to how many candidates the external mode will generate.

<!-- gh-comment-id:205520648 --> @frank-dittrich commented on GitHub (Apr 4, 2016): > Digging 'deeper', I think we can easily hook both mask, extern (or anything we want) into single mode, with almost no change to single. To do this, we simply hook them in the loader.c ldr_init_words() function. That is the function which chops up login, home and gecos fields into words. I think that's a very good idea. > NOTE, to do this, a user would also have to bump the total number of words to use (SingleWordsPairMax = x) quite a bit. But users would certainly prefer if SingleWordsPairMax wouln't need to be adjusted according to the mask you want to use or according to how many candidates the external mode will generate.
Author
Owner

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

Agreed. NOTE, this is just a hack that is working. It is not 'fully' thought out.

Single is a bitch. I am just seeing what works, and what does not work. Yes, rules work well for single. and it is done with a 'special' way of using the rules. It may be that making adjustments INSIDE single.c ends up being a better way in the end. Note, for external, I already had to make 'special' iterated methods within external, HOWEVER, that iterated method is not a bad tool to have in our arsenal.

Back to your concern, it would be easy to override what is in the .conf file, if we know that we are bumping up the words, using some stacked modes.

<!-- gh-comment-id:205621585 --> @jfoug commented on GitHub (Apr 5, 2016): Agreed. NOTE, this is just a hack that is working. It is not 'fully' thought out. Single is a bitch. I am just seeing what works, and what does not work. Yes, rules work well for single. and it is done with a 'special' way of using the rules. It may be that making adjustments INSIDE single.c ends up being a better way in the end. Note, for external, I already had to make 'special' iterated methods within external, HOWEVER, that iterated method is not a bad tool to have in our arsenal. Back to your concern, it would be easy to override what is in the .conf file, if we know that we are bumping up the words, using some stacked modes.
Author
Owner

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

The patch has been updated. This is looking like it may be a viable option.

One concern, is we use list_add_unique() function, which is pretty slow. Since it is only at load time, I guess it is ok, and only done one time. BUT it makes loading take bit. I just did a 5m salted load, and it took about 12 minutes to start.

<!-- gh-comment-id:206424340 --> @jfoug commented on GitHub (Apr 6, 2016): The patch has been updated. This is looking like it may be a viable option. One concern, is we use list_add_unique() function, which is pretty slow. Since it is only at load time, I guess it is ok, and only done one time. BUT it makes loading take bit. I just did a 5m salted load, and it took about 12 minutes to start.
Author
Owner

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

A thing like -single -mask:?w20?d?d would add years to the login name etc.

single rules already do this, but I know what you mean about being able to use mask.

Except mask mode will (often) be GPU accelerated, perhaps 1000x faster... We absolutely have to keep that property of mask mode even together with single mode!

Actually, if stacking like this, then the SingleWordMaxPairs should be very high

And SingleStackedMaxPairs will be a subset of that? I think it should be the other way round: SingleStackedMaxPairs should override (bump) SingleWordMaxPairs for hybrid external, only. Also, I think the default for SingleStackedMaxEach should be WAY higher than 256.

<!-- gh-comment-id:207095639 --> @magnumripper commented on GitHub (Apr 7, 2016): > > A thing like -single -mask:?w20?d?d would add years to the login name etc. > > single rules already do this, but I know what you mean about being able to use mask. Except mask mode will (often) be GPU accelerated, perhaps 1000x faster... We absolutely have to keep that property of mask mode even together with single mode! > Actually, if stacking like this, then the SingleWordMaxPairs should be very high And SingleStackedMaxPairs will be a subset of that? I think it should be the other way round: SingleStackedMaxPairs should override (bump) SingleWordMaxPairs for hybrid external, only. Also, I think the default for SingleStackedMaxEach should be WAY higher than 256.
Author
Owner

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

list_add_unique is O(n^2) and we have the same problem with loopback mode assembling LM halves. The workaround hack in that case is we skip list_add_unique once we reach 0x10000 items, and just use list_add instead (after merely checking consecutive dupes). I've been thinking about ways to fix this problem. We could have a faster list_add_unique that keeps context in allocated memory, something like this:

hash_buf = mem_alloc(needed size);
while (loop) {
    list_add_unique_fast(stuff, hash_buf);
}
mem_free(hash_buf);

The actual code for list_add_unique_fast could be similar to the one used in wordlist.c that was nicked from unique.c and modified. That's very fast.

<!-- gh-comment-id:207098396 --> @magnumripper commented on GitHub (Apr 7, 2016): list_add_unique is O(n^2) and we have the same problem with loopback mode assembling LM halves. The workaround hack in that case is we skip list_add_unique once we reach 0x10000 items, and just use list_add instead (after merely checking consecutive dupes). I've been thinking about ways to fix this problem. We could have a faster list_add_unique that keeps context in allocated memory, something like this: ``` hash_buf = mem_alloc(needed size); while (loop) { list_add_unique_fast(stuff, hash_buf); } mem_free(hash_buf); ``` The actual code for list_add_unique_fast could be similar to the one used in wordlist.c that was nicked from unique.c and modified. That's very fast.
Author
Owner

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

Several things I have dug in and found out (I actually nearly understand single mode now !.!.!).

  1. single probably sux for GPU, period and will until it can be redone.
  2. list_add_unique is O(n^2) does suck, and we need a better hashed way to do this. It would not take too much to make it much better O(lg(n)) at least.
  3. dumping data to the wordlist may not be the best way to go. It does work, but in real world testing, it does not find much more, and usually simply tossing more and different rules at the problem works much better.
  4. the biggest hurdle (especially for GPU). Each salt gets a buffer that is min-pw-count * plaintextlen bytes long. Each word gets dropped into this buffer (at offset x_plaintextlen) until min-pw-count values fill the buffer. Then the buffer is run, doing a strcpy from each &buffer[idx_plaintextlen] into a aligned buffer, calling set_key after each strcpy. Only then is a crypt_all done.

So, there really is no way to improve for GPU, OTHER than making some changes to push down the mask stuff. Rules would be run to fill the buffers, but then we would really need some sort of numeric type rules done in mask to make the GPU smoke any type fast format. For slow formats, it may not matter, as the format running overhead is so high, that the GPU still ends up being a win.

But the addition of external may not be the hugest win for CPU. That is unless there simply was no other way to do this using rules. And even then, we should be pushing this down INTO single, not messing with original words being produced. As I do more work with -single, I should learn it better, and then hopefully find where to properly insert stacked modes for CPU. Again, the only thing stacked that I would think useful for GPU would be mask. Without stacked mask, single in GPU is probably not a good option other than extremely slow hashes.

<!-- gh-comment-id:207118046 --> @jfoug commented on GitHub (Apr 7, 2016): Several things I have dug in and found out (I actually nearly understand single mode now !.!.!). 1. single probably sux for GPU, period and will until it can be redone. 2. list_add_unique is O(n^2) does suck, and we need a better hashed way to do this. It would not take too much to make it much better O(lg(n)) at least. 3. dumping data to the wordlist may not be the best way to go. It does work, but in real world testing, it does not find much more, and usually simply tossing more and different rules at the problem works much better. 4. the biggest hurdle (especially for GPU). Each salt gets a buffer that is min-pw-count \* plaintextlen bytes long. Each word gets dropped into this buffer (at offset x_plaintextlen) until min-pw-count values fill the buffer. Then the buffer is run, doing a strcpy from each &buffer[idx_plaintextlen] into a aligned buffer, calling set_key after each strcpy. Only then is a crypt_all done. So, there really is no way to improve for GPU, OTHER than making some changes to push down the mask stuff. Rules would be run to fill the buffers, but then we would really need some sort of numeric type rules done in mask to make the GPU smoke any type fast format. For slow formats, it may not matter, as the format running overhead is so high, that the GPU still ends up being a win. But the addition of external may not be the hugest win for CPU. That is unless there simply was no other way to do this using rules. And even then, we should be pushing this down INTO single, not messing with original words being produced. As I do more work with -single, I should learn it better, and then hopefully find where to properly insert stacked modes for CPU. Again, the only thing stacked that I would think useful for GPU would be mask. Without stacked mask, single in GPU is probably not a good option other than extremely slow hashes.
Author
Owner

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

Again, the only thing stacked that I would think useful for GPU would be mask. Without stacked mask, single in GPU is probably not a good option other than extremely slow hashes.

Yep. If we can get it to work with GPU-side mask, that would be great. Ideally with the (enhancement request already) option to have a mask where one of the resulting candidates is the baseword alone.

At some point in time, the RAR OpenCL support was built into the CPU format. There was just --format:rar and if you had a GPU, it would be used - otherwise it would be CPU. This had several advantages and one of them was that the format could automatically switch to CPU instead when single mode was used.

As no-one else jumped that train, I ended up splitting RAR to two separate formats like all the others.

<!-- gh-comment-id:207137313 --> @magnumripper commented on GitHub (Apr 7, 2016): > Again, the only thing stacked that I would think useful for GPU would be mask. Without stacked mask, single in GPU is probably not a good option other than extremely slow hashes. Yep. If we can get it to work with GPU-side mask, that would be great. Ideally with the (enhancement request already) option to have a mask where one of the resulting candidates is the baseword alone. At some point in time, the RAR OpenCL support was built into the CPU format. There was just --format:rar and if you had a GPU, it would be used - otherwise it would be CPU. This had several advantages and one of them was that the format could automatically switch to CPU instead when single mode was used. As no-one else jumped that train, I ended up splitting RAR to two separate formats like all the others.
Author
Owner

@solardiz commented on GitHub (Apr 8, 2016):

You're doing something really weird here. Why pre-mangle the single mode "words" instead of having the ruleset call into external modes (a feature I've been meaning to add)?

list_add_unique() was never meant to be used on more than just a few "words", and maybe we shouldn't change that.

<!-- gh-comment-id:207194214 --> @solardiz commented on GitHub (Apr 8, 2016): You're doing something really weird here. Why pre-mangle the single mode "words" instead of having the ruleset call into external modes (a feature I've been meaning to add)? list_add_unique() was never meant to be used on more than just a few "words", and maybe we shouldn't change that.
Author
Owner

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

Like mentioned, this was just a POC. I have been digging deeper into single, and do understand some of the logic better than I did. I have found the insertion of logic in the manner shown above was not close to ideal. However, it has allowed some limited testing of the concepts.

<!-- gh-comment-id:207195259 --> @jfoug commented on GitHub (Apr 8, 2016): Like mentioned, this was just a POC. I have been digging deeper into single, and do understand some of the logic better than I did. I have found the insertion of logic in the manner shown above was not close to ideal. However, it has allowed some limited testing of the concepts.
Author
Owner

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

What Solar said is obviously a superior solution, for speed and for dramatically less memory use. But like I said I never figured out how to accomplish that with mask mode, GPU-side or not.

<!-- gh-comment-id:207250075 --> @magnumripper commented on GitHub (Apr 8, 2016): What Solar said is obviously a superior solution, for speed and for dramatically less memory use. But like I said I never figured out how to accomplish that with mask mode, GPU-side or not.
Author
Owner

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

I am not sure how to get mask (especially on GPU) working. But I am pretty sure I can get external working just fine, especially since I now have this code in external.c:

char *external_hybrid_next();
char *external_hybrid_first();

With the ability to iterate, adding extern should be trivial. But this is still all CPU.

Now, for mask on GPU (which 'could' be a HUGE benefit), I still would have to figure out how to hook that in.

<!-- gh-comment-id:207459808 --> @jfoug commented on GitHub (Apr 8, 2016): I am not sure how to get mask (especially on GPU) working. But I am pretty sure I can get external working just fine, especially since I now have this code in external.c: ``` C char *external_hybrid_next(); char *external_hybrid_first(); ``` With the ability to iterate, adding extern should be trivial. But this is still all CPU. Now, for mask on GPU (which 'could' be a HUGE benefit), I still would have to figure out how to hook that in.
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#1411
No description provided.