1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-12-23 07:08:19 +00:00

Get rid of hash_mode in selftest.c

This commit is contained in:
jsteube 2018-12-19 10:58:06 +01:00
parent ea22065b9c
commit ac55386553
7 changed files with 224 additions and 242 deletions

View File

@ -41,6 +41,9 @@ bool module_warmup_disable (MAYBE_UNUSED const hashconfig_t *hash
int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED void *digest_buf, MAYBE_UNUSED salt_t *salt, MAYBE_UNUSED void *esalt_buf, const char *line_buf, MAYBE_UNUSED const int line_len);
int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const void *digest_buf, MAYBE_UNUSED const salt_t *salt, MAYBE_UNUSED const void *esalt_buf, char *line_buf, MAYBE_UNUSED const int line_size);
void hook12_func (hc_device_param_t *device_param, void *hook_salts_buf, const u32 salt_pos, const u64 pws_cnt);
void hook23_func (hc_device_param_t *device_param, void *hook_salts_buf, const u32 salt_pos, const u64 pws_cnt);
void module_register (module_ctx_t *module_ctx);
#endif // _MODULES_H

View File

@ -413,6 +413,7 @@ typedef enum opts_type
OPTS_TYPE_KEYBOARD_MAPPING = (1ULL << 42),
OPTS_TYPE_STATE_BUFFER_LE = (1ULL << 43),
OPTS_TYPE_STATE_BUFFER_BE = (1ULL << 44),
OPTS_TYPE_DEEP_COMP_KERNEL = (1ULL << 45), // 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;
@ -2266,6 +2267,9 @@ typedef struct module_ctx
int (*module_hash_decode) (const hashconfig_t *, void *, salt_t *, void *, const char *, const int);
int (*module_hash_encode) (const hashconfig_t *, const void *, const salt_t *, const void *, char *, int);
void (*module_hook12) (hc_device_param_t *, const void *, const u32, const u64);
void (*module_hook23) (hc_device_param_t *, const void *, const u32, const u64);
} module_ctx_t;
typedef struct hashcat_ctx

View File

@ -134,6 +134,8 @@ void module_register (module_ctx_t *module_ctx)
module_ctx->module_hash_type = module_hash_type;
module_ctx->module_hlfmt_disable = NULL;
module_ctx->module_hlfmt_pwdump_column = NULL;
module_ctx->module_hook12 = NULL;
module_ctx->module_hook23 = NULL;
module_ctx->module_hook_salt_size = NULL;
module_ctx->module_hook_size = NULL;
module_ctx->module_kern_type = module_kern_type;

View File

@ -1937,163 +1937,6 @@ u32 default_hlfmt_pwdump_column (MAYBE_UNUSED const hashconfig_t *hashconfig, MA
// migrate
void seven_zip_hook_func (hc_device_param_t *device_param, void *hook_salts_buf, const u32 salt_pos, const u64 pws_cnt)
{
seven_zip_hook_t *hook_items = (seven_zip_hook_t *) device_param->hooks_buf;
seven_zip_hook_salt_t *seven_zips = (seven_zip_hook_salt_t *) 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;
u32 unpack_size = seven_zip->unpack_size;
for (u64 pw_pos = 0; pw_pos < pws_cnt; pw_pos++)
{
// this hook data needs to be updated (the "hook_success" variable):
seven_zip_hook_t *hook_item = &hook_items[pw_pos];
const u8 *ukey = (const u8 *) hook_item->ukey;
// init AES
AES_KEY aes_key;
memset (&aes_key, 0, sizeof (aes_key));
AES_set_decrypt_key (ukey, 256, &aes_key);
int aes_len = seven_zip->aes_len;
u32 data[4];
u32 out [4];
u32 iv [4];
iv[0] = seven_zip->iv_buf[0];
iv[1] = seven_zip->iv_buf[1];
iv[2] = seven_zip->iv_buf[2];
iv[3] = seven_zip->iv_buf[3];
u32 out_full[81882];
// if aes_len > 16 we need to loop
int i = 0;
int j = 0;
for (i = 0, j = 0; i < aes_len - 16; i += 16, j += 4)
{
data[0] = data_buf[j + 0];
data[1] = data_buf[j + 1];
data[2] = data_buf[j + 2];
data[3] = data_buf[j + 3];
AES_decrypt (&aes_key, (u8*) data, (u8*) out);
out[0] ^= iv[0];
out[1] ^= iv[1];
out[2] ^= iv[2];
out[3] ^= iv[3];
iv[0] = data[0];
iv[1] = data[1];
iv[2] = data[2];
iv[3] = data[3];
out_full[j + 0] = out[0];
out_full[j + 1] = out[1];
out_full[j + 2] = out[2];
out_full[j + 3] = out[3];
}
// we need to run it at least once:
data[0] = data_buf[j + 0];
data[1] = data_buf[j + 1];
data[2] = data_buf[j + 2];
data[3] = data_buf[j + 3];
AES_decrypt (&aes_key, (u8*) data, (u8*) out);
out[0] ^= iv[0];
out[1] ^= iv[1];
out[2] ^= iv[2];
out[3] ^= iv[3];
out_full[j + 0] = out[0];
out_full[j + 1] = out[1];
out_full[j + 2] = out[2];
out_full[j + 3] = out[3];
/*
* check the CRC32 "hash"
*/
u32 seven_zip_crc = seven_zip->crc;
u32 crc;
if (data_type == 0) // uncompressed
{
crc = cpu_crc32_buffer ((u8 *) out_full, unpack_size);
}
else
{
u32 crc_len = seven_zip->crc_len;
char *coder_attributes = seven_zip->coder_attributes;
// input buffers and length
u8 *compressed_data = (u8 *) out_full;
SizeT compressed_data_len = aes_len;
// output buffers and length
unsigned char *decompressed_data;
decompressed_data = (unsigned char *) hcmalloc (crc_len);
SizeT decompressed_data_len = crc_len;
int ret;
if (data_type == 1) // LZMA1
{
ret = hc_lzma1_decompress (compressed_data, &compressed_data_len, decompressed_data, &decompressed_data_len, coder_attributes);
}
else // we only support LZMA2 in addition to LZMA1
{
ret = hc_lzma2_decompress (compressed_data, &compressed_data_len, decompressed_data, &decompressed_data_len, coder_attributes);
}
if (ret != SZ_OK)
{
hook_item->hook_success = 0;
hcfree (decompressed_data);
continue;
}
crc = cpu_crc32_buffer (decompressed_data, crc_len);
hcfree (decompressed_data);
}
if (crc == seven_zip_crc)
{
hook_item->hook_success = 1;
}
else
{
hook_item->hook_success = 0;
}
}
}
void to_hccapx_t (hashcat_ctx_t *hashcat_ctx, hccapx_t *hccapx, const u32 salt_pos, const u32 digest_pos)
{
const hashes_t *hashes = hashcat_ctx->hashes;

View File

@ -23910,6 +23910,7 @@ int hashconfig_init (hashcat_ctx_t *hashcat_ctx)
| OPTS_TYPE_AUX1
| OPTS_TYPE_AUX2
| OPTS_TYPE_AUX3
| OPTS_TYPE_DEEP_COMP_KERNEL
| OPTS_TYPE_BINARY_HASHFILE;
hashconfig->kern_type = KERN_TYPE_WPA_EAPOL_PBKDF2;
hashconfig->dgst_size = DGST_SIZE_4_4;
@ -23931,6 +23932,7 @@ int hashconfig_init (hashcat_ctx_t *hashcat_ctx)
| OPTS_TYPE_AUX1
| OPTS_TYPE_AUX2
| OPTS_TYPE_AUX3
| OPTS_TYPE_DEEP_COMP_KERNEL
| OPTS_TYPE_BINARY_HASHFILE;
hashconfig->kern_type = KERN_TYPE_WPA_EAPOL_PMK;
hashconfig->dgst_size = DGST_SIZE_4_4;
@ -25459,7 +25461,8 @@ int hashconfig_init (hashcat_ctx_t *hashcat_ctx)
case 9600: hashconfig->hash_type = HASH_TYPE_OFFICE2013;
hashconfig->salt_type = SALT_TYPE_EMBEDDED;
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_DEEP_COMP_KERNEL;
hashconfig->kern_type = KERN_TYPE_OFFICE2013;
hashconfig->dgst_size = DGST_SIZE_4_4;
hashconfig->parse_func = office2013_parse_hash;
@ -27297,7 +27300,8 @@ 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_AUX1;
| OPTS_TYPE_AUX1
| OPTS_TYPE_DEEP_COMP_KERNEL;
hashconfig->kern_type = KERN_TYPE_WPA_PMKID_PBKDF2;
hashconfig->dgst_size = DGST_SIZE_4_4;
hashconfig->parse_func = wpa_pmkid_pbkdf2_parse_hash;
@ -27315,7 +27319,8 @@ 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_AUX1;
| OPTS_TYPE_AUX1
| OPTS_TYPE_DEEP_COMP_KERNEL;
hashconfig->kern_type = KERN_TYPE_WPA_PMKID_PMK;
hashconfig->dgst_size = DGST_SIZE_4_4;
hashconfig->parse_func = wpa_pmkid_pmk_parse_hash;
@ -28187,3 +28192,161 @@ u32 default_forced_outfile_format
}
}
// goes into seven zip module
void module_hook23 (hc_device_param_t *device_param, const void *hook_salts_buf, const u32 salt_pos, const u64 pws_cnt)
{
seven_zip_hook_t *hook_items = (seven_zip_hook_t *) device_param->hooks_buf;
seven_zip_hook_salt_t *seven_zips = (seven_zip_hook_salt_t *) 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;
u32 unpack_size = seven_zip->unpack_size;
for (u64 pw_pos = 0; pw_pos < pws_cnt; pw_pos++)
{
// this hook data needs to be updated (the "hook_success" variable):
seven_zip_hook_t *hook_item = &hook_items[pw_pos];
const u8 *ukey = (const u8 *) hook_item->ukey;
// init AES
AES_KEY aes_key;
memset (&aes_key, 0, sizeof (aes_key));
AES_set_decrypt_key (ukey, 256, &aes_key);
int aes_len = seven_zip->aes_len;
u32 data[4];
u32 out [4];
u32 iv [4];
iv[0] = seven_zip->iv_buf[0];
iv[1] = seven_zip->iv_buf[1];
iv[2] = seven_zip->iv_buf[2];
iv[3] = seven_zip->iv_buf[3];
u32 out_full[81882];
// if aes_len > 16 we need to loop
int i = 0;
int j = 0;
for (i = 0, j = 0; i < aes_len - 16; i += 16, j += 4)
{
data[0] = data_buf[j + 0];
data[1] = data_buf[j + 1];
data[2] = data_buf[j + 2];
data[3] = data_buf[j + 3];
AES_decrypt (&aes_key, (u8*) data, (u8*) out);
out[0] ^= iv[0];
out[1] ^= iv[1];
out[2] ^= iv[2];
out[3] ^= iv[3];
iv[0] = data[0];
iv[1] = data[1];
iv[2] = data[2];
iv[3] = data[3];
out_full[j + 0] = out[0];
out_full[j + 1] = out[1];
out_full[j + 2] = out[2];
out_full[j + 3] = out[3];
}
// we need to run it at least once:
data[0] = data_buf[j + 0];
data[1] = data_buf[j + 1];
data[2] = data_buf[j + 2];
data[3] = data_buf[j + 3];
AES_decrypt (&aes_key, (u8*) data, (u8*) out);
out[0] ^= iv[0];
out[1] ^= iv[1];
out[2] ^= iv[2];
out[3] ^= iv[3];
out_full[j + 0] = out[0];
out_full[j + 1] = out[1];
out_full[j + 2] = out[2];
out_full[j + 3] = out[3];
/*
* check the CRC32 "hash"
*/
u32 seven_zip_crc = seven_zip->crc;
u32 crc;
if (data_type == 0) // uncompressed
{
crc = cpu_crc32_buffer ((u8 *) out_full, unpack_size);
}
else
{
u32 crc_len = seven_zip->crc_len;
char *coder_attributes = seven_zip->coder_attributes;
// input buffers and length
u8 *compressed_data = (u8 *) out_full;
SizeT compressed_data_len = aes_len;
// output buffers and length
unsigned char *decompressed_data;
decompressed_data = (unsigned char *) hcmalloc (crc_len);
SizeT decompressed_data_len = crc_len;
int ret;
if (data_type == 1) // LZMA1
{
ret = hc_lzma1_decompress (compressed_data, &compressed_data_len, decompressed_data, &decompressed_data_len, coder_attributes);
}
else // we only support LZMA2 in addition to LZMA1
{
ret = hc_lzma2_decompress (compressed_data, &compressed_data_len, decompressed_data, &decompressed_data_len, coder_attributes);
}
if (ret != SZ_OK)
{
hook_item->hook_success = 0;
hcfree (decompressed_data);
continue;
}
crc = cpu_crc32_buffer (decompressed_data, crc_len);
hcfree (decompressed_data);
}
if (crc == seven_zip_crc)
{
hook_item->hook_success = 1;
}
else
{
hook_item->hook_success = 0;
}
}
}

View File

@ -1208,6 +1208,7 @@ int choose_kernel (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param,
{
hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
hashes_t *hashes = hashcat_ctx->hashes;
module_ctx_t *module_ctx = hashcat_ctx->module_ctx;
status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
user_options_t *user_options = hashcat_ctx->user_options;
@ -1310,7 +1311,7 @@ int choose_kernel (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param,
if (CL_rc == -1) return -1;
// do something with data
module_ctx->module_hook12 (device_param, hashes->hook_salts_buf, salt_pos, pws_cnt);
CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_hooks, CL_TRUE, 0, device_param->size_hooks, device_param->hooks_buf, 0, NULL, NULL);
@ -1382,19 +1383,7 @@ int choose_kernel (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param,
if (CL_rc == -1) return -1;
/*
* The following section depends on the hash mode
*/
switch (hashconfig->hash_mode)
{
// for 7z we only need device_param->hooks_buf, but other hooks could use any info from device_param. All of them should/must update hooks_buf
case 11600: seven_zip_hook_func (device_param, hashes->hook_salts_buf, salt_pos, pws_cnt); break;
}
/*
* END of hash mode specific hook operations
*/
module_ctx->module_hook23 (device_param, hashes->hook_salts_buf, salt_pos, pws_cnt);
CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_hooks, CL_TRUE, 0, device_param->size_hooks, device_param->hooks_buf, 0, NULL, NULL);
@ -1444,7 +1433,7 @@ int choose_kernel (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param,
if (run_comp == true)
{
if ((hashconfig->hash_mode == 2500) || (hashconfig->hash_mode == 2501))
if (hashconfig->opts_type & OPTS_TYPE_DEEP_COMP_KERNEL)
{
const u32 loops_cnt = hashes->salts_buf[salt_pos].digests_cnt;
@ -1453,62 +1442,45 @@ int choose_kernel (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param,
device_param->kernel_params_buf32[28] = loops_pos;
device_param->kernel_params_buf32[29] = loops_cnt;
const u32 digests_offset = hashes->salts_buf[salt_pos].digests_offset;
if ((hashconfig->hash_mode == 2500) || (hashconfig->hash_mode == 2501))
{
const u32 digests_offset = hashes->salts_buf[salt_pos].digests_offset;
wpa_eapol_t *wpa_eapols = (wpa_eapol_t *) hashes->esalts_buf;
wpa_eapol_t *wpa_eapols = (wpa_eapol_t *) hashes->esalts_buf;
wpa_eapol_t *wpa_eapol = &wpa_eapols[digests_offset + loops_pos];
wpa_eapol_t *wpa_eapol = &wpa_eapols[digests_offset + loops_pos];
if (wpa_eapol->keyver == 1)
if (wpa_eapol->keyver == 1)
{
CL_rc = run_kernel (hashcat_ctx, device_param, KERN_RUN_AUX1, pws_cnt, false, 0);
if (CL_rc == -1) return -1;
}
else if (wpa_eapol->keyver == 2)
{
CL_rc = run_kernel (hashcat_ctx, device_param, KERN_RUN_AUX2, pws_cnt, false, 0);
if (CL_rc == -1) return -1;
}
else if (wpa_eapol->keyver == 3)
{
CL_rc = run_kernel (hashcat_ctx, device_param, KERN_RUN_AUX3, pws_cnt, false, 0);
if (CL_rc == -1) return -1;
}
}
else if (hashconfig->hash_mode == 9600)
{
CL_rc = run_kernel (hashcat_ctx, device_param, KERN_RUN_3, pws_cnt, false, 0);
if (CL_rc == -1) return -1;
}
else if ((hashconfig->hash_mode == 16800) || (hashconfig->hash_mode == 16801))
{
CL_rc = run_kernel (hashcat_ctx, device_param, KERN_RUN_AUX1, pws_cnt, false, 0);
if (CL_rc == -1) return -1;
}
else if (wpa_eapol->keyver == 2)
{
CL_rc = run_kernel (hashcat_ctx, device_param, KERN_RUN_AUX2, pws_cnt, false, 0);
if (CL_rc == -1) return -1;
}
else if (wpa_eapol->keyver == 3)
{
CL_rc = run_kernel (hashcat_ctx, device_param, KERN_RUN_AUX3, pws_cnt, false, 0);
if (CL_rc == -1) return -1;
}
if (status_ctx->run_thread_level2 == false) break;
}
}
else if (hashconfig->hash_mode == 9600)
{
const u32 loops_cnt = hashes->salts_buf[salt_pos].digests_cnt;
for (u32 loops_pos = 0; loops_pos < loops_cnt; loops_pos++)
{
device_param->kernel_params_buf32[28] = loops_pos;
device_param->kernel_params_buf32[29] = loops_cnt;
CL_rc = run_kernel (hashcat_ctx, device_param, KERN_RUN_3, pws_cnt, false, 0);
if (CL_rc == -1) return -1;
if (status_ctx->run_thread_level2 == false) break;
}
}
else if ((hashconfig->hash_mode == 16800) || (hashconfig->hash_mode == 16801))
{
const u32 loops_cnt = hashes->salts_buf[salt_pos].digests_cnt;
for (u32 loops_pos = 0; loops_pos < loops_cnt; loops_pos++)
{
device_param->kernel_params_buf32[28] = loops_pos;
device_param->kernel_params_buf32[29] = loops_cnt;
CL_rc = run_kernel (hashcat_ctx, device_param, KERN_RUN_AUX1, pws_cnt, false, 0);
if (CL_rc == -1) return -1;
if (status_ctx->run_thread_level2 == false) break;
}

View File

@ -17,6 +17,7 @@ static int selftest (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param
{
hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
hashes_t *hashes = hashcat_ctx->hashes;
module_ctx_t *module_ctx = hashcat_ctx->module_ctx;
status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
user_options_t *user_options = hashcat_ctx->user_options;
user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra;
@ -372,7 +373,7 @@ static int selftest (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param
if (CL_rc == -1) return -1;
// do something with data
module_ctx->module_hook12 (device_param, hashes->st_hook_salts_buf, 0, 1);
CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_hooks, CL_TRUE, 0, device_param->size_hooks, device_param->hooks_buf, 0, NULL, NULL);
@ -415,19 +416,7 @@ static int selftest (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param
if (CL_rc == -1) return -1;
/*
* The following section depends on the hash mode
*/
switch (hashconfig->hash_mode)
{
// for 7z we only need device_param->hooks_buf, but other hooks could use any info from device_param. All of them should/must update hooks_buf
case 11600: seven_zip_hook_func (device_param, hashes->st_hook_salts_buf, 0, 1); break;
}
/*
* END of hash mode specific hook operations
*/
module_ctx->module_hook23 (device_param, hashes->st_hook_salts_buf, 0, 1);
CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_hooks, CL_TRUE, 0, device_param->size_hooks, device_param->hooks_buf, 0, NULL, NULL);
@ -460,21 +449,27 @@ static int selftest (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param
}
}
if ((hashconfig->hash_mode == 2500) || (hashconfig->hash_mode == 2501))
if (hashconfig->opts_type & OPTS_TYPE_DEEP_COMP_KERNEL)
{
device_param->kernel_params_buf32[28] = 0;
device_param->kernel_params_buf32[29] = 1;
}
if (hashconfig->opts_type & OPTS_TYPE_AUX1)
{
CL_rc = run_kernel (hashcat_ctx, device_param, KERN_RUN_AUX1, 1, false, 0);
if (CL_rc == -1) return -1;
}
else if ((hashconfig->hash_mode == 16800) || (hashconfig->hash_mode == 16801))
else if (hashconfig->opts_type & OPTS_TYPE_AUX2)
{
device_param->kernel_params_buf32[28] = 0;
device_param->kernel_params_buf32[29] = 1;
CL_rc = run_kernel (hashcat_ctx, device_param, KERN_RUN_AUX2, 1, false, 0);
CL_rc = run_kernel (hashcat_ctx, device_param, KERN_RUN_AUX1, 1, false, 0);
if (CL_rc == -1) return -1;
}
else if (hashconfig->opts_type & OPTS_TYPE_AUX3)
{
CL_rc = run_kernel (hashcat_ctx, device_param, KERN_RUN_AUX3, 1, false, 0);
if (CL_rc == -1) return -1;
}