Openwall GNU/*/Linux - a small security-enhanced Linux distro for servers
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Mon, 18 Mar 2013 10:08:17 -0300
From: Claudio André <claudioandre.br@...il.com>
To: john-dev@...ts.openwall.com
Subject: Re: Cisco - Password type 4 - SHA256

Em 17-03-2013 07:22, Claudio André escreveu:
> Em 16-03-2013 15:07, Vlatko Kosturjak escreveu:
>> Thanks. Will try implement mentioned speedup.
>>
>> In the meantime, here's the simple working Perl implementation if
>> there's any interest:
>> https://gist.github.com/kost/5177541
>>
>> BR,
>
> While at it, please consider giving advices (also) to:
> - 
> https://github.com/claudioandre/JohnTheRipper/commit/c58597e1be8d88d5002c4bfb8aa00a49bfe2c745
> - 
> https://github.com/claudioandre/JohnTheRipper/commit/6d10106e7b0924838411467337507a7746142f12
>

Hi, if you are having problems looking at previous patches (above), i 
attach a new one (easier to deal but might harder to follow/understand).

Notice: it contains part of commit (7ac5b370) and i'm not sure if it is 
the right thing to do.
https://github.com/claudioandre/JohnTheRipper/commit/7ac5b3707d39c7199702da6ea060fa2336fbe7ac

It applies against Jumbo. Any problems, please, ping me.

Thanks again.


>From e04e85f6c8a3904fde00b7d19677274f62c1391a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Claudio=20Andr=C3=A9?= <claudio.andre@...reios.net.br>
Date: Mon, 18 Mar 2013 09:36:19 -0300
Subject: [PATCH 544/544] Create a cisco type 4 OpenCL format (re-using
 raw-sha256).

---
 src/john.c                 |    2 +
 src/opencl_rawsha256.h     |    9 +++
 src/opencl_rawsha256_fmt.c |  185 ++++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 189 insertions(+), 7 deletions(-)

diff --git a/src/john.c b/src/john.c
index 5f519bb..6adea56 100644
--- a/src/john.c
+++ b/src/john.c
@@ -129,6 +129,7 @@ extern struct fmt_main fmt_opencl_NT;
 extern struct fmt_main fmt_opencl_NTLMv2;
 extern struct fmt_main fmt_opencl_agilekeychain;
 extern struct fmt_main fmt_opencl_bf;
+extern struct fmt_main fmt_opencl_cisco4;
 extern struct fmt_main fmt_opencl_cryptMD5;
 extern struct fmt_main fmt_opencl_cryptsha256;
 extern struct fmt_main fmt_opencl_cryptsha256_ng;
@@ -316,6 +317,7 @@ static void john_register_all(void)
 		john_register_one(&fmt_opencl_NT);
 		john_register_one(&fmt_opencl_NTLMv2);
 		john_register_one(&fmt_opencl_agilekeychain);
+		john_register_one(&fmt_opencl_cisco4);
 		john_register_one(&fmt_opencl_cryptMD5);
 		john_register_one(&fmt_opencl_cryptsha256);
 		john_register_one(&fmt_opencl_cryptsha256_ng);
diff --git a/src/opencl_rawsha256.h b/src/opencl_rawsha256.h
index 2842526..f7a3c1c 100644
--- a/src/opencl_rawsha256.h
+++ b/src/opencl_rawsha256.h
@@ -18,6 +18,15 @@
 #include "opencl_sha256.h"
 
 //Constants.
+#define RAW_PLAINTEXT_LENGTH    32      /* 31 characters + 0x80 */
+#define CISCO_LIMIT_PLAINTEXT   26      /* 25 characters + 0x80 */
+#define CISCO_PLAINTEXT_LENGTH  28      /* CISCO_LIMIT_PLAINTEXT multiple of 4 */
+
+#define RAW_CIPHERTEXT_LENGTH   64
+#define CISCO_CIPHERTEXT_LENGTH 43
+#define RAW_PLAINTEXT_ARRAY     (RAW_PLAINTEXT_LENGTH / 4)
+#define CISCO_PLAINTEXT_ARRAY   (CISCO_PLAINTEXT_LENGTH / 4)
+
 #define PLAINTEXT_LENGTH        32      /* 31 characters + 0x80 */
 #define PLAINTEXT_TEXT          "32"
 #define CIPHERTEXT_LENGTH       64
diff --git a/src/opencl_rawsha256_fmt.c b/src/opencl_rawsha256_fmt.c
index 7b27014..ee9039a 100644
--- a/src/opencl_rawsha256_fmt.c
+++ b/src/opencl_rawsha256_fmt.c
@@ -3,6 +3,7 @@
  * Based on source code provided by Samuele Giovanni Tonon
  *
  * More information at http://openwall.info/wiki/john/OpenCL-RAWSHA-256
+ * More information at http://openwall.info/wiki/john/OpenCL-CISCO4
  *
  * Copyright (c) 2011 Samuele Giovanni Tonon <samu at linuxasylum dot net>
  * Copyright (c) 2012 Claudio André <claudio.andre at correios.net.br>
@@ -19,8 +20,11 @@
 #include "config.h"
 #include "opencl_rawsha256.h"
 
-#define FORMAT_LABEL			"raw-sha256-opencl"
-#define FORMAT_NAME			"Raw SHA-256 (pwlen < " PLAINTEXT_TEXT ")"
+#define RAW_FORMAT_LABEL		"raw-sha256-opencl"
+#define RAW_FORMAT_NAME			"Raw SHA-256 (pwlen < " PLAINTEXT_TEXT ")"
+#define CISCO_FORMAT_LABEL		"cisco4-opencl"
+#define CISCO_FORMAT_NAME		"Cisco \"type 4\" hashes SHA-256"
+
 #define ALGORITHM_NAME			"OpenCL (inefficient, development use mostly)"
 
 #define BENCHMARK_COMMENT		""
@@ -44,7 +48,7 @@ static int hash_found;
 static int crypt_all(int *pcount, struct db_salt *_salt);
 static int crypt_all_benchmark(int *pcount, struct db_salt *_salt);
 
-static struct fmt_tests tests[] = {
+static struct fmt_tests raw_tests[] = {
 	{"5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8", "password"},
 	{"$SHA256$ef797c8118f02dfb649607dd5d3f8c7623048c9c063d532cc95c5ed7a898a64f", "12345678"},
 	{"$SHA256$e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", ""},
@@ -54,6 +58,20 @@ static struct fmt_tests tests[] = {
 	{NULL}
 };
 
+static struct fmt_tests cisco_tests[] = {
+	{"$cisco4$OsOmQzwozC4ROs/CzpczJoShdCeW9lp7k/tGrPS5Kog", "1"},
+	{"$cisco4$LcV6aBcc/53FoCJjXQMd7rBUDEpeevrK8V5jQVoJEhU", "password"},
+	{"$cisco4$d7kgbEk.P6mpKdduC66fUy1BF0MImo3eyJ9uI/JbMRk", "openwall"},
+	{"$cisco4$p5BSCWNS3ivUDpZlWthR.k4Q/xWqlFyEqXdaPikHenI", "2"},
+	{"$cisco4$HwUf7ev9Fx84X2vvspULAeDbmwlg9jgm/Wk63kc3vfU", "11"},
+	{"$cisco4$bsPEUMVATKKO9yeUlJfE3OCzHlgf0s6goJpg3P1k0UU", "test"},
+	{"$cisco4$hUsuWZSE8dZERUBYNwRK8Aa8VxEGIHsuZFUCjNj2.Ac", "verylongbutweakpassword"},
+	{"$cisco4$fLUL1VG98zYDf9Q.M40nZ5blVT3M6UBex74Blw.UDCc", "thismaximumpasswordlength"},
+	{"$cisco4$Xq81UiuCj7bz9B..EX2BZumsU/d8pF5gs2NlRMW6sTk", "applesucks"},
+	{"$cisco4$O/D/cn1nawcByQoJfBxrNnUx6jjfWV.FNFx5TzmzihU", "AppleSucks"},
+	{NULL}
+};
+
 /* ------- Helper functions ------- */
 static size_t get_task_max_work_group_size(){
 
@@ -74,6 +92,29 @@ static size_t get_default_workgroup(){
 		return 128;
 }
 
+static void decode64(unsigned char * dst, unsigned char * src) {
+	int i, j;
+	unsigned int ch;
+
+	for (i = 0, j = 0; j < SHA256_DIGEST_LENGTH; j += 3) {
+		// Get 1st byte of input (1st and 2nd)
+	        ch = src[i++];
+		dst[j] = ((atoi64[ch] << 2) & 252) + (atoi64[src[i]] >> 4 & 0x03);
+
+		// Get 2nd byte of input (2nd and 3rd)
+		ch = src[i++];
+		dst[j + 1] = ((atoi64[ch] << 4) & 240) + (atoi64[src[i]] >> 2 & 0x0f);
+
+		// Size of destination string.
+		if (j + 2 == SHA256_DIGEST_LENGTH) {
+			break;
+		}
+		// Get 3rd byte of input (3rd and 4th)
+		ch = src[i++];
+		dst[j + 2] = ((atoi64[ch] << 6) & 192) + (atoi64[src[i++]] & 0x3f);
+	}
+}
+
 static void crypt_one(int index, sha256_hash * hash) {
 	SHA256_CTX ctx;
 
@@ -307,6 +348,31 @@ static char *split(char *ciphertext, int index, struct fmt_main *pFmt) {
 	return out;
 }
 
+static int valid_cisco(char * ciphertext, struct fmt_main * self) {
+	char *p, *q;
+
+	p = ciphertext;
+	if (!strncmp(p, "$cisco4$", 8))
+		p += 8;
+
+	q = p;
+	while (atoi64[ARCH_INDEX(*q)] != 0x7F)
+		q++;
+	return !*q && q - p == CISCO_CIPHERTEXT_LENGTH;
+}
+
+static char *split_cisco(char *ciphertext, int index, struct fmt_main *pFmt) {
+
+	static char out[8 + CISCO_CIPHERTEXT_LENGTH + 1];
+
+	if (!strncmp(ciphertext, "$cisco4$", 8))
+		return ciphertext;
+
+	memcpy(out, "$cisco4$", 8);
+	memcpy(out + 8, ciphertext, CISCO_CIPHERTEXT_LENGTH + 1);
+	return out;
+}
+
 /* ------- To binary functions ------- */
 static void * get_binary(char *ciphertext) {
 	static unsigned char *out;
@@ -347,6 +413,39 @@ static void * get_full_binary(char *ciphertext) {
 	return out;
 }
 
+static void * get_cisco_binary(char *ciphertext) {
+	static unsigned char *out;
+	uint32_t * b;
+	unsigned char *p;
+
+	if (!out) out = mem_alloc_tiny(BINARY_SIZE, MEM_ALIGN_WORD);
+
+	p = (unsigned char *) ciphertext + 8;
+
+	//Decode for CISCO-4.
+	decode64(out, p);
+
+	//Undo some computation.
+	b = (uint32_t *) out;
+	b[0] = SWAP32(b[3]) - H3;
+
+	return out;
+}
+
+static void * get_cisco_full_binary(char *ciphertext) {
+	static unsigned char *out;
+	unsigned char *p;
+
+	if (!out) out = mem_alloc_tiny(BINARY_SIZE, MEM_ALIGN_WORD);
+
+	p = (unsigned char *) ciphertext + 8;
+
+	//Decode for CISCO-4.
+	decode64(out, p);
+
+	return out;
+}
+
 /* ------- Crypt function ------- */
 static int crypt_all_benchmark(int *pcount, struct db_salt *_salt) {
 	int count = *pcount;
@@ -454,6 +553,21 @@ static int cmp_exact(char *source, int index) {
 	return !memcmp(binary, (void *) &full_hash, FULL_BINARY_SIZE);
 }
 
+static int cmp_exact_cisco(char *source, int index) {
+	//I don't know why, but this is called and i have to recheck.
+	//If i skip this final test i get:
+	//form=raw-sha512-ng-opencl	 guesses: 1468 time: 0:00:00:02 : Expected count(s) (1500)  [!!!FAILED!!!]
+	//.pot CHK:raw-sha512-ng-opencl	 guesses: 1452 time: 0:00:00:02 : Expected count(s) (1500)  [!!!FAILED!!!]
+
+	uint32_t * binary;
+	sha256_hash full_hash;
+
+	crypt_one(index, &full_hash);
+
+	binary = (uint32_t *) get_cisco_full_binary(source);
+	return !memcmp(binary, (void *) &full_hash, FULL_BINARY_SIZE);
+}
+
 /* ------- Binary Hash functions group ------- */
 #ifdef DEBUG
 static void print_binary(void * binary) {
@@ -502,8 +616,8 @@ static int get_hash_6(int index) { return calculated_hash[index] & 0x7FFFFFF; }
 /* ------- Format structure ------- */
 struct fmt_main fmt_opencl_rawsha256 = {
 	{
-		FORMAT_LABEL,
-		FORMAT_NAME,
+		RAW_FORMAT_LABEL,
+		RAW_FORMAT_NAME,
 		ALGORITHM_NAME,
 		BENCHMARK_COMMENT,
 		BENCHMARK_LENGTH,
@@ -514,8 +628,8 @@ struct fmt_main fmt_opencl_rawsha256 = {
 		SALT_ALIGN,
 		MIN_KEYS_PER_CRYPT,
 		MAX_KEYS_PER_CRYPT,
-		FMT_CASE | FMT_8_BIT,
-		tests
+		FMT_CASE | FMT_8_BIT | FMT_SPLIT_UNIFIES_CASE,
+		raw_tests
 	}, {
 		init,
 		done,
@@ -554,4 +668,61 @@ struct fmt_main fmt_opencl_rawsha256 = {
 		cmp_one,
 		cmp_exact
 	}
+};
+
+/* ------- Format structure ------- */
+struct fmt_main fmt_opencl_cisco4 = {
+	{
+		CISCO_FORMAT_LABEL,
+		CISCO_FORMAT_NAME,
+		ALGORITHM_NAME,
+		BENCHMARK_COMMENT,
+		BENCHMARK_LENGTH,
+		CISCO_LIMIT_PLAINTEXT - 1,
+		BINARY_SIZE,
+		BINARY_ALIGN,
+		SALT_SIZE,
+		SALT_ALIGN,
+		MIN_KEYS_PER_CRYPT,
+		MAX_KEYS_PER_CRYPT,
+		FMT_CASE | FMT_8_BIT,
+		cisco_tests
+	}, {
+		init,
+		done,
+		fmt_default_reset,
+		fmt_default_prepare,
+		valid_cisco,
+		split_cisco,
+		get_cisco_binary,
+		fmt_default_salt,
+		fmt_default_source,
+		{
+			binary_hash_0,
+			binary_hash_1,
+			binary_hash_2,
+			binary_hash_3,
+			binary_hash_4,
+			binary_hash_5,
+			binary_hash_6
+		},
+		fmt_default_salt_hash,
+		fmt_default_set_salt,
+		set_key,
+		get_key,
+		fmt_default_clear_keys,
+		crypt_all,
+		{
+			get_hash_0,
+			get_hash_1,
+			get_hash_2,
+			get_hash_3,
+			get_hash_4,
+			get_hash_5,
+			get_hash_6
+		},
+		cmp_all,
+		cmp_one,
+		cmp_exact_cisco
+	}
 };
\ No newline at end of file
-- 
1.7.9.5


Powered by blists - more mailing lists

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