diff -r cf2659afeaa2 src/Makefile --- a/src/Makefile Fri Feb 25 03:28:00 2011 -0800 +++ b/src/Makefile Fri Feb 25 03:45:10 2011 -0800 @@ -43,6 +43,7 @@ NT_fmt.o \ XSHA_fmt.o \ DOMINOSEC_fmt.o \ + hmailserver_fmt.o \ lotus5_fmt.o \ oracle_fmt.o \ oracle11_fmt.o \ diff -r cf2659afeaa2 src/hmailserver_fmt.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/hmailserver_fmt.c Fri Feb 25 03:45:10 2011 -0800 @@ -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 -r cf2659afeaa2 src/john.c --- a/src/john.c Fri Feb 25 03:28:00 2011 -0800 +++ b/src/john.c Fri Feb 25 03:45:10 2011 -0800 @@ -52,6 +52,7 @@ extern struct fmt_main fmt_rawMD5go; extern struct fmt_main fmt_MD5gen; extern struct fmt_main fmt_hmacMD5; +extern struct fmt_main fmt_hmailserver; extern struct fmt_main fmt_IPB2; extern struct fmt_main fmt_phpassmd5; extern struct fmt_main fmt_DMD5; @@ -143,6 +144,7 @@ john_register_one(&fmt_md4_gen); john_register_one(&fmt_KRB4); john_register_one(&fmt_KRB5); + john_register_one(&fmt_hmailserver); john_register_one(&fmt_NSLDAP); john_register_one(&fmt_NSLDAPS); john_register_one(&fmt_OPENLDAPS); diff -r cf2659afeaa2 src/options.c --- a/src/options.c Fri Feb 25 03:28:00 2011 -0800 +++ b/src/options.c Fri Feb 25 03:45:10 2011 -0800 @@ -140,7 +140,7 @@ "--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" \ +" hmailserver/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" \ @@ -279,7 +279,7 @@ if ( (options.flags & FLG_SHOW_SET) && options.showuncracked_str) { if (!strcasecmp( options.showuncracked_str, "left")) { options.loader.showuncracked = 1; - // Note we 'do' want the pot file to load normally, but during that load, + // Note we 'do' want the pot file to load normally, but during that load, // we print out hashes left. At the end of the load, john exits. However // we do NOT want the 'special' -SHOW_CHK logic to happen (which happens // instead of normal loading if we are in 'normal' show mode)