From 05f107cbe59476dc5b5701e990c525abdd946fd6 Mon Sep 17 00:00:00 2001 From: Jens Steube Date: Sat, 14 Aug 2021 11:43:32 +0200 Subject: [PATCH] Added option --generate-rules-func-sel to specify a pool of operators that the random rule generator is allowed to pick from --- docs/changes.txt | 1 + extra/tab_completion/hashcat.sh | 4 +- include/rp.h | 31 ++++- include/types.h | 40 +++--- src/rp.c | 236 ++++++++++++++++++++++++++++---- src/straight.c | 2 +- src/usage.c | 1 + src/user_options.c | 6 +- 8 files changed, 273 insertions(+), 48 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index e79fd083a..018ce4a38 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -6,6 +6,7 @@ - Added option --deprecated-check-disable to enable deprecated plugins - Added option --multiply-accel-disable (short: -M) to disable multiplying of the kernel accel with the multiprocessor count +- Added option --generate-rules-func-sel to specify a pool of operators that the random rule generator is allowed to pick from - Added rule function '3' to change the case of the first letter after the occurrence of N of character X - Added support for auto tuning --kernel-threads (-T) at startup - Added support for HIP version 4.3 or later and removed support for older HIP versions as they are not compatible diff --git a/extra/tab_completion/hashcat.sh b/extra/tab_completion/hashcat.sh index dac5d8adf..f9580cd7a 100644 --- a/extra/tab_completion/hashcat.sh +++ b/extra/tab_completion/hashcat.sh @@ -426,8 +426,8 @@ _hashcat () local BUILD_IN_CHARSETS='?l ?u ?d ?a ?b ?s ?h ?H' local SHORT_OPTS="-m -a -V -h -b -t -T -o -p -c -d -D -w -n -u -j -k -r -g -1 -2 -3 -4 -i -I -s -l -O -S -z" - local LONG_OPTS="--hash-type --attack-mode --version --help --quiet --benchmark --benchmark-all --hex-salt --hex-wordlist --hex-charset --force --status --status-json --status-timer --stdin-timeout-abort --machine-readable --loopback --markov-hcstat2 --markov-disable --markov-inverse --markov-classic --markov-threshold --runtime --session --speed-only --progress-only --restore --restore-file-path --restore-disable --outfile --outfile-format --outfile-autohex-disable --outfile-check-timer --outfile-check-dir --wordlist-autohex-disable --separator --show --deprecated-check-disable --left --username --remove --remove-timer --potfile-disable --potfile-path --debug-mode --debug-file --induction-dir --segment-size --bitmap-min --bitmap-max --cpu-affinity --example-hashes --hash-info --backend-ignore-cuda --backend-ignore-opencl --backend-info --backend-devices --opencl-device-types --backend-vector-width --workload-profile --kernel-accel --kernel-loops --kernel-threads --spin-damp --hwmon-disable --hwmon-temp-abort --skip --limit --keyspace --rule-left --rule-right --rules-file --generate-rules --generate-rules-func-min --generate-rules-func-max --generate-rules-seed --custom-charset1 --custom-charset2 --custom-charset3 --custom-charset4 --hook-threads --increment --increment-min --increment-max --logfile-disable --scrypt-tmto --keyboard-layout-mapping --truecrypt-keyfiles --veracrypt-keyfiles --veracrypt-pim-start --veracrypt-pim-stop --stdout --keep-guessing --hccapx-message-pair --nonce-error-corrections --encoding-from --encoding-to --optimized-kernel-enable --multiply-accel-disable --self-test-disable --slow-candidates --brain-server --brain-server-timer --brain-client --brain-client-features --brain-host --brain-port --brain-session --brain-session-whitelist --brain-password --identify" - local OPTIONS="-m -a -t -o -p -c -d -w -n -u -j -k -r -g -1 -2 -3 -4 -s -l --hash-type --attack-mode --status-timer --stdin-timeout-abort --markov-hcstat2 --markov-threshold --runtime --session --timer --outfile --outfile-format --outfile-check-timer --outfile-check-dir --separator --remove-timer --potfile-path --restore-file-path --debug-mode --debug-file --induction-dir --segment-size --bitmap-min --bitmap-max --cpu-affinity --backend-devices --opencl-device-types --backend-vector-width --workload-profile --kernel-accel --kernel-loops --kernel-threads --spin-damp --hwmon-temp-abort --skip --limit --rule-left --rule-right --rules-file --generate-rules --generate-rules-func-min --generate-rules-func-max --generate-rules-seed --custom-charset1 --custom-charset2 --custom-charset3 --custom-charset4 --hook-threads --increment-min --increment-max --scrypt-tmto --keyboard-layout-mapping --truecrypt-keyfiles --veracrypt-keyfiles --veracrypt-pim-start --veracrypt-pim-stop --hccapx-message-pair --nonce-error-corrections --encoding-from --encoding-to --brain-server-timer --brain-client-features --brain-host --brain-password --brain-port --brain-session --brain-session-whitelist" + local LONG_OPTS="--hash-type --attack-mode --version --help --quiet --benchmark --benchmark-all --hex-salt --hex-wordlist --hex-charset --force --status --status-json --status-timer --stdin-timeout-abort --machine-readable --loopback --markov-hcstat2 --markov-disable --markov-inverse --markov-classic --markov-threshold --runtime --session --speed-only --progress-only --restore --restore-file-path --restore-disable --outfile --outfile-format --outfile-autohex-disable --outfile-check-timer --outfile-check-dir --wordlist-autohex-disable --separator --show --deprecated-check-disable --left --username --remove --remove-timer --potfile-disable --potfile-path --debug-mode --debug-file --induction-dir --segment-size --bitmap-min --bitmap-max --cpu-affinity --example-hashes --hash-info --backend-ignore-cuda --backend-ignore-opencl --backend-info --backend-devices --opencl-device-types --backend-vector-width --workload-profile --kernel-accel --kernel-loops --kernel-threads --spin-damp --hwmon-disable --hwmon-temp-abort --skip --limit --keyspace --rule-left --rule-right --rules-file --generate-rules --generate-rules-func-min --generate-rules-func-max --generate-rules-func-sel --generate-rules-seed --custom-charset1 --custom-charset2 --custom-charset3 --custom-charset4 --hook-threads --increment --increment-min --increment-max --logfile-disable --scrypt-tmto --keyboard-layout-mapping --truecrypt-keyfiles --veracrypt-keyfiles --veracrypt-pim-start --veracrypt-pim-stop --stdout --keep-guessing --hccapx-message-pair --nonce-error-corrections --encoding-from --encoding-to --optimized-kernel-enable --multiply-accel-disable --self-test-disable --slow-candidates --brain-server --brain-server-timer --brain-client --brain-client-features --brain-host --brain-port --brain-session --brain-session-whitelist --brain-password --identify" + local OPTIONS="-m -a -t -o -p -c -d -w -n -u -j -k -r -g -1 -2 -3 -4 -s -l --hash-type --attack-mode --status-timer --stdin-timeout-abort --markov-hcstat2 --markov-threshold --runtime --session --timer --outfile --outfile-format --outfile-check-timer --outfile-check-dir --separator --remove-timer --potfile-path --restore-file-path --debug-mode --debug-file --induction-dir --segment-size --bitmap-min --bitmap-max --cpu-affinity --backend-devices --opencl-device-types --backend-vector-width --workload-profile --kernel-accel --kernel-loops --kernel-threads --spin-damp --hwmon-temp-abort --skip --limit --rule-left --rule-right --rules-file --generate-rules --generate-rules-func-min --generate-rules-func-max --generate-rules-func-sel --generate-rules-seed --custom-charset1 --custom-charset2 --custom-charset3 --custom-charset4 --hook-threads --increment-min --increment-max --scrypt-tmto --keyboard-layout-mapping --truecrypt-keyfiles --veracrypt-keyfiles --veracrypt-pim-start --veracrypt-pim-stop --hccapx-message-pair --nonce-error-corrections --encoding-from --encoding-to --brain-server-timer --brain-client-features --brain-host --brain-password --brain-port --brain-session --brain-session-whitelist" COMPREPLY=() local cur="${COMP_WORDS[COMP_CWORD]}" diff --git a/include/rp.h b/include/rp.h index 2fa6021e7..c44239f1a 100644 --- a/include/rp.h +++ b/include/rp.h @@ -16,6 +16,33 @@ #define RULES_MAX 32 #define MAX_KERNEL_RULES (RULES_MAX - 1) +typedef struct +{ + char *grp_op_nop_selection; + char *grp_op_pos_p0_selection; + char *grp_op_pos_p1_selection; + char *grp_op_chr_selection; + char *grp_op_chr_chr_selection; + char *grp_op_pos_chr_selection; + char *grp_op_pos_pos0_selection; + char *grp_op_pos_pos1_selection; + + int grp_op_nop_cnt; + int grp_op_pos_p0_cnt; + int grp_op_pos_p1_cnt; + int grp_op_chr_cnt; + int grp_op_chr_chr_cnt; + int grp_op_pos_chr_cnt; + int grp_op_pos_pos0_cnt; + int grp_op_pos_pos1_cnt; + + // 8 if all operator group types used, but can be lower if user is using operator selection options + + int grp_op_alias_buf[8]; + int grp_op_alias_cnt; + +} rp_gen_ops_t; + bool class_num (const u8 c); bool class_lower (const u8 c); bool class_upper (const u8 c); @@ -24,7 +51,7 @@ bool class_alpha (const u8 c); int conv_ctoi (const u8 c); int conv_itoc (const u8 c); -int generate_random_rule (char rule_buf[RP_RULE_SIZE], const u32 rp_gen_func_min, const u32 rp_gen_func_max); +int generate_random_rule (char rule_buf[RP_RULE_SIZE], const u32 rp_gen_func_min, const u32 rp_gen_func_max, const rp_gen_ops_t *rp_gen_ops); bool is_hex_notation (const char *rule_buf, u32 rule_len, u32 rule_pos); @@ -34,6 +61,6 @@ int kernel_rule_to_cpu_rule (char *rule_buf, kernel_rule_t *rule); bool kernel_rules_has_noop (const kernel_rule_t *kernel_rules_buf, const u32 kernel_rules_cnt); int kernel_rules_load (hashcat_ctx_t *hashcat_ctx, kernel_rule_t **out_buf, u32 *out_cnt); -int kernel_rules_generate (hashcat_ctx_t *hashcat_ctx, kernel_rule_t **out_buf, u32 *out_cnt); +int kernel_rules_generate (hashcat_ctx_t *hashcat_ctx, kernel_rule_t **out_buf, u32 *out_cnt, const char *rp_gen_func_selection); #endif // _RP_H diff --git a/include/types.h b/include/types.h index 0723960a8..528887e4a 100644 --- a/include/types.h +++ b/include/types.h @@ -783,34 +783,35 @@ typedef enum user_options_map IDX_RP_FILE = 'r', IDX_RP_GEN_FUNC_MAX = 0xff3c, IDX_RP_GEN_FUNC_MIN = 0xff3d, + IDX_RP_GEN_FUNC_SEL = 0xff3e, IDX_RP_GEN = 'g', - IDX_RP_GEN_SEED = 0xff3e, + IDX_RP_GEN_SEED = 0xff3f, IDX_RULE_BUF_L = 'j', IDX_RULE_BUF_R = 'k', - IDX_RUNTIME = 0xff3f, - IDX_SCRYPT_TMTO = 0xff40, + IDX_RUNTIME = 0xff40, + IDX_SCRYPT_TMTO = 0xff41, IDX_SEGMENT_SIZE = 'c', - IDX_SELF_TEST_DISABLE = 0xff41, + IDX_SELF_TEST_DISABLE = 0xff42, IDX_SEPARATOR = 'p', - IDX_SESSION = 0xff42, - IDX_SHOW = 0xff43, + IDX_SESSION = 0xff43, + IDX_SHOW = 0xff44, IDX_SKIP = 's', IDX_SLOW_CANDIDATES = 'S', - IDX_SPEED_ONLY = 0xff44, - IDX_SPIN_DAMP = 0xff45, - IDX_STATUS = 0xff46, - IDX_STATUS_JSON = 0xff47, - IDX_STATUS_TIMER = 0xff48, - IDX_STDOUT_FLAG = 0xff49, - IDX_STDIN_TIMEOUT_ABORT = 0xff4a, - IDX_TRUECRYPT_KEYFILES = 0xff4b, - IDX_USERNAME = 0xff4c, - IDX_VERACRYPT_KEYFILES = 0xff4d, - IDX_VERACRYPT_PIM_START = 0xff4e, - IDX_VERACRYPT_PIM_STOP = 0xff4f, + IDX_SPEED_ONLY = 0xff45, + IDX_SPIN_DAMP = 0xff46, + IDX_STATUS = 0xff47, + IDX_STATUS_JSON = 0xff48, + IDX_STATUS_TIMER = 0xff49, + IDX_STDOUT_FLAG = 0xff4a, + IDX_STDIN_TIMEOUT_ABORT = 0xff4b, + IDX_TRUECRYPT_KEYFILES = 0xff4c, + IDX_USERNAME = 0xff4d, + IDX_VERACRYPT_KEYFILES = 0xff4e, + IDX_VERACRYPT_PIM_START = 0xff4f, + IDX_VERACRYPT_PIM_STOP = 0xff50, IDX_VERSION_LOWER = 'v', IDX_VERSION = 'V', - IDX_WORDLIST_AUTOHEX_DISABLE = 0xff50, + IDX_WORDLIST_AUTOHEX_DISABLE = 0xff51, IDX_WORKLOAD_PROFILE = 'w', } user_options_map_t; @@ -2180,6 +2181,7 @@ typedef struct user_options char *potfile_path; char *restore_file_path; char **rp_files; + char *rp_gen_func_sel; char *separator; char *truecrypt_keyfiles; char *veracrypt_keyfiles; diff --git a/src/rp.c b/src/rp.c index a2954acbf..0954a2bac 100644 --- a/src/rp.c +++ b/src/rp.c @@ -127,51 +127,55 @@ int conv_itoc (const u8 c) return -1; } -int generate_random_rule (char rule_buf[RP_RULE_SIZE], const u32 rp_gen_func_min, const u32 rp_gen_func_max) +int generate_random_rule (char rule_buf[RP_RULE_SIZE], const u32 rp_gen_func_min, const u32 rp_gen_func_max, const rp_gen_ops_t *rp_gen_ops) { - u32 rp_gen_num = get_random_num (rp_gen_func_min, rp_gen_func_max); + // generate them - u32 j; + const u32 rp_gen_num = get_random_num (rp_gen_func_min, rp_gen_func_max); u32 rule_pos = 0; - for (j = 0; j < rp_gen_num; j++) + for (u32 j = 0; j < rp_gen_num; j++) { u32 r = 0; u32 p1 = 0; u32 p2 = 0; - switch ((char) get_random_num (0, 8)) + const int group_num = get_random_num (0, rp_gen_ops->grp_op_alias_cnt); + + const int group_num_alias = rp_gen_ops->grp_op_alias_buf[group_num]; + + switch (group_num_alias) { case 0: - r = get_random_num (0, sizeof (grp_op_nop)); - rule_buf[rule_pos++] = grp_op_nop[r]; + r = get_random_num (0, rp_gen_ops->grp_op_nop_cnt); + rule_buf[rule_pos++] = rp_gen_ops->grp_op_nop_selection[r]; break; case 1: - r = get_random_num (0, sizeof (grp_op_pos_p0)); - rule_buf[rule_pos++] = grp_op_pos_p0[r]; + r = get_random_num (0, rp_gen_ops->grp_op_pos_p0_cnt); + rule_buf[rule_pos++] = rp_gen_ops->grp_op_pos_p0_selection[r]; p1 = get_random_num (0, sizeof (grp_pos)); rule_buf[rule_pos++] = grp_pos[p1]; break; case 2: - r = get_random_num (0, sizeof (grp_op_pos_p1)); - rule_buf[rule_pos++] = grp_op_pos_p1[r]; + r = get_random_num (0, rp_gen_ops->grp_op_pos_p1_cnt); + rule_buf[rule_pos++] = rp_gen_ops->grp_op_pos_p1_selection[r]; p1 = get_random_num (1, 6); rule_buf[rule_pos++] = grp_pos[p1]; break; case 3: - r = get_random_num (0, sizeof (grp_op_chr)); - rule_buf[rule_pos++] = grp_op_chr[r]; + r = get_random_num (0, rp_gen_ops->grp_op_chr_cnt); + rule_buf[rule_pos++] = rp_gen_ops->grp_op_chr_selection[r]; p1 = get_random_num (0x20, 0x7e); rule_buf[rule_pos++] = (char) p1; break; case 4: - r = get_random_num (0, sizeof (grp_op_chr_chr)); - rule_buf[rule_pos++] = grp_op_chr_chr[r]; + r = get_random_num (0, rp_gen_ops->grp_op_chr_chr_cnt); + rule_buf[rule_pos++] = rp_gen_ops->grp_op_chr_chr_selection[r]; p1 = get_random_num (0x20, 0x7e); rule_buf[rule_pos++] = (char) p1; p2 = get_random_num (0x20, 0x7e); @@ -181,8 +185,8 @@ int generate_random_rule (char rule_buf[RP_RULE_SIZE], const u32 rp_gen_func_min break; case 5: - r = get_random_num (0, sizeof (grp_op_pos_chr)); - rule_buf[rule_pos++] = grp_op_pos_chr[r]; + r = get_random_num (0, rp_gen_ops->grp_op_pos_chr_cnt); + rule_buf[rule_pos++] = rp_gen_ops->grp_op_pos_chr_selection[r]; p1 = get_random_num (0, sizeof (grp_pos)); rule_buf[rule_pos++] = grp_pos[p1]; p2 = get_random_num (0x20, 0x7e); @@ -190,8 +194,8 @@ int generate_random_rule (char rule_buf[RP_RULE_SIZE], const u32 rp_gen_func_min break; case 6: - r = get_random_num (0, sizeof (grp_op_pos_pos0)); - rule_buf[rule_pos++] = grp_op_pos_pos0[r]; + r = get_random_num (0, rp_gen_ops->grp_op_pos_pos0_cnt); + rule_buf[rule_pos++] = rp_gen_ops->grp_op_pos_pos0_selection[r]; p1 = get_random_num (0, sizeof (grp_pos)); rule_buf[rule_pos++] = grp_pos[p1]; p2 = get_random_num (0, sizeof (grp_pos)); @@ -201,8 +205,8 @@ int generate_random_rule (char rule_buf[RP_RULE_SIZE], const u32 rp_gen_func_min break; case 7: - r = get_random_num (0, sizeof (grp_op_pos_pos1)); - rule_buf[rule_pos++] = grp_op_pos_pos1[r]; + r = get_random_num (0, rp_gen_ops->grp_op_pos_pos1_cnt); + rule_buf[rule_pos++] = rp_gen_ops->grp_op_pos_pos1_selection[r]; p1 = get_random_num (0, sizeof (grp_pos)); rule_buf[rule_pos++] = grp_pos[p1]; p2 = get_random_num (1, sizeof (grp_pos)); @@ -880,26 +884,212 @@ int kernel_rules_load (hashcat_ctx_t *hashcat_ctx, kernel_rule_t **out_buf, u32 return 0; } -int kernel_rules_generate (hashcat_ctx_t *hashcat_ctx, kernel_rule_t **out_buf, u32 *out_cnt) +int kernel_rules_generate (hashcat_ctx_t *hashcat_ctx, kernel_rule_t **out_buf, u32 *out_cnt, const char *rp_gen_func_selection) { const user_options_t *user_options = hashcat_ctx->user_options; u32 kernel_rules_cnt = 0; kernel_rule_t *kernel_rules_buf = (kernel_rule_t *) hccalloc (user_options->rp_gen, sizeof (kernel_rule_t)); + // operator selection + + rp_gen_ops_t rp_gen_ops; + + rp_gen_ops.grp_op_nop_selection = hcmalloc (sizeof (grp_op_nop)); + rp_gen_ops.grp_op_pos_p0_selection = hcmalloc (sizeof (grp_op_pos_p0)); + rp_gen_ops.grp_op_pos_p1_selection = hcmalloc (sizeof (grp_op_pos_p1)); + rp_gen_ops.grp_op_chr_selection = hcmalloc (sizeof (grp_op_chr)); + rp_gen_ops.grp_op_chr_chr_selection = hcmalloc (sizeof (grp_op_chr_chr)); + rp_gen_ops.grp_op_pos_chr_selection = hcmalloc (sizeof (grp_op_pos_chr)); + rp_gen_ops.grp_op_pos_pos0_selection = hcmalloc (sizeof (grp_op_pos_pos0)); + rp_gen_ops.grp_op_pos_pos1_selection = hcmalloc (sizeof (grp_op_pos_pos1)); + + rp_gen_ops.grp_op_nop_cnt = 0; + rp_gen_ops.grp_op_pos_p0_cnt = 0; + rp_gen_ops.grp_op_pos_p1_cnt = 0; + rp_gen_ops.grp_op_chr_cnt = 0; + rp_gen_ops.grp_op_chr_chr_cnt = 0; + rp_gen_ops.grp_op_pos_chr_cnt = 0; + rp_gen_ops.grp_op_pos_pos0_cnt = 0; + rp_gen_ops.grp_op_pos_pos1_cnt = 0; + + rp_gen_ops.grp_op_alias_cnt = 0; + + for (size_t i = 0; i < sizeof (grp_op_nop); i++) + { + if (rp_gen_func_selection == NULL) + { + rp_gen_ops.grp_op_nop_selection[rp_gen_ops.grp_op_nop_cnt] = grp_op_nop[i]; + + rp_gen_ops.grp_op_nop_cnt++; + } + else + { + if (index (rp_gen_func_selection, grp_op_nop[i]) == NULL) continue; + + rp_gen_ops.grp_op_nop_selection[rp_gen_ops.grp_op_nop_cnt] = grp_op_nop[i]; + + rp_gen_ops.grp_op_nop_cnt++; + } + } + + for (size_t i = 0; i < sizeof (grp_op_pos_p0); i++) + { + if (rp_gen_func_selection == NULL) + { + rp_gen_ops.grp_op_pos_p0_selection[rp_gen_ops.grp_op_pos_p0_cnt] = grp_op_nop[i]; + + rp_gen_ops.grp_op_pos_p0_cnt++; + } + else + { + if (index (rp_gen_func_selection, grp_op_pos_p0[i]) == NULL) continue; + + rp_gen_ops.grp_op_pos_p0_selection[rp_gen_ops.grp_op_pos_p0_cnt] = grp_op_pos_p0[i]; + + rp_gen_ops.grp_op_pos_p0_cnt++; + } + } + + for (size_t i = 0; i < sizeof (grp_op_pos_p1); i++) + { + if (rp_gen_func_selection == NULL) + { + rp_gen_ops.grp_op_pos_p1_selection[rp_gen_ops.grp_op_pos_p1_cnt] = grp_op_pos_p1[i]; + + rp_gen_ops.grp_op_pos_p1_cnt++; + } + else + { + if (index (rp_gen_func_selection, grp_op_pos_p1[i]) == NULL) continue; + + rp_gen_ops.grp_op_pos_p1_selection[rp_gen_ops.grp_op_pos_p1_cnt] = grp_op_pos_p1[i]; + + rp_gen_ops.grp_op_pos_p1_cnt++; + } + } + + for (size_t i = 0; i < sizeof (grp_op_chr); i++) + { + if (rp_gen_func_selection == NULL) + { + rp_gen_ops.grp_op_chr_selection[rp_gen_ops.grp_op_chr_cnt] = grp_op_chr[i]; + + rp_gen_ops.grp_op_chr_cnt++; + } + else + { + if (index (rp_gen_func_selection, grp_op_chr[i]) == NULL) continue; + + rp_gen_ops.grp_op_chr_selection[rp_gen_ops.grp_op_chr_cnt] = grp_op_chr[i]; + + rp_gen_ops.grp_op_chr_cnt++; + } + } + + for (size_t i = 0; i < sizeof (grp_op_chr_chr); i++) + { + if (rp_gen_func_selection == NULL) + { + rp_gen_ops.grp_op_chr_chr_selection[rp_gen_ops.grp_op_chr_chr_cnt] = grp_op_chr_chr[i]; + + rp_gen_ops.grp_op_chr_chr_cnt++; + } + else + { + if (index (rp_gen_func_selection, grp_op_chr_chr[i]) == NULL) continue; + + rp_gen_ops.grp_op_chr_chr_selection[rp_gen_ops.grp_op_chr_chr_cnt] = grp_op_chr_chr[i]; + + rp_gen_ops.grp_op_chr_chr_cnt++; + } + } + + for (size_t i = 0; i < sizeof (grp_op_pos_chr); i++) + { + if (rp_gen_func_selection == NULL) + { + rp_gen_ops.grp_op_pos_chr_selection[rp_gen_ops.grp_op_pos_chr_cnt] = grp_op_pos_chr[i]; + + rp_gen_ops.grp_op_pos_chr_cnt++; + } + else + { + if (index (rp_gen_func_selection, grp_op_pos_chr[i]) == NULL) continue; + + rp_gen_ops.grp_op_pos_chr_selection[rp_gen_ops.grp_op_pos_chr_cnt] = grp_op_pos_chr[i]; + + rp_gen_ops.grp_op_pos_chr_cnt++; + } + } + + for (size_t i = 0; i < sizeof (grp_op_pos_pos0); i++) + { + if (rp_gen_func_selection == NULL) + { + rp_gen_ops.grp_op_pos_pos0_selection[rp_gen_ops.grp_op_pos_pos0_cnt] = grp_op_pos_pos0[i]; + + rp_gen_ops.grp_op_pos_pos0_cnt++; + } + else + { + if (index (rp_gen_func_selection, grp_op_pos_pos0[i]) == NULL) continue; + + rp_gen_ops.grp_op_pos_pos0_selection[rp_gen_ops.grp_op_pos_pos0_cnt] = grp_op_pos_pos0[i]; + + rp_gen_ops.grp_op_pos_pos0_cnt++; + } + } + + for (size_t i = 0; i < sizeof (grp_op_pos_pos1); i++) + { + if (rp_gen_func_selection == NULL) + { + rp_gen_ops.grp_op_pos_pos1_selection[rp_gen_ops.grp_op_pos_pos1_cnt] = grp_op_pos_pos1[i]; + + rp_gen_ops.grp_op_pos_pos1_cnt++; + } + else + { + if (index (rp_gen_func_selection, grp_op_pos_pos1[i]) == NULL) continue; + + rp_gen_ops.grp_op_pos_pos1_selection[rp_gen_ops.grp_op_pos_pos1_cnt] = grp_op_pos_pos1[i]; + + rp_gen_ops.grp_op_pos_pos1_cnt++; + } + } + + if (rp_gen_ops.grp_op_nop_cnt) { rp_gen_ops.grp_op_alias_buf[rp_gen_ops.grp_op_alias_cnt++] = 0; }; + if (rp_gen_ops.grp_op_pos_p0_cnt) { rp_gen_ops.grp_op_alias_buf[rp_gen_ops.grp_op_alias_cnt++] = 1; }; + if (rp_gen_ops.grp_op_pos_p1_cnt) { rp_gen_ops.grp_op_alias_buf[rp_gen_ops.grp_op_alias_cnt++] = 2; }; + if (rp_gen_ops.grp_op_chr_cnt) { rp_gen_ops.grp_op_alias_buf[rp_gen_ops.grp_op_alias_cnt++] = 3; }; + if (rp_gen_ops.grp_op_chr_chr_cnt) { rp_gen_ops.grp_op_alias_buf[rp_gen_ops.grp_op_alias_cnt++] = 4; }; + if (rp_gen_ops.grp_op_pos_chr_cnt) { rp_gen_ops.grp_op_alias_buf[rp_gen_ops.grp_op_alias_cnt++] = 5; }; + if (rp_gen_ops.grp_op_pos_pos0_cnt) { rp_gen_ops.grp_op_alias_buf[rp_gen_ops.grp_op_alias_cnt++] = 6; }; + if (rp_gen_ops.grp_op_pos_pos1_cnt) { rp_gen_ops.grp_op_alias_buf[rp_gen_ops.grp_op_alias_cnt++] = 7; }; + char *rule_buf = (char *) hcmalloc (RP_RULE_SIZE); for (kernel_rules_cnt = 0; kernel_rules_cnt < user_options->rp_gen; kernel_rules_cnt++) { memset (rule_buf, 0, RP_RULE_SIZE); - int rule_len = generate_random_rule (rule_buf, user_options->rp_gen_func_min, user_options->rp_gen_func_max); + const int rule_len = generate_random_rule (rule_buf, user_options->rp_gen_func_min, user_options->rp_gen_func_max, &rp_gen_ops); if (cpu_rule_to_kernel_rule (rule_buf, rule_len, &kernel_rules_buf[kernel_rules_cnt]) == -1) continue; } hcfree (rule_buf); + hcfree (rp_gen_ops.grp_op_nop_selection); + hcfree (rp_gen_ops.grp_op_pos_p0_selection); + hcfree (rp_gen_ops.grp_op_pos_p1_selection); + hcfree (rp_gen_ops.grp_op_chr_selection); + hcfree (rp_gen_ops.grp_op_chr_chr_selection); + hcfree (rp_gen_ops.grp_op_pos_chr_selection); + hcfree (rp_gen_ops.grp_op_pos_pos0_selection); + hcfree (rp_gen_ops.grp_op_pos_pos1_selection); + *out_cnt = kernel_rules_cnt; *out_buf = kernel_rules_buf; diff --git a/src/straight.c b/src/straight.c index 2fe206d0b..46c0fe685 100644 --- a/src/straight.c +++ b/src/straight.c @@ -293,7 +293,7 @@ int straight_ctx_init (hashcat_ctx_t *hashcat_ctx) } else if (user_options->rp_gen) { - if (kernel_rules_generate (hashcat_ctx, &straight_ctx->kernel_rules_buf, &straight_ctx->kernel_rules_cnt) == -1) return -1; + if (kernel_rules_generate (hashcat_ctx, &straight_ctx->kernel_rules_buf, &straight_ctx->kernel_rules_cnt, user_options->rp_gen_func_sel) == -1) return -1; } } diff --git a/src/usage.c b/src/usage.c index 55b61ce51..dc6929181 100644 --- a/src/usage.c +++ b/src/usage.c @@ -117,6 +117,7 @@ static const char *const USAGE_BIG_PRE_HASHMODES[] = " -g, --generate-rules | Num | Generate X random rules | -g 10000", " --generate-rules-func-min | Num | Force min X functions per rule |", " --generate-rules-func-max | Num | Force max X functions per rule |", + " --generate-rules-func-sel | Str | Pool of rule operators valid for random rule engine | --generate-rules-func-sel=ioTlc", " --generate-rules-seed | Num | Force RNG seed set to X |", " -1, --custom-charset1 | CS | User-defined charset ?1 | -1 ?l?d?u", " -2, --custom-charset2 | CS | User-defined charset ?2 | -2 ?l?d?s", diff --git a/src/user_options.c b/src/user_options.c index cca5ab344..ef97d2b2b 100644 --- a/src/user_options.c +++ b/src/user_options.c @@ -55,6 +55,7 @@ static const struct option long_options[] = {"force", no_argument, NULL, IDX_FORCE}, {"generate-rules-func-max", required_argument, NULL, IDX_RP_GEN_FUNC_MAX}, {"generate-rules-func-min", required_argument, NULL, IDX_RP_GEN_FUNC_MIN}, + {"generate-rules-func-sel", required_argument, NULL, IDX_RP_GEN_FUNC_SEL}, {"generate-rules", required_argument, NULL, IDX_RP_GEN}, {"generate-rules-seed", required_argument, NULL, IDX_RP_GEN_SEED}, {"hwmon-disable", no_argument, NULL, IDX_HWMON_DISABLE}, @@ -167,7 +168,7 @@ int user_options_init (hashcat_ctx_t *hashcat_ctx) user_options->autodetect = AUTODETECT; user_options->backend_devices = NULL; user_options->backend_ignore_cuda = BACKEND_IGNORE_CUDA; - user_options->backend_ignore_hip = BACKEND_IGNORE_HIP; + user_options->backend_ignore_hip = BACKEND_IGNORE_HIP; user_options->backend_ignore_opencl = BACKEND_IGNORE_OPENCL; user_options->backend_info = BACKEND_INFO; user_options->backend_vector_width = BACKEND_VECTOR_WIDTH; @@ -247,6 +248,7 @@ int user_options_init (hashcat_ctx_t *hashcat_ctx) user_options->restore_timer = RESTORE_TIMER; user_options->rp_gen_func_max = RP_GEN_FUNC_MAX; user_options->rp_gen_func_min = RP_GEN_FUNC_MIN; + user_options->rp_gen_func_sel = NULL; user_options->rp_gen = RP_GEN; user_options->rp_gen_seed = RP_GEN_SEED; user_options->rule_buf_l = RULE_BUF_L; @@ -430,6 +432,7 @@ int user_options_getopt (hashcat_ctx_t *hashcat_ctx, int argc, char **argv) case IDX_RP_GEN: user_options->rp_gen = hc_strtoul (optarg, NULL, 10); break; case IDX_RP_GEN_FUNC_MIN: user_options->rp_gen_func_min = hc_strtoul (optarg, NULL, 10); break; case IDX_RP_GEN_FUNC_MAX: user_options->rp_gen_func_max = hc_strtoul (optarg, NULL, 10); break; + case IDX_RP_GEN_FUNC_SEL: user_options->rp_gen_func_sel = optarg; break; case IDX_RP_GEN_SEED: user_options->rp_gen_seed = hc_strtoul (optarg, NULL, 10); user_options->rp_gen_seed_chgd = true; break; case IDX_RULE_BUF_L: user_options->rule_buf_l = optarg; break; @@ -3071,6 +3074,7 @@ void user_options_logger (hashcat_ctx_t *hashcat_ctx) logfile_top_string (user_options->potfile_path); logfile_top_string (user_options->restore_file_path); logfile_top_string (user_options->rp_files[0]); + logfile_top_string (user_options->rp_gen_func_sel); logfile_top_string (user_options->rule_buf_l); logfile_top_string (user_options->rule_buf_r); logfile_top_string (user_options->session);