From 54a4ea3db2049d96883248014b391e6686457388 Mon Sep 17 00:00:00 2001 From: jsteube Date: Mon, 26 Sep 2016 01:18:00 +0200 Subject: [PATCH] Large but needed refactoring of mask handling, maskfiles, default mask, etc., expect smaller bugs --- include/interface.h | 4 +- include/mpsp.h | 8 +- include/opencl.h | 4 +- include/status.h | 4 +- include/stdout.h | 2 +- include/types.h | 41 +- src/dispatch.c | 10 +- src/hash_management.c | 13 +- src/hashcat.c | 931 ++++++++++++------------------------------ src/interface.c | 4 +- src/monitor.c | 3 +- src/mpsp.c | 295 ++++++++++++- src/opencl.c | 10 +- src/status.c | 28 +- src/stdout.c | 12 +- src/terminal.c | 3 +- src/user_options.c | 22 +- 17 files changed, 661 insertions(+), 733 deletions(-) diff --git a/include/interface.h b/include/interface.h index e7a306a54..26397282a 100644 --- a/include/interface.h +++ b/include/interface.h @@ -1542,7 +1542,7 @@ void hashconfig_destroy (hashconfig_t *hashconfig); uint hashconfig_general_pw_min (hashconfig_t *hashconfig); uint hashconfig_general_pw_max (hashconfig_t *hashconfig); void hashconfig_general_defaults (hashconfig_t *hashconfig, hashes_t *hashes, const user_options_t *user_options); -void hashconfig_benchmark_defaults (hashconfig_t *hashconfig, salt_t *salt, void *esalt); -char *hashconfig_benchmark_mask (hashconfig_t *hashconfig); +void hashconfig_benchmark_defaults (const hashconfig_t *hashconfig, salt_t *salt, void *esalt); +char *hashconfig_benchmark_mask (const hashconfig_t *hashconfig); #endif // _INTERFACE_H diff --git a/include/mpsp.h b/include/mpsp.h index ec32da491..192985273 100644 --- a/include/mpsp.h +++ b/include/mpsp.h @@ -24,12 +24,11 @@ void mp_css_to_uniq_tbl (uint css_cnt, cs_t *css, uint uniq_tbls[SP_PW_MAX][CHA void mp_cut_at (char *mask, uint max); uint mp_get_length (char *mask); void mp_exec (u64 val, char *buf, cs_t *css, int css_cnt); -cs_t *mp_gen_css (char *mask_buf, size_t mask_len, cs_t *mp_sys, cs_t *mp_usr, uint *css_cnt, hashconfig_t *hashconfig, const user_options_t *user_options); +cs_t *mp_gen_css (char *mask_buf, size_t mask_len, cs_t *mp_sys, cs_t *mp_usr, uint *css_cnt, const hashconfig_t *hashconfig, const user_options_t *user_options); u64 mp_get_sum (uint css_cnt, cs_t *css); void mp_setup_sys (cs_t *mp_sys); -void mp_setup_usr (cs_t *mp_sys, cs_t *mp_usr, char *buf, uint index, hashconfig_t *hashconfig, const user_options_t *user_options); +void mp_setup_usr (cs_t *mp_sys, cs_t *mp_usr, char *buf, uint index, const hashconfig_t *hashconfig, const user_options_t *user_options); void mp_reset_usr (cs_t *mp_usr, uint index); -char *mp_get_truncated_mask (char *mask_buf, size_t mask_len, uint len, const user_options_t *user_options); u64 sp_get_sum (uint start, uint stop, cs_t *root_css_buf); void sp_exec (u64 ctx, char *pw_buf, cs_t *root_css_buf, cs_t *markov_css_buf, uint start, uint stop); @@ -39,4 +38,7 @@ void sp_tbl_to_css (hcstat_table_t *root_table_buf, hcstat_table_t *markov_tabl void sp_stretch_markov (hcstat_table_t *in, hcstat_table_t *out); void sp_stretch_root (hcstat_table_t *in, hcstat_table_t *out); +int mask_ctx_init (mask_ctx_t *mask_ctx, const user_options_t *user_options, const user_options_extra_t *user_options_extra, const folder_config_t *folder_config, const restore_ctx_t *restore_ctx, const hashconfig_t *hashconfig); +void mask_ctx_destroy (mask_ctx_t *mask_ctx); + #endif // _MPSP_H diff --git a/include/opencl.h b/include/opencl.h index 434c411be..f8378d750 100644 --- a/include/opencl.h +++ b/include/opencl.h @@ -23,7 +23,7 @@ void writeProgramBin (char *dst, u8 *binary, size_t binary_size); int gidd_to_pw_t (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, const u64 gidd, pw_t *pw); -int choose_kernel (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, const user_options_t *user_options, const rules_ctx_t *rules_ctx, hashconfig_t *hashconfig, const uint attack_exec, const uint attack_mode, const uint opts_type, const salt_t *salt_buf, const uint highest_pw_len, const uint pws_cnt, const uint fast_iteration); +int choose_kernel (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, const user_options_t *user_options, const rules_ctx_t *rules_ctx, const mask_ctx_t *mask_ctx, hashconfig_t *hashconfig, const uint attack_exec, const uint attack_mode, const uint opts_type, const salt_t *salt_buf, const uint highest_pw_len, const uint pws_cnt, const uint fast_iteration); int run_kernel (const uint kern_run, opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, const uint num, const uint event_update, const uint iteration, hashconfig_t *hashconfig, const user_options_t *user_options); int run_kernel_mp (const uint kern_run, opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, const uint num); int run_kernel_tm (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param); @@ -33,7 +33,7 @@ int run_kernel_bzero (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, int run_copy (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, hashconfig_t *hashconfig, const user_options_t *user_options, const user_options_extra_t *user_options_extra, const uint pws_cnt); -int run_cracker (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, hashconfig_t *hashconfig, hashes_t *hashes, const user_options_t *user_options, const user_options_extra_t *user_options_extra, const rules_ctx_t *rules_ctx, const uint pws_cnt); +int run_cracker (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, hashconfig_t *hashconfig, hashes_t *hashes, const user_options_t *user_options, const user_options_extra_t *user_options_extra, const rules_ctx_t *rules_ctx, const mask_ctx_t *mask_ctx, const uint pws_cnt); int opencl_ctx_init (opencl_ctx_t *opencl_ctx, const user_options_t *user_options); void opencl_ctx_destroy (opencl_ctx_t *opencl_ctx); diff --git a/include/status.h b/include/status.h index a873484ce..5fc5853bb 100644 --- a/include/status.h +++ b/include/status.h @@ -11,8 +11,8 @@ double get_avg_exec_time (hc_device_param_t *device_param, const int last_num_entries); -void status_display_machine_readable (opencl_ctx_t *opencl_ctx, const hashes_t *hashes, const restore_ctx_t *restore_ctx, const user_options_t *user_options, const user_options_extra_t *user_options_extra, const rules_ctx_t *rules_ctx); -void status_display (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconfig, const hashes_t *hashes, const restore_ctx_t *restore_ctx, const user_options_t *user_options, const user_options_extra_t *user_options_extra, const rules_ctx_t *rules_ctx); +void status_display_machine_readable (opencl_ctx_t *opencl_ctx, const hashes_t *hashes, const restore_ctx_t *restore_ctx, const user_options_t *user_options, const user_options_extra_t *user_options_extra, const rules_ctx_t *rules_ctx, const mask_ctx_t *mask_ctx); +void status_display (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconfig, const hashes_t *hashes, const restore_ctx_t *restore_ctx, const user_options_t *user_options, const user_options_extra_t *user_options_extra, const rules_ctx_t *rules_ctx, const mask_ctx_t *mask_ctx); void status_benchmark_automate (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconfig); void status_benchmark (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconfig, const user_options_t *user_options); diff --git a/include/stdout.h b/include/stdout.h index aeae0ae51..c9fb90519 100644 --- a/include/stdout.h +++ b/include/stdout.h @@ -20,6 +20,6 @@ #include #endif // _POSIX -void process_stdout (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, const user_options_t *user_options, const rules_ctx_t *rules_ctx, const uint pws_cnt); +void process_stdout (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, const user_options_t *user_options, const rules_ctx_t *rules_ctx, const mask_ctx_t *mask_ctx, const uint pws_cnt); #endif // _STDOUT_H diff --git a/include/types.h b/include/types.h index 6421b5d55..a694acc7a 100644 --- a/include/types.h +++ b/include/types.h @@ -866,7 +866,7 @@ typedef struct u32 pid; u32 dictpos; - u32 maskpos; + u32 masks_pos; u64 words_cur; @@ -1114,6 +1114,33 @@ typedef struct } induct_ctx_t; +typedef struct +{ + cs_t mp_sys[6]; + cs_t mp_usr[4]; + + u32 bfs_cnt; + + cs_t *css_buf; + u32 css_cnt; + + hcstat_table_t *root_table_buf; + hcstat_table_t *markov_table_buf; + + cs_t *root_css_buf; + cs_t *markov_css_buf; + + bool mask_from_file; + + char **masks; + u32 masks_pos; + u32 masks_cnt; + u32 masks_avail; + + char *mask; + +} mask_ctx_t; + typedef struct { bool enabled; @@ -1153,14 +1180,6 @@ typedef struct u32 combs_mode; u32 combs_cnt; - u32 bfs_cnt; - - u32 css_cnt; - cs_t *css_buf; - - cs_t *root_css_buf; - cs_t *markov_css_buf; - /** * hardware watchdog */ @@ -1186,9 +1205,6 @@ typedef struct char *dictfile; char *dictfile2; - char *mask; - u32 maskcnt; - u32 maskpos; u32 pw_min; u32 pw_max; @@ -1208,6 +1224,7 @@ typedef struct logfile_ctx_t *logfile_ctx; rules_ctx_t *rules_ctx; restore_ctx_t *restore_ctx; + mask_ctx_t *mask_ctx; /** * status, timer diff --git a/src/dispatch.c b/src/dispatch.c index 302d95ccd..fd28c5733 100644 --- a/src/dispatch.c +++ b/src/dispatch.c @@ -121,6 +121,7 @@ void *thread_calc_stdin (void *p) hashes_t *hashes = data.hashes; rules_ctx_t *rules_ctx = data.rules_ctx; opencl_ctx_t *opencl_ctx = data.opencl_ctx; + mask_ctx_t *mask_ctx = data.mask_ctx; char *buf = (char *) mymalloc (HCBUFSIZ_LARGE); @@ -211,7 +212,7 @@ void *thread_calc_stdin (void *p) { run_copy (opencl_ctx, device_param, hashconfig, user_options, user_options_extra, pws_cnt); - run_cracker (opencl_ctx, device_param, hashconfig, hashes, user_options, user_options_extra, rules_ctx, pws_cnt); + run_cracker (opencl_ctx, device_param, hashconfig, hashes, user_options, user_options_extra, rules_ctx, mask_ctx, pws_cnt); device_param->pws_cnt = 0; @@ -247,8 +248,9 @@ void *thread_calc (void *p) user_options_extra_t *user_options_extra = data.user_options_extra; hashconfig_t *hashconfig = data.hashconfig; hashes_t *hashes = data.hashes; - rules_ctx_t *rules_ctx = data.rules_ctx; opencl_ctx_t *opencl_ctx = data.opencl_ctx; + rules_ctx_t *rules_ctx = data.rules_ctx; + mask_ctx_t *mask_ctx = data.mask_ctx; const uint attack_mode = user_options->attack_mode; const uint attack_kern = user_options_extra->attack_kern; @@ -272,7 +274,7 @@ void *thread_calc (void *p) { run_copy (opencl_ctx, device_param, hashconfig, user_options, user_options_extra, pws_cnt); - run_cracker (opencl_ctx, device_param, hashconfig, hashes, user_options, user_options_extra, rules_ctx, pws_cnt); + run_cracker (opencl_ctx, device_param, hashconfig, hashes, user_options, user_options_extra, rules_ctx, mask_ctx, pws_cnt); device_param->pws_cnt = 0; @@ -464,7 +466,7 @@ void *thread_calc (void *p) { run_copy (opencl_ctx, device_param, hashconfig, user_options, user_options_extra, pws_cnt); - run_cracker (opencl_ctx, device_param, hashconfig, hashes, user_options, user_options_extra, rules_ctx, pws_cnt); + run_cracker (opencl_ctx, device_param, hashconfig, hashes, user_options, user_options_extra, rules_ctx, mask_ctx, pws_cnt); device_param->pws_cnt = 0; diff --git a/src/hash_management.c b/src/hash_management.c index cf8d9bd4c..51e4d11b8 100644 --- a/src/hash_management.c +++ b/src/hash_management.c @@ -228,6 +228,7 @@ void check_hash (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, cons loopback_ctx_t *loopback_ctx = data.loopback_ctx; outfile_ctx_t *outfile_ctx = data.outfile_ctx; potfile_ctx_t *potfile_ctx = data.potfile_ctx; + mask_ctx_t *mask_ctx = data.mask_ctx; hashconfig_t *hashconfig = data.hashconfig; hashes_t *hashes = data.hashes; @@ -360,13 +361,13 @@ void check_hash (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, cons uint l_stop = device_param->kernel_params_mp_l_buf32[4]; uint r_stop = device_param->kernel_params_mp_r_buf32[4]; - sp_exec (l_off, (char *) plain_ptr + l_start, data.root_css_buf, data.markov_css_buf, l_start, l_start + l_stop); - sp_exec (r_off, (char *) plain_ptr + r_start, data.root_css_buf, data.markov_css_buf, r_start, r_start + r_stop); + sp_exec (l_off, (char *) plain_ptr + l_start, mask_ctx->root_css_buf, mask_ctx->markov_css_buf, l_start, l_start + l_stop); + sp_exec (r_off, (char *) plain_ptr + r_start, mask_ctx->root_css_buf, mask_ctx->markov_css_buf, r_start, r_start + r_stop); - plain_len = data.css_cnt; + plain_len = mask_ctx->css_cnt; crackpos += gidvid; - crackpos *= data.bfs_cnt; + crackpos *= mask_ctx->bfs_cnt; crackpos += device_param->innerloop_pos + il_pos; } else if (user_options->attack_mode == ATTACK_MODE_HYBRID1) @@ -387,7 +388,7 @@ void check_hash (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, cons uint start = 0; uint stop = device_param->kernel_params_mp_buf32[4]; - sp_exec (off, (char *) plain_ptr + plain_len, data.root_css_buf, data.markov_css_buf, start, start + stop); + sp_exec (off, (char *) plain_ptr + plain_len, mask_ctx->root_css_buf, mask_ctx->markov_css_buf, start, start + stop); plain_len += start + stop; @@ -420,7 +421,7 @@ void check_hash (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, cons memmove (plain_ptr + stop, plain_ptr, plain_len); - sp_exec (off, (char *) plain_ptr, data.root_css_buf, data.markov_css_buf, start, start + stop); + sp_exec (off, (char *) plain_ptr, mask_ctx->root_css_buf, mask_ctx->markov_css_buf, start, start + stop); plain_len += start + stop; diff --git a/src/hashcat.c b/src/hashcat.c index d87a8ed9c..4ba723a30 100644 --- a/src/hashcat.c +++ b/src/hashcat.c @@ -419,15 +419,13 @@ static int outer_loop (user_options_t *user_options, user_options_extra_t *user_ * charsets : keep them together for more easy maintainnce */ - cs_t mp_sys[6] = { { { 0 }, 0 } }; - cs_t mp_usr[4] = { { { 0 }, 0 } }; + mask_ctx_t *mask_ctx = (mask_ctx_t *) mymalloc (sizeof (mask_ctx_t)); - mp_setup_sys (mp_sys); + data.mask_ctx = mask_ctx; - if (user_options->custom_charset_1) mp_setup_usr (mp_sys, mp_usr, user_options->custom_charset_1, 0, hashconfig, user_options); - if (user_options->custom_charset_2) mp_setup_usr (mp_sys, mp_usr, user_options->custom_charset_2, 1, hashconfig, user_options); - if (user_options->custom_charset_3) mp_setup_usr (mp_sys, mp_usr, user_options->custom_charset_3, 2, hashconfig, user_options); - if (user_options->custom_charset_4) mp_setup_usr (mp_sys, mp_usr, user_options->custom_charset_4, 3, hashconfig, user_options); + const int rc_mask_init = mask_ctx_init (mask_ctx, user_options, user_options_extra, folder_config, restore_ctx, hashconfig); + + if (rc_mask_init == -1) return -1; /** * HM devices: init @@ -1035,15 +1033,9 @@ static int outer_loop (user_options_t *user_options, user_options_extra_t *user_ wl_data_init (wl_data, user_options, hashconfig); - cs_t *css_buf = NULL; - uint css_cnt = 0; uint dictcnt = 0; - uint maskcnt = 1; - char **masks = NULL; char **dictfiles = NULL; - uint mask_from_file = 0; - if (user_options->attack_mode == ATTACK_MODE_STRAIGHT) { if (user_options_extra->wordlist_mode == WL_MODE_FILE) @@ -1267,219 +1259,30 @@ static int outer_loop (user_options_t *user_options, user_options_extra_t *user_ } else if (user_options->attack_mode == ATTACK_MODE_BF) { - char *mask = NULL; - - maskcnt = 0; - - if (user_options->benchmark == false) + if (user_options->benchmark == true) { - mask = myargv[user_options_extra->optind + 1]; - - masks = (char **) mymalloc (INCR_MASKS * sizeof (char *)); - - if ((user_options_extra->optind + 2) <= myargc) - { - struct stat file_stat; - - if (stat (mask, &file_stat) == -1) - { - maskcnt = 1; - - masks[maskcnt - 1] = mystrdup (mask); - } - else - { - int wls_left = myargc - (user_options_extra->optind + 1); - - uint masks_avail = INCR_MASKS; - - for (int i = 0; i < wls_left; i++) - { - if (i != 0) - { - mask = myargv[user_options_extra->optind + 1 + i]; - - if (stat (mask, &file_stat) == -1) - { - log_error ("ERROR: %s: %s", mask, strerror (errno)); - - return -1; - } - } - - uint is_file = S_ISREG (file_stat.st_mode); - - if (is_file == 1) - { - FILE *mask_fp; - - if ((mask_fp = fopen (mask, "r")) == NULL) - { - log_error ("ERROR: %s: %s", mask, strerror (errno)); - - return -1; - } - - char *line_buf = (char *) mymalloc (HCBUFSIZ_LARGE); - - while (!feof (mask_fp)) - { - memset (line_buf, 0, HCBUFSIZ_LARGE); - - int line_len = fgetl (mask_fp, line_buf); - - if (line_len == 0) continue; - - if (line_buf[0] == '#') continue; - - if (masks_avail == maskcnt) - { - masks = (char **) myrealloc (masks, masks_avail * sizeof (char *), INCR_MASKS * sizeof (char *)); - - masks_avail += INCR_MASKS; - } - - masks[maskcnt] = mystrdup (line_buf); - - maskcnt++; - } - - myfree (line_buf); - - fclose (mask_fp); - } - else - { - log_error ("ERROR: %s: unsupported file-type", mask); - - return -1; - } - } - - mask_from_file = 1; - } - } - else - { - user_options->custom_charset_1 = (char *) "?l?d?u"; - user_options->custom_charset_2 = (char *) "?l?d"; - user_options->custom_charset_3 = (char *) "?l?d*!$@_"; - - mp_setup_usr (mp_sys, mp_usr, user_options->custom_charset_1, 0, hashconfig, user_options); - mp_setup_usr (mp_sys, mp_usr, user_options->custom_charset_2, 1, hashconfig, user_options); - mp_setup_usr (mp_sys, mp_usr, user_options->custom_charset_3, 2, hashconfig, user_options); - - maskcnt = 1; - - masks[maskcnt - 1] = mystrdup ("?1?2?2?2?2?2?2?3?3?3?3?d?d?d?d"); - - user_options->increment = true; - } - } - else - { - /** - * generate full masks and charsets - */ - - mask = hashconfig_benchmark_mask (hashconfig); - - pw_min = mp_get_length (mask); + pw_min = mp_get_length (mask_ctx->mask); pw_max = pw_min; - - masks = (char **) mymalloc (sizeof (char *)); - - maskcnt = 1; - - masks[maskcnt - 1] = mystrdup (mask); - - user_options->increment = true; } - dictfiles = (char **) mycalloc (pw_max, sizeof (char *)); - + /* i think we can do this better if (user_options->increment == true) { if (user_options->increment_min > pw_min) pw_min = user_options->increment_min; if (user_options->increment_max < pw_max) pw_max = user_options->increment_max; } + */ + + dictfiles = (char **) mycalloc (1, sizeof (char *)); + dictfiles[0] = "DUMMY"; + + dictcnt = 1; } else if (user_options->attack_mode == ATTACK_MODE_HYBRID1) { data.combs_mode = COMBINATOR_MODE_BASE_LEFT; - // display - - char *mask = myargv[myargc - 1]; - - maskcnt = 0; - - masks = (char **) mymalloc (1 * sizeof (char *)); - - // mod - - struct stat file_stat; - - if (stat (mask, &file_stat) == -1) - { - maskcnt = 1; - - masks[maskcnt - 1] = mystrdup (mask); - } - else - { - uint is_file = S_ISREG (file_stat.st_mode); - - if (is_file == 1) - { - FILE *mask_fp; - - if ((mask_fp = fopen (mask, "r")) == NULL) - { - log_error ("ERROR: %s: %s", mask, strerror (errno)); - - return -1; - } - - char *line_buf = (char *) mymalloc (HCBUFSIZ_LARGE); - - uint masks_avail = 1; - - while (!feof (mask_fp)) - { - memset (line_buf, 0, HCBUFSIZ_LARGE); - - int line_len = fgetl (mask_fp, line_buf); - - if (line_len == 0) continue; - - if (line_buf[0] == '#') continue; - - if (masks_avail == maskcnt) - { - masks = (char **) myrealloc (masks, masks_avail * sizeof (char *), INCR_MASKS * sizeof (char *)); - - masks_avail += INCR_MASKS; - } - - masks[maskcnt] = mystrdup (line_buf); - - maskcnt++; - } - - myfree (line_buf); - - fclose (mask_fp); - - mask_from_file = 1; - } - else - { - maskcnt = 1; - - masks[maskcnt - 1] = mystrdup (mask); - } - } + // mod -- moved to mpsp.c // base @@ -1561,104 +1364,12 @@ static int outer_loop (user_options_t *user_options, user_options_extra_t *user_ return -1; } - - if (user_options->increment == true) - { - maskcnt = 0; - - uint mask_min = user_options->increment_min; // we can't reject smaller masks here - uint mask_max = (user_options->increment_max < pw_max) ? user_options->increment_max : pw_max; - - for (uint mask_cur = mask_min; mask_cur <= mask_max; mask_cur++) - { - char *cur_mask = mp_get_truncated_mask (mask, strlen (mask), mask_cur, user_options); - - if (cur_mask == NULL) break; - - masks[maskcnt] = cur_mask; - - maskcnt++; - - masks = (char **) myrealloc (masks, maskcnt * sizeof (char *), sizeof (char *)); - } - } } else if (user_options->attack_mode == ATTACK_MODE_HYBRID2) { data.combs_mode = COMBINATOR_MODE_BASE_RIGHT; - // display - - char *mask = myargv[user_options_extra->optind + 1 + 0]; - - maskcnt = 0; - - masks = (char **) mymalloc (1 * sizeof (char *)); - - // mod - - struct stat file_stat; - - if (stat (mask, &file_stat) == -1) - { - maskcnt = 1; - - masks[maskcnt - 1] = mystrdup (mask); - } - else - { - uint is_file = S_ISREG (file_stat.st_mode); - - if (is_file == 1) - { - FILE *mask_fp; - - if ((mask_fp = fopen (mask, "r")) == NULL) - { - log_error ("ERROR: %s: %s", mask, strerror (errno)); - - return -1; - } - - char *line_buf = (char *) mymalloc (HCBUFSIZ_LARGE); - - uint masks_avail = 1; - - while (!feof (mask_fp)) - { - memset (line_buf, 0, HCBUFSIZ_LARGE); - - int line_len = fgetl (mask_fp, line_buf); - - if (line_len == 0) continue; - - if (line_buf[0] == '#') continue; - - if (masks_avail == maskcnt) - { - masks = (char **) myrealloc (masks, masks_avail * sizeof (char *), INCR_MASKS * sizeof (char *)); - - masks_avail += INCR_MASKS; - } - - masks[maskcnt] = mystrdup (line_buf); - - maskcnt++; - } - - myfree (line_buf); - - fclose (mask_fp); - - mask_from_file = 1; - } - else - { - maskcnt = 1; - - masks[maskcnt - 1] = mystrdup (mask); - } - } + // mod -- moved to mpsp.c // base @@ -1740,27 +1451,6 @@ static int outer_loop (user_options_t *user_options, user_options_extra_t *user_ return -1; } - - if (user_options->increment == true) - { - maskcnt = 0; - - uint mask_min = user_options->increment_min; // we can't reject smaller masks here - uint mask_max = (user_options->increment_max < pw_max) ? user_options->increment_max : pw_max; - - for (uint mask_cur = mask_min; mask_cur <= mask_max; mask_cur++) - { - char *cur_mask = mp_get_truncated_mask (mask, strlen (mask), mask_cur, user_options); - - if (cur_mask == NULL) break; - - masks[maskcnt] = cur_mask; - - maskcnt++; - - masks = (char **) myrealloc (masks, maskcnt * sizeof (char *), sizeof (char *)); - } - } } data.pw_min = pw_min; @@ -1846,17 +1536,15 @@ static int outer_loop (user_options_t *user_options, user_options_extra_t *user_ } } - hcstat_table_t *root_table_buf = NULL; - hcstat_table_t *markov_table_buf = NULL; - // still needed? // bool initial_restore_done = false; - data.maskcnt = maskcnt; + // still needed? + // mask_ctx->masks_cnt = maskcnt; restore_data_t *rd = restore_ctx->rd; - for (uint maskpos = rd->maskpos; maskpos < maskcnt; maskpos++) + for (uint masks_pos = rd->masks_pos; masks_pos < mask_ctx->masks_cnt; masks_pos++) { //opencl_ctx->run_main_level1 = true; //opencl_ctx->run_main_level2 = true; @@ -1864,21 +1552,22 @@ static int outer_loop (user_options_t *user_options, user_options_extra_t *user_ opencl_ctx->run_thread_level1 = true; opencl_ctx->run_thread_level2 = true; - if (maskpos > rd->maskpos) + if (masks_pos > rd->masks_pos) { rd->dictpos = 0; } - rd->maskpos = maskpos; - data.maskpos = maskpos; + rd->masks_pos = masks_pos; + + mask_ctx->masks_pos = masks_pos; if (user_options->attack_mode == ATTACK_MODE_HYBRID1 || user_options->attack_mode == ATTACK_MODE_HYBRID2 || user_options->attack_mode == ATTACK_MODE_BF) { - char *mask = masks[maskpos]; + mask_ctx->mask = mask_ctx->masks[mask_ctx->masks_pos]; - if (mask_from_file == true) + if (mask_ctx->mask_from_file == true) { - if (mask[0] == '\\' && mask[1] == '#') mask++; // escaped comment sign (sharp) "\#" + if (mask_ctx->mask[0] == '\\' && mask_ctx->mask[1] == '#') mask_ctx->mask++; // escaped comment sign (sharp) "\#" char *str_ptr; uint str_pos; @@ -1889,17 +1578,17 @@ static int outer_loop (user_options_t *user_options, user_options_extra_t *user_ for (separator_cnt = 0; separator_cnt < 4; separator_cnt++) { - str_ptr = strstr (mask + mask_offset, ","); + str_ptr = strstr (mask_ctx->mask + mask_offset, ","); if (str_ptr == NULL) break; - str_pos = str_ptr - mask; + str_pos = str_ptr - mask_ctx->mask; // escaped separator, i.e. "\," if (str_pos > 0) { - if (mask[str_pos - 1] == '\\') + if (mask_ctx->mask[str_pos - 1] == '\\') { separator_cnt --; @@ -1913,40 +1602,44 @@ static int outer_loop (user_options_t *user_options, user_options_extra_t *user_ mask_offset = 0; - mask[str_pos] = '\0'; + mask_ctx->mask[str_pos] = 0; switch (separator_cnt) { case 0: - mp_reset_usr (mp_usr, 0); + mp_reset_usr (mask_ctx->mp_usr, 0); - user_options->custom_charset_1 = mask; - mp_setup_usr (mp_sys, mp_usr, user_options->custom_charset_1, 0, hashconfig, user_options); + user_options->custom_charset_1 = mask_ctx->mask; + + mp_setup_usr (mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_1, 0, hashconfig, user_options); break; case 1: - mp_reset_usr (mp_usr, 1); + mp_reset_usr (mask_ctx->mp_usr, 1); - user_options->custom_charset_2 = mask; - mp_setup_usr (mp_sys, mp_usr, user_options->custom_charset_2, 1, hashconfig, user_options); + user_options->custom_charset_2 = mask_ctx->mask; + + mp_setup_usr (mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_2, 1, hashconfig, user_options); break; case 2: - mp_reset_usr (mp_usr, 2); + mp_reset_usr (mask_ctx->mp_usr, 2); - user_options->custom_charset_3 = mask; - mp_setup_usr (mp_sys, mp_usr, user_options->custom_charset_3, 2, hashconfig, user_options); + user_options->custom_charset_3 = mask_ctx->mask; + + mp_setup_usr (mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_3, 2, hashconfig, user_options); break; case 3: - mp_reset_usr (mp_usr, 3); + mp_reset_usr (mask_ctx->mp_usr, 3); - user_options->custom_charset_4 = mask; - mp_setup_usr (mp_sys, mp_usr, user_options->custom_charset_4, 3, hashconfig, user_options); + user_options->custom_charset_4 = mask_ctx->mask; + + mp_setup_usr (mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_4, 3, hashconfig, user_options); break; } - mask = mask + str_pos + 1; + mask_ctx->mask += str_pos + 1; } /** @@ -1957,14 +1650,14 @@ static int outer_loop (user_options_t *user_options, user_options_extra_t *user_ * Note: "\\" is not needed to replace all "\" within the mask! The meaning of "\\" within a line containing the string "\\," is just to allow "\" followed by "," */ - uint mask_len_cur = strlen (mask); + uint mask_len_cur = strlen (mask_ctx->mask); uint mask_out_pos = 0; char mask_prev = 0; for (uint mask_iter = 0; mask_iter < mask_len_cur; mask_iter++, mask_out_pos++) { - if (mask[mask_iter] == ',') + if (mask_ctx->mask[mask_iter] == ',') { if (mask_prev == '\\') { @@ -1972,52 +1665,25 @@ static int outer_loop (user_options_t *user_options, user_options_extra_t *user_ } } - mask_prev = mask[mask_iter]; + mask_prev = mask_ctx->mask[mask_iter]; - mask[mask_out_pos] = mask[mask_iter]; + mask_ctx->mask[mask_out_pos] = mask_ctx->mask[mask_iter]; } - mask[mask_out_pos] = '\0'; + mask_ctx->mask[mask_out_pos] = 0; } if ((user_options->attack_mode == ATTACK_MODE_HYBRID1) || (user_options->attack_mode == ATTACK_MODE_HYBRID2)) { - if (maskpos > 0) - { - local_free (css_buf); - local_free (data.root_css_buf); - local_free (data.markov_css_buf); - - local_free (masks[maskpos - 1]); - } - - css_buf = mp_gen_css (mask, strlen (mask), mp_sys, mp_usr, &css_cnt, hashconfig, user_options); - - data.mask = mask; - data.css_cnt = css_cnt; - data.css_buf = css_buf; + mask_ctx->css_buf = mp_gen_css (mask_ctx->mask, strlen (mask_ctx->mask), mask_ctx->mp_sys, mask_ctx->mp_usr, &mask_ctx->css_cnt, hashconfig, user_options); uint uniq_tbls[SP_PW_MAX][CHARSIZ] = { { 0 } }; - mp_css_to_uniq_tbl (css_cnt, css_buf, uniq_tbls); + mp_css_to_uniq_tbl (mask_ctx->css_cnt, mask_ctx->css_buf, uniq_tbls); - if (root_table_buf == NULL) root_table_buf = (hcstat_table_t *) mycalloc (SP_ROOT_CNT, sizeof (hcstat_table_t)); - if (markov_table_buf == NULL) markov_table_buf = (hcstat_table_t *) mycalloc (SP_MARKOV_CNT, sizeof (hcstat_table_t)); + sp_tbl_to_css (mask_ctx->root_table_buf, mask_ctx->markov_table_buf, mask_ctx->root_css_buf, mask_ctx->markov_css_buf, user_options->markov_threshold, uniq_tbls); - sp_setup_tbl (folder_config->shared_dir, user_options->markov_hcstat, user_options->markov_disable, user_options->markov_classic, root_table_buf, markov_table_buf); - - cs_t *root_css_buf = (cs_t *) mycalloc (SP_PW_MAX, sizeof (cs_t)); - cs_t *markov_css_buf = (cs_t *) mycalloc (SP_PW_MAX * CHARSIZ, sizeof (cs_t)); - - data.root_css_buf = root_css_buf; - data.markov_css_buf = markov_css_buf; - - sp_tbl_to_css (root_table_buf, markov_table_buf, root_css_buf, markov_css_buf, user_options->markov_threshold, uniq_tbls); - - data.combs_cnt = sp_get_sum (0, css_cnt, root_css_buf); - - local_free (root_table_buf); - local_free (markov_table_buf); + data.combs_cnt = sp_get_sum (0, mask_ctx->css_cnt, mask_ctx->root_css_buf); // args @@ -2032,7 +1698,7 @@ static int outer_loop (user_options_t *user_options, user_options_extra_t *user_ device_param->kernel_params_mp[2] = &device_param->d_markov_css_buf; device_param->kernel_params_mp_buf64[3] = 0; - device_param->kernel_params_mp_buf32[4] = css_cnt; + device_param->kernel_params_mp_buf32[4] = mask_ctx->css_cnt; device_param->kernel_params_mp_buf32[5] = 0; device_param->kernel_params_mp_buf32[6] = 0; device_param->kernel_params_mp_buf32[7] = 0; @@ -2064,8 +1730,8 @@ static int outer_loop (user_options_t *user_options, user_options_extra_t *user_ return -1; } - CL_err |= hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_root_css_buf, CL_TRUE, 0, device_param->size_root_css, root_css_buf, 0, NULL, NULL); - CL_err |= hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_markov_css_buf, CL_TRUE, 0, device_param->size_markov_css, markov_css_buf, 0, NULL, NULL); + CL_err |= hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_root_css_buf, CL_TRUE, 0, device_param->size_root_css, mask_ctx->root_css_buf, 0, NULL, NULL); + CL_err |= hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_markov_css_buf, CL_TRUE, 0, device_param->size_markov_css, mask_ctx->markov_css_buf, 0, NULL, NULL); if (CL_err != CL_SUCCESS) { @@ -2077,38 +1743,215 @@ static int outer_loop (user_options_t *user_options, user_options_extra_t *user_ } else if (user_options->attack_mode == ATTACK_MODE_BF) { - dictcnt = 0; // number of "sub-masks", i.e. when using incremental mode + mask_ctx->css_buf = mp_gen_css (mask_ctx->mask, strlen (mask_ctx->mask), mask_ctx->mp_sys, mask_ctx->mp_usr, &mask_ctx->css_cnt, hashconfig, user_options); - if (user_options->increment == true) + if (hashconfig->opts_type & OPTS_TYPE_PT_UNICODE) { - for (uint i = 0; i < dictcnt; i++) + u32 css_cnt_unicode = mask_ctx->css_cnt * 2; + + cs_t *css_buf_unicode = (cs_t *) mycalloc (css_cnt_unicode, sizeof (cs_t)); + + for (uint i = 0, j = 0; i < mask_ctx->css_cnt; i += 1, j += 2) { - local_free (dictfiles[i]); + memcpy (&css_buf_unicode[j + 0], &mask_ctx->css_buf[i], sizeof (cs_t)); + + css_buf_unicode[j + 1].cs_buf[0] = 0; + css_buf_unicode[j + 1].cs_len = 1; } - for (uint pw_len = MAX (1, pw_min); pw_len <= pw_max; pw_len++) + myfree (mask_ctx->css_buf); + + mask_ctx->css_buf = css_buf_unicode; + mask_ctx->css_cnt = css_cnt_unicode; + } + + // check if mask is not too large or too small for pw_min/pw_max (*2 if unicode) + + uint mask_min = pw_min; + uint mask_max = pw_max; + + if (hashconfig->opts_type & OPTS_TYPE_PT_UNICODE) + { + mask_min *= 2; + mask_max *= 2; + } + + if ((mask_ctx->css_cnt < mask_min) || (mask_ctx->css_cnt > mask_max)) + { + if (mask_ctx->css_cnt < mask_min) { - char *l1_filename = mp_get_truncated_mask (mask, strlen (mask), pw_len, user_options); + log_info ("WARNING: Skipping mask '%s' because it is smaller than the minimum password length", mask_ctx->mask); + } - if (l1_filename == NULL) break; + if (mask_ctx->css_cnt > mask_max) + { + log_info ("WARNING: Skipping mask '%s' because it is larger than the maximum password length", mask_ctx->mask); + } - dictcnt++; + // skip to next mask - dictfiles[dictcnt - 1] = l1_filename; + logfile_sub_msg ("STOP"); + + continue; + } + + u32 css_cnt_orig = mask_ctx->css_cnt; + + if (hashconfig->opti_type & OPTI_TYPE_SINGLE_HASH) + { + if (hashconfig->opti_type & OPTI_TYPE_APPENDED_SALT) + { + uint salt_len = (uint) hashes->salts_buf[0].salt_len; + char *salt_buf = (char *) hashes->salts_buf[0].salt_buf; + + uint css_cnt_salt = mask_ctx->css_cnt + salt_len; + + cs_t *css_buf_salt = (cs_t *) mycalloc (css_cnt_salt, sizeof (cs_t)); + + memcpy (css_buf_salt, mask_ctx->css_buf, mask_ctx->css_cnt * sizeof (cs_t)); + + for (uint i = 0, j = mask_ctx->css_cnt; i < salt_len; i++, j++) + { + css_buf_salt[j].cs_buf[0] = salt_buf[i]; + css_buf_salt[j].cs_len = 1; + } + + myfree (mask_ctx->css_buf); + + mask_ctx->css_buf = css_buf_salt; + mask_ctx->css_cnt = css_cnt_salt; + } + } + + uint uniq_tbls[SP_PW_MAX][CHARSIZ] = { { 0 } }; + + mp_css_to_uniq_tbl (mask_ctx->css_cnt, mask_ctx->css_buf, uniq_tbls); + + sp_tbl_to_css (mask_ctx->root_table_buf, mask_ctx->markov_table_buf, mask_ctx->root_css_buf, mask_ctx->markov_css_buf, user_options->markov_threshold, uniq_tbls); + + data.words_cnt = sp_get_sum (0, mask_ctx->css_cnt, mask_ctx->root_css_buf); + + // copy + args + + uint css_cnt_l = mask_ctx->css_cnt; + uint css_cnt_r; + + if (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL) + { + if (css_cnt_orig < 6) + { + css_cnt_r = 1; + } + else if (css_cnt_orig == 6) + { + css_cnt_r = 2; + } + else + { + if (hashconfig->opts_type & OPTS_TYPE_PT_UNICODE) + { + if (css_cnt_orig == 8 || css_cnt_orig == 10) + { + css_cnt_r = 2; + } + else + { + css_cnt_r = 4; + } + } + else + { + if ((mask_ctx->css_buf[0].cs_len * mask_ctx->css_buf[1].cs_len * mask_ctx->css_buf[2].cs_len) > 256) + { + css_cnt_r = 3; + } + else + { + css_cnt_r = 4; + } + } } } else { - dictcnt++; + css_cnt_r = 1; - dictfiles[dictcnt - 1] = mask; + /* unfinished code? + int sum = css_buf[css_cnt_r - 1].cs_len; + + for (uint i = 1; i < 4 && i < css_cnt; i++) + { + if (sum > 1) break; // we really don't need alot of amplifier them for slow hashes + + css_cnt_r++; + + sum *= css_buf[css_cnt_r - 1].cs_len; + } + */ } - if (dictcnt == 0) - { - log_error ("ERROR: Mask is too small"); + css_cnt_l -= css_cnt_r; - return -1; + mask_ctx->bfs_cnt = sp_get_sum (0, css_cnt_r, mask_ctx->root_css_buf); + + for (uint device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) + { + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; + + if (device_param->skipped) continue; + + device_param->kernel_params_mp_l[0] = &device_param->d_pws_buf; + device_param->kernel_params_mp_l[1] = &device_param->d_root_css_buf; + device_param->kernel_params_mp_l[2] = &device_param->d_markov_css_buf; + + device_param->kernel_params_mp_l_buf64[3] = 0; + device_param->kernel_params_mp_l_buf32[4] = css_cnt_l; + device_param->kernel_params_mp_l_buf32[5] = css_cnt_r; + device_param->kernel_params_mp_l_buf32[6] = 0; + device_param->kernel_params_mp_l_buf32[7] = 0; + device_param->kernel_params_mp_l_buf32[8] = 0; + + if (hashconfig->opts_type & OPTS_TYPE_PT_ADD01) device_param->kernel_params_mp_l_buf32[6] = full01; + if (hashconfig->opts_type & OPTS_TYPE_PT_ADD80) device_param->kernel_params_mp_l_buf32[6] = full80; + if (hashconfig->opts_type & OPTS_TYPE_PT_ADDBITS14) device_param->kernel_params_mp_l_buf32[7] = 1; + if (hashconfig->opts_type & OPTS_TYPE_PT_ADDBITS15) device_param->kernel_params_mp_l_buf32[8] = 1; + + device_param->kernel_params_mp_r[0] = &device_param->d_bfs; + device_param->kernel_params_mp_r[1] = &device_param->d_root_css_buf; + device_param->kernel_params_mp_r[2] = &device_param->d_markov_css_buf; + + device_param->kernel_params_mp_r_buf64[3] = 0; + device_param->kernel_params_mp_r_buf32[4] = css_cnt_r; + device_param->kernel_params_mp_r_buf32[5] = 0; + device_param->kernel_params_mp_r_buf32[6] = 0; + device_param->kernel_params_mp_r_buf32[7] = 0; + + cl_int CL_err = CL_SUCCESS; + + for (uint i = 0; i < 3; i++) CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel_mp_l, i, sizeof (cl_mem), (void *) device_param->kernel_params_mp_l[i]); + for (uint i = 3; i < 4; i++) CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel_mp_l, i, sizeof (cl_ulong), (void *) device_param->kernel_params_mp_l[i]); + for (uint i = 4; i < 9; i++) CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel_mp_l, i, sizeof (cl_uint), (void *) device_param->kernel_params_mp_l[i]); + + for (uint i = 0; i < 3; i++) CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel_mp_r, i, sizeof (cl_mem), (void *) device_param->kernel_params_mp_r[i]); + for (uint i = 3; i < 4; i++) CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel_mp_r, i, sizeof (cl_ulong), (void *) device_param->kernel_params_mp_r[i]); + for (uint i = 4; i < 8; i++) CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel_mp_r, i, sizeof (cl_uint), (void *) device_param->kernel_params_mp_r[i]); + + if (CL_err != CL_SUCCESS) + { + log_error ("ERROR: clSetKernelArg(): %s\n", val2cstr_cl (CL_err)); + + return -1; + } + + CL_err |= hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_root_css_buf, CL_TRUE, 0, device_param->size_root_css, mask_ctx->root_css_buf, 0, NULL, NULL); + CL_err |= hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_markov_css_buf, CL_TRUE, 0, device_param->size_markov_css, mask_ctx->markov_css_buf, 0, NULL, NULL); + + if (CL_err != CL_SUCCESS) + { + log_error ("ERROR: clEnqueueWriteBuffer(): %s\n", val2cstr_cl (CL_err)); + + return -1; + } } } } @@ -2125,7 +1968,7 @@ static int outer_loop (user_options_t *user_options, user_options_extra_t *user_ if (user_options->skip != 0 || user_options->limit != 0) { - if ((maskcnt > 1) || (dictcnt > 1)) + if ((mask_ctx->masks_cnt > 1) || (dictcnt > 1)) { log_error ("ERROR: --skip/--limit are not supported with --increment or mask files"); @@ -2139,7 +1982,7 @@ static int outer_loop (user_options_t *user_options, user_options_extra_t *user_ if (user_options->keyspace == true) { - if ((maskcnt > 1) || (dictcnt > 1)) + if ((mask_ctx->masks_cnt > 1) || (dictcnt > 1)) { log_error ("ERROR: --keyspace is not supported with --increment or mask files"); @@ -2333,10 +2176,8 @@ static int outer_loop (user_options_t *user_options, user_options_extra_t *user_ data.dictfile = dictfile; - char *mask = data.mask; - logfile_sub_string (dictfile); - logfile_sub_string (mask); + logfile_sub_string (mask_ctx->mask); FILE *fd2 = fopen (dictfile, "rb"); @@ -2360,246 +2201,7 @@ static int outer_loop (user_options_t *user_options, user_options_extra_t *user_ } else if (user_options->attack_mode == ATTACK_MODE_BF) { - local_free (css_buf); - local_free (data.root_css_buf); - local_free (data.markov_css_buf); - - char *mask = dictfiles[dictpos]; - - logfile_sub_string (mask); - - // base - - css_buf = mp_gen_css (mask, strlen (mask), mp_sys, mp_usr, &css_cnt, hashconfig, user_options); - - if (hashconfig->opts_type & OPTS_TYPE_PT_UNICODE) - { - uint css_cnt_unicode = css_cnt * 2; - - cs_t *css_buf_unicode = (cs_t *) mycalloc (css_cnt_unicode, sizeof (cs_t)); - - for (uint i = 0, j = 0; i < css_cnt; i += 1, j += 2) - { - memcpy (&css_buf_unicode[j + 0], &css_buf[i], sizeof (cs_t)); - - css_buf_unicode[j + 1].cs_buf[0] = 0; - css_buf_unicode[j + 1].cs_len = 1; - } - - free (css_buf); - - css_buf = css_buf_unicode; - css_cnt = css_cnt_unicode; - } - - // check if mask is not too large or too small for pw_min/pw_max (*2 if unicode) - - uint mask_min = pw_min; - uint mask_max = pw_max; - - if (hashconfig->opts_type & OPTS_TYPE_PT_UNICODE) - { - mask_min *= 2; - mask_max *= 2; - } - - if ((css_cnt < mask_min) || (css_cnt > mask_max)) - { - if (css_cnt < mask_min) - { - log_info ("WARNING: Skipping mask '%s' because it is smaller than the minimum password length", mask); - } - - if (css_cnt > mask_max) - { - log_info ("WARNING: Skipping mask '%s' because it is larger than the maximum password length", mask); - } - - // skip to next mask - - logfile_sub_msg ("STOP"); - - continue; - } - - uint save_css_cnt = css_cnt; - - if (hashconfig->opti_type & OPTI_TYPE_SINGLE_HASH) - { - if (hashconfig->opti_type & OPTI_TYPE_APPENDED_SALT) - { - uint salt_len = (uint) hashes->salts_buf[0].salt_len; - char *salt_buf = (char *) hashes->salts_buf[0].salt_buf; - - uint css_cnt_salt = css_cnt + salt_len; - - cs_t *css_buf_salt = (cs_t *) mycalloc (css_cnt_salt, sizeof (cs_t)); - - memcpy (css_buf_salt, css_buf, css_cnt * sizeof (cs_t)); - - for (uint i = 0, j = css_cnt; i < salt_len; i++, j++) - { - css_buf_salt[j].cs_buf[0] = salt_buf[i]; - css_buf_salt[j].cs_len = 1; - } - - free (css_buf); - - css_buf = css_buf_salt; - css_cnt = css_cnt_salt; - } - } - - data.mask = mask; - data.css_cnt = css_cnt; - data.css_buf = css_buf; - - if (maskpos > 0 && dictpos == 0) free (masks[maskpos - 1]); - - uint uniq_tbls[SP_PW_MAX][CHARSIZ] = { { 0 } }; - - mp_css_to_uniq_tbl (css_cnt, css_buf, uniq_tbls); - - if (root_table_buf == NULL) root_table_buf = (hcstat_table_t *) mycalloc (SP_ROOT_CNT, sizeof (hcstat_table_t)); - if (markov_table_buf == NULL) markov_table_buf = (hcstat_table_t *) mycalloc (SP_MARKOV_CNT, sizeof (hcstat_table_t)); - - sp_setup_tbl (folder_config->shared_dir, user_options->markov_hcstat, user_options->markov_disable, user_options->markov_classic, root_table_buf, markov_table_buf); - - cs_t *root_css_buf = (cs_t *) mycalloc (SP_PW_MAX, sizeof (cs_t)); - cs_t *markov_css_buf = (cs_t *) mycalloc (SP_PW_MAX * CHARSIZ, sizeof (cs_t)); - - data.root_css_buf = root_css_buf; - data.markov_css_buf = markov_css_buf; - - sp_tbl_to_css (root_table_buf, markov_table_buf, root_css_buf, markov_css_buf, user_options->markov_threshold, uniq_tbls); - - data.words_cnt = sp_get_sum (0, css_cnt, root_css_buf); - - local_free (root_table_buf); - local_free (markov_table_buf); - - // copy + args - - uint css_cnt_l = css_cnt; - uint css_cnt_r; - - if (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL) - { - if (save_css_cnt < 6) - { - css_cnt_r = 1; - } - else if (save_css_cnt == 6) - { - css_cnt_r = 2; - } - else - { - if (hashconfig->opts_type & OPTS_TYPE_PT_UNICODE) - { - if (save_css_cnt == 8 || save_css_cnt == 10) - { - css_cnt_r = 2; - } - else - { - css_cnt_r = 4; - } - } - else - { - if ((css_buf[0].cs_len * css_buf[1].cs_len * css_buf[2].cs_len) > 256) - { - css_cnt_r = 3; - } - else - { - css_cnt_r = 4; - } - } - } - } - else - { - css_cnt_r = 1; - - /* unfinished code? - int sum = css_buf[css_cnt_r - 1].cs_len; - - for (uint i = 1; i < 4 && i < css_cnt; i++) - { - if (sum > 1) break; // we really don't need alot of amplifier them for slow hashes - - css_cnt_r++; - - sum *= css_buf[css_cnt_r - 1].cs_len; - } - */ - } - - css_cnt_l -= css_cnt_r; - - data.bfs_cnt = sp_get_sum (0, css_cnt_r, root_css_buf); - - for (uint device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) - { - hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; - - if (device_param->skipped) continue; - - device_param->kernel_params_mp_l[0] = &device_param->d_pws_buf; - device_param->kernel_params_mp_l[1] = &device_param->d_root_css_buf; - device_param->kernel_params_mp_l[2] = &device_param->d_markov_css_buf; - - device_param->kernel_params_mp_l_buf64[3] = 0; - device_param->kernel_params_mp_l_buf32[4] = css_cnt_l; - device_param->kernel_params_mp_l_buf32[5] = css_cnt_r; - device_param->kernel_params_mp_l_buf32[6] = 0; - device_param->kernel_params_mp_l_buf32[7] = 0; - device_param->kernel_params_mp_l_buf32[8] = 0; - - if (hashconfig->opts_type & OPTS_TYPE_PT_ADD01) device_param->kernel_params_mp_l_buf32[6] = full01; - if (hashconfig->opts_type & OPTS_TYPE_PT_ADD80) device_param->kernel_params_mp_l_buf32[6] = full80; - if (hashconfig->opts_type & OPTS_TYPE_PT_ADDBITS14) device_param->kernel_params_mp_l_buf32[7] = 1; - if (hashconfig->opts_type & OPTS_TYPE_PT_ADDBITS15) device_param->kernel_params_mp_l_buf32[8] = 1; - - device_param->kernel_params_mp_r[0] = &device_param->d_bfs; - device_param->kernel_params_mp_r[1] = &device_param->d_root_css_buf; - device_param->kernel_params_mp_r[2] = &device_param->d_markov_css_buf; - - device_param->kernel_params_mp_r_buf64[3] = 0; - device_param->kernel_params_mp_r_buf32[4] = css_cnt_r; - device_param->kernel_params_mp_r_buf32[5] = 0; - device_param->kernel_params_mp_r_buf32[6] = 0; - device_param->kernel_params_mp_r_buf32[7] = 0; - - cl_int CL_err = CL_SUCCESS; - - for (uint i = 0; i < 3; i++) CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel_mp_l, i, sizeof (cl_mem), (void *) device_param->kernel_params_mp_l[i]); - for (uint i = 3; i < 4; i++) CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel_mp_l, i, sizeof (cl_ulong), (void *) device_param->kernel_params_mp_l[i]); - for (uint i = 4; i < 9; i++) CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel_mp_l, i, sizeof (cl_uint), (void *) device_param->kernel_params_mp_l[i]); - - for (uint i = 0; i < 3; i++) CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel_mp_r, i, sizeof (cl_mem), (void *) device_param->kernel_params_mp_r[i]); - for (uint i = 3; i < 4; i++) CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel_mp_r, i, sizeof (cl_ulong), (void *) device_param->kernel_params_mp_r[i]); - for (uint i = 4; i < 8; i++) CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel_mp_r, i, sizeof (cl_uint), (void *) device_param->kernel_params_mp_r[i]); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clSetKernelArg(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - - CL_err |= hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_root_css_buf, CL_TRUE, 0, device_param->size_root_css, root_css_buf, 0, NULL, NULL); - CL_err |= hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_markov_css_buf, CL_TRUE, 0, device_param->size_markov_css, markov_css_buf, 0, NULL, NULL); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clEnqueueWriteBuffer(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - } + logfile_sub_string (mask_ctx->mask); } u64 words_base = data.words_cnt; @@ -2620,9 +2222,9 @@ static int outer_loop (user_options_t *user_options, user_options_extra_t *user_ } else if (user_options_extra->attack_kern == ATTACK_KERN_BF) { - if (data.bfs_cnt) + if (mask_ctx->bfs_cnt) { - words_base /= data.bfs_cnt; + words_base /= mask_ctx->bfs_cnt; } } @@ -2662,7 +2264,7 @@ static int outer_loop (user_options_t *user_options, user_options_extra_t *user_ { for (uint i = 0; i < hashes->salts_cnt; i++) { - data.words_progress_restored[i] = data.words_cur * data.bfs_cnt; + data.words_progress_restored[i] = data.words_cur * mask_ctx->bfs_cnt; } } } @@ -2700,7 +2302,7 @@ static int outer_loop (user_options_t *user_options, user_options_extra_t *user_ { if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT) innerloop_cnt = rules_ctx->kernel_rules_cnt; else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI) innerloop_cnt = data.combs_cnt; - else if (user_options_extra->attack_kern == ATTACK_KERN_BF) innerloop_cnt = data.bfs_cnt; + else if (user_options_extra->attack_kern == ATTACK_KERN_BF) innerloop_cnt = mask_ctx->bfs_cnt; } else { @@ -2863,7 +2465,7 @@ static int outer_loop (user_options_t *user_options, user_options_extra_t *user_ { clear_prompt (); - status_display (opencl_ctx, hashconfig, hashes, restore_ctx, user_options, user_options_extra, rules_ctx); + status_display (opencl_ctx, hashconfig, hashes, restore_ctx, user_options, user_options_extra, rules_ctx, mask_ctx); log_info (""); } @@ -2871,7 +2473,7 @@ static int outer_loop (user_options_t *user_options, user_options_extra_t *user_ { if (user_options->status == true) { - status_display (opencl_ctx, hashconfig, hashes, restore_ctx, user_options, user_options_extra, rules_ctx); + status_display (opencl_ctx, hashconfig, hashes, restore_ctx, user_options, user_options_extra, rules_ctx, mask_ctx); log_info (""); } @@ -2946,11 +2548,11 @@ static int outer_loop (user_options_t *user_options, user_options_extra_t *user_ } else if (user_options->attack_mode == ATTACK_MODE_BF) { - if (data.mask == NULL) + if (mask_ctx->mask == NULL) { hc_timer_set (&data.timer_running); - data.mask = masks[0]; + mask_ctx->mask = mask_ctx->masks[0]; } } @@ -3166,19 +2768,16 @@ static int outer_loop (user_options_t *user_options, user_options_extra_t *user_ bitmap_ctx_destroy (bitmap_ctx); + mask_ctx_destroy (mask_ctx); + hashes_destroy (hashes); hashconfig_destroy (hashconfig); - local_free (masks); - local_free (od_clock_mem_status); local_free (od_power_control_status); local_free (nvml_power_limit); - global_free (root_css_buf); - global_free (markov_css_buf); - global_free (words_progress_done); global_free (words_progress_rejected); global_free (words_progress_restored); diff --git a/src/interface.c b/src/interface.c index a2e9ae6fa..a02bb5f7f 100644 --- a/src/interface.c +++ b/src/interface.c @@ -20080,7 +20080,7 @@ void hashconfig_general_defaults (hashconfig_t *hashconfig, hashes_t *hashes, co } } -void hashconfig_benchmark_defaults (hashconfig_t *hashconfig, salt_t *salt, void *esalt) +void hashconfig_benchmark_defaults (const hashconfig_t *hashconfig, salt_t *salt, void *esalt) { if (hashconfig->is_salted) { @@ -20393,7 +20393,7 @@ void hashconfig_benchmark_defaults (hashconfig_t *hashconfig, salt_t *salt, void } } -char *hashconfig_benchmark_mask (hashconfig_t *hashconfig) +char *hashconfig_benchmark_mask (const hashconfig_t *hashconfig) { char *mask = "?b?b?b?b?b?b?b"; diff --git a/src/monitor.c b/src/monitor.c index 359bea545..1ddfbde33 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -46,6 +46,7 @@ void *thread_monitor (void *p) hashes_t *hashes = data.hashes; opencl_ctx_t *opencl_ctx = data.opencl_ctx; rules_ctx_t *rules_ctx = data.rules_ctx; + mask_ctx_t *mask_ctx = data.mask_ctx; bool runtime_check = false; bool remove_check = false; @@ -345,7 +346,7 @@ void *thread_monitor (void *p) if (user_options->quiet == false) log_info (""); - status_display (opencl_ctx, hashconfig, hashes, restore_ctx, user_options, user_options_extra, rules_ctx); + status_display (opencl_ctx, hashconfig, hashes, restore_ctx, user_options, user_options_extra, rules_ctx, mask_ctx); if (user_options->quiet == false) log_info (""); diff --git a/src/mpsp.c b/src/mpsp.c index 6e1e09a95..b1aedd503 100644 --- a/src/mpsp.c +++ b/src/mpsp.c @@ -13,6 +13,7 @@ #include "logging.h" #include "convert.h" #include "filehandling.h" +#include "interface.h" #include "mpsp.h" const unsigned int full01 = 0x01010101; @@ -45,7 +46,7 @@ void mp_css_to_uniq_tbl (uint css_cnt, cs_t *css, uint uniq_tbls[SP_PW_MAX][CHAR } } -static void mp_add_cs_buf (uint *in_buf, size_t in_len, cs_t *css, int css_cnt, hashconfig_t *hashconfig) +static void mp_add_cs_buf (uint *in_buf, size_t in_len, cs_t *css, int css_cnt, const hashconfig_t *hashconfig) { cs_t *cs = &css[css_cnt]; @@ -80,7 +81,7 @@ static void mp_add_cs_buf (uint *in_buf, size_t in_len, cs_t *css, int css_cnt, myfree (css_uniq); } -static void mp_expand (char *in_buf, size_t in_len, cs_t *mp_sys, cs_t *mp_usr, int mp_usr_offset, int interpret, hashconfig_t *hashconfig, const user_options_t *user_options) +static void mp_expand (char *in_buf, size_t in_len, cs_t *mp_sys, cs_t *mp_usr, int mp_usr_offset, int interpret, const hashconfig_t *hashconfig, const user_options_t *user_options) { size_t in_pos; @@ -179,7 +180,7 @@ u64 mp_get_sum (uint css_cnt, cs_t *css) return (sum); } -cs_t *mp_gen_css (char *mask_buf, size_t mask_len, cs_t *mp_sys, cs_t *mp_usr, uint *css_cnt, hashconfig_t *hashconfig, const user_options_t *user_options) +cs_t *mp_gen_css (char *mask_buf, size_t mask_len, cs_t *mp_sys, cs_t *mp_usr, uint *css_cnt, const hashconfig_t *hashconfig, const user_options_t *user_options) { cs_t *css = (cs_t *) mycalloc (256, sizeof (cs_t)); @@ -357,7 +358,7 @@ void mp_setup_sys (cs_t *mp_sys) mp_sys[5].cs_len = pos; } } -void mp_setup_usr (cs_t *mp_sys, cs_t *mp_usr, char *buf, uint index, hashconfig_t *hashconfig, const user_options_t *user_options) +void mp_setup_usr (cs_t *mp_sys, cs_t *mp_usr, char *buf, uint index, const hashconfig_t *hashconfig, const user_options_t *user_options) { FILE *fp = fopen (buf, "rb"); @@ -395,7 +396,7 @@ void mp_reset_usr (cs_t *mp_usr, uint index) memset (mp_usr[index].cs_buf, 0, sizeof (mp_usr[index].cs_buf)); } -char *mp_get_truncated_mask (char *mask_buf, size_t mask_len, uint len, const user_options_t *user_options) +static char *mp_get_truncated_mask (const char *mask_buf, const size_t mask_len, const uint len, const user_options_t *user_options) { char *new_mask_buf = (char *) mymalloc (256); @@ -817,3 +818,287 @@ void sp_stretch_markov (hcstat_table_t *in, hcstat_table_t *out) } } } + +static void mask_append_final (mask_ctx_t *mask_ctx, const char *mask) +{ + if (mask_ctx->masks_avail == mask_ctx->masks_cnt) + { + mask_ctx->masks = (char **) myrealloc (mask_ctx->masks, mask_ctx->masks_avail * sizeof (char *), INCR_MASKS * sizeof (char *)); + + mask_ctx->masks_avail += INCR_MASKS; + } + + mask_ctx->masks[mask_ctx->masks_cnt] = mystrdup (mask); + + mask_ctx->masks_cnt++; +} + +static void mask_append (mask_ctx_t *mask_ctx, const user_options_t *user_options, const char *mask) +{ + if (user_options->increment == true) + { + for (uint mask_len = user_options->increment_min; mask_len <= user_options->increment_max; mask_len++) + { + char *mask_truncated = mp_get_truncated_mask (mask, strlen (mask), mask_len, user_options); + + if (mask_truncated == NULL) break; + + mask_append_final (mask_ctx, mask_truncated); + } + } + else + { + mask_append_final (mask_ctx, mask); + } +} + +int mask_ctx_init (mask_ctx_t *mask_ctx, const user_options_t *user_options, const user_options_extra_t *user_options_extra, const folder_config_t *folder_config, const restore_ctx_t *restore_ctx, const hashconfig_t *hashconfig) +{ + memset (mask_ctx, 0, sizeof (mask_ctx_t)); + + mask_ctx->root_table_buf = (hcstat_table_t *) mycalloc (SP_ROOT_CNT, sizeof (hcstat_table_t)); + mask_ctx->markov_table_buf = (hcstat_table_t *) mycalloc (SP_MARKOV_CNT, sizeof (hcstat_table_t)); + + sp_setup_tbl (folder_config->shared_dir, user_options->markov_hcstat, user_options->markov_disable, user_options->markov_classic, mask_ctx->root_table_buf, mask_ctx->markov_table_buf); + + mask_ctx->root_css_buf = (cs_t *) mycalloc (SP_PW_MAX, sizeof (cs_t)); + mask_ctx->markov_css_buf = (cs_t *) mycalloc (SP_PW_MAX * CHARSIZ, sizeof (cs_t)); + + mask_ctx->css_cnt = 0; + mask_ctx->css_buf = NULL; + + mask_ctx->mask_from_file = false; + + mask_ctx->masks = NULL; + mask_ctx->masks_pos = 0; + mask_ctx->masks_cnt = 0; + + mp_setup_sys (mask_ctx->mp_sys); + + if (user_options->custom_charset_1) mp_setup_usr (mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_1, 0, hashconfig, user_options); + if (user_options->custom_charset_2) mp_setup_usr (mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_2, 1, hashconfig, user_options); + if (user_options->custom_charset_3) mp_setup_usr (mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_3, 2, hashconfig, user_options); + if (user_options->custom_charset_4) mp_setup_usr (mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_4, 3, hashconfig, user_options); + + if (user_options->attack_mode == ATTACK_MODE_BF) + { + if (user_options->benchmark == false) + { + if ((user_options_extra->optind + 2) <= restore_ctx->argc) + { + char *arg = restore_ctx->argv[user_options_extra->optind + 1]; + + struct stat file_stat; + + if (stat (arg, &file_stat) == -1) + { + mask_append (mask_ctx, user_options, arg); + } + else + { + mask_ctx->mask_from_file = true; + + int arg_left = restore_ctx->argc - (user_options_extra->optind + 1); + + for (int i = 0; i < arg_left; i++) + { + arg = restore_ctx->argv[user_options_extra->optind + 1 + i]; + + if (stat (arg, &file_stat) == -1) + { + log_error ("ERROR: %s: %s", arg, strerror (errno)); + + return -1; + } + + if (S_ISREG (file_stat.st_mode)) + { + FILE *mask_fp = fopen (arg, "r"); + + if (mask_fp == NULL) + { + log_error ("ERROR: %s: %s", arg, strerror (errno)); + + return -1; + } + + char *line_buf = (char *) mymalloc (HCBUFSIZ_LARGE); + + while (!feof (mask_fp)) + { + const int line_len = fgetl (mask_fp, line_buf); + + if (line_len == 0) continue; + + if (line_buf[0] == '#') continue; + + mask_append (mask_ctx, user_options, line_buf); + } + + myfree (line_buf); + + fclose (mask_fp); + } + else + { + log_error ("ERROR: %s: unsupported file-type", arg); + + return -1; + } + } + } + } + else + { + const char *mask = "?1?2?2?2?2?2?2?3?3?3?3?d?d?d?d"; + + mask_append (mask_ctx, user_options, mask); + } + } + else + { + const char *mask = hashconfig_benchmark_mask (hashconfig); + + mask_append (mask_ctx, user_options, mask); + } + } + else if (user_options->attack_mode == ATTACK_MODE_HYBRID1) + { + // display + + char *arg = restore_ctx->argv[restore_ctx->argc - 1]; + + // mod + + struct stat file_stat; + + if (stat (arg, &file_stat) == -1) + { + mask_append (mask_ctx, user_options, arg); + } + else + { + if (S_ISREG (file_stat.st_mode)) + { + mask_ctx->mask_from_file = true; + + FILE *mask_fp = fopen (arg, "r"); + + if (mask_fp == NULL) + { + log_error ("ERROR: %s: %s", arg, strerror (errno)); + + return -1; + } + + char *line_buf = (char *) mymalloc (HCBUFSIZ_LARGE); + + while (!feof (mask_fp)) + { + const int line_len = fgetl (mask_fp, line_buf); + + if (line_len == 0) continue; + + if (line_buf[0] == '#') continue; + + mask_append (mask_ctx, user_options, line_buf); + } + + myfree (line_buf); + + fclose (mask_fp); + } + else + { + log_error ("ERROR: %s: unsupported file-type", arg); + + return -1; + } + } + } + else if (user_options->attack_mode == ATTACK_MODE_HYBRID2) + { + // display + + char *arg = restore_ctx->argv[user_options_extra->optind + 1]; + + // mod + + struct stat file_stat; + + if (stat (arg, &file_stat) == -1) + { + mask_append (mask_ctx, user_options, arg); + } + else + { + if (S_ISREG (file_stat.st_mode)) + { + mask_ctx->mask_from_file = true; + + FILE *mask_fp = fopen (arg, "r"); + + if (mask_fp == NULL) + { + log_error ("ERROR: %s: %s", arg, strerror (errno)); + + return -1; + } + + char *line_buf = (char *) mymalloc (HCBUFSIZ_LARGE); + + while (!feof (mask_fp)) + { + const int line_len = fgetl (mask_fp, line_buf); + + if (line_len == 0) continue; + + if (line_buf[0] == '#') continue; + + mask_append (mask_ctx, user_options, line_buf); + } + + myfree (line_buf); + + fclose (mask_fp); + } + else + { + log_error ("ERROR: %s: unsupported file-type", arg); + + return -1; + } + } + } + + if (mask_ctx->masks_cnt == 0) + { + log_error ("ERROR: Invalid mask"); + + return -1; + } + + mask_ctx->mask = mask_ctx->masks[0]; + + return 0; +} + +void mask_ctx_destroy (mask_ctx_t *mask_ctx) +{ + myfree (mask_ctx->css_buf); + + myfree (mask_ctx->root_css_buf); + myfree (mask_ctx->markov_css_buf); + + myfree (mask_ctx->root_table_buf); + myfree (mask_ctx->markov_table_buf); + + for (u32 mask_pos = 0; mask_pos < mask_ctx->masks_cnt; mask_pos++) + { + myfree (mask_ctx->masks[mask_pos]); + } + + myfree (mask_ctx->masks); + + myfree (mask_ctx); +} diff --git a/src/opencl.c b/src/opencl.c index 490728062..a1f7b77d6 100644 --- a/src/opencl.c +++ b/src/opencl.c @@ -291,13 +291,13 @@ int gidd_to_pw_t (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, con return 0; } -int choose_kernel (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, const user_options_t *user_options, const rules_ctx_t *rules_ctx, hashconfig_t *hashconfig, const uint attack_exec, const uint attack_mode, const uint opts_type, const salt_t *salt_buf, const uint highest_pw_len, const uint pws_cnt, const uint fast_iteration) +int choose_kernel (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, const user_options_t *user_options, const rules_ctx_t *rules_ctx, const mask_ctx_t *mask_ctx, hashconfig_t *hashconfig, const uint attack_exec, const uint attack_mode, const uint opts_type, const salt_t *salt_buf, const uint highest_pw_len, const uint pws_cnt, const uint fast_iteration) { cl_int CL_err = CL_SUCCESS; if (hashconfig->hash_mode == 2000) { - process_stdout (opencl_ctx, device_param, user_options, rules_ctx, pws_cnt); + process_stdout (opencl_ctx, device_param, user_options, rules_ctx, mask_ctx, pws_cnt); return 0; } @@ -1004,7 +1004,7 @@ int run_copy (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, hashcon return 0; } -int run_cracker (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, hashconfig_t *hashconfig, hashes_t *hashes, const user_options_t *user_options, const user_options_extra_t *user_options_extra, const rules_ctx_t *rules_ctx, const uint pws_cnt) +int run_cracker (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, hashconfig_t *hashconfig, hashes_t *hashes, const user_options_t *user_options, const user_options_extra_t *user_options_extra, const rules_ctx_t *rules_ctx, const mask_ctx_t *mask_ctx, const uint pws_cnt) { char *line_buf = (char *) mymalloc (HCBUFSIZ_LARGE); @@ -1071,7 +1071,7 @@ int run_cracker (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, hash if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT) innerloop_cnt = rules_ctx->kernel_rules_cnt; else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI) innerloop_cnt = data.combs_cnt; - else if (user_options_extra->attack_kern == ATTACK_KERN_BF) innerloop_cnt = data.bfs_cnt; + else if (user_options_extra->attack_kern == ATTACK_KERN_BF) innerloop_cnt = mask_ctx->bfs_cnt; // innerloops @@ -1281,7 +1281,7 @@ int run_cracker (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, hash hc_timer_set (&device_param->timer_speed); } - int rc = choose_kernel (opencl_ctx, device_param, user_options, rules_ctx, hashconfig, hashconfig->attack_exec, user_options->attack_mode, hashconfig->opts_type, salt_buf, highest_pw_len, pws_cnt, fast_iteration); + int rc = choose_kernel (opencl_ctx, device_param, user_options, rules_ctx, mask_ctx, hashconfig, hashconfig->attack_exec, user_options->attack_mode, hashconfig->opts_type, salt_buf, highest_pw_len, pws_cnt, fast_iteration); if (rc == -1) return -1; diff --git a/src/status.c b/src/status.c index ad0467dfe..26b263643 100644 --- a/src/status.c +++ b/src/status.c @@ -164,7 +164,7 @@ double get_avg_exec_time (hc_device_param_t *device_param, const int last_num_en return exec_ms_sum / exec_ms_cnt; } -void status_display_machine_readable (opencl_ctx_t *opencl_ctx, const hashes_t *hashes, const restore_ctx_t *restore_ctx, const user_options_t *user_options, const user_options_extra_t *user_options_extra, const rules_ctx_t *rules_ctx) +void status_display_machine_readable (opencl_ctx_t *opencl_ctx, const hashes_t *hashes, const restore_ctx_t *restore_ctx, const user_options_t *user_options, const user_options_extra_t *user_options_extra, const rules_ctx_t *rules_ctx, const mask_ctx_t *mask_ctx) { if (opencl_ctx->devices_status == STATUS_INIT) { @@ -257,7 +257,7 @@ void status_display_machine_readable (opencl_ctx_t *opencl_ctx, const hashes_t * if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT) progress_skip *= rules_ctx->kernel_rules_cnt; else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI) progress_skip *= data.combs_cnt; - else if (user_options_extra->attack_kern == ATTACK_KERN_BF) progress_skip *= data.bfs_cnt; + else if (user_options_extra->attack_kern == ATTACK_KERN_BF) progress_skip *= mask_ctx->bfs_cnt; } if (user_options->limit) @@ -266,7 +266,7 @@ void status_display_machine_readable (opencl_ctx_t *opencl_ctx, const hashes_t * if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT) progress_end *= rules_ctx->kernel_rules_cnt; else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI) progress_end *= data.combs_cnt; - else if (user_options_extra->attack_kern == ATTACK_KERN_BF) progress_end *= data.bfs_cnt; + else if (user_options_extra->attack_kern == ATTACK_KERN_BF) progress_end *= mask_ctx->bfs_cnt; } u64 progress_cur_relative_skip = progress_cur - progress_skip; @@ -313,7 +313,7 @@ void status_display_machine_readable (opencl_ctx_t *opencl_ctx, const hashes_t * fflush (out); } -void status_display (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconfig, const hashes_t *hashes, const restore_ctx_t *restore_ctx, const user_options_t *user_options, const user_options_extra_t *user_options_extra, const rules_ctx_t *rules_ctx) +void status_display (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconfig, const hashes_t *hashes, const restore_ctx_t *restore_ctx, const user_options_t *user_options, const user_options_extra_t *user_options_extra, const rules_ctx_t *rules_ctx, const mask_ctx_t *mask_ctx) { if (opencl_ctx->devices_status == STATUS_INIT) { @@ -327,7 +327,7 @@ void status_display (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconfig, c if (user_options->machine_readable == true) { - status_display_machine_readable (opencl_ctx, hashes, restore_ctx, user_options, user_options_extra, rules_ctx); + status_display_machine_readable (opencl_ctx, hashes, restore_ctx, user_options, user_options_extra, rules_ctx, mask_ctx); return; } @@ -403,11 +403,11 @@ void status_display (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconfig, c } else if (user_options->attack_mode == ATTACK_MODE_BF) { - char *mask = data.mask; + char *mask = mask_ctx->mask; if (mask != NULL) { - uint mask_len = data.css_cnt; + uint mask_len = mask_ctx->css_cnt; tmp_len += snprintf (tmp_buf + tmp_len, sizeof (tmp_buf) - tmp_len, "Mask (%s)", mask); @@ -426,9 +426,9 @@ void status_display (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconfig, c tmp_len += snprintf (tmp_buf + tmp_len, sizeof (tmp_buf) - tmp_len, " [%i]", mask_len); } - if (data.maskcnt > 1) + if (mask_ctx->masks_cnt > 1) { - double mask_percentage = (double) data.maskpos / (double) data.maskcnt; + double mask_percentage = (double) mask_ctx->masks_pos / (double) mask_ctx->masks_cnt; tmp_len += snprintf (tmp_buf + tmp_len, sizeof (tmp_buf) - tmp_len, " (%.02f%%)", mask_percentage * 100); } @@ -450,8 +450,8 @@ void status_display (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconfig, c } else if (user_options->attack_mode == ATTACK_MODE_HYBRID1) { - if (data.dictfile != NULL) log_info ("Input.Left.....: File (%s)", data.dictfile); - if (data.mask != NULL) log_info ("Input.Right....: Mask (%s) [%i]", data.mask, data.css_cnt); + if (data.dictfile != NULL) log_info ("Input.Left.....: File (%s)", data.dictfile); + if (mask_ctx->mask != NULL) log_info ("Input.Right....: Mask (%s) [%i]", mask_ctx->mask, mask_ctx->css_cnt); if ((custom_charset_1 != NULL) || (custom_charset_2 != NULL) || (custom_charset_3 != NULL) || (custom_charset_4 != NULL)) { @@ -465,7 +465,7 @@ void status_display (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconfig, c } else if (user_options->attack_mode == ATTACK_MODE_HYBRID2) { - if (data.mask != NULL) log_info ("Input.Left.....: Mask (%s) [%i]", data.mask, data.css_cnt); + if (mask_ctx->mask != NULL) log_info ("Input.Left.....: Mask (%s) [%i]", mask_ctx->mask, mask_ctx->css_cnt); if (data.dictfile != NULL) log_info ("Input.Right....: File (%s)", data.dictfile); if ((custom_charset_1 != NULL) || (custom_charset_2 != NULL) || (custom_charset_3 != NULL) || (custom_charset_4 != NULL)) @@ -730,7 +730,7 @@ void status_display (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconfig, c if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT) progress_skip *= rules_ctx->kernel_rules_cnt; else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI) progress_skip *= data.combs_cnt; - else if (user_options_extra->attack_kern == ATTACK_KERN_BF) progress_skip *= data.bfs_cnt; + else if (user_options_extra->attack_kern == ATTACK_KERN_BF) progress_skip *= mask_ctx->bfs_cnt; } if (user_options->limit) @@ -739,7 +739,7 @@ void status_display (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconfig, c if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT) progress_end *= rules_ctx->kernel_rules_cnt; else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI) progress_end *= data.combs_cnt; - else if (user_options_extra->attack_kern == ATTACK_KERN_BF) progress_end *= data.bfs_cnt; + else if (user_options_extra->attack_kern == ATTACK_KERN_BF) progress_end *= mask_ctx->bfs_cnt; } u64 progress_cur_relative_skip = progress_cur - progress_skip; diff --git a/src/stdout.c b/src/stdout.c index 56760c41d..a3b77c37c 100644 --- a/src/stdout.c +++ b/src/stdout.c @@ -59,7 +59,7 @@ static void out_push (out_t *out, const u8 *pw_buf, const int pw_len) } } -void process_stdout (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, const user_options_t *user_options, const rules_ctx_t *rules_ctx, const uint pws_cnt) +void process_stdout (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, const user_options_t *user_options, const rules_ctx_t *rules_ctx, const mask_ctx_t *mask_ctx, const uint pws_cnt) { out_t out; @@ -177,10 +177,10 @@ void process_stdout (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, uint l_stop = device_param->kernel_params_mp_l_buf32[4]; uint r_stop = device_param->kernel_params_mp_r_buf32[4]; - sp_exec (l_off, (char *) plain_ptr + l_start, data.root_css_buf, data.markov_css_buf, l_start, l_start + l_stop); - sp_exec (r_off, (char *) plain_ptr + r_start, data.root_css_buf, data.markov_css_buf, r_start, r_start + r_stop); + sp_exec (l_off, (char *) plain_ptr + l_start, mask_ctx->root_css_buf, mask_ctx->markov_css_buf, l_start, l_start + l_stop); + sp_exec (r_off, (char *) plain_ptr + r_start, mask_ctx->root_css_buf, mask_ctx->markov_css_buf, r_start, r_start + r_stop); - plain_len = data.css_cnt; + plain_len = mask_ctx->css_cnt; out_push (&out, plain_ptr, plain_len); } @@ -208,7 +208,7 @@ void process_stdout (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, uint start = 0; uint stop = device_param->kernel_params_mp_buf32[4]; - sp_exec (off, (char *) plain_ptr + plain_len, data.root_css_buf, data.markov_css_buf, start, start + stop); + sp_exec (off, (char *) plain_ptr + plain_len, mask_ctx->root_css_buf, mask_ctx->markov_css_buf, start, start + stop); plain_len += start + stop; @@ -240,7 +240,7 @@ void process_stdout (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, memmove (plain_ptr + stop, plain_ptr, plain_len); - sp_exec (off, (char *) plain_ptr, data.root_css_buf, data.markov_css_buf, start, start + stop); + sp_exec (off, (char *) plain_ptr, mask_ctx->root_css_buf, mask_ctx->markov_css_buf, start, start + stop); plain_len += start + stop; diff --git a/src/terminal.c b/src/terminal.c index 14fc90891..4ba95840c 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -69,6 +69,7 @@ void *thread_keypress (void *p) hashconfig_t *hashconfig = data.hashconfig; hashes_t *hashes = data.hashes; rules_ctx_t *rules_ctx = data.rules_ctx; + mask_ctx_t *mask_ctx = data.mask_ctx; const bool quiet = user_options->quiet; @@ -99,7 +100,7 @@ void *thread_keypress (void *p) log_info (""); - status_display (opencl_ctx, hashconfig, hashes, restore_ctx, user_options, user_options_extra, rules_ctx); + status_display (opencl_ctx, hashconfig, hashes, restore_ctx, user_options, user_options_extra, rules_ctx, mask_ctx); log_info (""); diff --git a/src/user_options.c b/src/user_options.c index fe766d9ea..85032dc81 100644 --- a/src/user_options.c +++ b/src/user_options.c @@ -255,7 +255,6 @@ int user_options_parse (user_options_t *user_options, int argc, char **argv) user_options->restore = false; user_options->restore_disable = true; user_options->restore_timer = 0; - user_options->markov_disable = true; user_options->logfile_disable = true; user_options->weak_hash_threshold = 0; user_options->nvidia_spin_damp = 0; @@ -268,6 +267,7 @@ int user_options_parse (user_options_t *user_options, int argc, char **argv) { user_options->session = "benchmark"; user_options->attack_mode = ATTACK_MODE_BF; + user_options->increment = false; if (user_options->workload_profile_chgd == false) { @@ -868,6 +868,26 @@ int user_options_extra_init (user_options_t *user_options, restore_ctx_t *restor } */ + // default mask + + if (user_options->benchmark == false) + { + if ((user_options_extra->optind + 2) <= restore_ctx->argc) + { + // user provides mask + } + else + { + // prepare default mask charset + + user_options->custom_charset_1 = (char *) "?l?d?u"; + user_options->custom_charset_2 = (char *) "?l?d"; + user_options->custom_charset_3 = (char *) "?l?d*!$@_"; + + user_options->increment = true; + } + } + return 0; }