Openwall GNU/*/Linux - a small security-enhanced Linux distro for servers
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date: Thu, 26 Mar 2009 06:21:39 +0300
From: Solar Designer <solar@...nwall.com>
To: john-users@...ts.openwall.com
Subject: Re: Adding Characters to the end of strings inside of DumbForce?

On Wed, Mar 25, 2009 at 09:52:53AM -0500, Minga Minga wrote:
> I am using a 'DumbForce' section of john.conf to brute force ALL possible 6
> character passwords,

Why not just use an "incremental" mode such as? -

[Incremental:All6]
File = $JOHN/all.chr
MinLen = 6
MaxLen = 6
CharCount = 95

That would be more efficient.

> But I want to ADD the string '2008' to the end of each
> password generated.
> 
> (I want it to try aaaaaa2008 aaaaab2008 aaaaac2008 ... ... ..)
> 
> Is there a way to do this in john.conf?

Yes.  The most efficient and easiest way to do it is with the All6
"incremental" mode defined above, in combination with:

[List.External:6plus2008]
void init()
{
	word[10] = 0;
}

void filter()
{
	word[6] = '2';
	word[7] = '0';
	word[8] = '0';
	word[9] = '8';
}

You invoke this as follows:

./john -i=All6 -e=6plus2008 passwd

>         i = 0;
>         charset[i++] = 65;

Why are you appending the ASCII code for letter 'A' here?

>         c = ' ';
>         while (c < '~')
>                 charset[i++] = c++;

This is almost the entire printable ASCII charset, less the '~' character.

>         c = '~' + 1;
>         while (c <= 0x7e)
>                 charset[i++] = c++;

This is nothing, because the ASCII code for the '~' character is exactly
0x7e, so the "while" loop condition is never true.

The result is that your charset contains two instances of 'A', but does
not contain '~'.

>         c++;

This is probably a no-op as well.

Instead of all the lines quoted above, you should have used:

	i = 0;
	c = ' ';			// Start with space (ASCII 32) and
	while (c <= 0x7e)		// proceed for all printable ASCII
		charset[i++] = c++;

That's all.

Now, in case you still don't want to use the combination of "incremental"
mode with an external filter() suggested above, as well as to illustrate
things, I am attaching a modification of the DumbForce mode and a
modification of the KnownForce mode to this message.  Either achieves
what you asked for, and additionally the modification of DumbForce is
capable of trying a range of password lengths.

Notice how with DumbForce I had to modify not only init(), but also
generate() and restore().  I could avoid modifying init() and
generate(), though, but instead introduce a filter() similar to one
shown above.

Also notice how with KnownForce my modifications are limited to init().
That's because what you asked for matches that mode better - you have a
portion of the password that is known ("2008" at the end), and there's a
way to specify that (which is why the mode is called KnownForce).
Perhaps the special-purpose modified DumbForce mode is faster, though.

I am also attaching .diff files between the original definitions for
these modes in JtR 1.7.3.1 and the modified versions described above.
This is to illustrate the changes I've made.

All of these attachments use the text/plain MIME type, so they should be
visible in web archives of this mailing list.

Alexander

[List.External:DumbForce-All6plus2008]
int maxlength;		// Maximum password length to try
int last;		// Last character position, zero-based
int lastid;		// Character index in the last position
int id[0x7f];		// Current character indices for other positions
int charset[0x100], c0;	// Character set

void init()
{
	int minlength;
	int i, c;

	minlength = 6;	// Initial password length to try, must be at least 1
	maxlength = 6;	// Must be at least same as minlength

/* This defines the character set */
	i = 0;
	c = ' ';			// Start with space (ASCII 32) and
	while (c <= 0x7e)		// proceed for all printable ASCII
		charset[i++] = c++;

/* Zero-terminate it, and cache the first character */
	charset[i] = 0;
	c0 = charset[0];

	last = minlength - 1;
	i = 0;
	while (i <= last) {
		id[i] = 0;
		word[i++] = c0;
	}
	lastid = -1;

/* Append "2008" and NUL-terminate the "word" */
	word[i++] = '2';
	word[i++] = '0';
	word[i++] = '0';
	word[i++] = '8';
	word[i] = 0;
}

void generate()
{
	int i;

/* Handle the typical case specially */
	if (word[last] = charset[++lastid]) return;

	lastid = 0;
	word[i = last] = c0;
	while (i--) {			// Have a preceding position?
		if (word[i] = charset[++id[i]]) return;
		id[i] = 0;
		word[i] = c0;
	}

	if (++last < maxlength) {	// Next length?
		id[last] = lastid = 0;
		word[last] = c0;
		word[last + 1] = '2';
		word[last + 2] = '0';
		word[last + 3] = '0';
		word[last + 4] = '8';
		word[last + 5] = 0;
	} else				// We're done
		word = 0;
}

void restore()
{
	int i, c;

/* Calculate the current length and infer the character indices */
	last = 0;
	while (c = word[last]) {
		i = 0; while (charset[i] != c && charset[i]) i++;
		if (!charset[i]) i = 0;	// Not found
		id[last++] = i;
	}
	if (last > 4) last -= 4; // Omit "2008"
	lastid = id[--last];
}

[List.External:KnownForce-All6plus2008]
int last;		// Last character position, zero-based
int lastofs;		// Last character position offset into charset[]
int lastid;		// Current character index in the last position
int id[0x7f];		// Current character indices for other positions
int charset[0x7f00];	// Character sets, 0x100 elements for each position

void init()
{
	int length;
	int pos, ofs, i, c;

	length = 10;	// Password length to try

/* This defines the character sets for different character positions */
	pos = 0;
	while (pos < 6) {
		ofs = pos++ << 8;
		i = 0;
		c = ' ';
		while (c <= 0x7e)
			charset[ofs + i++] = c++;
		charset[ofs + i] = 0;
	}
/* Use single character "character sets" for the remaining positions */
	ofs = pos << 8;
	charset[ofs] = '2';
	charset[ofs + 1] = 0;
	ofs += 1 << 8;
	charset[ofs] = '0';
	charset[ofs + 1] = 0;
	ofs += 1 << 8;
	charset[ofs] = '0';
	charset[ofs + 1] = 0;
	ofs += 1 << 8;
	charset[ofs] = '8';
	charset[ofs + 1] = 0;

	last = length - 1;
	pos = -1;
	while (++pos <= last)
		word[pos] = charset[id[pos] = pos << 8];
	lastid = (lastofs = last << 8) - 1;
	word[pos] = 0;
}

void generate()
{
	int pos;

/* Handle the typical case specially */
	if (word[last] = charset[++lastid]) return;

	word[pos = last] = charset[lastid = lastofs];
	while (pos--) {			// Have a preceding position?
		if (word[pos] = charset[++id[pos]]) return;
		word[pos] = charset[id[pos] = pos << 8];
	}

	word = 0;			// We're done
}

void restore()
{
	int i, c;

/* Calculate the current length and infer the character indices */
	last = 0;
	while (c = word[last]) {
		i = lastofs = last << 8;
		while (charset[i] != c && charset[i]) i++;
		if (!charset[i]) i = lastofs; // Not found
		id[last++] = i;
	}
	lastid = id[--last];
}

--- DumbForce-1.7.3.1	2009-03-26 05:27:15 +0300
+++ DumbForce-All6plus2008	2009-03-26 05:39:05 +0300
@@ -1,4 +1,4 @@
-[List.External:DumbForce]
+[List.External:DumbForce-All6plus2008]
 int maxlength;		// Maximum password length to try
 int last;		// Last character position, zero-based
 int lastid;		// Character index in the last position
@@ -10,43 +10,14 @@
 	int minlength;
 	int i, c;
 
-	minlength = 1;	// Initial password length to try, must be at least 1
-	maxlength = 7;	// Must be at least same as minlength
+	minlength = 6;	// Initial password length to try, must be at least 1
+	maxlength = 6;	// Must be at least same as minlength
 
-/*
- * This defines the character set.
- *
- * Let's say, we want to try TAB, all non-control ASCII characters, and all
- * 8-bit characters, including the 8-bit terminal controls range (as these are
- * used as regular national characters with some 8-bit encodings), but except
- * for known terminal controls (risky for the terminal we may be running on).
- *
- * Also, let's say our hashes are case-insensitive, so skip lowercase letters
- * (this is right for LM hashes).
- */
+/* This defines the character set */
 	i = 0;
-	charset[i++] = 9;		// Add horizontal TAB (ASCII 9), then
-	c = ' ';			// start with space (ASCII 32) and
-	while (c < 'a')			// proceed till lowercase 'a'
-		charset[i++] = c++;
-	c = 'z' + 1;			// Skip lowercase letters and
+	c = ' ';			// Start with space (ASCII 32) and
 	while (c <= 0x7e)		// proceed for all printable ASCII
 		charset[i++] = c++;
-	c++;				// Skip DEL (ASCII 127) and
-	while (c < 0x84)		// proceed over 8-bit codes till IND
-		charset[i++] = c++;
-	charset[i++] = 0x86;		// Skip IND (84 hex) and NEL (85 hex)
-	charset[i++] = 0x87;
-	c = 0x89;			// Skip HTS (88 hex)
-	while (c < 0x8d)		// Proceed till RI (8D hex)
-		charset[i++] = c++;
-	c = 0x91;			// Skip RI, SS2, SS3, DCS
-	while (c < 0x96)		// Proceed till SPA (96 hex)
-		charset[i++] = c++;
-	charset[i++] = 0x99;		// Skip SPA, EPA, SOS
-	c = 0xa0;			// Skip DECID, CSI, ST, OSC, PM, APC
-	while (c <= 0xff)		// Proceed with the rest of 8-bit codes
-		charset[i++] = c++;
 
 /* Zero-terminate it, and cache the first character */
 	charset[i] = 0;
@@ -59,6 +30,12 @@
 		word[i++] = c0;
 	}
 	lastid = -1;
+
+/* Append "2008" and NUL-terminate the "word" */
+	word[i++] = '2';
+	word[i++] = '0';
+	word[i++] = '0';
+	word[i++] = '8';
 	word[i] = 0;
 }
 
@@ -80,6 +57,11 @@
 	if (++last < maxlength) {	// Next length?
 		id[last] = lastid = 0;
 		word[last] = c0;
+		word[last + 1] = '2';
+		word[last + 2] = '0';
+		word[last + 3] = '0';
+		word[last + 4] = '8';
+		word[last + 5] = 0;
 	} else				// We're done
 		word = 0;
 }
@@ -95,5 +77,6 @@
 		if (!charset[i]) i = 0;	// Not found
 		id[last++] = i;
 	}
+	if (last > 4) last -= 4; // Omit "2008"
 	lastid = id[--last];
 }

--- KnownForce-1.7.3.1	2009-03-26 05:27:20 +0300
+++ KnownForce-All6plus2008	2009-03-26 05:46:03 +0300
@@ -1,4 +1,4 @@
-[List.External:KnownForce]
+[List.External:KnownForce-All6plus2008]
 int last;		// Last character position, zero-based
 int lastofs;		// Last character position offset into charset[]
 int lastid;		// Current character index in the last position
@@ -10,29 +10,31 @@
 	int length;
 	int pos, ofs, i, c;
 
-	length = 8;	// Password length to try
+	length = 10;	// Password length to try
 
 /* This defines the character sets for different character positions */
 	pos = 0;
-	while (pos < 4) {
+	while (pos < 6) {
 		ofs = pos++ << 8;
 		i = 0;
-		c = 'a';
-		while (c <= 'z')
-			charset[ofs + i++] = c++;
-		c = 'A';
-		while (c <= 'Z')
-			charset[ofs + i++] = c++;
-		charset[ofs + i] = 0;
-	}
-	while (pos < length) {
-		ofs = pos++ << 8;
-		i = 0;
-		c = '0';
-		while (c <= '9')
+		c = ' ';
+		while (c <= 0x7e)
 			charset[ofs + i++] = c++;
 		charset[ofs + i] = 0;
 	}
+/* Use single character "character sets" for the remaining positions */
+	ofs = pos << 8;
+	charset[ofs] = '2';
+	charset[ofs + 1] = 0;
+	ofs += 1 << 8;
+	charset[ofs] = '0';
+	charset[ofs + 1] = 0;
+	ofs += 1 << 8;
+	charset[ofs] = '0';
+	charset[ofs + 1] = 0;
+	ofs += 1 << 8;
+	charset[ofs] = '8';
+	charset[ofs + 1] = 0;
 
 	last = length - 1;
 	pos = -1;


-- 
To unsubscribe, e-mail john-users-unsubscribe@...ts.openwall.com and reply
to the automated confirmation request that will be sent to you.

Powered by blists - more mailing lists

Your e-mail address:

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