X-Git-Url: https://www.flypig.org.uk/git/?a=blobdiff_plain;f=src%2Fhashcat.c;h=057663d28d4bb5653a7d5ee3fb9f7bd80964c39a;hb=9b4e6056d452fa9429112eafaf7cced19e63f09c;hp=9d4299e32e7c36f0087817c871d7e5d9a63135a9;hpb=752e548f4e696ab7bd09c301bff2729e200b2dac;p=hashcat.git diff --git a/src/hashcat.c b/src/hashcat.c index 9d4299e..057663d 100644 --- a/src/hashcat.c +++ b/src/hashcat.c @@ -76,6 +76,7 @@ double TARGET_MS_PROFILE[4] = { 2, 12, 96, 480 }; #define INCREMENT 0 #define INCREMENT_MIN 1 #define INCREMENT_MAX PW_MAX +#define MANGLE 0 #define SEPARATOR ':' #define BITMAP_MIN 16 #define BITMAP_MAX 24 @@ -447,6 +448,7 @@ const char *USAGE_BIG[] = " -i, --increment | | Enable mask increment mode |", " --increment-min | Num | Start mask incrementing at X | --increment-min=4", " --increment-max | Num | Stop mask incrementing at X | --increment-max=8", + " --mangle | | Mangle password before hashing |", "", "- [ Hash modes ] -", "", @@ -1387,13 +1389,13 @@ void status_display () #ifdef WIN - __time64_t runtime_left = data.proc_start + data.runtime - runtime_cur; + __time64_t runtime_left = data.proc_start + data.runtime + data.prepare_time - runtime_cur; tmp = _gmtime64 (&runtime_left); #else - time_t runtime_left = data.proc_start + data.runtime - runtime_cur; + time_t runtime_left = data.proc_start + data.runtime + data.prepare_time - runtime_cur; tmp = gmtime (&runtime_left); @@ -1816,31 +1818,43 @@ static void status_benchmark () * hashcat -only- functions */ -static void generate_source_kernel_filename (const uint attack_exec, const uint attack_kern, const uint kern_type, char *shared_dir, char *source_file) +static void generate_source_kernel_filename (const uint attack_exec, const uint attack_kern, const uint kern_type, uint mangle, char *shared_dir, char *source_file) { + char const * postfix = ""; + if (mangle == 1) + { + postfix = "_m"; + } + if (attack_exec == ATTACK_EXEC_INSIDE_KERNEL) { if (attack_kern == ATTACK_KERN_STRAIGHT) - snprintf (source_file, 255, "%s/OpenCL/m%05d_a0.cl", shared_dir, (int) kern_type); + snprintf (source_file, 255, "%s/OpenCL/m%05d_a0%s.cl", shared_dir, (int) kern_type, postfix); else if (attack_kern == ATTACK_KERN_COMBI) - snprintf (source_file, 255, "%s/OpenCL/m%05d_a1.cl", shared_dir, (int) kern_type); + snprintf (source_file, 255, "%s/OpenCL/m%05d_a1%s.cl", shared_dir, (int) kern_type, postfix); else if (attack_kern == ATTACK_KERN_BF) - snprintf (source_file, 255, "%s/OpenCL/m%05d_a3.cl", shared_dir, (int) kern_type); + snprintf (source_file, 255, "%s/OpenCL/m%05d_a3%s.cl", shared_dir, (int) kern_type, postfix); } else snprintf (source_file, 255, "%s/OpenCL/m%05d.cl", shared_dir, (int) kern_type); } -static void generate_cached_kernel_filename (const uint attack_exec, const uint attack_kern, const uint kern_type, char *profile_dir, const char *device_name_chksum, char *cached_file) +static void generate_cached_kernel_filename (const uint attack_exec, const uint attack_kern, const uint kern_type, uint mangle, char *profile_dir, const char *device_name_chksum, char *cached_file) { + char const * postfix = ""; + if (mangle == 1) + { + postfix = "_m"; + } + if (attack_exec == ATTACK_EXEC_INSIDE_KERNEL) { if (attack_kern == ATTACK_KERN_STRAIGHT) - snprintf (cached_file, 255, "%s/kernels/m%05d_a0.%s.kernel", profile_dir, (int) kern_type, device_name_chksum); + snprintf (cached_file, 255, "%s/kernels/m%05d_a0%s.%s.kernel", profile_dir, (int) kern_type, postfix, device_name_chksum); else if (attack_kern == ATTACK_KERN_COMBI) - snprintf (cached_file, 255, "%s/kernels/m%05d_a1.%s.kernel", profile_dir, (int) kern_type, device_name_chksum); + snprintf (cached_file, 255, "%s/kernels/m%05d_a1%s.%s.kernel", profile_dir, (int) kern_type, postfix, device_name_chksum); else if (attack_kern == ATTACK_KERN_BF) - snprintf (cached_file, 255, "%s/kernels/m%05d_a3.%s.kernel", profile_dir, (int) kern_type, device_name_chksum); + snprintf (cached_file, 255, "%s/kernels/m%05d_a3%s.%s.kernel", profile_dir, (int) kern_type, postfix, device_name_chksum); } else { @@ -3592,7 +3606,7 @@ static int autotune (hc_device_param_t *device_param) { for (int i = 0; i < STEPS_CNT; i++) { - const u32 kernel_accel_try = 1 << i; + const u32 kernel_accel_try = 1u << i; if (kernel_accel_try < kernel_accel_min) continue; if (kernel_accel_try > kernel_accel_max) break; @@ -4692,7 +4706,7 @@ static void *thread_monitor (void *p) time (&runtime_cur); - int runtime_left = data.proc_start + data.runtime - runtime_cur; + int runtime_left = data.proc_start + data.runtime + data.prepare_time - runtime_cur; if (runtime_left <= 0) { @@ -6175,6 +6189,10 @@ int main (int argc, char **argv) data.proc_start = proc_start; + time_t prepare_start; + + time (&prepare_start); + int myargc = argc; char **myargv = argv; @@ -6239,6 +6257,7 @@ int main (int argc, char **argv) uint increment = INCREMENT; uint increment_min = INCREMENT_MIN; uint increment_max = INCREMENT_MAX; + uint mangle = MANGLE; char *cpu_affinity = NULL; OCL_PTR *ocl = NULL; char *opencl_devices = NULL; @@ -6303,6 +6322,7 @@ int main (int argc, char **argv) #define IDX_INCREMENT 'i' #define IDX_INCREMENT_MIN 0xff12 #define IDX_INCREMENT_MAX 0xff13 + #define IDX_MANGLE 0xff80 #define IDX_OUTFILE 'o' #define IDX_OUTFILE_FORMAT 0xff14 #define IDX_OUTFILE_AUTOHEX_DISABLE 0xff39 @@ -6430,6 +6450,7 @@ int main (int argc, char **argv) {"increment", no_argument, 0, IDX_INCREMENT}, {"increment-min", required_argument, 0, IDX_INCREMENT_MIN}, {"increment-max", required_argument, 0, IDX_INCREMENT_MAX}, + {"mangle", no_argument, 0, IDX_MANGLE}, {"custom-charset1", required_argument, 0, IDX_CUSTOM_CHARSET_1}, {"custom-charset2", required_argument, 0, IDX_CUSTOM_CHARSET_2}, {"custom-charset3", required_argument, 0, IDX_CUSTOM_CHARSET_3}, @@ -6563,6 +6584,66 @@ int main (int argc, char **argv) myfree (exec_path); + /** + * There's alot of problem related to bad support -I parameters when building the kernel. + * Each OpenCL runtime handles it slightly different. + * The most problematic is with new AMD drivers on Windows, which can not handle quote characters! + * The best workaround found so far is to modify the TMP variable (only inside hashcat process) before the runtime is load + */ + + char cpath[1024] = { 0 }; + + #if _WIN + + snprintf (cpath, sizeof (cpath) - 1, "%s\\OpenCL\\", shared_dir); + + char *cpath_real = mymalloc (MAX_PATH); + + if (GetFullPathName (cpath, MAX_PATH, cpath_real, NULL) == 0) + { + log_error ("ERROR: %s: %s", cpath, "GetFullPathName()"); + + return -1; + } + + #else + + snprintf (cpath, sizeof (cpath) - 1, "%s/OpenCL/", shared_dir); + + char *cpath_real = mymalloc (PATH_MAX); + + if (realpath (cpath, cpath_real) == NULL) + { + log_error ("ERROR: %s: %s", cpath, strerror (errno)); + + return -1; + } + + #endif + + //if (getenv ("TMP") == NULL) + if (1) + { + char tmp[1000]; + + snprintf (tmp, sizeof (tmp) - 1, "TMP=%s", cpath_real); + + putenv (tmp); + } + + #if _WIN + + naive_replace (cpath_real, '\\', '/'); + + // not escaping here, windows using quotes later + // naive_escape (cpath_real, PATH_MAX, ' ', '\\'); + + #else + + naive_escape (cpath_real, PATH_MAX, ' ', '\\'); + + #endif + /** * kernel cache, we need to make sure folder exist */ @@ -6756,6 +6837,7 @@ int main (int argc, char **argv) increment_min_chgd = 1; break; case IDX_INCREMENT_MAX: increment_max = atoi (optarg); increment_max_chgd = 1; break; + case IDX_MANGLE: mangle = 1; break; case IDX_CUSTOM_CHARSET_1: custom_charset_1 = optarg; break; case IDX_CUSTOM_CHARSET_2: custom_charset_2 = optarg; break; case IDX_CUSTOM_CHARSET_3: custom_charset_3 = optarg; break; @@ -7579,6 +7661,7 @@ int main (int argc, char **argv) logfile_top_uint (increment); logfile_top_uint (increment_max); logfile_top_uint (increment_min); + logfile_top_uint (mangle); logfile_top_uint (keyspace); logfile_top_uint (left); logfile_top_uint (logfile_disable); @@ -7833,6 +7916,32 @@ int main (int argc, char **argv) dgst_pos1 = 3; dgst_pos2 = 2; dgst_pos3 = 1; +// mangle = 0; + break; + + case 1: hash_type = HASH_TYPE_MD5; + salt_type = SALT_TYPE_NONE; + attack_exec = ATTACK_EXEC_INSIDE_KERNEL; + opts_type = OPTS_TYPE_PT_GENERATE_LE + | OPTS_TYPE_PT_ADD80 + | OPTS_TYPE_PT_ADDBITS14; + kern_type = KERN_TYPE_MD5; + dgst_size = DGST_SIZE_4_4; + parse_func = md5_parse_hash; + sort_by_digest = sort_by_digest_4_4; + opti_type = OPTI_TYPE_ZERO_BYTE + | OPTI_TYPE_PRECOMPUTE_INIT + | OPTI_TYPE_PRECOMPUTE_MERKLE + | OPTI_TYPE_MEET_IN_MIDDLE + | OPTI_TYPE_EARLY_SKIP + | OPTI_TYPE_NOT_ITERATED + | OPTI_TYPE_NOT_SALTED + | OPTI_TYPE_RAW_HASH; + dgst_pos0 = 0; + dgst_pos1 = 3; + dgst_pos2 = 2; + dgst_pos3 = 1; +// mangle = 1; break; case 10: hash_type = HASH_TYPE_MD5; @@ -13781,14 +13890,14 @@ int main (int argc, char **argv) if (bitmap_max < bitmap_min) bitmap_max = bitmap_min; - uint *bitmap_s1_a = (uint *) mymalloc ((1 << bitmap_max) * sizeof (uint)); - uint *bitmap_s1_b = (uint *) mymalloc ((1 << bitmap_max) * sizeof (uint)); - uint *bitmap_s1_c = (uint *) mymalloc ((1 << bitmap_max) * sizeof (uint)); - uint *bitmap_s1_d = (uint *) mymalloc ((1 << bitmap_max) * sizeof (uint)); - uint *bitmap_s2_a = (uint *) mymalloc ((1 << bitmap_max) * sizeof (uint)); - uint *bitmap_s2_b = (uint *) mymalloc ((1 << bitmap_max) * sizeof (uint)); - uint *bitmap_s2_c = (uint *) mymalloc ((1 << bitmap_max) * sizeof (uint)); - uint *bitmap_s2_d = (uint *) mymalloc ((1 << bitmap_max) * sizeof (uint)); + uint *bitmap_s1_a = (uint *) mymalloc ((1u << bitmap_max) * sizeof (uint)); + uint *bitmap_s1_b = (uint *) mymalloc ((1u << bitmap_max) * sizeof (uint)); + uint *bitmap_s1_c = (uint *) mymalloc ((1u << bitmap_max) * sizeof (uint)); + uint *bitmap_s1_d = (uint *) mymalloc ((1u << bitmap_max) * sizeof (uint)); + uint *bitmap_s2_a = (uint *) mymalloc ((1u << bitmap_max) * sizeof (uint)); + uint *bitmap_s2_b = (uint *) mymalloc ((1u << bitmap_max) * sizeof (uint)); + uint *bitmap_s2_c = (uint *) mymalloc ((1u << bitmap_max) * sizeof (uint)); + uint *bitmap_s2_d = (uint *) mymalloc ((1u << bitmap_max) * sizeof (uint)); uint bitmap_bits; uint bitmap_nums; @@ -13799,7 +13908,7 @@ int main (int argc, char **argv) { if (data.quiet == 0) log_info_nn ("Generating bitmap tables with %u bits...", bitmap_bits); - bitmap_nums = 1 << bitmap_bits; + bitmap_nums = 1u << bitmap_bits; bitmap_mask = bitmap_nums - 1; @@ -13813,7 +13922,7 @@ int main (int argc, char **argv) break; } - bitmap_nums = 1 << bitmap_bits; + bitmap_nums = 1u << bitmap_bits; bitmap_mask = bitmap_nums - 1; @@ -14103,7 +14212,7 @@ int main (int argc, char **argv) for (uint platform_id = 0; platform_id < platforms_cnt; platform_id++) { - if ((opencl_platforms_filter & (1 << platform_id)) == 0) continue; + if ((opencl_platforms_filter & (1u << platform_id)) == 0) continue; cl_platform_id platform = platforms[platform_id]; @@ -14235,7 +14344,7 @@ int main (int argc, char **argv) platform_vendor_id = VENDOR_ID_GENERIC; } - uint platform_skipped = ((opencl_platforms_filter & (1 << platform_id)) == 0); + uint platform_skipped = ((opencl_platforms_filter & (1u << platform_id)) == 0); CL_err = hc_clGetDeviceIDs (data.ocl, platform, CL_DEVICE_TYPE_ALL, DEVICES_MAX, platform_devices, &platform_devices_cnt); @@ -14742,7 +14851,7 @@ int main (int argc, char **argv) // skipped - device_param->skipped |= ((devices_filter & (1 << device_id)) == 0); + device_param->skipped |= ((devices_filter & (1u << device_id)) == 0); device_param->skipped |= ((device_types_filter & (device_type)) == 0); // driver_version @@ -15309,6 +15418,8 @@ int main (int argc, char **argv) log_info ("Rules: %u", kernel_rules_cnt); } + log_info ("Mangle: %d", mangle); + if (opti_type) { log_info ("Applicable Optimizers:"); @@ -15785,7 +15896,7 @@ int main (int argc, char **argv) { size_scrypt = (128 * scrypt_r) * scrypt_N; - size_scrypt /= 1 << tmto; + size_scrypt /= 1u << tmto; size_scrypt *= device_param->device_processors * device_param->kernel_threads * device_param->kernel_accel_max; @@ -16090,46 +16201,19 @@ int main (int argc, char **argv) * default building options */ - char cpath[1024] = { 0 }; - - char build_opts[1024] = { 0 }; - - #if _WIN - - snprintf (cpath, sizeof (cpath) - 1, "%s\\OpenCL\\", shared_dir); - - char *cpath_real = mymalloc (MAX_PATH); - - if (GetFullPathName (cpath, MAX_PATH, cpath_real, NULL) == 0) + if (chdir (cpath_real) == -1) { - log_error ("ERROR: %s: %s", cpath, "GetFullPathName()"); + log_error ("ERROR: %s: %s", cpath_real, strerror (errno)); return -1; } - naive_replace (cpath_real, '\\', '/'); - - // not escaping here, windows has quotes + char build_opts[1024] = { 0 }; + #if _WIN snprintf (build_opts, sizeof (build_opts) - 1, "-I \"%s\"", cpath_real); - #else - - snprintf (cpath, sizeof (cpath) - 1, "%s/OpenCL/", shared_dir); - - char *cpath_real = mymalloc (PATH_MAX); - - if (realpath (cpath, cpath_real) == NULL) - { - log_error ("ERROR: %s: %s", cpath, strerror (errno)); - - return -1; - } - - naive_escape (cpath_real, PATH_MAX, ' ', '\\'); - snprintf (build_opts, sizeof (build_opts) - 1, "-I %s", cpath_real); - #endif // include check @@ -16157,13 +16241,6 @@ int main (int argc, char **argv) "inc_vendor.cl", }; - if (chdir (cpath_real) == -1) - { - log_error ("ERROR: %s: %s", cpath_real, strerror (errno)); - - return -1; - } - for (int i = 0; i < files_cnt; i++) { FILE *fd = fopen (files_names[i], "r"); @@ -16189,8 +16266,6 @@ int main (int argc, char **argv) fclose (fd); } - myfree (cpath_real); - // we don't have sm_* on vendors not NV but it doesn't matter char build_opts_new[1024] = { 0 }; @@ -16214,7 +16289,7 @@ int main (int argc, char **argv) char source_file[256] = { 0 }; - generate_source_kernel_filename (attack_exec, attack_kern, kern_type, shared_dir, source_file); + generate_source_kernel_filename (attack_exec, attack_kern, kern_type, mangle, shared_dir, source_file); struct stat sst; @@ -16231,7 +16306,7 @@ int main (int argc, char **argv) char cached_file[256] = { 0 }; - generate_cached_kernel_filename (attack_exec, attack_kern, kern_type, profile_dir, device_name_chksum, cached_file); + generate_cached_kernel_filename (attack_exec, attack_kern, kern_type, mangle, profile_dir, device_name_chksum, cached_file); int cached = 1; @@ -17548,6 +17623,7 @@ int main (int argc, char **argv) char *hash_type = strhashtype (data.hash_mode); // not a bug log_info ("Hashtype: %s", hash_type); + log_info ("Mangle: %d", mangle); log_info (""); } } @@ -19412,6 +19488,8 @@ int main (int argc, char **argv) data.runtime_start = runtime_start; + data.prepare_time += runtime_start - prepare_start; + for (uint device_id = 0; device_id < data.devices_cnt; device_id++) { hc_device_param_t *device_param = &devices_param[device_id]; @@ -19501,6 +19579,8 @@ int main (int argc, char **argv) logfile_sub_uint (runtime_start); logfile_sub_uint (runtime_stop); + time (&prepare_start); + logfile_sub_msg ("STOP"); global_free (subid);