Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20060205074054.GA2843@openwall.com>
Date: Sun, 5 Feb 2006 10:40:54 +0300
From: Solar Designer <solar@...nwall.com>
To: john-users@...ts.openwall.com
Subject: "keyboard-based" external mode

[ I am re-posting this.  Please use this and not the previous instance
of the message for any replies.  I made the mistake of "replying" to
Radim's message instead of posting an entirely new one and I did not
kill the References header.  This caused Gmane to thread the message
along with the discussion which occurred in December, so few people
monitoring this list via Gmane would have noticed this "added comment".
MARC apparently did not archive the message at all (or at least I failed
to find the message on MARC).  My apologies to those who are actually
receiving this twice (directly via the mailing list).  I'll try to avoid
this kind of mistake in the future. ]

In December, Radim has suggested to try candidate passwords for which:

> The next character in password is just one key of keyboard 
> distance away from the previous. Like asdf, but also qazwsx, 1q2w3e
> 
> (With and without the possible repetition of last char.) I haven't yet 
> written a program that would generate those, external filter for john would be 
> the best - any volunteers? :)

To which I replied:

> It's easier to code this in Perl, although if you really want to
> generate _all_ possible passwords of this kind, an external mode could
> do better.

Well, I've implemented this external mode.  It does not currently try
Shift'ed characters and repeated characters (it will try "qwq", but not
"qq"), and it lacks restore(), but other than that it works and cracks
some passwords.

Just copy the following into your john.conf (john.ini on Win32/DOS) and
enjoy the new cracking mode (to be invoked with "--external=keyboard").

[List.External:Keyboard]
int maxlength, length;	// Maximum passwords length to try, current length
int fuzz;		// The desired "fuzz factor", 0 or 1
int id[15];		// Current character indices for each position
int m[0x400], mc[0x80];	// The keys matrix, counts of adjacent keys
int f[0x40], fc;	// Characters for the first position, their count

void init()
{
	int i, j, c, p;
	int k[0x40];

	maxlength = 8;	// Maximum passwords length to try, up to 15
	fuzz = 1;	// "Fuzz factor", set to 0 for much quicker runs

	i = 0; while (i < 0x40) k[i++] = 0;
	k[0] = '`';
	i = 0; while (++i <= 9) k[i] = '0' + i;
	k[10] = '0'; k[11] = '-'; k[12] = '=';
	k[0x11] = 'q'; k[0x12] = 'w'; k[0x13] = 'e'; k[0x14] = 'r';
	k[0x15] = 't'; k[0x16] = 'y'; k[0x17] = 'u'; k[0x18] = 'i';
	k[0x19] = 'o'; k[0x1a] = 'p'; k[0x1b] = '['; k[0x1c] = ']';
	k[0x1d] = '\\';
	k[0x21] = 'a'; k[0x22] = 's'; k[0x23] = 'd'; k[0x24] = 'f';
	k[0x25] = 'g'; k[0x26] = 'h'; k[0x27] = 'j'; k[0x28] = 'k';
	k[0x29] = 'l'; k[0x2a] = ';'; k[0x2b] = '\'';
	k[0x31] = 'z'; k[0x32] = 'x'; k[0x33] = 'c'; k[0x34] = 'v';
	k[0x35] = 'b'; k[0x36] = 'n'; k[0x37] = 'm'; k[0x38] = ',';
	k[0x39] = '.'; k[0x3a] = '/';

	i = 0; while (i < 0x80) mc[i++] = 0;
	fc = 0;

	/* rows */
	c = 0;
	i = 0;
	while (i < 0x40) {
		p = c;
		c = k[i++];
		if (!c) continue;
		f[fc++] = c;
		if (!p) continue;
		m[(c << 3) + mc[c]++] = p;
		m[(p << 3) + mc[p]++] = c;
	}
	f[fc] = 0;

	/* columns */
	i = 0;
	while (i < 0x30) {
		p = k[i++];
		if (!p) continue;
		j = 1 - fuzz;
		while (j <= 1 + fuzz) {
			c = k[i + 0x10 - j++];
			if (!c) continue;
			m[(c << 3) + mc[c]++] = p;
			m[(p << 3) + mc[p]++] = c;
		}
	}

	id[0] = 0;
	length = 1;
}

void generate()
{
	int i, p, maxcount;

	word[0] = p = f[id[0]];
	i = 1;
	while (i < length) {
		word[i] = p = m[(p << 3) + id[i]];
		i++;
	}
	word[i--] = 0;

	if (i) maxcount = mc[word[i - 1]]; else maxcount = fc;
	while (++id[i] >= maxcount) {
		if (!i) {
			if (length < maxlength) {
				id[0] = 0;
				id[length++] = 0;
			}
			return;
		}
		id[i--] = 0;
		if (i) maxcount = mc[word[i - 1]]; else maxcount = fc;
	}
}

-- 
Alexander Peslyak <solar at openwall.com>
GPG key ID: B35D3598  fp: 6429 0D7E F130 C13E C929  6447 73C3 A290 B35D 3598
http://www.openwall.com - bringing security into open computing environments

Was I helpful?  Please give your feedback here: http://rate.affero.net/solar

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.