From 888da50aad404c1902e1621359b94b8fe96cb9ec Mon Sep 17 00:00:00 2001 From: jsteube Date: Sat, 5 Jan 2019 19:18:30 +0100 Subject: [PATCH] Get rid of hash_mode depending branches in status.c --- include/modules.h | 1 + include/types.h | 1 + modules/module_01000.c | 3 +- src/interface.c | 1 - src/interface_migrate.c | 61 ++++++++++++++++++++++++++++++++ src/status.c | 77 ++++++++++------------------------------- 6 files changed, 84 insertions(+), 60 deletions(-) diff --git a/include/modules.h b/include/modules.h index c8e453d77..374040eec 100644 --- a/include/modules.h +++ b/include/modules.h @@ -52,6 +52,7 @@ bool module_warmup_disable (MAYBE_UNUSED const hashconfig_t *ha int module_hash_decode_outfile (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_decode_zero_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED void *digest_buf, MAYBE_UNUSED salt_t *salt, MAYBE_UNUSED void *esalt_buf); 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_status (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); 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); u64 module_extra_buffer_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra, MAYBE_UNUSED const hashes_t *hashes, MAYBE_UNUSED const hc_device_param_t *device_param); diff --git a/include/types.h b/include/types.h index 35f9e4e31..07a9025b2 100644 --- a/include/types.h +++ b/include/types.h @@ -2297,6 +2297,7 @@ typedef struct module_ctx int (*module_hash_decode_outfile) (const hashconfig_t *, void *, salt_t *, void *, const char *, const int); int (*module_hash_decode_zero_hash) (const hashconfig_t *, void *, salt_t *, void *); int (*module_hash_decode) (const hashconfig_t *, void *, salt_t *, void *, const char *, const int); + int (*module_hash_encode_status) (const hashconfig_t *, const void *, const salt_t *, const void *, char *, int); int (*module_hash_encode) (const hashconfig_t *, const void *, const salt_t *, const void *, char *, int); u64 (*module_extra_buffer_size) (const hashconfig_t *, const user_options_t *, const user_options_extra_t *, const hashes_t *, const hc_device_param_t *); diff --git a/modules/module_01000.c b/modules/module_01000.c index 7c9f8b7ac..642cf7746 100644 --- a/modules/module_01000.c +++ b/modules/module_01000.c @@ -131,9 +131,10 @@ void module_init (module_ctx_t *module_ctx) module_ctx->module_esalt_size = NULL; module_ctx->module_extra_buffer_size = NULL; module_ctx->module_forced_outfile_format = NULL; - module_ctx->module_hash_decode = module_hash_decode; module_ctx->module_hash_decode_outfile = NULL; module_ctx->module_hash_decode_zero_hash = NULL; + module_ctx->module_hash_decode = module_hash_decode; + module_ctx->module_hash_encode_status = NULL; module_ctx->module_hash_encode = module_hash_encode; module_ctx->module_hash_mode = NULL; module_ctx->module_hash_name = module_hash_name; diff --git a/src/interface.c b/src/interface.c index 1eb9f4776..b89239405 100644 --- a/src/interface.c +++ b/src/interface.c @@ -592,7 +592,6 @@ int ascii_digest (const hashconfig_t *hashconfig, const hashes_t *hashes, const return out_len; - /* if (salt_type == SALT_TYPE_GENERIC) { diff --git a/src/interface_migrate.c b/src/interface_migrate.c index 94b56508c..b4fd1cd51 100644 --- a/src/interface_migrate.c +++ b/src/interface_migrate.c @@ -28994,5 +28994,66 @@ u32 module_deep_comp_kernel (MAYBE_UNUSED const hashes_t *hashes, MAYBE_UNUSED c } } +int module_hash_encode_status (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) +{ + if (hashes->digests_cnt == 1) + { + if ((hashconfig->hash_mode == 2500) || (hashconfig->hash_mode == 2501)) + { + char *tmp_buf; + + wpa_eapol_t *wpa_eapol = (wpa_eapol_t *) hashes->esalts_buf; + + hc_asprintf (&tmp_buf, "%s (AP:%02x:%02x:%02x:%02x:%02x:%02x STA:%02x:%02x:%02x:%02x:%02x:%02x)", + (char *) hashes->salts_buf[0].salt_buf, + wpa_eapol->orig_mac_ap[0], + wpa_eapol->orig_mac_ap[1], + wpa_eapol->orig_mac_ap[2], + wpa_eapol->orig_mac_ap[3], + wpa_eapol->orig_mac_ap[4], + wpa_eapol->orig_mac_ap[5], + wpa_eapol->orig_mac_sta[0], + wpa_eapol->orig_mac_sta[1], + wpa_eapol->orig_mac_sta[2], + wpa_eapol->orig_mac_sta[3], + wpa_eapol->orig_mac_sta[4], + wpa_eapol->orig_mac_sta[5]); + + return tmp_buf; + } + else if (hashconfig->hash_mode == 5200) + { + return hashes->hashfile; + } + else if (hashconfig->hash_mode == 9000) + { + return hashes->hashfile; + } + else if ((hashconfig->hash_mode >= 6200) && (hashconfig->hash_mode <= 6299)) + { + return hashes->hashfile; + } + else if ((hashconfig->hash_mode >= 13700) && (hashconfig->hash_mode <= 13799)) + { + return hashes->hashfile; + } + } + else + { + if (hashconfig->hash_mode == 3000) + { + char *tmp_buf; + + char out_buf1[64] = { 0 }; + char out_buf2[64] = { 0 }; + ascii_digest (hashcat_ctx->hashconfig, hashcat_ctx->hashes, hashcat_ctx->module_ctx, out_buf1, sizeof (out_buf1), 0, 0); + ascii_digest (hashcat_ctx->hashconfig, hashcat_ctx->hashes, hashcat_ctx->module_ctx, out_buf2, sizeof (out_buf2), 0, 1); + + hc_asprintf (&tmp_buf, "%s, %s", out_buf1, out_buf2); + + return tmp_buf; + } + } +} diff --git a/src/status.c b/src/status.c index f6cca5c3e..18b01ccfa 100644 --- a/src/status.c +++ b/src/status.c @@ -300,80 +300,41 @@ const char *status_get_hash_target (const hashcat_ctx_t *hashcat_ctx) { const hashconfig_t *hashconfig = hashcat_ctx->hashconfig; const hashes_t *hashes = hashcat_ctx->hashes; + const module_ctx_t *module_ctx = hashcat_ctx->module_ctx; - if (hashes->digests_cnt == 1) + if (module_ctx->module_hash_encode_status) { - if ((hashconfig->hash_mode == 2500) || (hashconfig->hash_mode == 2501)) - { - char *tmp_buf; - - wpa_eapol_t *wpa_eapol = (wpa_eapol_t *) hashes->esalts_buf; - - hc_asprintf (&tmp_buf, "%s (AP:%02x:%02x:%02x:%02x:%02x:%02x STA:%02x:%02x:%02x:%02x:%02x:%02x)", - (char *) hashes->salts_buf[0].salt_buf, - wpa_eapol->orig_mac_ap[0], - wpa_eapol->orig_mac_ap[1], - wpa_eapol->orig_mac_ap[2], - wpa_eapol->orig_mac_ap[3], - wpa_eapol->orig_mac_ap[4], - wpa_eapol->orig_mac_ap[5], - wpa_eapol->orig_mac_sta[0], - wpa_eapol->orig_mac_sta[1], - wpa_eapol->orig_mac_sta[2], - wpa_eapol->orig_mac_sta[3], - wpa_eapol->orig_mac_sta[4], - wpa_eapol->orig_mac_sta[5]); - - return tmp_buf; - } - else if (hashconfig->hash_mode == 5200) - { - return hashes->hashfile; - } - else if (hashconfig->hash_mode == 9000) - { - return hashes->hashfile; - } - else if ((hashconfig->hash_mode >= 6200) && (hashconfig->hash_mode <= 6299)) - { - return hashes->hashfile; - } - else if ((hashconfig->hash_mode >= 13700) && (hashconfig->hash_mode <= 13799)) - { - return hashes->hashfile; - } - else - { - char *tmp_buf = (char *) hcmalloc (HCBUFSIZ_LARGE); + char *tmp_buf = (char *) hcmalloc (HCBUFSIZ_LARGE); - tmp_buf[0] = 0; + const int tmp_len = module_ctx->module_hash_encode_status (hashconfig, hashes->digests_buf, hashes->salts_buf, hashes->esalts_buf, tmp_buf, HCBUFSIZ_LARGE); - ascii_digest (hashcat_ctx->hashconfig, hashcat_ctx->hashes, hashcat_ctx->module_ctx, tmp_buf, HCBUFSIZ_LARGE, 0, 0); + char *tmp_buf2 = (char *) hcmalloc (tmp_len + 1); - compress_terminal_line_length (tmp_buf, 19, 6); // 19 = strlen ("Hash.Target......: ") + memcpy (tmp_buf2, tmp_buf, tmp_len); - char *tmp_buf2 = strdup (tmp_buf); + free (tmp_buf); - free (tmp_buf); + tmp_buf2[tmp_len] = 0; - return tmp_buf2; - } + return tmp_buf2; } else { - if (hashconfig->hash_mode == 3000) + if (hashes->digests_cnt == 1) { - char *tmp_buf; + char *tmp_buf = (char *) hcmalloc (HCBUFSIZ_LARGE); - char out_buf1[64] = { 0 }; - char out_buf2[64] = { 0 }; + tmp_buf[0] = 0; + + ascii_digest (hashcat_ctx->hashconfig, hashcat_ctx->hashes, hashcat_ctx->module_ctx, tmp_buf, HCBUFSIZ_LARGE, 0, 0); + + compress_terminal_line_length (tmp_buf, 19, 6); // 19 = strlen ("Hash.Target......: ") - ascii_digest (hashcat_ctx->hashconfig, hashcat_ctx->hashes, hashcat_ctx->module_ctx, out_buf1, sizeof (out_buf1), 0, 0); - ascii_digest (hashcat_ctx->hashconfig, hashcat_ctx->hashes, hashcat_ctx->module_ctx, out_buf2, sizeof (out_buf2), 0, 1); + char *tmp_buf2 = strdup (tmp_buf); - hc_asprintf (&tmp_buf, "%s, %s", out_buf1, out_buf2); + free (tmp_buf); - return tmp_buf; + return tmp_buf2; } else {