>From b81594faa40da671c2dec2855570ddfb6318f376 Mon Sep 17 00:00:00 2001 From: Frank Dittrich Date: Fri, 20 Jul 2012 23:20:19 +0200 Subject: [PATCH] New external mode variable "maxlen" The third predefined variable for external modes,"maxlen", contains the maximum password length in bytes (from the format or from --stdout[=LENGTH]). Exernal modes [List.External:Repeats*] make use of this variable via the included section [List.External_base:Repeats] to stop generating new candidates when the max. password length is exceeded. (Previously, the max. length was hard coded to 72.) --- doc/EXTERNAL | 6 ++++++ run/john.conf | 15 +++++++++------ src/external.c | 17 +++++++++++++---- src/external.h | 2 +- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/doc/EXTERNAL b/doc/EXTERNAL index 311a4da..2ce6c0e 100644 --- a/doc/EXTERNAL +++ b/doc/EXTERNAL @@ -53,6 +53,12 @@ displayed (just like on a keypress), respectively. These actions are taken after having tested at least all of the candidate passwords that were in external mode's "word" so far. In other words, the actions may be delayed in order to process any buffered candidate passwords. +From 1.7.9.5-jumbo-7 on, a third variable is defined: "maxlen". +This variable is of type "int". It contains the maximum password length +in bytes, either from the format definition or from --stdout[=LENGTH]. +This variable should not be changed by the external mode. +Instead, it can be used to stop generating new candidates should the +password length get larger than "maxlen". The language. diff --git a/run/john.conf b/run/john.conf index 4157ce1..f7cb9fe 100644 --- a/run/john.conf +++ b/run/john.conf @@ -1209,7 +1209,7 @@ void restore() # Try strings of repeated characters. [List.External_base:Repeats] -int minlength, maxlength, minc, maxc, length, c; +int minlength, minc, maxc, length, c; void generate() { @@ -1224,7 +1224,14 @@ void generate() return; c = minc; - if (++length > maxlength) + + // "maxlen" is a new predefined variable, see ../doc/EXTERNAL + // john sets this variable to the maximum plaintext length + // of the format or to the length from --stdout[=LENGTH] + // Password candidates longer than "maxlen" would be cut to + // length "maxlen" anyway, so the external mode would produce + // duplicate password candidates if we didn't stop here. + if (++length > maxlen) c = 0; // Will NUL out the next "word" and thus terminate } @@ -1233,7 +1240,6 @@ void generate() void init() { minlength = 1; - maxlength = 72; minc = 0x20; maxc = 0xff; @@ -1245,7 +1251,6 @@ void init() void init() { minlength = 1; - maxlength = 72; minc = '0'; maxc = '9'; @@ -1257,7 +1262,6 @@ void init() void init() { minlength = 1; - maxlength = 72; minc = 'a'; maxc = 'z'; @@ -1269,7 +1273,6 @@ void init() void init() { minlength = 1; - maxlength = 72; minc = ' '; maxc = '~'; diff --git a/src/external.c b/src/external.c index bdbebed..e030d6e 100644 --- a/src/external.c +++ b/src/external.c @@ -19,6 +19,7 @@ #include "config.h" #include "cracker.h" #include "external.h" +#include "options.h" #ifdef HAVE_MPI #include "john-mpi.h" @@ -32,7 +33,7 @@ unsigned int ext_flags = 0; static char *ext_mode; static c_int ext_word[PLAINTEXT_BUFFER_SIZE]; -c_int ext_abort, ext_status; +c_int ext_abort, ext_status, ext_maxlen; static struct c_ident ext_ident_status = { NULL, @@ -46,8 +47,13 @@ static struct c_ident ext_ident_abort = { &ext_abort }; -static struct c_ident ext_globals = { +static struct c_ident ext_ident_maxlen = { &ext_ident_abort, + "maxlen", + &ext_maxlen +}; +static struct c_ident ext_globals = { + &ext_ident_maxlen, "word", ext_word }; @@ -108,10 +114,13 @@ int ext_has_function(char *mode, char *function) void ext_init(char *mode, struct db_main *db) { - if (db) { - maxlen = db->format->params.plaintext_length; + if (db!= NULL && db->format != NULL) { + ext_maxlen = maxlen = db->format->params.plaintext_length; return; } + else { + ext_maxlen = options.length; + } if (!(ext_source = cfg_get_list(SECTION_EXT, mode))) { #ifdef HAVE_MPI diff --git a/src/external.h b/src/external.h index 4afa74b..9fd1f41 100644 --- a/src/external.h +++ b/src/external.h @@ -22,7 +22,7 @@ extern unsigned int ext_flags; -extern c_int ext_abort, ext_status; +extern c_int ext_abort, ext_status, ext_maxlen; /* * Defined for use in the ext_filter() macro, below. -- 1.7.7.6