1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-12-24 15:38:11 +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_HOOK23 = (1 << 27),
OPTS_TYPE_BINARY_HASHFILE = (1 << 28),
OPTS_TYPE_HOOK_SALT = (1 << 29),
} opts_type_t;
@ -675,8 +674,6 @@ typedef struct hashinfo
user_t *user;
char *orighash;
void *hook_salt; // additional salt info only used by the hook (host)
} hashinfo_t;
typedef struct hash
@ -684,6 +681,7 @@ typedef struct hash
void *digest;
salt_t *salt;
void *esalt;
void *hook_salt; // additional salt info only used by the hook (host)
int cracked;
hashinfo_t *hash_info;
char *pw_buf;
@ -732,6 +730,8 @@ typedef struct hashes
void *esalts_buf;
void *hook_salts_buf;
u32 hashes_cnt_orig;
u32 hashes_cnt;
hash_t *hashes_buf;
@ -762,6 +762,7 @@ struct hashconfig
u32 is_salted;
u32 esalt_size;
u32 hook_salt_size;
u32 tmp_size;
u32 hook_size;

View File

@ -561,16 +561,17 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx)
* load hashes, part II: allocate required memory, set pointers
*/
hash_t *hashes_buf = NULL;
void *digests_buf = NULL;
salt_t *salts_buf = NULL;
void *esalts_buf = NULL;
hash_t *hashes_buf = NULL;
void *digests_buf = NULL;
salt_t *salts_buf = NULL;
void *esalts_buf = NULL;
void *hook_salts_buf = NULL;
hashes_buf = (hash_t *) hccalloc (hashes_avail, sizeof (hash_t));
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;
@ -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);
}
if (hashconfig->hook_salt_size)
{
hook_salts_buf = (seven_zip_hook_salt_t *) hccalloc (hashes_avail, hashconfig->hook_salt_size);
}
}
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);
}
if (hashconfig->hook_salt_size)
{
hashes_buf[hash_pos].hook_salt = ((char *) hook_salts_buf) + (hash_pos * hashconfig->hook_salt_size);
}
}
else
{
@ -636,10 +640,11 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx)
}
}
hashes->hashes_buf = hashes_buf;
hashes->digests_buf = digests_buf;
hashes->salts_buf = salts_buf;
hashes->esalts_buf = esalts_buf;
hashes->hashes_buf = hashes_buf;
hashes->digests_buf = digests_buf;
hashes->salts_buf = salts_buf;
hashes->esalts_buf = esalts_buf;
hashes->hook_salts_buf = hook_salts_buf;
/**
* 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)
{
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 = "-";
@ -699,16 +704,6 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx)
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)
{
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);
}
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)
{
memset (hashes_buf[hashes_cnt].salt, 0, sizeof (salt_t));
@ -1119,9 +1104,10 @@ int hashes_init_stage2 (hashcat_ctx_t *hashcat_ctx)
* Now generate all the buffers required for later
*/
void *digests_buf_new = (void *) hccalloc (hashes_cnt, hashconfig->dgst_size);
salt_t *salts_buf_new = NULL;
void *esalts_buf_new = NULL;
void *digests_buf_new = (void *) hccalloc (hashes_cnt, hashconfig->dgst_size);
salt_t *salts_buf_new = NULL;
void *esalts_buf_new = NULL;
void *hook_salts_buf_new = NULL;
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);
}
if (hashconfig->hook_salt_size)
{
hook_salts_buf_new = (void *) hccalloc (hashes_cnt, hashconfig->hook_salt_size);
}
EVENT (EVENT_HASHLIST_SORT_SALT_PRE);
u32 digests_cnt = hashes_cnt;
@ -1150,7 +1141,7 @@ int hashes_init_stage2 (hashcat_ctx_t *hashcat_ctx)
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 *));
}
@ -1177,6 +1168,15 @@ int hashes_init_stage2 (hashcat_ctx_t *hashcat_ctx)
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_done = 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;
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;
}
@ -1220,6 +1220,15 @@ int hashes_init_stage2 (hashcat_ctx_t *hashcat_ctx)
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_done = 0;
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;
}
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++;
@ -1245,7 +1261,7 @@ int hashes_init_stage2 (hashcat_ctx_t *hashcat_ctx)
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;
}
@ -1256,21 +1272,23 @@ int hashes_init_stage2 (hashcat_ctx_t *hashcat_ctx)
hcfree (hashes->digests_buf);
hcfree (hashes->salts_buf);
hcfree (hashes->esalts_buf);
hcfree (hashes->hook_salts_buf);
hashes->digests_cnt = digests_cnt;
hashes->digests_done = digests_done;
hashes->digests_buf = digests_buf_new;
hashes->digests_shown = digests_shown;
hashes->digests_shown_tmp = digests_shown_tmp;
hashes->digests_cnt = digests_cnt;
hashes->digests_done = digests_done;
hashes->digests_buf = digests_buf_new;
hashes->digests_shown = digests_shown;
hashes->digests_shown_tmp = digests_shown_tmp;
hashes->salts_cnt = salts_cnt;
hashes->salts_done = salts_done;
hashes->salts_buf = salts_buf_new;
hashes->salts_shown = salts_shown;
hashes->salts_cnt = salts_cnt;
hashes->salts_done = salts_done;
hashes->salts_buf = salts_buf_new;
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;
return 0;
}
@ -1421,9 +1439,7 @@ void hashes_destroy (hashcat_ctx_t *hashcat_ctx)
hcfree (hashes->salts_buf);
hcfree (hashes->salts_shown);
hcfree (hashes->esalts_buf);
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))
{
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);
}
if (hashconfig->opts_type & OPTS_TYPE_HOOK_SALT)
{
hcfree (hashes->hash_info[hash_pos]->hook_salt);
}
}
}
hcfree (hashes->hash_info);
hcfree (hashes->esalts_buf);
hcfree (hashes->hook_salts_buf);
hcfree (hashes->out_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;
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
@ -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;
salt_t *salts_buf = hashes->salts_buf;
salt_t salt = salts_buf[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;
seven_zip_hook_salt_t *seven_zips = (seven_zip_hook_salt_t *) hashes->hook_salts_buf;
seven_zip_hook_salt_t *seven_zip = &seven_zips[salt_pos];
u8 data_type = seven_zip->data_type;
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)
{
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_zip_hook_salt_t *) hashinfo_ptr[digest_idx]->hook_salt;
seven_zip_hook_salt_t *seven_zip = &seven_zips[salt_pos];
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->dgst_size = 0;
hashconfig->esalt_size = 0;
hashconfig->hook_salt_size = 0;
hashconfig->tmp_size = 0;
hashconfig->hook_size = 0;
hashconfig->opti_type = 0;
@ -20331,8 +20326,7 @@ int hashconfig_init (hashcat_ctx_t *hashcat_ctx)
hashconfig->salt_type = SALT_TYPE_EMBEDDED;
hashconfig->attack_exec = ATTACK_EXEC_OUTSIDE_KERNEL;
hashconfig->opts_type = OPTS_TYPE_PT_GENERATE_LE
| OPTS_TYPE_HOOK23
| OPTS_TYPE_HOOK_SALT;
| OPTS_TYPE_HOOK23;
hashconfig->kern_type = KERN_TYPE_SEVEN_ZIP;
hashconfig->dgst_size = DGST_SIZE_4_4; // originally DGST_SIZE_4_2
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;
}
// 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
hashconfig->tmp_size = 4;

View File

@ -26,22 +26,24 @@ static int outfile_remove (hashcat_ctx_t *hashcat_ctx)
status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
user_options_t *user_options = hashcat_ctx->user_options;
u32 dgst_size = hashconfig->dgst_size;
u32 is_salted = hashconfig->is_salted;
u32 esalt_size = hashconfig->esalt_size;
u32 hash_mode = hashconfig->hash_mode;
char separator = hashconfig->separator;
u32 dgst_size = hashconfig->dgst_size;
u32 is_salted = hashconfig->is_salted;
u32 esalt_size = hashconfig->esalt_size;
u32 hook_salt_size = hashconfig->hook_salt_size;
u32 hash_mode = hashconfig->hash_mode;
char separator = hashconfig->separator;
char *root_directory = outcheck_ctx->root_directory;
u32 outfile_check_timer = user_options->outfile_check_timer;
// 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);
if (is_salted) hash_buf.salt = (salt_t *) hcmalloc (sizeof (salt_t));
if (esalt_size) hash_buf.esalt = (void *) hcmalloc (esalt_size);
if (is_salted) hash_buf.salt = (salt_t *) hcmalloc (sizeof (salt_t));
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 };
@ -293,6 +295,7 @@ static int outfile_remove (hashcat_ctx_t *hashcat_ctx)
}
hcfree (hash_buf.esalt);
hcfree (hash_buf.hook_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.salt = NULL;
hash_buf.esalt = NULL;
hash_buf.hook_salt = NULL;
hash_buf.hash_info = NULL;
hash_buf.cracked = 0;
@ -303,6 +304,11 @@ int potfile_remove_parse (hashcat_ctx_t *hashcat_ctx)
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
// 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);
}
if (hashconfig->hook_salt_size)
{
memset (hash_buf.hook_salt, 0, hashconfig->hook_salt_size);
}
hash_t *found = NULL;
if (hashconfig->hash_mode == 6800)
@ -489,6 +500,11 @@ int potfile_remove_parse (hashcat_ctx_t *hashcat_ctx)
hcfree (hash_buf.esalt);
}
if (hashconfig->hook_salt_size)
{
hcfree (hash_buf.hook_salt);
}
if (hashconfig->is_salted)
{
hcfree (hash_buf.salt);