From b2e120ba693cf822afb9e5d9b7a5971984753b4f Mon Sep 17 00:00:00 2001 From: PenguinKeeper7 Date: Thu, 29 Feb 2024 23:32:35 +0000 Subject: [PATCH 1/8] Add --increment-inverse https://github.com/hashcat/hashcat/issues/3959 --- include/types.h | 3 +++ src/mpsp.c | 40 +++++++++++++++++++++++++++++++++++++--- src/user_options.c | 19 +++++++++++++++++++ 3 files changed, 59 insertions(+), 3 deletions(-) diff --git a/include/types.h b/include/types.h index e6ea946f9..85301d862 100644 --- a/include/types.h +++ b/include/types.h @@ -655,6 +655,7 @@ typedef enum user_options_defaults HOOK_THREADS = 0, IDENTIFY = false, INCREMENT = false, + INCREMENT_INVERSE = false, INCREMENT_MAX = PW_MAX, INCREMENT_MIN = 1, KEEP_GUESSING = false, @@ -774,6 +775,7 @@ typedef enum user_options_map IDX_HOOK_THREADS = 0xff1f, IDX_IDENTIFY = 0xff20, IDX_INCREMENT = 'i', + IDX_INCREMENT_INVERSE = 0xff56, IDX_INCREMENT_MAX = 0xff21, IDX_INCREMENT_MIN = 0xff22, IDX_INDUCTION_DIR = 0xff23, @@ -2349,6 +2351,7 @@ typedef struct user_options bool hex_salt; bool hex_wordlist; bool increment; + bool increment_inverse; bool keep_guessing; bool keyspace; bool left; diff --git a/src/mpsp.c b/src/mpsp.c index 3efe345d7..c316a6db7 100644 --- a/src/mpsp.c +++ b/src/mpsp.c @@ -1072,6 +1072,26 @@ static int mask_append_final (hashcat_ctx_t *hashcat_ctx, const char *mask) return 0; } +// ?l?u?d -> ?d?u?l +static char* reverseMask(const char *mask) { + int length = strlen(mask); + char *tmp_buf = (char *) hcmalloc (256); + + for (int i = length - 1, j = 0; i >= 0; i--) { + if (mask[i] == '\0') + continue; + if (i != 0 && mask[i - 1] == '?') { + tmp_buf[j++] = '?'; + tmp_buf[j++] = mask[i]; + i--; + } else { + tmp_buf[j++] = mask[i]; + } + } + + return tmp_buf; +} + static int mask_append (hashcat_ctx_t *hashcat_ctx, const char *mask, const char *prepend) { hashconfig_t *hashconfig = hashcat_ctx->hashconfig; @@ -1108,11 +1128,25 @@ static int mask_append (hashcat_ctx_t *hashcat_ctx, const char *mask, const char mask_truncated_next += snprintf (mask_truncated, 256, "%s,", prepend); } - if (mp_get_truncated_mask (hashcat_ctx, mask, strlen (mask), increment_len, mask_truncated_next) == -1) + if (user_options->increment_inverse == true) { - hcfree (mask_truncated); + if (mp_get_truncated_mask (hashcat_ctx, reverseMask(mask), strlen (mask), increment_len, mask_truncated_next) == -1) + { + hcfree (mask_truncated); - break; + break; + } + + mask_truncated = reverseMask(mask_truncated); + } + else + { + if (mp_get_truncated_mask (hashcat_ctx, mask, strlen (mask), increment_len, mask_truncated_next) == -1) + { + hcfree (mask_truncated); + + break; + } } const int rc = mask_append_final (hashcat_ctx, mask_truncated); diff --git a/src/user_options.c b/src/user_options.c index b1ed588f4..ec7430540 100644 --- a/src/user_options.c +++ b/src/user_options.c @@ -78,6 +78,7 @@ static const struct option long_options[] = {"increment-max", required_argument, NULL, IDX_INCREMENT_MAX}, {"increment-min", required_argument, NULL, IDX_INCREMENT_MIN}, {"increment", no_argument, NULL, IDX_INCREMENT}, + {"increment-inverse", no_argument, NULL, IDX_INCREMENT_INVERSE}, {"induction-dir", required_argument, NULL, IDX_INDUCTION_DIR}, {"keep-guessing", no_argument, NULL, IDX_KEEP_GUESSING}, {"kernel-accel", required_argument, NULL, IDX_KERNEL_ACCEL}, @@ -221,6 +222,7 @@ int user_options_init (hashcat_ctx_t *hashcat_ctx) user_options->hook_threads = HOOK_THREADS; user_options->identify = IDENTIFY; user_options->increment = INCREMENT; + user_options->increment = INCREMENT_INVERSE; user_options->increment_max = INCREMENT_MAX; user_options->increment_min = INCREMENT_MIN; user_options->induction_dir = NULL; @@ -524,6 +526,7 @@ int user_options_getopt (hashcat_ctx_t *hashcat_ctx, int argc, char **argv) case IDX_BITMAP_MAX: user_options->bitmap_max = hc_strtoul (optarg, NULL, 10); break; case IDX_HOOK_THREADS: user_options->hook_threads = hc_strtoul (optarg, NULL, 10); break; case IDX_INCREMENT: user_options->increment = true; break; + case IDX_INCREMENT_INVERSE: user_options->increment_inverse = true; break; case IDX_INCREMENT_MIN: user_options->increment_min = hc_strtoul (optarg, NULL, 10); user_options->increment_min_chgd = true; break; case IDX_INCREMENT_MAX: user_options->increment_max = hc_strtoul (optarg, NULL, 10); @@ -865,6 +868,13 @@ int user_options_sanity (hashcat_ctx_t *hashcat_ctx) return -1; } + if ((user_options->increment == false) && (user_options->increment_inverse == true)) + { + event_log_error (hashcat_ctx, "Increment-inverse is only supported combined with -i/--increment."); + + return -1; + } + if (user_options->increment_min > user_options->increment_max) { event_log_error (hashcat_ctx, "Invalid --increment-min value specified - must be >= --increment-max."); @@ -1305,6 +1315,13 @@ int user_options_sanity (hashcat_ctx_t *hashcat_ctx) return -1; } + if (user_options->increment_inverse == true) + { + event_log_error (hashcat_ctx, "Can't change --increment-inverse in benchmark mode."); + + return -1; + } + if (user_options->restore == true) { event_log_error (hashcat_ctx, "Can't change --restore in benchmark mode."); @@ -1883,6 +1900,7 @@ void user_options_preprocess (hashcat_ctx_t *hashcat_ctx) user_options->attack_mode = ATTACK_MODE_BF; user_options->hwmon_temp_abort = 0; user_options->increment = false; + user_options->increment_inverse = false; user_options->left = false; user_options->logfile = false; user_options->spin_damp = 0; @@ -3243,6 +3261,7 @@ void user_options_logger (hashcat_ctx_t *hashcat_ctx) logfile_top_uint (user_options->hook_threads); logfile_top_uint (user_options->identify); logfile_top_uint (user_options->increment); + logfile_top_uint (user_options->increment_inverse); logfile_top_uint (user_options->increment_max); logfile_top_uint (user_options->increment_min); logfile_top_uint (user_options->keep_guessing); From e55939a99cbb87cfbf05a76474240be349496b0a Mon Sep 17 00:00:00 2001 From: PenguinKeeper7 Date: Thu, 29 Feb 2024 23:41:02 +0000 Subject: [PATCH 2/8] Add whitespace formatting --- src/mpsp.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/mpsp.c b/src/mpsp.c index c316a6db7..e9109590e 100644 --- a/src/mpsp.c +++ b/src/mpsp.c @@ -1073,8 +1073,8 @@ static int mask_append_final (hashcat_ctx_t *hashcat_ctx, const char *mask) } // ?l?u?d -> ?d?u?l -static char* reverseMask(const char *mask) { - int length = strlen(mask); +static char* reverseMask (const char *mask) { + int length = strlen (mask); char *tmp_buf = (char *) hcmalloc (256); for (int i = length - 1, j = 0; i >= 0; i--) { @@ -1130,14 +1130,14 @@ static int mask_append (hashcat_ctx_t *hashcat_ctx, const char *mask, const char if (user_options->increment_inverse == true) { - if (mp_get_truncated_mask (hashcat_ctx, reverseMask(mask), strlen (mask), increment_len, mask_truncated_next) == -1) + if (mp_get_truncated_mask (hashcat_ctx, reverseMask (mask), strlen (mask), increment_len, mask_truncated_next) == -1) { hcfree (mask_truncated); break; } - mask_truncated = reverseMask(mask_truncated); + mask_truncated = reverseMask (mask_truncated); } else { From 73959cbad57b63fec369b7fe8a245f396891474a Mon Sep 17 00:00:00 2001 From: PenguinKeeper7 Date: Fri, 1 Mar 2024 00:00:30 +0000 Subject: [PATCH 3/8] Update changes.txt --- docs/changes.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changes.txt b/docs/changes.txt index 283e3c0d4..d9bf7b630 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -441,6 +441,7 @@ - Added option --markov-inverse to inverse markov statistics, with the idea of reversing the order of the password candidates - Added temperature watchdog and fanspeed readings for CPU and GPU on macOS using iokit - Added temperature watchdog and utilization for CPU on linux using sysfs and procfs +- Added option --increment-inverse to increment masks from right-to-left instead of left-to-right ## ## Bugs From 7c24f36db0b6c387f7ac33ea6baba444d5db5233 Mon Sep 17 00:00:00 2001 From: PenguinKeeper7 Date: Fri, 1 Mar 2024 00:07:29 +0000 Subject: [PATCH 4/8] Update usage.c --- src/usage.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/usage.c b/src/usage.c index 7cbf22348..c25979d96 100644 --- a/src/usage.c +++ b/src/usage.c @@ -132,6 +132,7 @@ static const char *const USAGE_BIG_PRE_HASHMODES[] = " -4, --custom-charset4 | CS | User-defined charset ?4 |", " --identify | | Shows all supported algorithms for input hashes | --identify my.hash", " -i, --increment | | Enable mask increment mode |", + " --increment-inverse | | Increment from right-to-left |", " --increment-min | Num | Start mask incrementing at X | --increment-min=4", " --increment-max | Num | Stop mask incrementing at X | --increment-max=8", " -S, --slow-candidates | | Enable slower (but advanced) candidate generators |", From cbc34706429a0d12fb494df987e635c6ea9623ae Mon Sep 17 00:00:00 2001 From: PenguinKeeper7 Date: Mon, 4 Mar 2024 22:22:31 +0000 Subject: [PATCH 5/8] Parse maskfiles and escaped ?s properly Replace the old reversal function with an improved one, that both respects custom charsets in mask files and escaped question marks --- src/mpsp.c | 60 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 18 deletions(-) diff --git a/src/mpsp.c b/src/mpsp.c index e9109590e..dd1e67ea5 100644 --- a/src/mpsp.c +++ b/src/mpsp.c @@ -1073,23 +1073,40 @@ static int mask_append_final (hashcat_ctx_t *hashcat_ctx, const char *mask) } // ?l?u?d -> ?d?u?l -static char* reverseMask (const char *mask) { - int length = strlen (mask); - char *tmp_buf = (char *) hcmalloc (256); - - for (int i = length - 1, j = 0; i >= 0; i--) { - if (mask[i] == '\0') - continue; - if (i != 0 && mask[i - 1] == '?') { - tmp_buf[j++] = '?'; - tmp_buf[j++] = mask[i]; - i--; - } else { - tmp_buf[j++] = mask[i]; - } - } +static char* reverseMask (const char *mask, const char *prepend) +{ + u32 maskLength = strlen (mask); + u32 prependLength = strlen (prepend); + + char *tmp_buf = (char *) hcmalloc (256); - return tmp_buf; + u32 i = 0; + + // Add prepend section to tmp_buf, avoiding reversal + if (prependLength != 0) + { + for (i = 0; i < prependLength ; i++) + { + tmp_buf[i] = prepend[i]; + } + tmp_buf[i++] = ','; + } + + for (u32 j = maskLength - 1; i <= maskLength - 1 ; i++) + { + if (mask[i] == '?' && mask[i + 1] != '\0') + { + tmp_buf[j--] = mask[i + 1]; + tmp_buf[j--] = mask[i]; + i++; + } + else + { + tmp_buf[j--] = mask[i]; + } + } + + return tmp_buf; } static int mask_append (hashcat_ctx_t *hashcat_ctx, const char *mask, const char *prepend) @@ -1130,14 +1147,21 @@ static int mask_append (hashcat_ctx_t *hashcat_ctx, const char *mask, const char if (user_options->increment_inverse == true) { - if (mp_get_truncated_mask (hashcat_ctx, reverseMask (mask), strlen (mask), increment_len, mask_truncated_next) == -1) + if (mp_get_truncated_mask (hashcat_ctx, reverseMask (mask, ""), strlen (mask), increment_len, mask_truncated_next) == -1) { hcfree (mask_truncated); break; } - mask_truncated = reverseMask (mask_truncated); + if (prepend) + { + mask_truncated = reverseMask (mask_truncated, prepend); + } + else + { + mask_truncated = reverseMask (mask_truncated, ""); + } } else { From 18a35bdffdffcc8a7f06ebdfe2c2ddca18f941a4 Mon Sep 17 00:00:00 2001 From: PenguinKeeper7 Date: Mon, 4 Mar 2024 23:05:06 +0000 Subject: [PATCH 6/8] -ii as an alias for --increment-inverse --- include/user_options.h | 2 ++ src/user_options.c | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/include/user_options.h b/include/user_options.h index a0e176944..d94b908b1 100644 --- a/include/user_options.h +++ b/include/user_options.h @@ -34,4 +34,6 @@ int user_options_check_files (hashcat_ctx_t *hashcat_ctx); void user_options_info (hashcat_ctx_t *hashcat_ctx); +void increment_parse (hashcat_ctx_t *hashcat_ctx); + #endif // HC_USER_OPTIONS_H diff --git a/src/user_options.c b/src/user_options.c index ec7430540..c74ac5b30 100644 --- a/src/user_options.c +++ b/src/user_options.c @@ -525,7 +525,7 @@ int user_options_getopt (hashcat_ctx_t *hashcat_ctx, int argc, char **argv) case IDX_BITMAP_MIN: user_options->bitmap_min = hc_strtoul (optarg, NULL, 10); break; case IDX_BITMAP_MAX: user_options->bitmap_max = hc_strtoul (optarg, NULL, 10); break; case IDX_HOOK_THREADS: user_options->hook_threads = hc_strtoul (optarg, NULL, 10); break; - case IDX_INCREMENT: user_options->increment = true; break; + case IDX_INCREMENT: increment_parse(hashcat_ctx); break; case IDX_INCREMENT_INVERSE: user_options->increment_inverse = true; break; case IDX_INCREMENT_MIN: user_options->increment_min = hc_strtoul (optarg, NULL, 10); user_options->increment_min_chgd = true; break; @@ -3204,6 +3204,21 @@ int user_options_check_files (hashcat_ctx_t *hashcat_ctx) return 0; } +void increment_parse (hashcat_ctx_t *hashcat_ctx) +{ + user_options_t *user_options = hashcat_ctx->user_options; + + // Set increment inverse when -ii + if (user_options->increment == true) + { + user_options->increment_inverse = true; + } + else + { + user_options->increment = true; + } +} + void user_options_logger (hashcat_ctx_t *hashcat_ctx) { user_options_t *user_options = hashcat_ctx->user_options; From 0fb6e68c7604d4f9c78b6c20251301a7af61f7d2 Mon Sep 17 00:00:00 2001 From: PenguinKeeper7 Date: Mon, 4 Mar 2024 23:05:54 +0000 Subject: [PATCH 7/8] No longer require -i with --increment-inverse --- src/user_options.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/user_options.c b/src/user_options.c index c74ac5b30..c463e63ce 100644 --- a/src/user_options.c +++ b/src/user_options.c @@ -868,13 +868,6 @@ int user_options_sanity (hashcat_ctx_t *hashcat_ctx) return -1; } - if ((user_options->increment == false) && (user_options->increment_inverse == true)) - { - event_log_error (hashcat_ctx, "Increment-inverse is only supported combined with -i/--increment."); - - return -1; - } - if (user_options->increment_min > user_options->increment_max) { event_log_error (hashcat_ctx, "Invalid --increment-min value specified - must be >= --increment-max."); From ce86bfac1737691a78b676a937faaafbc2f7737e Mon Sep 17 00:00:00 2001 From: PenguinKeeper7 Date: Mon, 4 Mar 2024 23:15:38 +0000 Subject: [PATCH 8/8] Add -ii in the --help text --- src/usage.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/usage.c b/src/usage.c index c25979d96..5d00ace6d 100644 --- a/src/usage.c +++ b/src/usage.c @@ -132,7 +132,7 @@ static const char *const USAGE_BIG_PRE_HASHMODES[] = " -4, --custom-charset4 | CS | User-defined charset ?4 |", " --identify | | Shows all supported algorithms for input hashes | --identify my.hash", " -i, --increment | | Enable mask increment mode |", - " --increment-inverse | | Increment from right-to-left |", + " -ii,--increment-inverse | | Increment from right-to-left |", " --increment-min | Num | Start mask incrementing at X | --increment-min=4", " --increment-max | Num | Stop mask incrementing at X | --increment-max=8", " -S, --slow-candidates | | Enable slower (but advanced) candidate generators |",