Openwall GNU/*/Linux - a small security-enhanced Linux distro for servers
[<prev] [next>] [day] [month] [year] [list]
Date: Fri, 15 Jun 2012 18:58:15 +0200
From: Frank Dittrich <frank_dittrich@...mail.com>
To: john-dev@...ts.openwall.com
Subject: More Markov mode patches (but still no --markov=section...)

Hi,

some more changes for Markov mode.
IMO useful enhancements, but still no --markov=SECTION support

The 3rd patch touches config.c and config.h, but the change is trivial.
Otherwise, only Markov mode specific files are changed.


[PATCH 1/4] Markov mode: move parameter validation into new function
 get_markov_options Additionaly, the logic has been
 changed so that the max. values for level and length
 are adjusted prior to checking min. values, to avoid
 adjusting min. value to a max. value which is changed
 afterwards:

Instead of
$ ./john --markov=501-500:0:0:35-31 --stdout
Warning: max level(500) < min level(501), min level set to 500
Warning: minimum length(35) < maximum length(31), minimum length set to 31
Warning: Maxlen = 31 is too large (max = 30)
Warning: Level = 500 is too large (max = 400)
MKV start (lvl=500-400 len=31-30 pwd=182847102117099741)
the new logic will be
$ ./john --markov=501-500:0:0:35-31 --stdout
Warning: Level = 500 is too large (max = 400)
Warning: Maxlen = 31 is too large (max = 30)
Warning: max level(400) < min level(501), min level set to 400
Warning: minimum length(35) < maximum length(30), minimum length set to 30
MKV start (lvl=400-400 len=30-30 pwd=182847102117099741)

Furthermore, maxlen > MAX_MKV_LEN will only be checked if
db->format->params.plaintext_length > MAX_MKV_LEN.
(Otherwise, the format specific max. length is the limit.)


[PATCH 2/4] genmkvpwd should use MAX_MKV_LVL

Furthermore, for level 0, calculate statistics up to level MAX_MKV_LVL


[PATCH 3/4] Markov: different error messages for missing
 [Markov:Default] section and for missing Statsfile
 definition in an existing [Markov:Default] section


[PATCH 4/4] Markov: improved logging

$ ./john pw --markov
Loaded 1 password hash (dummy [N/A])
MKV start (stats=$JOHN/stats, lvl=200 len=12 pwd=259356431)

0:00:00:00 Proceeding with Markov mode
0:00:00:00 - Statsfile: $JOHN/stats
0:00:00:00 - Markov level: 0 - 200
0:00:00:00 - Length: 0 - 12
0:00:00:00 - Start-End: 0 - 259356431

$ ./john pw --markov=100-200:0:25935643:6-10
Loaded 1 password hash (dummy [N/A])
MKV start (stats=$JOHN/stats, lvl=100-200 len=6-10 pwd=25935643)

0:00:00:00 Proceeding with Markov mode 100-200:0:25935643:6-10
0:00:00:00 - Statsfile: $JOHN/stats
0:00:00:00 - Markov level: 100 - 200
0:00:00:00 - Length: 6 - 10
0:00:00:00 - Start-End: 0 - 25935643


Frank

>From d4749798f42bf3f6a5261ed3028137236b3852e5 Mon Sep 17 00:00:00 2001
From: Frank Dittrich <frank_dittrich@...mail.com>
Date: Fri, 15 Jun 2012 12:23:33 +0200
Subject: [PATCH 1/4] Markov mode: move parameter validation into new function
 get_markov_options Additionaly, the logic has been
 changed so that the max. values for level and length
 are adjusted prior to checking min. values, to avoid
 adjusting min. value to a max. value which is changed
 afterwards:

Instead of
$ ./john --markov=501-500:0:0:35-31 --stdout
Warning: max level(500) < min level(501), min level set to 500
Warning: minimum length(35) < maximum length(31), minimum length set to 31
Warning: Maxlen = 31 is too large (max = 30)
Warning: Level = 500 is too large (max = 400)
MKV start (lvl=500-400 len=31-30 pwd=182847102117099741)
the new logic will be
$ ./john --markov=501-500:0:0:35-31 --stdout
Warning: Level = 500 is too large (max = 400)
Warning: Maxlen = 31 is too large (max = 30)
Warning: max level(400) < min level(501), min level set to 400
Warning: minimum length(35) < maximum length(30), minimum length set to 30
MKV start (lvl=400-400 len=30-30 pwd=182847102117099741)

Furthermore, maxlen > MAX_MKV_LEN will only be checked if
db->format->params.plaintext_length > MAX_MKV_LEN.
(Otherwise, the format specific max. length is the limit.)
---
 src/mkv.c |  148 +++++++++++++++++++++++++++++++++---------------------------
 1 files changed, 81 insertions(+), 67 deletions(-)

diff --git a/src/mkv.c b/src/mkv.c
index dd43e24..e72188f 100644
--- a/src/mkv.c
+++ b/src/mkv.c
@@ -239,31 +239,29 @@ static int get_progress(int *hundth_perc)
 	return per;
 }
 
-
-void do_markov_crack(struct db_main *db, char * mkv_param)
+void get_markov_options(struct db_main *db,
+                        char *mkv_param,
+                        unsigned int *minlevel, unsigned int *level, 
+                        unsigned long long *start, unsigned long long *end,
+                        unsigned int *minlen, unsigned int *maxlen,
+                        char **statfile)
 {
-	char * statfile;
-	unsigned int mkv_minlevel, mkv_level,  mkv_maxlen, mkv_minlen;
-	unsigned long long mkv_start, mkv_end;
-
-#ifdef HAVE_MPI
-	unsigned long long mkv_size;
-#endif
 	char * token;
 
-	mkv_level = 0;
-	mkv_start = 0;
-	mkv_end = 0;
-	mkv_maxlen = 0;
-	mkv_minlevel = 0;
-	mkv_minlen = 0;
+	*level = 0;
+	*start = 0;
+	*end = 0;
+	*maxlen = 0;
+	*minlevel = 0;
+	*minlen = 0;
+
 	if (mkv_param)
 	{
 		token = strtok(mkv_param, ":");
-		if(sscanf(token, "%d-%d", &mkv_minlevel, &mkv_level) != 2)
+		if(sscanf(token, "%d-%d", minlevel, level) != 2)
 		{
-			mkv_minlevel = 0;
-			if (sscanf(token, "%d", &mkv_level) != 1)
+			*minlevel = 0;
+			if (sscanf(token, "%d", level) != 1)
 			{
 #ifdef HAVE_MPI
 				if (mpi_id == 0)
@@ -273,40 +271,23 @@ void do_markov_crack(struct db_main *db, char * mkv_param)
 			}
 		}
 		token = strtok(NULL, ":");
-		if( (token != NULL) && (sscanf(token, LLd, &mkv_start)==1) )
+		if( (token != NULL) && (sscanf(token, LLd, start)==1) )
 		{
 			token = strtok(NULL, ":");
-			if( (token != NULL) && (sscanf(token, LLd, &mkv_end)==1) )
+			if( (token != NULL) && (sscanf(token, LLd, end)==1) )
 			{
 				token = strtok(NULL, ":");
-				if( (token != NULL) && (sscanf(token, "%d-%d", &mkv_minlen, &mkv_maxlen)!=2) )
+				if( (token != NULL) && (sscanf(token, "%d-%d", minlen, maxlen)!=2) )
 				{
-					mkv_minlen = 0;
-					sscanf(token, "%d", &mkv_maxlen);
+					*minlen = 0;
+					sscanf(token, "%d", maxlen);
 				}
 			}
 		}
 	}
-	if(mkv_level<mkv_minlevel)
-	{
-#ifdef HAVE_MPI
-		if (mpi_id == 0)
-#endif
-		fprintf(stderr, "Warning: max level(%d) < min level(%d), min level set to %d\n", mkv_level, mkv_minlevel, mkv_level);
-		mkv_minlevel = mkv_level;
-	}
-	if(mkv_minlen > mkv_maxlen)
-	{
-#ifdef HAVE_MPI
-		if (mpi_id == 0)
-#endif
-		fprintf(stderr, "Warning: minimum length(%d) < maximum length(%d), minimum length set to %d\n", mkv_minlen, mkv_maxlen, mkv_maxlen);
-		mkv_minlen = mkv_maxlen;
-	}
 
-
-	if(mkv_level == 0)
-		if( (mkv_level = cfg_get_int(SECTION_MARKOV, SUBSECTION_DEFAULT, "MkvLvl")) == -1 )
+	if(*level == 0)
+		if( (*level = cfg_get_int(SECTION_MARKOV, SUBSECTION_DEFAULT, "MkvLvl")) == -1 )
 		{
 			log_event("no markov level defined!");
 #ifdef HAVE_MPI
@@ -316,8 +297,17 @@ void do_markov_crack(struct db_main *db, char * mkv_param)
 			error();
 		}
 
-	if(mkv_maxlen == 0)
-		if( (mkv_maxlen = cfg_get_int(SECTION_MARKOV, SUBSECTION_DEFAULT, "MkvMaxLen")) == -1 )
+	if (*level > MAX_MKV_LVL) {
+		log_event("! Level = %d is too large (max=%d)", *level, MAX_MKV_LVL);
+#ifdef HAVE_MPI
+		if (mpi_id == 0)
+#endif
+		fprintf(stderr, "Warning: Level = %d is too large (max = %d)\n", *level, MAX_MKV_LVL);
+		*level = MAX_MKV_LVL;
+	}
+
+	if(*maxlen == 0)
+		if( (*maxlen = cfg_get_int(SECTION_MARKOV, SUBSECTION_DEFAULT, "MkvMaxLen")) == -1 )
 		{
 			log_event("no markov max length defined!");
 #ifdef HAVE_MPI
@@ -327,47 +317,71 @@ void do_markov_crack(struct db_main *db, char * mkv_param)
 			error();
 		}
 
-	statfile = cfg_get_param(SECTION_MARKOV, SUBSECTION_DEFAULT, "Statsfile");
-	if(statfile == NULL)
-	{
-		log_event("statfile not defined");
-#ifdef HAVE_MPI
-		if (mpi_id == 0)
-#endif
-		fprintf(stderr, "Statfile not defined\n");
-		error();
-	}
-
-	if (mkv_maxlen > db->format->params.plaintext_length) {
+	if (db->format->params.plaintext_length <= MAX_MKV_LEN &&
+	    *maxlen > db->format->params.plaintext_length) {
 		log_event("! MaxLen = %d is too large for this hash type",
-			mkv_maxlen);
+			*maxlen);
 #ifdef HAVE_MPI
 		if (mpi_id == 0)
 #endif
 		fprintf(stderr, "Warning: "
 			"MaxLen = %d is too large for the current hash type, "
 			"reduced to %d\n",
-			mkv_maxlen, db->format->params.plaintext_length);
-		mkv_maxlen = db->format->params.plaintext_length;
+			*maxlen, db->format->params.plaintext_length);
+		*maxlen = db->format->params.plaintext_length;
+	}
+	else
+	if (*maxlen > MAX_MKV_LEN) {
+		log_event("! MaxLen = %d is too large (max=%d)", *maxlen, MAX_MKV_LEN);
+#ifdef HAVE_MPI
+		if (mpi_id == 0)
+#endif
+		fprintf(stderr, "Warning: Maxlen = %d is too large (max = %d)\n", *maxlen, MAX_MKV_LEN);
+		*maxlen = MAX_MKV_LEN;
 	}
 
-	if (mkv_maxlen > MAX_MKV_LEN) {
-		log_event("! MaxLen = %d is too large (max=%d)", mkv_maxlen, MAX_MKV_LEN);
+	if(*level<*minlevel)
+	{
+#ifdef HAVE_MPI
+		if (mpi_id == 0)
+#endif
+		fprintf(stderr, "Warning: max level(%d) < min level(%d), min level set to %d\n", *level, *minlevel, *level);
+		*minlevel = *level;
+	}
+	if(*minlen > *maxlen)
+	{
 #ifdef HAVE_MPI
 		if (mpi_id == 0)
 #endif
-		fprintf(stderr, "Warning: Maxlen = %d is too large (max = %d)\n", mkv_maxlen, MAX_MKV_LEN);
-		mkv_maxlen = MAX_MKV_LEN;
+		fprintf(stderr, "Warning: minimum length(%d) < maximum length(%d), minimum length set to %d\n", *minlen, *maxlen, *maxlen);
+		*minlen = *maxlen;
 	}
 
-	if (mkv_level > MAX_MKV_LVL) {
-		log_event("! Level = %d is too large (max=%d)", mkv_level, MAX_MKV_LVL);
+	*statfile = cfg_get_param(SECTION_MARKOV, SUBSECTION_DEFAULT, "Statsfile");
+	if(*statfile == NULL)
+	{
+		log_event("statfile not defined");
 #ifdef HAVE_MPI
 		if (mpi_id == 0)
 #endif
-		fprintf(stderr, "Warning: Level = %d is too large (max = %d)\n", mkv_level, MAX_MKV_LVL);
-		mkv_level = MAX_MKV_LVL;
+		fprintf(stderr, "Statfile not defined\n");
+		error();
 	}
+}
+void do_markov_crack(struct db_main *db, char *mkv_param)
+{
+	char *statfile = NULL;
+	unsigned int mkv_minlevel, mkv_level,  mkv_maxlen, mkv_minlen;
+	unsigned long long mkv_start, mkv_end;
+
+#ifdef HAVE_MPI
+	unsigned long long mkv_size;
+#endif
+
+	get_markov_options(db,
+	                   mkv_param,
+	                   &mkv_minlevel, &mkv_level, &mkv_start, &mkv_end,
+	                   &mkv_minlen, &mkv_maxlen, &statfile);
 
 	gidx = 0;
 	status_init(get_progress, 0);
-- 
1.7.7.6


>From eb5b366b240382b1a95edce47bd62ac5db92a5f4 Mon Sep 17 00:00:00 2001
From: Frank Dittrich <frank_dittrich@...mail.com>
Date: Fri, 15 Jun 2012 14:00:24 +0200
Subject: [PATCH 2/4] genmkvpwd should use MAX_MKV_LVL

Furthermore, for level 0, calculate statistics up to level MAX_MKV_LVL
---
 src/genmkvpwd.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/src/genmkvpwd.c b/src/genmkvpwd.c
index b651246..8c943d9 100644
--- a/src/genmkvpwd.c
+++ b/src/genmkvpwd.c
@@ -230,7 +230,7 @@ int main(int argc, char * * argv)
 
 	if(max_lvl==0)
 	{
-		for(max_lvl=100;max_lvl<400;max_lvl++)
+		for(max_lvl=100;max_lvl<=MAX_MKV_LVL;max_lvl++)
 		{
 			nbparts = mem_alloc(256*(max_lvl+1)*sizeof(long long)*(max_len+1));
 			printf("lvl=%u (%lu KB for nbparts) ", max_lvl, 256UL*(max_lvl+1)*(max_len+1)*sizeof(long long)/1024);
@@ -248,6 +248,10 @@ int main(int argc, char * * argv)
 		}
 		goto fin;
 	}
+	if(max_lvl>MAX_MKV_LVL) {
+		fprintf(stderr, "Warning: Level = %d is too large (max = %d)\n", max_lvl, MAX_MKV_LVL);
+		max_lvl = MAX_MKV_LVL;
+	}
 
 	nbparts = mem_alloc(256*(max_lvl+1)*sizeof(long long)*(max_len+1));
 	fprintf(stderr, "allocated %lu KB for nbparts\n", 256UL*(max_lvl+1)*(max_len+1)*sizeof(long long)/1024);
-- 
1.7.7.6


>From 331701daa0fdebc0635cab02509d98916cccc0e5 Mon Sep 17 00:00:00 2001
From: Frank Dittrich <frank_dittrich@...mail.com>
Date: Fri, 15 Jun 2012 16:19:16 +0200
Subject: [PATCH 3/4] Markov: different error messages for missing
 [Markov:Default] section and for missing Statsfile
 definition in an existing [Markov:Default] section

---
 src/config.c |    2 +-
 src/config.h |    6 ++++++
 src/mkv.c    |   43 ++++++++++++++++++++++++++++++-------------
 3 files changed, 37 insertions(+), 14 deletions(-)

diff --git a/src/config.c b/src/config.c
index a48f608..eb88563 100644
--- a/src/config.c
+++ b/src/config.c
@@ -162,7 +162,7 @@ void cfg_init(char *name, int allow_missing)
 	if (fclose(file)) pexit("fclose");
 }
 
-static struct cfg_section *cfg_get_section(char *section, char *subsection)
+struct cfg_section *cfg_get_section(char *section, char *subsection)
 {
 	struct cfg_section *current;
 	char *p1, *p2;
diff --git a/src/config.h b/src/config.h
index bc932d5..62888ef 100644
--- a/src/config.h
+++ b/src/config.h
@@ -59,6 +59,12 @@ extern char *cfg_name;
  */
 extern void cfg_init(char *name, int allow_missing);
 
+
+/*
+ * Returns a section list entry, or NULL if not found
+ */
+extern struct cfg_section *cfg_get_section(char *section, char *subsection);
+
 /*
  * Searches for a section with the supplied name, and returns its line list
  * structure, or NULL if the search fails.
diff --git a/src/mkv.c b/src/mkv.c
index e72188f..04c8c37 100644
--- a/src/mkv.c
+++ b/src/mkv.c
@@ -246,7 +246,9 @@ void get_markov_options(struct db_main *db,
                         unsigned int *minlen, unsigned int *maxlen,
                         char **statfile)
 {
-	char * token;
+	//struct cfg_section *section;
+	char *token;
+	//char *mode;
 
 	*level = 0;
 	*start = 0;
@@ -255,6 +257,29 @@ void get_markov_options(struct db_main *db,
 	*minlevel = 0;
 	*minlen = 0;
 
+	if(cfg_get_section(SECTION_MARKOV, SUBSECTION_DEFAULT) == NULL)
+	{
+#ifdef HAVE_MPI
+		if (mpi_id == 0)
+#endif
+		fprintf(stderr, 
+		        "Section [" SECTION_MARKOV "%s] not found\n",
+		        SUBSECTION_DEFAULT);
+		error();
+	}
+	*statfile = cfg_get_param(SECTION_MARKOV, SUBSECTION_DEFAULT, "Statsfile");
+	if(*statfile == NULL)
+	{
+		log_event("Statsfile not defined");
+#ifdef HAVE_MPI
+		if (mpi_id == 0)
+#endif
+		fprintf(stderr, 
+		        "Statsfile not defined in section [" 
+		        SECTION_MARKOV SUBSECTION_DEFAULT "]\n");
+		error();
+	}
+
 	if (mkv_param)
 	{
 		token = strtok(mkv_param, ":");
@@ -318,7 +343,8 @@ void get_markov_options(struct db_main *db,
 		}
 
 	if (db->format->params.plaintext_length <= MAX_MKV_LEN &&
-	    *maxlen > db->format->params.plaintext_length) {
+	    *maxlen > db->format->params.plaintext_length)
+	{
 		log_event("! MaxLen = %d is too large for this hash type",
 			*maxlen);
 #ifdef HAVE_MPI
@@ -331,7 +357,8 @@ void get_markov_options(struct db_main *db,
 		*maxlen = db->format->params.plaintext_length;
 	}
 	else
-	if (*maxlen > MAX_MKV_LEN) {
+	if (*maxlen > MAX_MKV_LEN)
+	{
 		log_event("! MaxLen = %d is too large (max=%d)", *maxlen, MAX_MKV_LEN);
 #ifdef HAVE_MPI
 		if (mpi_id == 0)
@@ -357,16 +384,6 @@ void get_markov_options(struct db_main *db,
 		*minlen = *maxlen;
 	}
 
-	*statfile = cfg_get_param(SECTION_MARKOV, SUBSECTION_DEFAULT, "Statsfile");
-	if(*statfile == NULL)
-	{
-		log_event("statfile not defined");
-#ifdef HAVE_MPI
-		if (mpi_id == 0)
-#endif
-		fprintf(stderr, "Statfile not defined\n");
-		error();
-	}
 }
 void do_markov_crack(struct db_main *db, char *mkv_param)
 {
-- 
1.7.7.6


>From ab8f8e6859cae21b4c2b1629f834096e4db26d4f Mon Sep 17 00:00:00 2001
From: Frank Dittrich <frank_dittrich@...mail.com>
Date: Fri, 15 Jun 2012 18:18:57 +0200
Subject: [PATCH 4/4] Markov: improved logging

$ ./john pw --markov
Loaded 1 password hash (dummy [N/A])
MKV start (stats=$JOHN/stats, lvl=200 len=12 pwd=259356431)

0:00:00:00 Proceeding with Markov mode
0:00:00:00 - Statsfile: $JOHN/stats
0:00:00:00 - Markov level: 0 - 200
0:00:00:00 - Length: 0 - 12
0:00:00:00 - Start-End: 0 - 259356431

$ ./john pw --markov=100-200:0:25935643:6-10
Loaded 1 password hash (dummy [N/A])
MKV start (stats=$JOHN/stats, lvl=100-200 len=6-10 pwd=25935643)

0:00:00:00 Proceeding with Markov mode 100-200:0:25935643:6-10
0:00:00:00 - Statsfile: $JOHN/stats
0:00:00:00 - Markov level: 100 - 200
0:00:00:00 - Length: 6 - 10
0:00:00:00 - Start-End: 0 - 25935643
---
 src/mkv.c |   22 ++++++++++++++++++++--
 1 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/src/mkv.c b/src/mkv.c
index 04c8c37..bd8fe9c 100644
--- a/src/mkv.c
+++ b/src/mkv.c
@@ -388,6 +388,7 @@ void get_markov_options(struct db_main *db,
 void do_markov_crack(struct db_main *db, char *mkv_param)
 {
 	char *statfile = NULL;
+	char *param = NULL;
 	unsigned int mkv_minlevel, mkv_level,  mkv_maxlen, mkv_minlen;
 	unsigned long long mkv_start, mkv_end;
 
@@ -395,6 +396,13 @@ void do_markov_crack(struct db_main *db, char *mkv_param)
 	unsigned long long mkv_size;
 #endif
 
+	if(mkv_param != NULL)
+	{
+		param = str_alloc_copy(mkv_param);
+		if(param == NULL)
+			param = mkv_param;
+	}
+	
 	get_markov_options(db,
 	                   mkv_param,
 	                   &mkv_minlevel, &mkv_level, &mkv_start, &mkv_end,
@@ -444,7 +452,7 @@ void do_markov_crack(struct db_main *db, char *mkv_param)
 
 #ifdef HAVE_MPI
 	if (mpi_id == 0) {
-		fprintf(stderr, "MKV start (lvl=");
+		fprintf(stderr, "MKV start (stats=%s, lvl=", statfile);
 		if(mkv_minlevel>0) fprintf(stderr, "%d-", mkv_minlevel);
 		fprintf(stderr, "%d len=", mkv_level);
 		if(mkv_minlen>0) fprintf(stderr, "%d-", mkv_minlen);
@@ -463,13 +471,23 @@ void do_markov_crack(struct db_main *db, char *mkv_param)
 	gend = mkv_end + 10; /* omg !! */
 
 #ifndef HAVE_MPI
-	fprintf(stderr, "MKV start (lvl=");
+	fprintf(stderr, "MKV start (stats=%s, lvl=", statfile);
 	if(mkv_minlevel>0) fprintf(stderr, "%d-", mkv_minlevel);
 	fprintf(stderr, "%d len=", mkv_level);
 	if(mkv_minlen>0) fprintf(stderr, "%d-", mkv_minlen);
 	fprintf(stderr, "%d pwd="LLd")\n", mkv_maxlen, mkv_end-mkv_start);
 #endif
 
+	if(param)
+		log_event("Proceeding with Markov mode %s", param);
+	else	
+		log_event("Proceeding with Markov mode");
+
+	log_event("- Statsfile: %s", statfile);
+	log_event("- Markov level: %d - %d", mkv_minlevel, mkv_level);
+	log_event("- Length: %d - %d", mkv_minlen, mkv_maxlen);
+	log_event("- Start-End: "LLd" - "LLd, mkv_start, mkv_end);
+ 
 	show_pwd(mkv_start);
 
 	if (!event_abort)
-- 
1.7.7.6


Powered by blists - more mailing lists

Your e-mail address:

Powered by Openwall GNU/*/Linux - Powered by OpenVZ