From e537197184394320298dec0e61fc74afe7b8f2e8 Mon Sep 17 00:00:00 2001 From: jsteube Date: Thu, 3 Jan 2019 15:43:19 +0100 Subject: [PATCH] Add module_build_plain_postprocess() --- include/modules.h | 16 +++++++++------- include/types.h | 2 ++ modules/module_01000.c | 1 + src/hashes.c | 25 +++++++++++++------------ src/interface.c | 1 - src/interface_migrate.c | 16 ++++++++++++++++ 6 files changed, 41 insertions(+), 20 deletions(-) diff --git a/include/modules.h b/include/modules.h index d11807a83..bb0d68d01 100644 --- a/include/modules.h +++ b/include/modules.h @@ -2,6 +2,8 @@ #ifndef _MODULES_H #define _MODULES_H +void module_init (module_ctx_t *module_ctx); + u32 module_attack_exec (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra); void *module_benchmark_esalt (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra); void *module_benchmark_hook_salt (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra); @@ -42,14 +44,14 @@ const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *ha u64 module_tmp_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); bool module_warmup_disable (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra); -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 (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_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 (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_hook12 (hc_device_param_t *device_param, void *hook_salts_buf, const u32 salt_pos, const u64 pws_cnt); +void module_hook23 (hc_device_param_t *device_param, void *hook_salts_buf, const u32 salt_pos, const u64 pws_cnt); -void module_init (module_ctx_t *module_ctx); +int module_build_plain_postprocess (const u32 *src_buf, MAYBE_UNUSED const size_t src_sz, const int src_len, u32 *dst_buf, MAYBE_UNUSED const size_t dst_sz); #endif // _MODULES_H diff --git a/include/types.h b/include/types.h index 97637cb92..da4a90a79 100644 --- a/include/types.h +++ b/include/types.h @@ -2288,6 +2288,8 @@ typedef struct module_ctx 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); + int (*module_build_plain_postprocess) (const u32 *, const size_t, const int, u32 *, const size_t); + } module_ctx_t; typedef struct hashcat_ctx diff --git a/modules/module_01000.c b/modules/module_01000.c index 83a884b90..99e248e4a 100644 --- a/modules/module_01000.c +++ b/modules/module_01000.c @@ -120,6 +120,7 @@ void module_init (module_ctx_t *module_ctx) module_ctx->module_benchmark_hook_salt = NULL; module_ctx->module_benchmark_mask = NULL; module_ctx->module_benchmark_salt = NULL; + module_ctx->module_build_plain_postprocess = NULL; module_ctx->module_dgst_pos0 = module_dgst_pos0; module_ctx->module_dgst_pos1 = module_dgst_pos1; module_ctx->module_dgst_pos2 = module_dgst_pos2; diff --git a/src/hashes.c b/src/hashes.c index 6009ffa00..9e465d448 100644 --- a/src/hashes.c +++ b/src/hashes.c @@ -263,10 +263,11 @@ int save_hash (hashcat_ctx_t *hashcat_ctx) void check_hash (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, plain_t *plain) { - debugfile_ctx_t *debugfile_ctx = hashcat_ctx->debugfile_ctx; - loopback_ctx_t *loopback_ctx = hashcat_ctx->loopback_ctx; - hashes_t *hashes = hashcat_ctx->hashes; - hashconfig_t *hashconfig = hashcat_ctx->hashconfig; + const debugfile_ctx_t *debugfile_ctx = hashcat_ctx->debugfile_ctx; + const hashes_t *hashes = hashcat_ctx->hashes; + const hashconfig_t *hashconfig = hashcat_ctx->hashconfig; + const loopback_ctx_t *loopback_ctx = hashcat_ctx->loopback_ctx; + const module_ctx_t *module_ctx = hashcat_ctx->module_ctx; const u32 salt_pos = plain->salt_pos; const u32 digest_pos = plain->digest_pos; // relative @@ -288,18 +289,18 @@ void check_hash (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, pl build_plain (hashcat_ctx, device_param, plain, plain_buf, &plain_len); - // TOTP should be base32 encoded - if (hashconfig->hash_mode == KERN_TYPE_TOTP_HMACSHA1) + if (module_ctx->module_build_plain_postprocess) { - // we need a temp buffer for the base32 encoding u32 temp_buf[64] = { 0 }; - u8 *temp_ptr = (u8 *) temp_buf; - // encode our plain - plain_len = base32_encode (int_to_base32, (const u8 *) plain_ptr, plain_len, (u8 *) temp_buf); + const int temp_len = module_ctx->module_build_plain_postprocess (plain_buf, sizeof (plain_buf), plain_len, temp_buf, sizeof (temp_buf)); - // copy the base32 content into our plain buffer - strncpy ((char *) plain_ptr, (char *) temp_ptr, sizeof (plain_buf)); + if (temp_len < (int) sizeof (plain_buf)) + { + memcpy (plain_buf, temp_buf, temp_len); + + plain_len = temp_len; + } } // crackpos diff --git a/src/interface.c b/src/interface.c index adeff4f05..e0a35a9e6 100644 --- a/src/interface.c +++ b/src/interface.c @@ -1425,7 +1425,6 @@ bool default_potfile_disable (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE return potfile_disable; } - // migrate void to_hccapx_t (hashcat_ctx_t *hashcat_ctx, hccapx_t *hccapx, const u32 salt_pos, const u32 digest_pos) diff --git a/src/interface_migrate.c b/src/interface_migrate.c index b7a74e7c0..576628fed 100644 --- a/src/interface_migrate.c +++ b/src/interface_migrate.c @@ -28533,3 +28533,19 @@ bool potfile_keep_all_hashes } } + + + +int build_plain_postprocess (const u32 *src_buf, MAYBE_UNUSED const size_t src_sz, const int src_len, u32 *dst_buf, MAYBE_UNUSED const size_t dst_sz) +{ + // TOTP should be base32 encoded + if (hashconfig->hash_mode == 18100) + { + + + // encode our plain + return base32_encode (int_to_base32, (const u8 *) src_buf, src_len, (u8 *) temp_buf); + + + } +}