diff --git a/src/Makefile b/src/Makefile index 32247f9..436e687 100644 --- a/src/Makefile +++ b/src/Makefile @@ -5,6 +5,9 @@ # ...with changes in the jumbo patch, by various authors # +# Uncomment the 2 lines below for hmailserver format (requires OpenSSL 0.9.8+) +#HMAILSERVER = hmailserver_fmt.o +#HMAILFLAGS = -DHMAILSERVER CC = gcc AS = $(CC) LD = $(CC) @@ -21,7 +24,7 @@ OMPFLAGS = #OMPFLAGS = -fopenmp # Sun Studio with OpenMP (set the OMP_NUM_THREADS env var at runtime) #OMPFLAGS = -xopenmp -CFLAGS = -c -Wall -O2 -fomit-frame-pointer -I/usr/local/include $(OMPFLAGS) +CFLAGS = -c -Wall -O2 -fomit-frame-pointer -I/usr/local/include $(OMPFLAGS) $(HMAILFLAGS) # -DHAVE_SKEY ASFLAGS = -c $(OMPFLAGS) LDFLAGS = -s -L/usr/local/lib -L/usr/local/ssl/lib -lcrypto -lm $(OMPFLAGS) @@ -32,6 +35,7 @@ OPT_NORMAL = -funroll-loops OPT_INLINE = -finline-functions JOHN_OBJS = \ + $(HMAILSERVER) \ DES_fmt.o DES_std.o DES_bs.o DES_bs_b.o \ BSDI_fmt.o \ MD5_fmt.o MD5_std.o \ diff --git a/src/hmailserver_fmt.c b/src/hmailserver_fmt.c new file mode 100644 index 0000000..b1c6382 --- /dev/null +++ b/src/hmailserver_fmt.c @@ -0,0 +1,248 @@ +/* + * This patch Copyright (C) 2010 by James Nobis - quel + * - quel NOSPAM quelrod NOSPAM net, and it is herby released to the general + * public under the follow terms: + * Redistribution and use in source and binary forms, with or without + * modification, are permitted. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * format specification + * http://www.hmailserver.com/forum/viewtopic.php?p=97515&sid=b2c1c6ba1e10c2f0654ca9421b2059e8#p97515 + * inspiration from the generic sha-1 and md5 + * Copyright (c) 2010 by Solar Designer + */ + +#include +#include + +#include "arch.h" +#include "params.h" +#include "common.h" +#include "formats.h" + +#define FORMAT_LABEL "hmailserver" +#define FORMAT_NAME "hmailserver" + +#define ALGORITHM_NAME "32/" ARCH_BITS_STR + +#define BENCHMARK_COMMENT "" +#define BENCHMARK_LENGTH 0 + +#define PLAINTEXT_LENGTH 70 +#define CIPHERTEXT_LENGTH 64 + +#define BINARY_SIZE 32 +#define SALT_SIZE 6 + +#define MIN_KEYS_PER_CRYPT 1 +#define MAX_KEYS_PER_CRYPT 1 + +static struct fmt_tests hmailserver_tests[] = { + {"cc06fa688a64cdeea43d3c0fb761fede7e3ccf00a9daea9c79f7d458e06f88327f16dd", "password"}, + {"fee4fd4446aebcb3332aa5c61845b7bcbe5a3126fedf51a6359663d61b87d4f6ee87df", "12345678"}, + {"2d7b784370c488b6548394ba11513e159220c83e2458ed01d8c7cdadd6bf486b433703", "1234"}, + {"0926aadc8d49682c3f091af2dbf7f16f1cc7130b8e6dc86978d3f1bef914ce0096d4b3", "0123456789ABCDE"}, + {NULL} +}; + +static char saved_salt[SALT_SIZE]; +static int saved_key_length; +static char saved_key[PLAINTEXT_LENGTH + 1]; +static SHA256_CTX ctx; +static ARCH_WORD_32 crypt_out[8] = {0}; // 8 * 32 = 256 + +static int valid(char *ciphertext) +{ + int i; + + if ( ciphertext == NULL ) + return 0; + + if ( strnlen( ciphertext, PLAINTEXT_LENGTH ) != PLAINTEXT_LENGTH ) + return 0; + + for ( i = 0; i < PLAINTEXT_LENGTH - 1; i++ ) + if (!( (('0' <= ciphertext[i] ) && ( ciphertext[i] <= '9' )) + || (('a' <= ciphertext[i] ) && ( ciphertext[i] <= 'f' )) )) + return 0; + + return 1; +} + +static void *get_binary(char *ciphertext) +{ + static unsigned char out[BINARY_SIZE]; + char *p; + int i; + + p = ciphertext + SALT_SIZE; + for (i = 0; i < sizeof(out); i++) { + out[i] = + (atoi16[ARCH_INDEX(*p)] << 4) | + atoi16[ARCH_INDEX(p[1])]; + p += 2; + } + + return out; +} + +static void *salt(char *ciphertext) +{ + static unsigned char out[SALT_SIZE]; + + memcpy(out, ciphertext, SALT_SIZE); + + return out; +} + +static int binary_hash_0(void *binary) +{ + return *(ARCH_WORD_32 *)binary & 0xF; +} + +static int binary_hash_1(void *binary) +{ + return *(ARCH_WORD_32 *)binary & 0xFF; +} + +static int binary_hash_2(void *binary) +{ + return *(ARCH_WORD_32 *)binary & 0xFFF; +} + +static int binary_hash_3(void *binary) +{ + return *(ARCH_WORD_32 *)binary & 0xFFFF; +} + +static int binary_hash_4(void *binary) +{ + return *(ARCH_WORD_32 *)binary & 0xFFFFF; +} + +static int get_hash_0(int index) +{ + return crypt_out[0] & 0xF; +} + +static int get_hash_1(int index) +{ + return crypt_out[0] & 0xFF; +} + +static int get_hash_2(int index) +{ + return crypt_out[0] & 0xFFF; +} + +static int get_hash_3(int index) +{ + return crypt_out[0] & 0xFFFF; +} + +static int get_hash_4(int index) +{ + return crypt_out[0] & 0xFFFFF; +} + +static int salt_hash(void *salt) +{ + int x, y; + x = ((ARCH_WORD_32)(ARCH_INDEX(((unsigned char *)salt)[0])-' ')); + y = (((ARCH_WORD_32)(ARCH_INDEX(((unsigned char *)salt)[1])-' ')<<4)); + return (x+y) & 0x3FF; +} + +static void set_salt(void *salt) +{ + memcpy(saved_salt, salt, SALT_SIZE); +} + +static void set_key(char *key, int index) +{ + saved_key_length = strlen(key); + if (saved_key_length > PLAINTEXT_LENGTH) + saved_key_length = PLAINTEXT_LENGTH; + memcpy(saved_key, key, saved_key_length); +} + +static char *get_key(int index) +{ + saved_key[saved_key_length] = 0; + return saved_key; +} + +static void crypt_all(int count) +{ + SHA256_Init(&ctx); + SHA256_Update(&ctx, saved_salt, SALT_SIZE); + SHA256_Update(&ctx, saved_key, saved_key_length); + SHA256_Final((unsigned char *)crypt_out, &ctx); +} + +static int cmp_all(void *binary, int count) +{ + return !memcmp(binary, crypt_out, BINARY_SIZE); +} + +static int cmp_exact(char *source, int index) +{ + return 1; +} + +struct fmt_main fmt_hmailserver = { + { + FORMAT_LABEL, + FORMAT_NAME, + ALGORITHM_NAME, + BENCHMARK_COMMENT, + BENCHMARK_LENGTH, + PLAINTEXT_LENGTH, + BINARY_SIZE, + SALT_SIZE, + MIN_KEYS_PER_CRYPT, + MAX_KEYS_PER_CRYPT, + FMT_CASE | FMT_8_BIT, + hmailserver_tests + }, { + fmt_default_init, + valid, + fmt_default_split, + get_binary, + salt, + { + binary_hash_0, + binary_hash_1, + binary_hash_2, + binary_hash_3, + binary_hash_4 + }, + salt_hash, + 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 + }, + cmp_all, + cmp_all, + cmp_exact + } +}; diff --git a/src/john.c b/src/john.c index ae812e5..037ad33 100644 --- a/src/john.c +++ b/src/john.c @@ -52,6 +52,9 @@ extern struct fmt_main fmt_PO; extern struct fmt_main fmt_rawMD5go; extern struct fmt_main fmt_MD5gen; extern struct fmt_main fmt_hmacMD5; +#ifdef HMAILSERVER +extern struct fmt_main fmt_hmailserver; +#endif extern struct fmt_main fmt_IPB2; extern struct fmt_main fmt_phpassmd5; extern struct fmt_main fmt_DMD5; @@ -144,6 +147,9 @@ static void john_register_all(void) john_register_one(&fmt_md4_gen); john_register_one(&fmt_KRB4); john_register_one(&fmt_KRB5); +#ifdef HMAILSERVER + john_register_one(&fmt_hmailserver); +#endif john_register_one(&fmt_NSLDAP); john_register_one(&fmt_NSLDAPS); john_register_one(&fmt_OPENLDAPS); diff --git a/src/options.c b/src/options.c index 2a5752c..d7a3e27 100644 --- a/src/options.c +++ b/src/options.c @@ -110,6 +110,12 @@ static struct opt_entry opt_list[] = { #define MAYBE_CRYPT "" #endif +#ifdef HMAILSERVER +#define MAYBE_HMAIL "hmailserver/" +#else +#define MAYBE_HMAIL "" +#endif + #define JOHN_USAGE \ "John the Ripper password cracker, version " JOHN_VERSION "\n" \ "Copyright (c) 1996-2011 by " JOHN_COPYRIGHT "\n" \ @@ -140,7 +146,9 @@ static struct opt_entry opt_list[] = { "--format=NAME force hash type NAME:\n" \ " DES/BSDI/MD5/BF/AFS/LM/NT/XSHA/PO/raw-MD5/MD5-gen/\n" \ " IPB2/raw-sha1/md5a/hmac-md5/phpass-md5/KRB5/bfegg/\n" \ -" nsldap/ssha/openssha/oracle/oracle11/MYSQL/\n" \ +" " \ +MAYBE_HMAIL \ + "nsldap/ssha/openssha/oracle/oracle11/MYSQL/\n" \ " mysql-sha1/mscash/mscash2/lotus5/DOMINOSEC/\n" \ " NETLM/NETNTLM/NETLMv2/NETNTLMv2/NETHALFLM/MSCHAPv2/\n" \ " mssql/mssql05/epi/phps/mysql-fast/pix-md5/sapG/\n" \