>From 5b7aa99ce90d2d86eea5f4aa28aaf311e23359c0 Mon Sep 17 00:00:00 2001 From: Frank Dittrich Date: Mon, 25 Jun 2012 14:04:04 +0200 Subject: [PATCH] Markov: allow start and/or end to be specified in percent Instead of absolute numbers, it is now allowed to use integer values, followed by '%'. For start, 0% - 99% are allowed, for end 0% will be the same as 100%. $ ./john --stdout --markov:200:1%:2%:12 |head -n 1 End: 2% converted to 5187128 Start: 1% converted to 2593564 MKV start (stats=$JOHN/stats, lvl=200 len=12 pwd=2593564) cholplet $ ./john --stdout --markov:200:2%:4%:12 |head -n 1 End: 4% converted to 10374256 Start: 2% converted to 5187128 MKV start (stats=$JOHN/stats, lvl=200 len=12 pwd=5187128) coratudo --- doc/MARKOV | 6 +++ src/mkv.c | 141 ++++++++++++++++++++++++++++++++++++++---------------------- 2 files changed, 95 insertions(+), 52 deletions(-) diff --git a/doc/MARKOV b/doc/MARKOV index 0a846ff..a6c88cd 100644 --- a/doc/MARKOV +++ b/doc/MARKOV @@ -28,9 +28,15 @@ if MODE is not specified on the command line, see CONFIGURATION OPTIONS. * START is the index of the first password that is going to be tested, starting with 0. +You can specify an integer value < 100, followed by a percent sign, e.g. 10%. +This will be converted into the correct start word depending on the total number +of words. * END is the index of the last password that is going to be tested. When it is set to 0, it will represent the last possible password. +You can specify an integer value <= 100, followed by a percent sign, e.g. 20%. +This will be converted into the correct end word depending on the total number +of words. * LENGTH determines the length of passwords generated. It can be specified as MIN_LENGTH-MAX_LENGTH or as MAX_LENGTH. diff --git a/src/mkv.c b/src/mkv.c index e5ff550..5e0c359 100644 --- a/src/mkv.c +++ b/src/mkv.c @@ -244,21 +244,19 @@ static int get_progress(int *hundth_perc) void get_markov_options(struct db_main *db, char *mkv_param, unsigned int *mkv_minlevel, unsigned int *mkv_level, - unsigned long long *start, unsigned long long *end, + char **start_token, char **end_token, unsigned int *mkv_minlen, unsigned int *mkv_maxlen, char **statfile) { char * mode = NULL; char *lvl_token = NULL; - char *start_token = NULL; - char *end_token = NULL; char *len_token = NULL; char *dummy_token = NULL; int minlevel, level, minlen, maxlen; - *start = 0; - *end = 0; + *start_token = NULL; + *end_token = NULL; minlevel = -1; level = -1; @@ -300,8 +298,8 @@ void get_markov_options(struct db_main *db, } } - start_token = strtok(NULL, ":"); - end_token = strtok(NULL, ":"); + *start_token = strtok(NULL, ":"); + *end_token = strtok(NULL, ":"); len_token = strtok(NULL, ":"); dummy_token = strtok(NULL, ":"); @@ -363,50 +361,15 @@ void get_markov_options(struct db_main *db, minlevel = 0; } - if((start_token != NULL) && (sscanf(start_token, LLd, start)==1) ) - { - if((end_token != NULL) && (sscanf(end_token, LLd, end)==1) ) - { - if( (len_token != NULL) && (sscanf(len_token, "%d-%d", &minlen, &maxlen)!=2) ) - { - sscanf(len_token, "%d", &maxlen); - if(maxlen == 0) - /* get min. and max. length from markov section */ - minlen = -1; - else - minlen = 0; - } - } - else if(end_token != NULL) - { -#ifdef HAVE_MPI - if (mpi_id == 0) -#endif - fprintf(stderr, - "invalid end: %s\n", end_token); - error(); - } - } - /* - * Currently I see no use case for MkvStart and MkvEnd as variables - * in a [Markov:mode] section. - * If that changes, I'll need - * start_token = cfg_get_param(SECTION_MARKOV, mode, "MkvStart") - * and - * sscanf(start_token, LLd, start) - * because the values could be too large for integers - */ - else if(start_token != NULL) - { -#ifdef HAVE_MPI - if (mpi_id == 0) -#endif - fprintf(stderr, - "invalid start: %s\n", start_token); - error(); - - } - + } + if( (len_token != NULL) && (sscanf(len_token, "%d-%d", &minlen, &maxlen)!=2) ) + { + sscanf(len_token, "%d", &maxlen); + if(maxlen == 0) + /* get min. and max. length from markov section */ + minlen = -1; + else + minlen = 0; } if(level <= 0) @@ -503,6 +466,8 @@ void get_markov_options(struct db_main *db, void do_markov_crack(struct db_main *db, char *mkv_param) { char *statfile = NULL; + char *start_token = NULL; + char *end_token = NULL; char *param = NULL; unsigned int mkv_minlevel, mkv_level, mkv_maxlen, mkv_minlen; unsigned long long mkv_start, mkv_end; @@ -520,9 +485,43 @@ void do_markov_crack(struct db_main *db, char *mkv_param) get_markov_options(db, mkv_param, - &mkv_minlevel, &mkv_level, &mkv_start, &mkv_end, + &mkv_minlevel, &mkv_level, &start_token, &end_token, &mkv_minlen, &mkv_maxlen, &statfile); + if((start_token != NULL) && (sscanf(start_token, LLd, &mkv_start)==1) ) + { + if((end_token != NULL) && (sscanf(end_token, LLd, &mkv_end)==1) ) + { + } + else if(end_token != NULL) + { +#ifdef HAVE_MPI + if (mpi_id == 0) +#endif + fprintf(stderr, + "invalid end: %s\n", end_token); + error(); + } + } + /* + * Currently I see no use case for MkvStart and MkvEnd as variables + * in a [Markov:mode] section. + * If that changes, I'll need + * start_token = cfg_get_param(SECTION_MARKOV, mode, "MkvStart") + * and + * sscanf(start_token, LLd, start) + * because the values could be too large for integers + */ + else if(start_token != NULL) + { +#ifdef HAVE_MPI + if (mpi_id == 0) +#endif + fprintf(stderr, + "invalid start: %s\n", start_token); + error(); + } + gidx = 0; status_init(get_progress, 0); rec_restore_mode(restore_state); @@ -537,11 +536,49 @@ void do_markov_crack(struct db_main *db, char *mkv_param) gmin_level = mkv_minlevel; gmin_len = mkv_minlen; + nbparts = mem_alloc(256*(mkv_level+1)*sizeof(long long)*(mkv_maxlen+1)); memset(nbparts, 0, 256*(mkv_level+1)*(mkv_maxlen+1)*sizeof(long long)); nb_parts(0, 0, 0, mkv_level, mkv_maxlen); + if (end_token[strlen(end_token)-1] == '%') { + if (mkv_end >= 100) { + if (mkv_end > 100) { +#ifdef HAVE_MPI + if (mpi_id == 0) +#endif + fprintf(stderr, "Warning: End = %s is too large (max = 100%%)\n", end_token); + } + mkv_end = 0; + } else if (mkv_end > 0) { + mkv_end = nbparts[0] / 100 * mkv_end; + log_event("- End: %s converted to "LLd"", end_token, mkv_end); +#ifdef HAVE_MPI + if (mpi_id == 0) +#endif + fprintf(stderr, "End: %s converted to "LLd"\n", end_token, mkv_end); + } + } + if (start_token[strlen(start_token)-1] == '%') { + if (mkv_start >= 100) { + log_event("! Start = %s is too large (max < 100%%)", end_token); +#ifdef HAVE_MPI + if (mpi_id == 0) +#endif + fprintf(stderr, "Error: Start = %s is too large (max < 100%%)\n", start_token); + exit(1); + } else if (mkv_start > 0) { + mkv_start = nbparts[0] / 100 * mkv_start; + log_event("- Start: %s converted to "LLd, start_token, mkv_start); +#ifdef HAVE_MPI + if (mpi_id == 0) +#endif + fprintf(stderr, "Start: %s converted to "LLd"\n", start_token, mkv_start); + } + } + + if(mkv_end==0) mkv_end = nbparts[0]; -- 1.7.7.6