diff -rubN john-1.7.6-jumbo-5/src/MSCHAPv2_fmt.c john-1.7.6-jumbo-5-jmk/src/MSCHAPv2_fmt.c --- john-1.7.6-jumbo-5/src/MSCHAPv2_fmt.c 1969-12-31 18:00:00.000000000 -0600 +++ john-1.7.6-jumbo-5-jmk/src/MSCHAPv2_fmt.c 2010-07-19 16:02:33.971860046 -0500 @@ -0,0 +1,295 @@ +/* + * MSCHAPv2_fmt.c -- Microsoft PPP CHAP Extensions, Version 2 + * + * Written by JoMo-Kun in 2010 + * and placed in the public domain. + * + * This algorithm is designed for performing brute-force cracking of the + * MSCHAPv2 challenge/response sets exchanged during network-based + * authentication attempts. The captured challenge/response set from these + * attempts should be stored using the following format: + * + * USERNAME:::AUTHENTICATOR CHALLENGE:MSCHAPv2 RESPONSE:PEER CHALLENGE + * USERNAME::DOMAIN:AUTHENTICATOR CHALLENGE:MSCHAPv2 RESPONSE:PEER CHALLENGE + * DOMAIN\USERNAME:::AUTHENTICATOR CHALLENGE:MSCHAPv2 RESPONSE:PEER CHALLENGE + * + * For example: + * User:::5B5D7C7D7B3F2F3E3C2C602132262628:82309ECD8D708B5EA08FAA3981CD83544233114A3D85D6DF:21402324255E262A28295F2B3A337C7E + * domain\fred:::56d64cbe7bad61349a0b752335100eaf:d7d829d9545cef1d631b4e568ffb7586050fa3a4d02dbc0b:7f8a466cff2a6bf0c80218bbf56d76bc + * + * http://freeradius.org/rfc/rfc2759.txt + * + */ + +#include +#include + +#include "misc.h" +#include "common.h" +#include "formats.h" + +#include "sha.h" +#include + +#ifndef uchar +#define uchar unsigned char +#endif + +#define FORMAT_LABEL "mschapv2" +#define FORMAT_NAME "MSCHAPv2 C/R MD4 DES" +#define ALGORITHM_NAME "mschapv2" +#define BENCHMARK_COMMENT "" +#define BENCHMARK_LENGTH 0 +#define PLAINTEXT_LENGTH 54 /* lmcons.h - PWLEN (256) ? 127 ? */ +#define USERNAME_LENGTH 256 /* lmcons.h - UNLEN (256) / LM20_UNLEN (20) */ +#define DOMAIN_LENGTH 15 /* lmcons.h - CNLEN / DNLEN */ +#define BINARY_SIZE 24 +#define CHALLENGE_LENGTH 64 +#define SALT_SIZE 8 +#define CIPHERTEXT_LENGTH 48 +#define TOTAL_LENGTH 13 + USERNAME_LENGTH + CHALLENGE_LENGTH + CIPHERTEXT_LENGTH +#define MIN_KEYS_PER_CRYPT 1 +#define MAX_KEYS_PER_CRYPT 1 + +static struct fmt_tests tests[] = { + {"$MSCHAPv2$5B5D7C7D7B3F2F3E3C2C602132262628$82309ECD8D708B5EA08FAA3981CD83544233114A3D85D6DF$21402324255E262A28295F2B3A337C7E$User", "clientPass"}, + {"$MSCHAPv2$d07054459a1fdbc266a006f0220e6fac$33c8331a9b03b7e003f09dd253d740a2bead544143cc8bde$3545cb1d89b507a5de104435e81b14a4$testuser1", "Cricket8"}, + {"$MSCHAPv2$56d64cbe7bad61349a0b752335100eaf$d7d829d9545cef1d631b4e568ffb7586050fa3a4d02dbc0b$7f8a466cff2a6bf0c80218bbf56d76bc$fred", "OMG!BBQ!11!one"}, /* domain\fred */ + {"$MSCHAPv2$b3c42db475b881d3c52ff3923d7b3bf8$f07c7a4eb391f5debe32d814679a5a69661b86b33227c4f8$6321f8649b971bd11ce8d5cb22a4a738$bOb", "asdblahblahblahblahblahblahblahblah"}, /* WorkGroup\bOb */ + {"$MSCHAPv2$d94e7c7972b2376b28c268583e162de7$eba25a3b04d2c7085d01f842e2befc91745c40db0f792356$0677ca7318fd7f65ae1b4f58c9f4f400$lameuser", ""}, /* no password */ + {NULL} +}; + +uchar saved_plain[PLAINTEXT_LENGTH + 1]; +uchar challenge[SALT_SIZE + 1]; +uchar output[BINARY_SIZE + 1]; + +extern void E_md4hash(uchar *passwd, uchar *p16); +extern void setup_des_key(unsigned char key_56[], DES_key_schedule *ks); + +static int mschapv2_valid(char *ciphertext) +{ + char *pos, *pos2; + + if (ciphertext == NULL) return 0; + else if (strncmp(ciphertext, "$MSCHAPv2$", 10)!=0) return 0; + + /* Validate Authenticator/Server Challenge Length */ + pos = &ciphertext[10]; + for (pos2 = pos; strncmp(pos2, "$", 1) != 0; pos2++) + if (atoi16[ARCH_INDEX(*pos2)] == 0x7F) + return 0; + + if ( !(*pos2 && (pos2 - pos == CHALLENGE_LENGTH / 2)) ) + return 0; + + /* Validate MSCHAPv2 Response Length */ + pos2++; pos = pos2; + for (; strncmp(pos2, "$", 1) != 0; pos2++) + if (atoi16[ARCH_INDEX(*pos2)] == 0x7F) + return 0; + + if ( !(*pos2 && (pos2 - pos == CIPHERTEXT_LENGTH)) ) + return 0; + + /* Validate Peer/Client Challenge Length */ + pos2++; pos = pos2; + for (; strncmp(pos2, "$", 1) != 0; pos2++) + if (atoi16[ARCH_INDEX(*pos2)] == 0x7F) + return 0; + + if ( !(*pos2 && (pos2 - pos == CHALLENGE_LENGTH / 2)) ) + return 0; + + /* Validate Username Length */ + pos2++; pos = pos2; + for (; atoi16[ARCH_INDEX(*pos2)] != 0x7F; pos2++); + if ( !(*pos2 && (pos2 - pos <= USERNAME_LENGTH)) ) + return 0; + + return 1; +} + +static char *mschapv2_split(char *ciphertext, int index) +{ + static char out[TOTAL_LENGTH + 1]; + int i; + + memset(out, 0, TOTAL_LENGTH + 1); + memcpy(&out, ciphertext, strlen(ciphertext)); + + /* convert hashes to lower-case - exclude $MSCHAPv2 and USERNAME */ + for (i = 10; i < 10 + 16*2 + 1 + 24*2 + 1 + 16*2; i++) + if (out[i] >= 'A' && out[i] <= 'Z') + out[i] |= 0x20; + + return out; +} + +static void *mschapv2_get_binary(char *ciphertext) +{ + static uchar binary[BINARY_SIZE]; + int i; + + ciphertext += 10 + 16*2 + 1; /* Skip - $MSCHAPv2$, Authenticator Challenge */ + + for (i=0; ifield_sep_char); + char *mschapv2 = ldr_get_field(&line, db_options->field_sep_char); + char *cli_challenge = ldr_get_field(&line, db_options->field_sep_char); + char *username = NULL; + + /* DOMAIN\USERNAME -or - USERNAME -- ignore DOMAIN */ + if ((tmp = strstr(*login, "\\")) == NULL) + tmp = *login; + else + tmp++; + + username = (char *) mem_alloc(strlen(tmp) + 1); + strcpy(username, tmp); + + tmp = (char *) mem_alloc_tiny(8 + strlen(srv_challenge) + 1 + strlen(mschapv2) + 1 + strlen(cli_challenge) + 1 + strlen(username) + 1, MEM_ALIGN_NONE); + sprintf(tmp, "$MSCHAPv2$%s$%s$%s$%s", srv_challenge, mschapv2, cli_challenge, username); + *ciphertext = tmp; + } if ((db_options->flags & DB_WORDS) || db_options->shells->head) { if (!gid) diff -rubN john-1.7.6-jumbo-5/src/options.c john-1.7.6-jumbo-5-jmk/src/options.c --- john-1.7.6-jumbo-5/src/options.c 2010-07-19 15:55:34.519665780 -0500 +++ john-1.7.6-jumbo-5-jmk/src/options.c 2010-07-19 15:59:35.950115620 -0500 @@ -142,7 +142,7 @@ " IPB2/raw-sha1/md5a/hmac-md5/phpass-md5/KRB5/bfegg/\n" \ " nsldap/ssha/openssha/oracle/oracle11/MYSQL/\n" \ " mysql-sha1/mscash/lotus5/DOMINOSEC/\n" \ -" NETLM/NETNTLM/NETLMv2/NETNTLMv2/NETHALFLM/\n" \ +" NETLM/NETNTLM/NETLMv2/NETNTLMv2/NETHALFLM/MSCHAPv2/\n" \ " mssql/mssql05/epi/phps/mysql-fast/pix-md5/sapG/\n" \ " sapB/md5ns/HDAA/DMD5" MAYBE_CRYPT "\n" \ "--subformat=NAME Some formats such as MD5-gen have subformats\n" \