1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-11-22 08:08:10 +00:00

Add generic_salt_encode so we have both function types

This commit is contained in:
jsteube 2019-02-14 10:52:24 +01:00
parent 6f4b72bcd3
commit 0096f1a56b
13 changed files with 89 additions and 98 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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";

View File

@ -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";

View File

@ -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";

View File

@ -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";

View File

@ -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";

View File

@ -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";

View File

@ -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;

View File

@ -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!!!";

View File

@ -1123,45 +1123,43 @@ bool generic_salt_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, const u8
{
u32 tmp_u32[(64 * 2) + 1] = { 0 };
u8 *tmp_u8 = (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
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;
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;
if (tmp2_len % 4) max++;
for (u32 i = 0; i < max; i++)
{
tmp_u32[i] = byte_swap_32 (tmp_u32[i]);
}
// 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
if (tmp2_len % 4) tmp2_len += 4 - (tmp2_len % 4);
}
memcpy (out_buf, tmp_buf, tmp2_len);
memcpy (out_buf, tmp_u8, tmp2_len);
*out_len = tmp_len;
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)
{
const u8 p = tmp_u8[j];
tmp_u8[i] = p;
}
tmp_len = tmp_len / 2;
}
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];
u8_to_hex (in_buf[i], tmp_u8 + j);
}
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;
}