1
0
mirror of https://github.com/hashcat/hashcat.git synced 2025-01-12 08:41:07 +00:00

Merge pull request #990 from philsmd/master

hook code: refactored the hook salt to be part of the hash_t struct
This commit is contained in:
Jens Steube 2017-01-24 16:05:41 +01:00 committed by GitHub
commit fd5548e689
5 changed files with 123 additions and 86 deletions

View File

@ -365,7 +365,6 @@ typedef enum opts_type
OPTS_TYPE_HOOK12 = (1 << 26), OPTS_TYPE_HOOK12 = (1 << 26),
OPTS_TYPE_HOOK23 = (1 << 27), OPTS_TYPE_HOOK23 = (1 << 27),
OPTS_TYPE_BINARY_HASHFILE = (1 << 28), OPTS_TYPE_BINARY_HASHFILE = (1 << 28),
OPTS_TYPE_HOOK_SALT = (1 << 29),
} opts_type_t; } opts_type_t;
@ -675,8 +674,6 @@ typedef struct hashinfo
user_t *user; user_t *user;
char *orighash; char *orighash;
void *hook_salt; // additional salt info only used by the hook (host)
} hashinfo_t; } hashinfo_t;
typedef struct hash typedef struct hash
@ -684,6 +681,7 @@ typedef struct hash
void *digest; void *digest;
salt_t *salt; salt_t *salt;
void *esalt; void *esalt;
void *hook_salt; // additional salt info only used by the hook (host)
int cracked; int cracked;
hashinfo_t *hash_info; hashinfo_t *hash_info;
char *pw_buf; char *pw_buf;
@ -732,6 +730,8 @@ typedef struct hashes
void *esalts_buf; void *esalts_buf;
void *hook_salts_buf;
u32 hashes_cnt_orig; u32 hashes_cnt_orig;
u32 hashes_cnt; u32 hashes_cnt;
hash_t *hashes_buf; hash_t *hashes_buf;
@ -762,6 +762,7 @@ struct hashconfig
u32 is_salted; u32 is_salted;
u32 esalt_size; u32 esalt_size;
u32 hook_salt_size;
u32 tmp_size; u32 tmp_size;
u32 hook_size; u32 hook_size;

View File

@ -565,12 +565,13 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx)
void *digests_buf = NULL; void *digests_buf = NULL;
salt_t *salts_buf = NULL; salt_t *salts_buf = NULL;
void *esalts_buf = NULL; void *esalts_buf = NULL;
void *hook_salts_buf = NULL;
hashes_buf = (hash_t *) hccalloc (hashes_avail, sizeof (hash_t)); hashes_buf = (hash_t *) hccalloc (hashes_avail, sizeof (hash_t));
digests_buf = (void *) hccalloc (hashes_avail, hashconfig->dgst_size); digests_buf = (void *) hccalloc (hashes_avail, hashconfig->dgst_size);
if ((user_options->username == true) || (hashconfig->opts_type & OPTS_TYPE_HASH_COPY) || (hashconfig->opts_type & OPTS_TYPE_HOOK_SALT)) if ((user_options->username == true) || (hashconfig->opts_type & OPTS_TYPE_HASH_COPY))
{ {
u32 hash_pos; u32 hash_pos;
@ -593,13 +594,6 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx)
} }
} }
if (hashconfig->opts_type & OPTS_TYPE_HOOK_SALT)
{
if (hashconfig->hash_mode == 11600)
{
hash_info->hook_salt = (seven_zip_hook_salt_t *) hcmalloc (sizeof (seven_zip_hook_salt_t));
}
}
} }
} }
@ -611,6 +605,11 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx)
{ {
esalts_buf = (void *) hccalloc (hashes_avail, hashconfig->esalt_size); esalts_buf = (void *) hccalloc (hashes_avail, hashconfig->esalt_size);
} }
if (hashconfig->hook_salt_size)
{
hook_salts_buf = (seven_zip_hook_salt_t *) hccalloc (hashes_avail, hashconfig->hook_salt_size);
}
} }
else else
{ {
@ -629,6 +628,11 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx)
{ {
hashes_buf[hash_pos].esalt = ((char *) esalts_buf) + (hash_pos * hashconfig->esalt_size); hashes_buf[hash_pos].esalt = ((char *) esalts_buf) + (hash_pos * hashconfig->esalt_size);
} }
if (hashconfig->hook_salt_size)
{
hashes_buf[hash_pos].hook_salt = ((char *) hook_salts_buf) + (hash_pos * hashconfig->hook_salt_size);
}
} }
else else
{ {
@ -640,6 +644,7 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx)
hashes->digests_buf = digests_buf; hashes->digests_buf = digests_buf;
hashes->salts_buf = salts_buf; hashes->salts_buf = salts_buf;
hashes->esalts_buf = esalts_buf; hashes->esalts_buf = esalts_buf;
hashes->hook_salts_buf = hook_salts_buf;
/** /**
* load hashes, part III: parse hashes or generate them if benchmark * load hashes, part III: parse hashes or generate them if benchmark
@ -649,7 +654,7 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx)
if (user_options->benchmark == true) if (user_options->benchmark == true)
{ {
hashconfig_benchmark_defaults (hashcat_ctx, hashes_buf[0].salt, hashes_buf[0].esalt, hashes_buf[0].hash_info->hook_salt); hashconfig_benchmark_defaults (hashcat_ctx, hashes_buf[0].salt, hashes_buf[0].esalt, hashes_buf[0].hook_salt);
hashes->hashfile = "-"; hashes->hashfile = "-";
@ -699,16 +704,6 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx)
hash_info_tmp->orighash = hcstrdup (hash_buf); hash_info_tmp->orighash = hcstrdup (hash_buf);
} }
if (hashconfig->opts_type & OPTS_TYPE_HOOK_SALT)
{
hashinfo_t *hash_info_tmp = hashes_buf[hashes_cnt].hash_info;
if (hashconfig->hash_mode == 11600)
{
hash_info_tmp->hook_salt = hash_info_tmp->hook_salt;
}
}
if (hashconfig->is_salted) if (hashconfig->is_salted)
{ {
memset (hashes_buf[0].salt, 0, sizeof (salt_t)); memset (hashes_buf[0].salt, 0, sizeof (salt_t));
@ -947,16 +942,6 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx)
hash_info_tmp->orighash = hcstrdup (hash_buf); hash_info_tmp->orighash = hcstrdup (hash_buf);
} }
if (hashconfig->opts_type & OPTS_TYPE_HOOK_SALT)
{
hashinfo_t *hash_info_tmp = hashes_buf[hashes_cnt].hash_info;
if (hashconfig->hash_mode == 11600)
{
hash_info_tmp->hook_salt = hash_info_tmp->hook_salt;
}
}
if (hashconfig->is_salted) if (hashconfig->is_salted)
{ {
memset (hashes_buf[hashes_cnt].salt, 0, sizeof (salt_t)); memset (hashes_buf[hashes_cnt].salt, 0, sizeof (salt_t));
@ -1122,6 +1107,7 @@ int hashes_init_stage2 (hashcat_ctx_t *hashcat_ctx)
void *digests_buf_new = (void *) hccalloc (hashes_cnt, hashconfig->dgst_size); void *digests_buf_new = (void *) hccalloc (hashes_cnt, hashconfig->dgst_size);
salt_t *salts_buf_new = NULL; salt_t *salts_buf_new = NULL;
void *esalts_buf_new = NULL; void *esalts_buf_new = NULL;
void *hook_salts_buf_new = NULL;
if (hashconfig->is_salted) if (hashconfig->is_salted)
{ {
@ -1137,6 +1123,11 @@ int hashes_init_stage2 (hashcat_ctx_t *hashcat_ctx)
esalts_buf_new = (void *) hccalloc (hashes_cnt, hashconfig->esalt_size); esalts_buf_new = (void *) hccalloc (hashes_cnt, hashconfig->esalt_size);
} }
if (hashconfig->hook_salt_size)
{
hook_salts_buf_new = (void *) hccalloc (hashes_cnt, hashconfig->hook_salt_size);
}
EVENT (EVENT_HASHLIST_SORT_SALT_PRE); EVENT (EVENT_HASHLIST_SORT_SALT_PRE);
u32 digests_cnt = hashes_cnt; u32 digests_cnt = hashes_cnt;
@ -1150,7 +1141,7 @@ int hashes_init_stage2 (hashcat_ctx_t *hashcat_ctx)
hashinfo_t **hash_info = NULL; hashinfo_t **hash_info = NULL;
if ((user_options->username == true) || (hashconfig->opts_type & OPTS_TYPE_HASH_COPY) || (hashconfig->opts_type & OPTS_TYPE_HOOK_SALT)) if ((user_options->username == true) || (hashconfig->opts_type & OPTS_TYPE_HASH_COPY))
{ {
hash_info = (hashinfo_t **) hccalloc (hashes_cnt, sizeof (hashinfo_t *)); hash_info = (hashinfo_t **) hccalloc (hashes_cnt, sizeof (hashinfo_t *));
} }
@ -1177,6 +1168,15 @@ int hashes_init_stage2 (hashcat_ctx_t *hashcat_ctx)
hashes_buf[0].esalt = esalts_buf_new_ptr; hashes_buf[0].esalt = esalts_buf_new_ptr;
} }
if (hashconfig->hook_salt_size)
{
char *hook_salts_buf_new_ptr = ((char *) hook_salts_buf_new) + (salts_cnt * hashconfig->hook_salt_size);
memcpy (hook_salts_buf_new_ptr, hashes_buf[0].hook_salt, hashconfig->hook_salt_size);
hashes_buf[0].hook_salt = hook_salts_buf_new_ptr;
}
salt_buf->digests_cnt = 0; salt_buf->digests_cnt = 0;
salt_buf->digests_done = 0; salt_buf->digests_done = 0;
salt_buf->digests_offset = 0; salt_buf->digests_offset = 0;
@ -1192,7 +1192,7 @@ int hashes_init_stage2 (hashcat_ctx_t *hashcat_ctx)
hashes_buf[0].digest = digests_buf_new_ptr; hashes_buf[0].digest = digests_buf_new_ptr;
if ((user_options->username == true) || (hashconfig->opts_type & OPTS_TYPE_HASH_COPY) || (hashconfig->opts_type & OPTS_TYPE_HOOK_SALT)) if ((user_options->username == true) || (hashconfig->opts_type & OPTS_TYPE_HASH_COPY))
{ {
hash_info[0] = hashes_buf[0].hash_info; hash_info[0] = hashes_buf[0].hash_info;
} }
@ -1220,6 +1220,15 @@ int hashes_init_stage2 (hashcat_ctx_t *hashcat_ctx)
hashes_buf[hashes_pos].esalt = esalts_buf_new_ptr; hashes_buf[hashes_pos].esalt = esalts_buf_new_ptr;
} }
if (hashconfig->hook_salt_size)
{
char *hook_salts_buf_new_ptr = ((char *) hook_salts_buf_new) + (salts_cnt * hashconfig->hook_salt_size);
memcpy (hook_salts_buf_new_ptr, hashes_buf[hashes_pos].hook_salt, hashconfig->hook_salt_size);
hashes_buf[hashes_pos].hook_salt = hook_salts_buf_new_ptr;
}
salt_buf->digests_cnt = 0; salt_buf->digests_cnt = 0;
salt_buf->digests_done = 0; salt_buf->digests_done = 0;
salt_buf->digests_offset = hashes_pos; salt_buf->digests_offset = hashes_pos;
@ -1235,6 +1244,13 @@ int hashes_init_stage2 (hashcat_ctx_t *hashcat_ctx)
hashes_buf[hashes_pos].esalt = esalts_buf_new_ptr; hashes_buf[hashes_pos].esalt = esalts_buf_new_ptr;
} }
if (hashconfig->hook_salt_size)
{
char *hook_salts_buf_new_ptr = ((char *) hook_salts_buf_new) + (salts_cnt * hashconfig->hook_salt_size);
hashes_buf[hashes_pos].hook_salt = hook_salts_buf_new_ptr;
}
} }
salt_buf->digests_cnt++; salt_buf->digests_cnt++;
@ -1245,7 +1261,7 @@ int hashes_init_stage2 (hashcat_ctx_t *hashcat_ctx)
hashes_buf[hashes_pos].digest = digests_buf_new_ptr; hashes_buf[hashes_pos].digest = digests_buf_new_ptr;
if ((user_options->username == true) || (hashconfig->opts_type & OPTS_TYPE_HASH_COPY) || (hashconfig->opts_type & OPTS_TYPE_HOOK_SALT)) if ((user_options->username == true) || (hashconfig->opts_type & OPTS_TYPE_HASH_COPY))
{ {
hash_info[hashes_pos] = hashes_buf[hashes_pos].hash_info; hash_info[hashes_pos] = hashes_buf[hashes_pos].hash_info;
} }
@ -1256,6 +1272,7 @@ int hashes_init_stage2 (hashcat_ctx_t *hashcat_ctx)
hcfree (hashes->digests_buf); hcfree (hashes->digests_buf);
hcfree (hashes->salts_buf); hcfree (hashes->salts_buf);
hcfree (hashes->esalts_buf); hcfree (hashes->esalts_buf);
hcfree (hashes->hook_salts_buf);
hashes->digests_cnt = digests_cnt; hashes->digests_cnt = digests_cnt;
hashes->digests_done = digests_done; hashes->digests_done = digests_done;
@ -1269,6 +1286,7 @@ int hashes_init_stage2 (hashcat_ctx_t *hashcat_ctx)
hashes->salts_shown = salts_shown; hashes->salts_shown = salts_shown;
hashes->esalts_buf = esalts_buf_new; hashes->esalts_buf = esalts_buf_new;
hashes->hook_salts_buf = hook_salts_buf_new;
hashes->hash_info = hash_info; hashes->hash_info = hash_info;
@ -1421,9 +1439,7 @@ void hashes_destroy (hashcat_ctx_t *hashcat_ctx)
hcfree (hashes->salts_buf); hcfree (hashes->salts_buf);
hcfree (hashes->salts_shown); hcfree (hashes->salts_shown);
hcfree (hashes->esalts_buf); if ((user_options->username == true) || (hashconfig->opts_type & OPTS_TYPE_HASH_COPY))
if ((user_options->username == true) || (hashconfig->opts_type & OPTS_TYPE_HASH_COPY) || (hashconfig->opts_type & OPTS_TYPE_HOOK_SALT))
{ {
for (u32 hash_pos = 0; hash_pos < hashes->hashes_cnt; hash_pos++) for (u32 hash_pos = 0; hash_pos < hashes->hashes_cnt; hash_pos++)
{ {
@ -1436,16 +1452,14 @@ void hashes_destroy (hashcat_ctx_t *hashcat_ctx)
{ {
hcfree (hashes->hash_info[hash_pos]->orighash); hcfree (hashes->hash_info[hash_pos]->orighash);
} }
if (hashconfig->opts_type & OPTS_TYPE_HOOK_SALT)
{
hcfree (hashes->hash_info[hash_pos]->hook_salt);
}
} }
} }
hcfree (hashes->hash_info); hcfree (hashes->hash_info);
hcfree (hashes->esalts_buf);
hcfree (hashes->hook_salts_buf);
hcfree (hashes->out_buf); hcfree (hashes->out_buf);
hcfree (hashes->tmp_buf); hcfree (hashes->tmp_buf);

View File

@ -11060,7 +11060,7 @@ int seven_zip_parse_hash (u8 *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_
salt_t *salt = hash_buf->salt; salt_t *salt = hash_buf->salt;
seven_zip_hook_salt_t *seven_zip = (seven_zip_hook_salt_t *) hash_buf->hash_info->hook_salt; seven_zip_hook_salt_t *seven_zip = (seven_zip_hook_salt_t *) hash_buf->hook_salt;
/** /**
* parse line * parse line
@ -13531,12 +13531,8 @@ void seven_zip_hook_func (hc_device_param_t *device_param, hashes_t *hashes, con
{ {
seven_zip_hook_t *hook_items = (seven_zip_hook_t *) device_param->hooks_buf; seven_zip_hook_t *hook_items = (seven_zip_hook_t *) device_param->hooks_buf;
salt_t *salts_buf = hashes->salts_buf; seven_zip_hook_salt_t *seven_zips = (seven_zip_hook_salt_t *) hashes->hook_salts_buf;
salt_t salt = salts_buf[salt_pos]; seven_zip_hook_salt_t *seven_zip = &seven_zips[salt_pos];
hashinfo_t *hash_info = hashes->hash_info[salt.digests_offset];
seven_zip_hook_salt_t *seven_zip = (seven_zip_hook_salt_t *) hash_info->hook_salt;
u8 data_type = seven_zip->data_type; u8 data_type = seven_zip->data_type;
u32 *data_buf = seven_zip->data_buf; u32 *data_buf = seven_zip->data_buf;
@ -16410,11 +16406,9 @@ int ascii_digest (hashcat_ctx_t *hashcat_ctx, char *out_buf, const size_t out_le
} }
else if (hash_mode == 11600) else if (hash_mode == 11600)
{ {
u32 digest_idx = salt.digests_offset + digest_pos; seven_zip_hook_salt_t *seven_zips = (seven_zip_hook_salt_t *) hashes->hook_salts_buf;
hashinfo_t **hashinfo_ptr = hash_info; seven_zip_hook_salt_t *seven_zip = &seven_zips[salt_pos];
seven_zip_hook_salt_t *seven_zip = (seven_zip_hook_salt_t *) hashinfo_ptr[digest_idx]->hook_salt;
const u32 data_len = seven_zip->data_len; const u32 data_len = seven_zip->data_len;
@ -17302,6 +17296,7 @@ int hashconfig_init (hashcat_ctx_t *hashcat_ctx)
hashconfig->kern_type = 0; hashconfig->kern_type = 0;
hashconfig->dgst_size = 0; hashconfig->dgst_size = 0;
hashconfig->esalt_size = 0; hashconfig->esalt_size = 0;
hashconfig->hook_salt_size = 0;
hashconfig->tmp_size = 0; hashconfig->tmp_size = 0;
hashconfig->hook_size = 0; hashconfig->hook_size = 0;
hashconfig->opti_type = 0; hashconfig->opti_type = 0;
@ -20331,8 +20326,7 @@ int hashconfig_init (hashcat_ctx_t *hashcat_ctx)
hashconfig->salt_type = SALT_TYPE_EMBEDDED; hashconfig->salt_type = SALT_TYPE_EMBEDDED;
hashconfig->attack_exec = ATTACK_EXEC_OUTSIDE_KERNEL; hashconfig->attack_exec = ATTACK_EXEC_OUTSIDE_KERNEL;
hashconfig->opts_type = OPTS_TYPE_PT_GENERATE_LE hashconfig->opts_type = OPTS_TYPE_PT_GENERATE_LE
| OPTS_TYPE_HOOK23 | OPTS_TYPE_HOOK23;
| OPTS_TYPE_HOOK_SALT;
hashconfig->kern_type = KERN_TYPE_SEVEN_ZIP; hashconfig->kern_type = KERN_TYPE_SEVEN_ZIP;
hashconfig->dgst_size = DGST_SIZE_4_4; // originally DGST_SIZE_4_2 hashconfig->dgst_size = DGST_SIZE_4_4; // originally DGST_SIZE_4_2
hashconfig->parse_func = seven_zip_parse_hash; hashconfig->parse_func = seven_zip_parse_hash;
@ -21167,6 +21161,15 @@ int hashconfig_init (hashcat_ctx_t *hashcat_ctx)
case 14600: hashconfig->esalt_size = sizeof (luks_t); break; case 14600: hashconfig->esalt_size = sizeof (luks_t); break;
} }
// hook_salt_size
hashconfig->hook_salt_size = 0;
switch (hashconfig->hash_mode)
{
case 11600: hashconfig->hook_salt_size = sizeof (seven_zip_hook_salt_t); break;
}
// tmp_size // tmp_size
hashconfig->tmp_size = 4; hashconfig->tmp_size = 4;

View File

@ -29,6 +29,7 @@ static int outfile_remove (hashcat_ctx_t *hashcat_ctx)
u32 dgst_size = hashconfig->dgst_size; u32 dgst_size = hashconfig->dgst_size;
u32 is_salted = hashconfig->is_salted; u32 is_salted = hashconfig->is_salted;
u32 esalt_size = hashconfig->esalt_size; u32 esalt_size = hashconfig->esalt_size;
u32 hook_salt_size = hashconfig->hook_salt_size;
u32 hash_mode = hashconfig->hash_mode; u32 hash_mode = hashconfig->hash_mode;
char separator = hashconfig->separator; char separator = hashconfig->separator;
@ -36,12 +37,13 @@ static int outfile_remove (hashcat_ctx_t *hashcat_ctx)
u32 outfile_check_timer = user_options->outfile_check_timer; u32 outfile_check_timer = user_options->outfile_check_timer;
// buffers // buffers
hash_t hash_buf = { 0, 0, 0, 0, 0, NULL, 0 }; hash_t hash_buf = { 0, 0, 0, 0, 0, 0, NULL, 0 };
hash_buf.digest = hcmalloc (dgst_size); hash_buf.digest = hcmalloc (dgst_size);
if (is_salted) hash_buf.salt = (salt_t *) hcmalloc (sizeof (salt_t)); if (is_salted) hash_buf.salt = (salt_t *) hcmalloc (sizeof (salt_t));
if (esalt_size) hash_buf.esalt = (void *) hcmalloc (esalt_size); if (esalt_size) hash_buf.esalt = (void *) hcmalloc (esalt_size);
if (hook_salt_size) hash_buf.hook_salt = (void *) hcmalloc (hook_salt_size);
u32 digest_buf[64] = { 0 }; u32 digest_buf[64] = { 0 };
@ -293,6 +295,7 @@ static int outfile_remove (hashcat_ctx_t *hashcat_ctx)
} }
hcfree (hash_buf.esalt); hcfree (hash_buf.esalt);
hcfree (hash_buf.hook_salt);
hcfree (hash_buf.salt); hcfree (hash_buf.salt);

View File

@ -290,6 +290,7 @@ int potfile_remove_parse (hashcat_ctx_t *hashcat_ctx)
hash_buf.digest = hcmalloc (hashconfig->dgst_size); hash_buf.digest = hcmalloc (hashconfig->dgst_size);
hash_buf.salt = NULL; hash_buf.salt = NULL;
hash_buf.esalt = NULL; hash_buf.esalt = NULL;
hash_buf.hook_salt = NULL;
hash_buf.hash_info = NULL; hash_buf.hash_info = NULL;
hash_buf.cracked = 0; hash_buf.cracked = 0;
@ -303,6 +304,11 @@ int potfile_remove_parse (hashcat_ctx_t *hashcat_ctx)
hash_buf.esalt = hcmalloc (hashconfig->esalt_size); hash_buf.esalt = hcmalloc (hashconfig->esalt_size);
} }
if (hashconfig->hook_salt_size)
{
hash_buf.hook_salt = hcmalloc (hashconfig->hook_salt_size);
}
// this is usually detected by weak-hash-check // this is usually detected by weak-hash-check
// but not if bitslice // but not if bitslice
@ -365,6 +371,11 @@ int potfile_remove_parse (hashcat_ctx_t *hashcat_ctx)
memset (hash_buf.esalt, 0, hashconfig->esalt_size); memset (hash_buf.esalt, 0, hashconfig->esalt_size);
} }
if (hashconfig->hook_salt_size)
{
memset (hash_buf.hook_salt, 0, hashconfig->hook_salt_size);
}
hash_t *found = NULL; hash_t *found = NULL;
if (hashconfig->hash_mode == 6800) if (hashconfig->hash_mode == 6800)
@ -489,6 +500,11 @@ int potfile_remove_parse (hashcat_ctx_t *hashcat_ctx)
hcfree (hash_buf.esalt); hcfree (hash_buf.esalt);
} }
if (hashconfig->hook_salt_size)
{
hcfree (hash_buf.hook_salt);
}
if (hashconfig->is_salted) if (hashconfig->is_salted)
{ {
hcfree (hash_buf.salt); hcfree (hash_buf.salt);