diff --git a/include/shared.h b/include/shared.h index 27a9b37f3..79a68f03c 100644 --- a/include/shared.h +++ b/include/shared.h @@ -90,6 +90,7 @@ const char *strhashcategory (const u32 hash_category); const char *stroptitype (const u32 opti_type); bool generic_salt_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, const u8 *in_buf, const int in_len, u8 *out_buf, int *out_len); +int generic_salt_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, const u8 *in_buf, const int in_len, u8 *out_buf); int input_tokenizer (const u8 *input_buf, const int input_len, token_t *token); diff --git a/include/types.h b/include/types.h index 8633bf279..9603c6111 100644 --- a/include/types.h +++ b/include/types.h @@ -391,26 +391,24 @@ typedef enum opts_type OPTS_TYPE_ST_ADD80 = (1ULL << 22), OPTS_TYPE_ST_ADDBITS14 = (1ULL << 23), OPTS_TYPE_ST_ADDBITS15 = (1ULL << 24), - OPTS_TYPE_ST_GENERATE_LE = (1ULL << 25), - OPTS_TYPE_ST_GENERATE_BE = (1ULL << 26), - OPTS_TYPE_ST_HEX = (1ULL << 27), - OPTS_TYPE_ST_BASE64 = (1ULL << 28), - OPTS_TYPE_ST_HASH_MD5 = (1ULL << 29), - OPTS_TYPE_HASH_COPY = (1ULL << 30), - OPTS_TYPE_HASH_SPLIT = (1ULL << 31), - OPTS_TYPE_HOOK12 = (1ULL << 32), - OPTS_TYPE_HOOK23 = (1ULL << 33), - OPTS_TYPE_INIT2 = (1ULL << 34), - OPTS_TYPE_LOOP2 = (1ULL << 35), - OPTS_TYPE_AUX1 = (1ULL << 36), - OPTS_TYPE_AUX2 = (1ULL << 37), - OPTS_TYPE_AUX3 = (1ULL << 38), - OPTS_TYPE_AUX4 = (1ULL << 39), - OPTS_TYPE_BINARY_HASHFILE = (1ULL << 40), - OPTS_TYPE_PREFERED_THREAD = (1ULL << 41), // some algorithms (complicated ones with many branches) benefit from this - OPTS_TYPE_PT_ADD06 = (1ULL << 42), - OPTS_TYPE_KEYBOARD_MAPPING = (1ULL << 43), - OPTS_TYPE_DEEP_COMP_KERNEL = (1ULL << 44), // if we have to iterate through each hash inside the comp kernel, for example if each hash has to be decrypted separately + OPTS_TYPE_ST_HEX = (1ULL << 25), + OPTS_TYPE_ST_BASE64 = (1ULL << 26), + OPTS_TYPE_ST_HASH_MD5 = (1ULL << 27), + OPTS_TYPE_HASH_COPY = (1ULL << 28), + OPTS_TYPE_HASH_SPLIT = (1ULL << 29), + OPTS_TYPE_HOOK12 = (1ULL << 30), + OPTS_TYPE_HOOK23 = (1ULL << 31), + OPTS_TYPE_INIT2 = (1ULL << 32), + OPTS_TYPE_LOOP2 = (1ULL << 33), + OPTS_TYPE_AUX1 = (1ULL << 34), + OPTS_TYPE_AUX2 = (1ULL << 35), + OPTS_TYPE_AUX3 = (1ULL << 36), + OPTS_TYPE_AUX4 = (1ULL << 37), + OPTS_TYPE_BINARY_HASHFILE = (1ULL << 38), + OPTS_TYPE_PREFERED_THREAD = (1ULL << 39), // some algorithms (complicated ones with many branches) benefit from this + OPTS_TYPE_PT_ADD06 = (1ULL << 40), + OPTS_TYPE_KEYBOARD_MAPPING = (1ULL << 41), + OPTS_TYPE_DEEP_COMP_KERNEL = (1ULL << 42), // if we have to iterate through each hash inside the comp kernel, for example if each hash has to be decrypted separately } opts_type_t; diff --git a/src/modules/module_00010.c b/src/modules/module_00010.c index e39a9f2d0..6e428edba 100644 --- a/src/modules/module_00010.c +++ b/src/modules/module_00010.c @@ -136,9 +136,7 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE out_len += 1; - memcpy (out_buf + out_len, salt->salt_buf, salt->salt_len); - - out_len += salt->salt_len; + out_len += generic_salt_encode (hashconfig, (const u8 *) salt->salt_buf, (const int) salt->salt_len, out_buf + out_len); return out_len; } diff --git a/src/modules/module_01100.c b/src/modules/module_01100.c index a67343acb..8543c834e 100644 --- a/src/modules/module_01100.c +++ b/src/modules/module_01100.c @@ -140,25 +140,7 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE out_len += 1; - const u8 *ptr = (const u8 *) salt->salt_buf; - - if (hashconfig->opts_type & OPTS_TYPE_ST_UTF16LE) - { - for (u32 i = 0; i < salt->salt_len; i += 2) - { - out_buf[out_len] = ptr[i]; - - out_len++; - } - - out_buf[out_len] = 0; - } - else - { - memcpy (out_buf + out_len, salt->salt_buf, salt->salt_len); - - out_len += salt->salt_len; - } + out_len += generic_salt_encode (hashconfig, (const u8 *) salt->salt_buf, (const int) salt->salt_len, out_buf + out_len); return out_len; } diff --git a/src/modules/module_03200.c b/src/modules/module_03200.c index 57e641323..f1a27777c 100644 --- a/src/modules/module_03200.c +++ b/src/modules/module_03200.c @@ -20,8 +20,7 @@ static const u32 HASH_CATEGORY = HASH_CATEGORY_OS; static const char *HASH_NAME = "bcrypt $2*$, Blowfish (Unix)"; static const u64 KERN_TYPE = 3200; static const u32 OPTI_TYPE = OPTI_TYPE_ZERO_BYTE; -static const u64 OPTS_TYPE = OPTS_TYPE_PT_GENERATE_LE - | OPTS_TYPE_ST_GENERATE_LE; +static const u64 OPTS_TYPE = OPTS_TYPE_PT_GENERATE_LE; static const u32 SALT_TYPE = SALT_TYPE_EMBEDDED; static const char *ST_PASS = "hashcat"; static const char *ST_HASH = "$2a$05$MBCzKhG1KhezLh.0LRa0Kuw12nLJtpHy6DIaU.JAnqJUDYspHC.Ou"; diff --git a/src/modules/module_09000.c b/src/modules/module_09000.c index 6f27204cd..068b87589 100644 --- a/src/modules/module_09000.c +++ b/src/modules/module_09000.c @@ -21,7 +21,6 @@ static const char *HASH_NAME = "Password Safe v2"; static const u64 KERN_TYPE = 9000; static const u32 OPTI_TYPE = OPTI_TYPE_ZERO_BYTE; static const u64 OPTS_TYPE = OPTS_TYPE_PT_GENERATE_LE - | OPTS_TYPE_ST_GENERATE_LE | OPTS_TYPE_BINARY_HASHFILE; static const u32 SALT_TYPE = SALT_TYPE_EMBEDDED; static const char *ST_PASS = "hashcat"; diff --git a/src/modules/module_11500.c b/src/modules/module_11500.c index 82e4eab2d..97bb63913 100644 --- a/src/modules/module_11500.c +++ b/src/modules/module_11500.c @@ -21,7 +21,6 @@ static const char *HASH_NAME = "CRC32"; static const u64 KERN_TYPE = 11500; static const u32 OPTI_TYPE = OPTI_TYPE_ZERO_BYTE; static const u64 OPTS_TYPE = OPTS_TYPE_PT_GENERATE_LE - | OPTS_TYPE_ST_GENERATE_LE | OPTS_TYPE_ST_HEX; static const u32 SALT_TYPE = SALT_TYPE_EMBEDDED; static const char *ST_PASS = "hashcat"; @@ -163,4 +162,4 @@ void module_init (module_ctx_t *module_ctx) module_ctx->module_tmp_size = MODULE_DEFAULT; module_ctx->module_unstable_warning = MODULE_DEFAULT; module_ctx->module_warmup_disable = MODULE_DEFAULT; -} \ No newline at end of file +} diff --git a/src/modules/module_14000.c b/src/modules/module_14000.c index 250fa0762..28d00bfb7 100644 --- a/src/modules/module_14000.c +++ b/src/modules/module_14000.c @@ -23,7 +23,6 @@ static const u64 KERN_TYPE = 14000; static const u32 OPTI_TYPE = OPTI_TYPE_ZERO_BYTE; static const u64 OPTS_TYPE = OPTS_TYPE_PT_GENERATE_LE | OPTS_TYPE_PT_BITSLICE - | OPTS_TYPE_ST_GENERATE_LE | OPTS_TYPE_ST_HEX; static const u32 SALT_TYPE = SALT_TYPE_EMBEDDED; static const char *ST_PASS = "hashcat1"; diff --git a/src/modules/module_14100.c b/src/modules/module_14100.c index 9473c0d22..26484d9df 100644 --- a/src/modules/module_14100.c +++ b/src/modules/module_14100.c @@ -22,7 +22,6 @@ static const char *HASH_NAME = "3DES (PT = $salt, key = $pass)"; static const u64 KERN_TYPE = 14100; static const u32 OPTI_TYPE = OPTI_TYPE_ZERO_BYTE; static const u64 OPTS_TYPE = OPTS_TYPE_PT_GENERATE_LE - | OPTS_TYPE_ST_GENERATE_LE | OPTS_TYPE_ST_HEX; static const u32 SALT_TYPE = SALT_TYPE_EMBEDDED; static const char *ST_PASS = "hashcat1hashcat1hashcat1"; diff --git a/src/modules/module_14700.c b/src/modules/module_14700.c index 8933f8126..dbdcc4291 100644 --- a/src/modules/module_14700.c +++ b/src/modules/module_14700.c @@ -22,7 +22,6 @@ static const u64 KERN_TYPE = 14700; static const u32 OPTI_TYPE = OPTI_TYPE_ZERO_BYTE | OPTI_TYPE_SLOW_HASH_SIMD_LOOP; static const u64 OPTS_TYPE = OPTS_TYPE_PT_GENERATE_LE - | OPTS_TYPE_ST_GENERATE_LE | OPTS_TYPE_ST_HEX; static const u32 SALT_TYPE = SALT_TYPE_EMBEDDED; static const char *ST_PASS = "hashcat"; diff --git a/src/modules/module_14800.c b/src/modules/module_14800.c index 0193b7c9b..83f8cd783 100644 --- a/src/modules/module_14800.c +++ b/src/modules/module_14800.c @@ -22,7 +22,6 @@ static const u64 KERN_TYPE = 14800; static const u32 OPTI_TYPE = OPTI_TYPE_ZERO_BYTE | OPTI_TYPE_SLOW_HASH_SIMD_LOOP; static const u64 OPTS_TYPE = OPTS_TYPE_PT_GENERATE_LE - | OPTS_TYPE_ST_GENERATE_LE | OPTS_TYPE_ST_HEX | OPTS_TYPE_INIT2 | OPTS_TYPE_LOOP2; diff --git a/src/modules/module_14900.c b/src/modules/module_14900.c index 5112244bd..bbe0cdbbb 100644 --- a/src/modules/module_14900.c +++ b/src/modules/module_14900.c @@ -21,7 +21,6 @@ static const char *HASH_NAME = "Skip32 (PT = $salt, key = $pass)"; static const u64 KERN_TYPE = 14900; static const u32 OPTI_TYPE = OPTI_TYPE_ZERO_BYTE; static const u64 OPTS_TYPE = OPTS_TYPE_PT_GENERATE_LE - | OPTS_TYPE_ST_GENERATE_LE | OPTS_TYPE_PT_NEVERCRACK; static const u32 SALT_TYPE = SALT_TYPE_EMBEDDED; static const char *ST_PASS = "hashcat!!!"; diff --git a/src/shared.c b/src/shared.c index 41c2d1de4..6af2dbc43 100644 --- a/src/shared.c +++ b/src/shared.c @@ -1123,45 +1123,43 @@ bool generic_salt_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, const u8 { u32 tmp_u32[(64 * 2) + 1] = { 0 }; - if (in_len > 512) return false; // 512 = 2 * 256 -- (2 * because of hex), 256 because of maximum salt length in salt_t + u8 *tmp_u8 = (u8 *) tmp_u32; - if (hashconfig->opts_type & OPTS_TYPE_ST_HEX) - { - if (in_len < (int) (hashconfig->salt_min * 2)) return false; - if (in_len > (int) (hashconfig->salt_max * 2)) return false; - } - else - { - if (in_len < (int) hashconfig->salt_min) return false; - if (in_len > (int) hashconfig->salt_max) return false; - } - - u8 *tmp_buf = (u8 *) tmp_u32; + if (in_len > 512) return false; // 512 = 2 * 256 -- (2 * because of hex), 256 because of maximum salt length in salt_t int tmp_len = 0; if (hashconfig->opts_type & OPTS_TYPE_ST_HEX) { - if (tmp_len & 1) return false; + if (in_len < (int) (hashconfig->salt_min * 2)) return false; + if (in_len > (int) (hashconfig->salt_max * 2)) return false; - tmp_len = in_len / 2; + if (in_len & 1) return false; - for (int i = 0, j = 0; i < tmp_len; i += 1, j += 2) + for (int i = 0, j = 0; j < in_len; i += 1, j += 2) { u8 p0 = in_buf[j + 0]; u8 p1 = in_buf[j + 1]; - tmp_buf[i] = hex_convert (p1) << 0; - tmp_buf[i] |= hex_convert (p0) << 4; + tmp_u8[i] = hex_convert (p1) << 0; + tmp_u8[i] |= hex_convert (p0) << 4; } + + tmp_len = in_len / 2; } else if (hashconfig->opts_type & OPTS_TYPE_ST_BASE64) { - tmp_len = base64_decode (base64_to_int, (const u8 *) in_buf, in_len, tmp_buf); + if (in_len < (int) ((hashconfig->salt_min * 8) / 6)) return false; + if (in_len > (int) ((hashconfig->salt_max * 8) / 6)) return false; + + tmp_len = base64_decode (base64_to_int, (const u8 *) in_buf, in_len, tmp_u8); } else { - if (in_len) memcpy (tmp_buf, in_buf, in_len); + if (in_len < (int) hashconfig->salt_min) return false; + if (in_len > (int) hashconfig->salt_max) return false; + + memcpy (tmp_u8, in_buf, in_len); tmp_len = in_len; } @@ -1183,12 +1181,12 @@ bool generic_salt_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, const u8 if (hashconfig->opts_type & OPTS_TYPE_ST_LOWER) { - lowercase (tmp_buf, tmp_len); + lowercase (tmp_u8, tmp_len); } if (hashconfig->opts_type & OPTS_TYPE_ST_UPPER) { - uppercase (tmp_buf, tmp_len); + uppercase (tmp_u8, tmp_len); } int tmp2_len = tmp_len; @@ -1197,40 +1195,62 @@ bool generic_salt_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, const u8 { if (tmp2_len >= 256) return false; - tmp_buf[tmp2_len++] = 0x80; + tmp_u8[tmp2_len++] = 0x80; } if (hashconfig->opts_type & OPTS_TYPE_ST_ADD01) { if (tmp2_len >= 256) return false; - tmp_buf[tmp2_len++] = 0x01; + tmp_u8[tmp2_len++] = 0x01; } - if (hashconfig->opts_type & OPTS_TYPE_ST_GENERATE_BE) - { - u32 max = tmp2_len / 4; + memcpy (out_buf, tmp_u8, tmp2_len); - if (tmp2_len % 4) max++; + *out_len = tmp_len; - for (u32 i = 0; i < max; i++) + return true; +} + +int generic_salt_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, const u8 *in_buf, const int in_len, u8 *out_buf) +{ + u32 tmp_u32[(64 * 2) + 1] = { 0 }; + + u8 *tmp_u8 = (u8 *) tmp_u32; + + memcpy (tmp_u8, in_buf, in_len); + + int tmp_len = in_len; + + if (hashconfig->opts_type & OPTS_TYPE_ST_UTF16LE) + { + for (int i = 0, j = 0; j < in_len; i += 1, j += 2) { - tmp_u32[i] = byte_swap_32 (tmp_u32[i]); - } + const u8 p = tmp_u8[j]; - // Important: we may need to increase the length of memcpy since - // we don't want to "loose" some swapped bytes (could happen if - // they do not perfectly fit in the 4-byte blocks) - // Memcpy does always copy the bytes in the BE order, but since - // we swapped them, some important bytes could be in positions - // we normally skip with the original len + tmp_u8[i] = p; + } - if (tmp2_len % 4) tmp2_len += 4 - (tmp2_len % 4); + tmp_len = tmp_len / 2; } - memcpy (out_buf, tmp_buf, tmp2_len); + if (hashconfig->opts_type & OPTS_TYPE_ST_HEX) + { + for (int i = 0, j = 0; i < in_len; i += 1, j += 2) + { + const u8 p = in_buf[i]; - *out_len = tmp_len; + u8_to_hex (in_buf[i], tmp_u8 + j); + } - return true; + tmp_len = in_len * 2; + } + else if (hashconfig->opts_type & OPTS_TYPE_ST_BASE64) + { + tmp_len = base64_encode (int_to_base64, in_buf, in_len, tmp_u8); + } + + memcpy (out_buf, tmp_u8, tmp_len); + + return tmp_len; }