Openwall GNU/*/Linux - a small security-enhanced Linux distro for servers
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Mon, 11 Jun 2012 12:45:10 +0200
From: Frank Dittrich <frank_dittrich@...mail.com>
To: john-dev@...ts.openwall.com
Subject: Re: Patch: allow --markov=SECTION in addition to --markov[=[MIN_LEVEL-]LEVEL[:START[:END[:[MIN_LENGHT-]LENGTH]]]]

On 06/09/2012 09:18 PM, Frank Dittrich wrote:
> I verified that the old logic still works, and that I can interrupt and
> restore a session using --markov=section

In addition to the segfault when using --markov I also found errors when
reading MkvStart ans MkvEnd.

In preparation of adding --markov=SECTION support, I'd like to get two
other patches into magnum's repository on github:

1. Move markov option handling to mkv.c (do_markov_crack)

Doing all parameter validation in one place (mkv.c, do_mkv_crack())
instead of in two places (options.c in opt_init() and in mkv.c in
do_mkv_crack())
---
 src/john.c    |    2 +-
 src/mkv.c     |   60 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 src/mkv.h     |    2 +-
 src/options.c |   65
---------------------------------------------------------
 src/options.h |    6 -----
 5 files changed, 61 insertions(+), 74 deletions(-)


2. use [Markov:Default] instead of [Options:Markov] for --markov

 doc/MARKOV    |   22 +++++++++++++++++++++-
 run/john.conf |   17 ++++++++++-------
 src/mkv.c     |    8 +++++---
 src/params.h  |    2 +-
 4 files changed, 37 insertions(+), 12 deletions(-)


I'd like to get these changes in prior to the next jumbo release,
even if I don't manage the --markov=SECTION stuff in time.
The reason is, I'd like to avoid another incompatible change.
Now Markov default values are unter [Options], next jumbo moves them to
[Options:Markov], --markov=SECTION support moves them to [Markov:Default].

Should I resend those patches together with the third patch which will
introduce --markov=SECTION support?
The third patch will not yet support --markov=SECTION:LEVEL...

This will be a 4th patch.

Frank

>From 6427e2ef225c0151473fb2d093a56ac6734d3b50 Mon Sep 17 00:00:00 2001
From: Frank Dittrich <frank_dittrich@...mail.com>
Date: Mon, 11 Jun 2012 11:08:46 +0200
Subject: [PATCH 1/2] Move markov option handling to mkv.c (do_markov_crack)

Doing all parameter validation in one place (mkv.c, do_mkv_crack())
instead of in two places (options.c in opt_init() and in mkv.c in
do_mkv_crack())
---
 src/john.c    |    2 +-
 src/mkv.c     |   60 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 src/mkv.h     |    2 +-
 src/options.c |   65 ---------------------------------------------------------
 src/options.h |    6 -----
 5 files changed, 61 insertions(+), 74 deletions(-)

diff --git a/src/john.c b/src/john.c
index 64ee6a8..408c12f 100644
--- a/src/john.c
+++ b/src/john.c
@@ -823,7 +823,7 @@ static void john_run(void)
 			do_incremental_crack(&database, options.charset);
 		else
 		if (options.flags & FLG_MKV_CHK)
-			do_markov_crack(&database, options.mkv_level, options.mkv_start, options.mkv_end, options.mkv_maxlen, options.mkv_minlevel, options.mkv_minlen);
+			do_markov_crack(&database, options.mkv_param);
 		else
 		if (options.flags & FLG_EXTERNAL_CHK)
 			do_external_crack(&database);
diff --git a/src/mkv.c b/src/mkv.c
index f29fac6..ab87da2 100644
--- a/src/mkv.c
+++ b/src/mkv.c
@@ -238,13 +238,71 @@ static int get_progress(int *hundth_perc)
 }
 
 
-void do_markov_crack(struct db_main *db, unsigned int mkv_level, unsigned long long mkv_start, unsigned long long mkv_end, unsigned int mkv_maxlen, unsigned int mkv_minlevel, unsigned int mkv_minlen)
+void do_markov_crack(struct db_main *db, char * mkv_param)
 {
 	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;
+	if (mkv_param)
+	{
+		token = strtok(mkv_param, ":");
+		if(sscanf(token, "%d-%d", &mkv_minlevel, &mkv_level) != 2)
+		{
+			mkv_minlevel = 0;
+			if (sscanf(token, "%d", &mkv_level) != 1)
+			{
+#ifdef HAVE_MPI
+				if (mpi_id == 0)
+#endif
+				fprintf(stderr, "Could not parse markov parameters\n");
+				error();
+			}
+		}
+		token = strtok(NULL, ":");
+		if( (token != NULL) && (sscanf(token, LLd, &mkv_start)==1) )
+		{
+			token = strtok(NULL, ":");
+			if( (token != NULL) && (sscanf(token, LLd, &mkv_end)==1) )
+			{
+				token = strtok(NULL, ":");
+				if( (token != NULL) && (sscanf(token, "%d-%d", &mkv_minlen, &mkv_maxlen)!=2) )
+				{
+					mkv_minlen = 0;
+					sscanf(token, "%d", &mkv_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("Options", SUBSECTION_MARKOV, "MkvLvl")) == -1 )
 		{
diff --git a/src/mkv.h b/src/mkv.h
index 0913eed..fd998b1 100644
--- a/src/mkv.h
+++ b/src/mkv.h
@@ -12,6 +12,6 @@
 /*
  * Runs the markov mode cracker.
  */
-extern void do_markov_crack(struct db_main *db, unsigned int mkv_level, unsigned long long mkv_start, unsigned long long mkv_end, unsigned int mkv_maxlen, unsigned int mkv_minlevel, unsigned int mkv_minlen);
+extern void do_markov_crack(struct db_main *db, char *mkv_param);
 
 #endif
diff --git a/src/options.c b/src/options.c
index a1ed020..04d6a76 100644
--- a/src/options.c
+++ b/src/options.c
@@ -48,15 +48,6 @@ extern int gpu_id;
 struct options_main options;
 static char *field_sep_char_string;
 
-#if defined (__MINGW32__) || defined (_MSC_VER)
-// Later versions of MSVC can handle %lld but some older
-// ones can only handle %I64d.  Easiest to simply use
-// %I64d then all versions of MSVC will handle it just fine
-#define LLd "%I64d"
-#else
-#define LLd "%lld"
-#endif
-
 static struct opt_entry opt_list[] = {
 	{"", FLG_PASSWD, 0, 0, 0, OPT_FMT_ADD_LIST, &options.passwd},
 	{"single", FLG_SINGLE_SET, FLG_CRACKING_CHK, 0, 0,
@@ -425,62 +416,6 @@ void opt_init(char *name, int argc, char **argv)
 		error();
 	}
 
-	if (options.flags & FLG_MKV_CHK) {
-		char * token;
-
-		options.mkv_start = 0;
-		options.mkv_end = 0;
-		options.mkv_maxlen = 0;
-		options.mkv_minlevel = 0;
-		options.mkv_minlen = 0;
-		if (options.mkv_param)
-		{
-			token = strtok(options.mkv_param, ":");
-			if(sscanf(token, "%d-%d", &options.mkv_minlevel, &options.mkv_level) != 2)
-			{
-				options.mkv_minlevel = 0;
-				if (sscanf(token, "%d", &options.mkv_level) != 1)
-				{
-#ifdef HAVE_MPI
-					if (mpi_id == 0)
-#endif
-					fprintf(stderr, "Could not parse markov parameters\n");
-					error();
-				}
-			}
-			token = strtok(NULL, ":");
-			if( (token != NULL) && (sscanf(token, LLd, &options.mkv_start)==1) )
-			{
-				token = strtok(NULL, ":");
-				if( (token != NULL) && (sscanf(token, LLd, &options.mkv_end)==1) )
-				{
-					token = strtok(NULL, ":");
-					if( (token != NULL) && (sscanf(token, "%d-%d", &options.mkv_minlen, &options.mkv_maxlen)!=2) )
-					{
-						options.mkv_minlen = 0;
-						sscanf(token, "%d", &options.mkv_maxlen);
-					}
-				}
-			}
-		}
-		if(options.mkv_level<options.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", options.mkv_level, options.mkv_minlevel, options.mkv_level);
-			options.mkv_minlevel = options.mkv_level;
-		}
-		if(options.mkv_minlen > options.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", options.mkv_minlen, options.mkv_maxlen, options.mkv_maxlen);
-			options.mkv_minlen = options.mkv_maxlen;
-		}
-	}
-
 #ifdef HAVE_MPI
 	if (options.flags & (FLG_STDIN_CHK | FLG_SHOW_CHK | FLG_MAKECHR_CHK ) && (mpi_p > 1)) {
 		if (mpi_id == 0) fprintf(stderr, "Chosen mode not suitable for running on multiple nodes\n");
diff --git a/src/options.h b/src/options.h
index 4dfc172..931bdcb 100644
--- a/src/options.h
+++ b/src/options.h
@@ -138,12 +138,6 @@ struct options_main {
 
 /* Markov stuff */
 	char *mkv_param;
-	unsigned long long mkv_start;
-	unsigned long long mkv_end;
-	unsigned int mkv_level;
-	unsigned int mkv_maxlen;
-	unsigned int mkv_minlevel;
-	unsigned int mkv_minlen;
 
 /* Maximum plaintext length for stdout mode */
 	int length;
-- 
1.7.7.6


>From 3b89ceb8bd1d157163300e5a90d30a8817d2a53b Mon Sep 17 00:00:00 2001
From: Frank Dittrich <frank_dittrich@...mail.com>
Date: Mon, 11 Jun 2012 12:01:19 +0200
Subject: [PATCH 2/2] use [Markov:Default] instead of [Options:Markov] for
 --markov

---
 doc/MARKOV    |   22 +++++++++++++++++++++-
 run/john.conf |   17 ++++++++++-------
 src/mkv.c     |    8 +++++---
 src/params.h  |    2 +-
 4 files changed, 37 insertions(+), 12 deletions(-)

diff --git a/doc/MARKOV b/doc/MARKOV
index accbbc0..def07a3 100644
--- a/doc/MARKOV
+++ b/doc/MARKOV
@@ -74,11 +74,31 @@ proportionnal with the CPU's cracking speed.
 
 
 CONFIGURATION OPTIONS
-New options are available in the john.conf file:
+Default options for values not specified on the command line are available
+in the john.conf file.
+Unlike previous john versions which required these values to be specified
+in the general [Options] section, starting from this version, these values
+have to be specified in the [Markov:Default] secion.
+
+These are the values that can be specified:
+
 Statsfile - This is the path of the "stat" file.
+
+Specifying a Statsfile in the [Markov:Default] section is mandatory 
+for Markov mode, because the Statsfile cannot be specified as a 
+command line parameter with --markov=<params>.
+
 MkvLvl - the default level
+
+MkvLvl should be specified in this section, as a fallback for the maximum
+Markov level when using --markov (without any additional parameters)
+
 MkvMaxLen - the default length
 
+MkvMaxLen should also be specified in this section, as a fallback for the
+maximum password length when using --markov (without any additional
+parameters), --markov=<level>, or similar options that don't include a
+value for the password length.
 
 WHAT IS THE STAT FILE?
 The markov mode is based on statistical data from real passwords. This data is
diff --git a/run/john.conf b/run/john.conf
index ce497cf..077f3ad 100644
--- a/run/john.conf
+++ b/run/john.conf
@@ -61,13 +61,6 @@ CPstoreUTF8 = N
 LogCrackedPasswords = N
 
 
-[Options:Markov]
-# Default Markov mode settings
-Statsfile = $JOHN/stats
-MkvLvl = 200
-MkvMaxLen = 12
-
-
 [Options:MPI]
 # Automagically disable OMP if MPI is used (set to N if
 # you want to run one MPI process per multi-core host)
@@ -98,6 +91,16 @@ Device = 0
 #cryptsha512_LWS = 64
 #cryptsha512_GWS = 8192
 
+[Markov:Default]
+# Default Markov mode settings
+# Statsfile cannot be specified on the command line, so 
+# specifying it here is mandatory
+Statsfile = $JOHN/stats
+# MkvLvl and MkvMaxLen should also be specified here, as a fallback for
+# --markov usage without specifying LEVEL and/or LENGTH on the command line
+MkvLvl = 200
+MkvMaxLen = 12
+
 
 # A user defined character class is named with a single digit, ie. 0..9. After
 # the equal-sign, just list all characters that this class should match. You
diff --git a/src/mkv.c b/src/mkv.c
index ab87da2..dd43e24 100644
--- a/src/mkv.c
+++ b/src/mkv.c
@@ -37,6 +37,8 @@
 #define LLd "%lld"
 #endif
 
+#define SUBSECTION_DEFAULT	"Default"
+
 extern struct fmt_main fmt_LM;
 
 static long long tidx;
@@ -304,7 +306,7 @@ void do_markov_crack(struct db_main *db, char * mkv_param)
 
 
 	if(mkv_level == 0)
-		if( (mkv_level = cfg_get_int("Options", SUBSECTION_MARKOV, "MkvLvl")) == -1 )
+		if( (mkv_level = cfg_get_int(SECTION_MARKOV, SUBSECTION_DEFAULT, "MkvLvl")) == -1 )
 		{
 			log_event("no markov level defined!");
 #ifdef HAVE_MPI
@@ -315,7 +317,7 @@ void do_markov_crack(struct db_main *db, char * mkv_param)
 		}
 
 	if(mkv_maxlen == 0)
-		if( (mkv_maxlen = cfg_get_int("Options", SUBSECTION_MARKOV, "MkvMaxLen")) == -1 )
+		if( (mkv_maxlen = cfg_get_int(SECTION_MARKOV, SUBSECTION_DEFAULT, "MkvMaxLen")) == -1 )
 		{
 			log_event("no markov max length defined!");
 #ifdef HAVE_MPI
@@ -325,7 +327,7 @@ void do_markov_crack(struct db_main *db, char * mkv_param)
 			error();
 		}
 
-	statfile = cfg_get_param("Options", SUBSECTION_MARKOV, "Statsfile");
+	statfile = cfg_get_param(SECTION_MARKOV, SUBSECTION_DEFAULT, "Statsfile");
 	if(statfile == NULL)
 	{
 		log_event("statfile not defined");
diff --git a/src/params.h b/src/params.h
index f11ed95..7ab1e64 100644
--- a/src/params.h
+++ b/src/params.h
@@ -163,13 +163,13 @@
  * Configuration file section names.
  */
 #define SECTION_OPTIONS			"Options"
-#define SUBSECTION_MARKOV		":Markov"
 #define SUBSECTION_MPI			":MPI"
 #define SECTION_RULES			"List.Rules:"
 #define SUBSECTION_SINGLE		"Single"
 #define SUBSECTION_WORDLIST		"Wordlist"
 #define SECTION_INC			"Incremental:"
 #define SECTION_EXT			"List.External:"
+#define SECTION_MARKOV			"Markov:"
 
 /*
  * Number of different password hash table sizes.
-- 
1.7.7.6


Powered by blists - more mailing lists

Your e-mail address:

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