From dcaba1f4737176334a80461f145fa31657bb481f Mon Sep 17 00:00:00 2001 From: Jens Steube Date: Sat, 26 Jun 2021 20:24:45 +0200 Subject: [PATCH] Brain: Add brain_ctx_t to hashcat_ctx_t to enable runtime check if hashcat was compiled with brain support --- docs/changes.txt | 2 ++ include/brain.h | 3 +++ include/types.h | 8 ++++++++ src/brain.c | 35 +++++++++++++++++++++++++++++++++++ src/hashcat.c | 9 +++++++++ 5 files changed, 57 insertions(+) diff --git a/docs/changes.txt b/docs/changes.txt index d31edcd16..3f7a1ad6d 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -11,6 +11,7 @@ - Added hash-mode: AES-192-ECB NOKDF (PT = $salt, key = $pass) - Added hash-mode: AES-256-ECB NOKDF (PT = $salt, key = $pass) + ## ## Bugs ## @@ -40,6 +41,7 @@ ## Technical ## +- Brain: Add brain_ctx_t to hashcat_ctx_t to enable runtime check if hashcat was compiled with brain support - Autodetect: Limit the number of errors per hash-mode try to 100 to avoid long startup time - Folders: Do not escape the variable cpath_real to prevent certain OpenCL runtimes from running into an error which do not support escape characters - LM: Workaround JiT compiler bug in -m 3000 on NV leading to false negatives with large amount of hashes diff --git a/include/brain.h b/include/brain.h index fcd370772..d6dc7ec7a 100644 --- a/include/brain.h +++ b/include/brain.h @@ -249,4 +249,7 @@ void brain_server_db_attack_init (brain_server_db_attack_t *brain_server_ bool brain_server_db_attack_realloc (brain_server_db_attack_t *brain_server_db_attack, const i64 new_long_cnt, const i64 new_short_cnt); void brain_server_db_attack_free (brain_server_db_attack_t *brain_server_db_attack); +int brain_ctx_init (hashcat_ctx_t *hashcat_ctx); +void brain_ctx_destroy (hashcat_ctx_t *hashcat_ctx); + #endif // _BRAIN_H diff --git a/include/types.h b/include/types.h index 3c0afe9ec..b8565ac0f 100644 --- a/include/types.h +++ b/include/types.h @@ -2120,6 +2120,13 @@ typedef struct user_options_extra } user_options_extra_t; +typedef struct brain_ctx +{ + bool support; // general brain support compiled in (server or client) + bool enabled; // brain support required by user request on command line + +} brain_ctx_t; + typedef struct bitmap_ctx { bool enabled; @@ -2585,6 +2592,7 @@ typedef struct module_ctx typedef struct hashcat_ctx { + brain_ctx_t *brain_ctx; bitmap_ctx_t *bitmap_ctx; combinator_ctx_t *combinator_ctx; cpt_ctx_t *cpt_ctx; diff --git a/src/brain.c b/src/brain.c index 1243d936a..371e818f6 100644 --- a/src/brain.c +++ b/src/brain.c @@ -3352,3 +3352,38 @@ int brain_server (const char *listen_host, const int listen_port, const char *br return 0; } + +int brain_ctx_init (hashcat_ctx_t *hashcat_ctx) +{ + brain_ctx_t *brain_ctx = hashcat_ctx->brain_ctx; + user_options_t *user_options = hashcat_ctx->user_options; + + #ifdef WITH_BRAIN + brain_ctx->support = true; + #else + brain_ctx->support = false; + #endif + + if (brain_ctx->support == false) return 0; + + if (user_options->brain_client == true) + { + brain_ctx->enabled = true; + } + + if (user_options->brain_server == true) + { + brain_ctx->enabled = true; + } + + return 0; +} + +void brain_ctx_destroy (hashcat_ctx_t *hashcat_ctx) +{ + brain_ctx_t *brain_ctx = hashcat_ctx->brain_ctx; + + if (brain_ctx->support == false) return; + + memset (brain_ctx, 0, sizeof (brain_ctx_t)); +} diff --git a/src/hashcat.c b/src/hashcat.c index c1544d872..e4ac1a549 100644 --- a/src/hashcat.c +++ b/src/hashcat.c @@ -868,6 +868,7 @@ static int outer_loop (hashcat_ctx_t *hashcat_ctx) // clean up + brain_ctx_destroy (hashcat_ctx); bitmap_ctx_destroy (hashcat_ctx); combinator_ctx_destroy (hashcat_ctx); cpt_ctx_destroy (hashcat_ctx); @@ -897,6 +898,7 @@ int hashcat_init (hashcat_ctx_t *hashcat_ctx, void (*event) (const u32, struct h hashcat_ctx->event = event; } + hashcat_ctx->brain_ctx = (brain_ctx_t *) hcmalloc (sizeof (brain_ctx_t)); hashcat_ctx->bitmap_ctx = (bitmap_ctx_t *) hcmalloc (sizeof (bitmap_ctx_t)); hashcat_ctx->combinator_ctx = (combinator_ctx_t *) hcmalloc (sizeof (combinator_ctx_t)); hashcat_ctx->cpt_ctx = (cpt_ctx_t *) hcmalloc (sizeof (cpt_ctx_t)); @@ -931,6 +933,7 @@ int hashcat_init (hashcat_ctx_t *hashcat_ctx, void (*event) (const u32, struct h void hashcat_destroy (hashcat_ctx_t *hashcat_ctx) { + hcfree (hashcat_ctx->brain_ctx); hcfree (hashcat_ctx->bitmap_ctx); hcfree (hashcat_ctx->combinator_ctx); hcfree (hashcat_ctx->cpt_ctx); @@ -1035,6 +1038,12 @@ int hashcat_session_init (hashcat_ctx_t *hashcat_ctx, const char *install_folder #endif #endif + /** + * brain + */ + + if (brain_ctx_init (hashcat_ctx) == -1) return -1; + /** * logfile */