Permalink
Browse files

Rename --length to --max-length and also add --min-length. Make Marko…

…v and

Incremental modes honour them. Add req_minlen and req_maxlen variables to
External mode for accessing them. Change a bunch of existing external modes
to honour them.
TO DO: --min-length support for Wordlist and Single. And regression testing!
  • Loading branch information...
1 parent 42e9e60 commit f6a6c2214550131623620b33cb9b63bc41818a96 @magnumripper committed Dec 13, 2012
Showing with 174 additions and 40 deletions.
  1. +8 −2 run/dumb16.conf
  2. +8 −2 run/dumb32.conf
  3. +108 −28 run/john.conf
  4. +21 −2 src/external.c
  5. +1 −1 src/formats.c
  6. +7 −0 src/inc.c
  7. +9 −0 src/mkv.c
  8. +7 −3 src/options.c
  9. +5 −2 src/options.h
View
@@ -22,8 +22,14 @@ void init()
int minlength;
int i, c;
- minlength = 1; // Initial password length to try, must be at least 1
- maxlength = 2; // Must be at least same as minlength
+ if (req_minlen)
+ minlength = req_minlen;
+ else
+ minlength = 1;
+ if (req_maxlen)
+ maxlength = req_maxlen;
+ else
+ maxlength = 2;
# UTF-8 representation is up to 3x the character length
if (maxlength * 3 > cipher_limit)
View
@@ -22,8 +22,14 @@ void init()
int minlength;
int i, c;
- minlength = 1; // Initial password length to try, must be at least 1
- maxlength = 2; // Must be at least same as minlength
+ if (req_minlen)
+ minlength = req_minlen;
+ else
+ minlength = 1;
+ if (req_maxlen)
+ maxlength = req_maxlen;
+ else
+ maxlength = 2;
# UTF-8 representation is up to 3x the character length
if (maxlength * 3 > cipher_limit)
View
@@ -459,6 +459,8 @@ MinLen = 0
MaxLen = 8
CharCount = 95
+# The following are deprecated: We can now use the base mode and add
+# --min-length and --max-length options.
[Incremental:All15]
.include [Incremental:All]
MaxLen = 5
@@ -574,11 +576,20 @@ void filter()
# A simple cracker for LM hashes
[List.External:LanMan]
int length; // Current length
+int maxlength;
void init()
{
+ if (req_minlen)
+ length = req_minlen;
+ else
+ length = 1;
+ if (req_maxlen)
+ maxlength = req_maxlen;
+ else // the format's limit
+ maxlength = cipher_limit;
word[0] = 'A' - 1; // Start with "A"
- word[length = 1] = 0;
+ word[length] = 0;
}
void generate()
@@ -595,7 +606,7 @@ void generate()
// If we use the new variable "cipher_limit" instead,
// the same external mode can be used for other formats
// with a different maximum password length.
- if (length < cipher_limit) {
+ if (length < max_length) {
word[i = ++length] = 0; // Switch to the next length
while (i--)
word[i] = 'A';
@@ -717,9 +728,17 @@ void init()
{
int i;
- i = length = 2; // Start with 4 character long words
+ if (req_minlen)
+ i = length = (req_minlen + 1) / 2;
+ else
+ i = length = 2; // Start with 4 character long words
while (i--) current[i] = 'a'; // Set our half-word to "aa"
- max = 4;
+ if (req_maxlen)
+ max = (req_maxlen + 1) / 2;
+ else if (length > 4)
+ max = length;
+ else
+ max = 4;
}
[List.External:Double_alnum]
@@ -783,11 +802,17 @@ void init()
void init()
{
int i;
+ int maxlength;
+
+ if (req_maxlen)
+ maxlength = req_maxlen;
+ else // the format's limit
+ maxlength = cipher_limit;
i = length = 6; // Start with 12 character long words
// (assume double10_alnum has already been run)
while (i--) current[i] = 'a'; // Set our half-word to "aaaaa"
- max = (cipher_limit - cipher_limit % 2) / 2;
+ max = (maxlength - maxlength % 2) / 2;
if (max < 6) {
// Don't generate any candidates, because the format's
@@ -815,9 +840,13 @@ void init()
/* Password lengths to try; Strip can generate passwords of 4 to 16
* characters, but traditional crypt(3) hashes are limited to 8. */
- minlength = 4;
- // use the format's maximum password length here
- maxlength = cipher_limit;
+ minlength = req_minlen;
+ if (minlength < 4)
+ minlength = 4;
+ if (req_maxlen)
+ maxlength = req_maxlen;
+ else // the format's limit
+ maxlength = cipher_limit;
if (maxlength >16) maxlength = 16;
/* Password types to try (Numeric, Alpha-Num, Alpha-Num w/ Meta). */
@@ -892,8 +921,15 @@ void init()
int i, j, c, p;
int k[0x40];
- minlength = 1; // Initial password length to try
- maxlength = cipher_limit; // the format's limit
+ // Initial password length to try
+ if (req_minlen)
+ minlength = req_minlen;
+ else
+ minlength = 1;
+ if (req_maxlen)
+ maxlength = req_maxlen;
+ else
+ maxlength = cipher_limit; // the format's limit
fuzz = 1; // "Fuzz factor", set to 0 for much quicker runs
/*
@@ -1011,11 +1047,14 @@ void init()
int i, c;
// Initial password length to try, must be at least 1
- minlength = 1;
- // Maximum password length to try, must be at least same as minlength
- // We use the format's maximum password length
- // (or the one from --stdin=LENGTH) here
- maxlength = cipher_limit;
+ if (req_minlen)
+ minlength = req_minlen;
+ else
+ minlength = 1;
+ if (req_maxlen)
+ maxlength = req_maxlen;
+ else
+ maxlength = cipher_limit; // the format's limit
/*
* This defines the character set.
@@ -1117,15 +1156,22 @@ int charset[0x7f00]; // Character sets, 0x100 elements for each position
void init()
{
- int length;
+ int length, maxlength;
int pos, ofs, i, c;
- length = 8; // Password length to try (NOTE: other [eg. shorter]
- // lengths will not be tried!)
+ if (req_minlen)
+ length = req_minlen;
+ else
+ length = 8; // Password length to try (NOTE: other [eg. shorter]
+ // lengths will not be tried!)
+ if (req_maxlen)
+ maxlength = req_maxlen;
+ else
+ maxlength = cipher_limit; // the format's limit
/* This defines the character sets for different character positions */
- if (length > cipher_limit)
- length = cipher_limit;
+ if (length > maxlength)
+ length = maxlength;
pos = 0;
while (pos < 4) {
ofs = pos++ << 8;
@@ -1294,7 +1340,7 @@ void restore()
# then all the candidates for the minimum length will be generated
# nevertheless.
[List.External_base:Repeats]
-int minlength, minc, maxc, length, c;
+int minlength, maxlength, minc, maxc, length, c;
void generate()
{
@@ -1316,7 +1362,7 @@ void generate()
// Password candidates longer than "cipher_limit" would be cut to
// length "cipher_limit" anyway, so the external mode would produce
// duplicate password candidates if we didn't stop here.
- if (++length > cipher_limit)
+ if (++length > maxlength)
c = 0; // Will NUL out the next "word" and thus terminate
}
@@ -1325,7 +1371,14 @@ void generate()
.include [List.External_base:Repeats]
void init()
{
- minlength = 1;
+ if (req_minlen)
+ minlength = req_minlen;
+ else
+ minlength = 1;
+ if (req_maxlen)
+ maxlength = req_maxlen;
+ else
+ maxlength = cipher_limit; // the format's limit
minc = 0x20;
maxc = 0xff;
@@ -1337,7 +1390,14 @@ void init()
.include [List.External_base:Repeats]
void init()
{
- minlength = 1;
+ if (req_minlen)
+ minlength = req_minlen;
+ else
+ minlength = 1;
+ if (req_maxlen)
+ maxlength = req_maxlen;
+ else
+ maxlength = cipher_limit; // the format's limit
minc = '0';
maxc = '9';
@@ -1349,7 +1409,14 @@ void init()
.include [List.External_base:Repeats]
void init()
{
- minlength = 1;
+ if (req_minlen)
+ minlength = req_minlen;
+ else
+ minlength = 1;
+ if (req_maxlen)
+ maxlength = req_maxlen;
+ else
+ maxlength = cipher_limit; // the format's limit
minc = 'a';
maxc = 'z';
@@ -1362,7 +1429,14 @@ void init()
.include [List.External_base:Repeats]
void init()
{
- minlength = 1;
+ if (req_minlen)
+ minlength = req_minlen;
+ else
+ minlength = 1;
+ if (req_maxlen)
+ maxlength = req_maxlen;
+ else
+ maxlength = cipher_limit; // the format's limit
minc = ' ';
maxc = '~';
@@ -1688,9 +1762,15 @@ void init()
int i, c;
// Minimum password length to try, must be at least 1
- minlength = 1;
+ if (req_minlen)
+ minlength = req_minlen;
+ else
+ minlength = 1;
// Maximum password length to try, must be at least same as minlength
- maxlength = 8;
+ if (req_maxlen)
+ maxlength = req_maxlen;
+ else
+ maxlength = 8;
// "cipher_limit" is the variable which contains the format's
// maximum password length
View
@@ -33,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, ext_cipher_limit;
+c_int ext_abort, ext_status, ext_cipher_limit, ext_minlen, ext_maxlen;
static struct c_ident ext_ident_status = {
NULL,
@@ -52,8 +52,21 @@ static struct c_ident ext_ident_cipher_limit = {
"cipher_limit",
&ext_cipher_limit
};
-static struct c_ident ext_globals = {
+
+static struct c_ident ext_ident_minlen = {
&ext_ident_cipher_limit,
+ "req_minlen",
+ &ext_minlen
+};
+
+static struct c_ident ext_ident_maxlen = {
+ &ext_ident_minlen,
+ "req_maxlen",
+ &ext_maxlen
+};
+
+static struct c_ident ext_globals = {
+ &ext_ident_maxlen,
"word",
ext_word
};
@@ -122,6 +135,12 @@ void ext_init(char *mode, struct db_main *db)
ext_cipher_limit = options.length;
}
+ ext_maxlen = options.force_maxlength;
+ if (options.force_minlength > 0)
+ ext_minlen = options.force_minlength;
+ else
+ ext_minlen = 0;
+
if (!(ext_source = cfg_get_list(SECTION_EXT, mode))) {
#ifdef HAVE_MPI
if (mpi_id == 0)
View
@@ -47,7 +47,7 @@ void fmt_init(struct fmt_main *format)
format->params.plaintext_length =
options.force_maxlength;
else {
- fprintf(stderr, "Can't set length larger than %u for %s format\n", format->params.plaintext_length, format->params.label);
+ fprintf(stderr, "Can't set max length larger than %u for %s format\n", format->params.plaintext_length, format->params.label);
error();
}
}
View
@@ -23,6 +23,7 @@
#include "charset.h"
#include "external.h"
#include "cracker.h"
+#include "options.h"
extern struct fmt_main fmt_LM;
extern struct fmt_main fmt_NETLM;
@@ -465,6 +466,12 @@ void do_incremental_crack(struct db_main *db, char *mode)
max_length = CHARSET_LENGTH;
max_count = cfg_get_int(SECTION_INC, mode, "CharCount");
+ /* Command-line can over-ride lengths from config file */
+ if (options.force_minlength >= 0)
+ min_length = options.force_minlength;
+ if (options.force_maxlength)
+ max_length = options.force_maxlength;
+
if (min_length > max_length) {
log_event("! MinLen = %d exceeds MaxLen = %d",
min_length, max_length);
View
@@ -23,6 +23,7 @@
#include "charset.h"
#include "external.h"
#include "cracker.h"
+#include "options.h"
#ifdef HAVE_MPI
#include "john-mpi.h"
@@ -407,6 +408,14 @@ void get_markov_options(struct db_main *db,
minlevel = level;
}
+ /* Command-line --min-length and --max-length can over-ride lengths
+ from config file. This may clash with the len_token stuff, or rather
+ it will over-ride that too. */
+ if (options.force_minlength >= 0)
+ minlen = options.force_minlength;
+ if (options.force_maxlength)
+ maxlen = options.force_maxlength;
+
if(maxlen <= 0)
if( (maxlen = cfg_get_int(SECTION_MARKOV, mode, "MkvMaxLen")) == -1 )
{
Oops, something went wrong.

0 comments on commit f6a6c22

Please sign in to comment.