1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-12-22 14:48:12 +00:00

Run weak-hash checks only in straight-attack mode, this greatly reduces code complexity

This commit is contained in:
Jens Steube 2016-01-13 22:22:46 +01:00
parent cfff6220fc
commit 49d0767aa8
3 changed files with 24 additions and 207 deletions

View File

@ -67,6 +67,10 @@ Type.: Feature
File.: Host
Desc.: Moved rules_optimize to hashcat-utils
Type.: Feature
File.: Host
Desc.: Run weak-hash checks only in straight-attack mode, this greatly reduces code complexity
Type.: Change
File.: Host
Desc.: Renamed option --gpu-accel to --kernel-accel

View File

@ -1565,7 +1565,6 @@ extern hc_thread_mutex_t mux_display;
#define KERN_RUN_2 2000
#define KERN_RUN_23 2500
#define KERN_RUN_3 3000
#define KERN_RUN_WEAK 9000
/*
* functions

View File

@ -2364,7 +2364,6 @@ static void run_kernel (const uint kern_run, hc_device_param_t *device_param, co
case KERN_RUN_2: kernel = device_param->kernel2; break;
case KERN_RUN_23: kernel = device_param->kernel23; break;
case KERN_RUN_3: kernel = device_param->kernel3; break;
case KERN_RUN_WEAK: kernel = device_param->kernel_weak; break;
}
hc_clSetKernelArg (kernel, 21, sizeof (cl_uint), device_param->kernel_params[21]);
@ -4541,16 +4540,10 @@ static void weak_hash_check (hc_device_param_t *device_param, const uint salt_po
device_param->kernel_params_buf32[31] = 1;
char *dictfile_old = data.dictfile;
char *dictfile2_old = data.dictfile2;
char *mask_old = data.mask;
int attack_mode_old = data.attack_mode;
const char *weak_hash_check = "weak-hash-check";
data.dictfile = (char *) weak_hash_check;
data.dictfile2 = (char *) weak_hash_check;
data.mask = (char *) weak_hash_check;
data.attack_mode = ATTACK_MODE_STRAIGHT;
/**
* run the kernel
@ -4558,7 +4551,7 @@ static void weak_hash_check (hc_device_param_t *device_param, const uint salt_po
if (data.attack_exec == ATTACK_EXEC_INSIDE_KERNEL)
{
run_kernel (KERN_RUN_WEAK, device_param, 1);
run_kernel (KERN_RUN_1, device_param, 1);
}
else
{
@ -4601,9 +4594,6 @@ static void weak_hash_check (hc_device_param_t *device_param, const uint salt_po
device_param->kernel_params_buf32[31] = 0;
data.dictfile = dictfile_old;
data.dictfile2 = dictfile2_old;
data.mask = mask_old;
data.attack_mode = attack_mode_old;
}
// hlfmt hashcat
@ -6097,6 +6087,18 @@ int main (int argc, char **argv)
}
}
if (attack_mode != ATTACK_MODE_STRAIGHT)
{
if (weak_hash_threshold != WEAK_HASH_THRESHOLD)
{
log_error ("ERROR: setting --weak-hash-threshold allowed only in straight-attack mode");
return (-1);
}
weak_hash_threshold = 0;
}
/**
* induction directory
*/
@ -13309,149 +13311,6 @@ int main (int argc, char **argv)
sprintf (build_opts, "-I%s/ -DVENDOR_ID=%d -DCUDA_ARCH=%d", shared_dir, device_param->vendor_id, (device_param->sm_major * 100) + device_param->sm_minor);
/**
* a0 kernel, required for some fast hashes to make weak_hash_check work
*/
const uint add_flag = OPTS_TYPE_PT_ADD01
| OPTS_TYPE_PT_ADD02
| OPTS_TYPE_PT_ADD80
| OPTS_TYPE_PT_ADDBITS14
| OPTS_TYPE_PT_ADDBITS15
| OPTS_TYPE_ST_ADD01
| OPTS_TYPE_ST_ADD02
| OPTS_TYPE_ST_ADD80
| OPTS_TYPE_ST_ADDBITS14
| OPTS_TYPE_ST_ADDBITS15
| OPTS_TYPE_PT_BITSLICE;
if ((weak_hash_threshold) && (attack_exec == ATTACK_EXEC_INSIDE_KERNEL) && (opts_type & add_flag))
{
/**
* kernel source filename
*/
char source_file[256];
memset (source_file, 0, sizeof (source_file));
generate_source_kernel_filename (attack_exec, ATTACK_KERN_STRAIGHT, kern_type, shared_dir, source_file);
struct stat sst;
if (stat (source_file, &sst) == -1)
{
log_error ("ERROR: %s: %s", source_file, strerror (errno));
return -1;
}
/**
* kernel cached filename
*/
char cached_file[256];
memset (cached_file, 0, sizeof (cached_file));
generate_cached_kernel_filename (attack_exec, ATTACK_KERN_STRAIGHT, kern_type, profile_dir, device_name_chksum, cached_file);
int cached = 1;
struct stat cst;
if (stat (cached_file, &cst) == -1)
{
cached = 0;
}
/**
* kernel compile or load
*/
size_t *kernel_lengths = (size_t *) mymalloc (sizeof (size_t));
const unsigned char **kernel_sources = (const unsigned char **) mymalloc (sizeof (unsigned char *));
if (force_jit_compilation == 0)
{
if (cached == 0)
{
if (quiet == 0) log_info ("Device #%u: Kernel %s not found in cache! Building may take a while...", device_id + 1, cached_file);
load_kernel (source_file, 1, kernel_lengths, kernel_sources);
device_param->program_weak = hc_clCreateProgramWithSource (device_param->context, 1, (const char **) kernel_sources, NULL);
hc_clBuildProgram (device_param->program_weak, 1, &device_param->device, build_opts, NULL, NULL);
size_t binary_size;
clGetProgramInfo (device_param->program_weak, CL_PROGRAM_BINARY_SIZES, sizeof (size_t), &binary_size, NULL);
unsigned char *binary = (unsigned char *) mymalloc (binary_size);
clGetProgramInfo (device_param->program_weak, CL_PROGRAM_BINARIES, sizeof (binary), &binary, NULL);
writeProgramBin (cached_file, binary, binary_size);
local_free (binary);
}
else
{
if (quiet == 0) log_info ("Device #%u: Kernel %s (%ld bytes)", device_id + 1, cached_file, cst.st_size);
load_kernel (cached_file, 1, kernel_lengths, kernel_sources);
device_param->program_weak = hc_clCreateProgramWithBinary (device_param->context, 1, &device_param->device, kernel_lengths, (const unsigned char **) kernel_sources, NULL);
hc_clBuildProgram (device_param->program_weak, 1, &device_param->device, build_opts, NULL, NULL);
}
}
else
{
if (quiet == 0) log_info ("Device #%u: Kernel %s (%ld bytes)", device_id + 1, source_file, sst.st_size);
load_kernel (source_file, 1, kernel_lengths, kernel_sources);
device_param->program_weak = hc_clCreateProgramWithSource (device_param->context, 1, (const char **) kernel_sources, NULL);
if (force_jit_compilation == 1500)
{
sprintf (build_opts, "%s -DDESCRYPT_SALT=%d", build_opts, data.salts_buf[0].salt_buf[0]);
}
else if (force_jit_compilation == 8900)
{
sprintf (build_opts, "%s -DSCRYPT_N=%d -DSCRYPT_R=%d -DSCRYPT_P=%d -DSCRYPT_TMTO=%d", build_opts, data.salts_buf[0].scrypt_N, data.salts_buf[0].scrypt_r, data.salts_buf[0].scrypt_p, 1 << data.salts_buf[0].scrypt_tmto);
}
hc_clBuildProgram (device_param->program_weak, 1, &device_param->device, build_opts, NULL, NULL);
}
local_free (kernel_lengths);
local_free (kernel_sources[0]);
local_free (kernel_sources);
// this is mostly for debug
size_t ret_val_size = 0;
clGetProgramBuildInfo (device_param->program_weak, device_param->device, CL_PROGRAM_BUILD_LOG, 0, NULL, &ret_val_size);
if (ret_val_size > 2)
{
char *build_log = (char *) mymalloc (ret_val_size + 1);
memset (build_log, 0, ret_val_size + 1);
clGetProgramBuildInfo (device_param->program_weak, device_param->device, CL_PROGRAM_BUILD_LOG, ret_val_size, build_log, NULL);
puts (build_log);
myfree (build_log);
}
}
/**
* main kernel
*/
@ -13810,7 +13669,6 @@ int main (int argc, char **argv)
device_param->d_pws_buf = hc_clCreateBuffer (device_param->context, CL_MEM_READ_ONLY, size_pws, NULL);
device_param->d_pws_amp_buf = hc_clCreateBuffer (device_param->context, CL_MEM_READ_ONLY, size_pws, NULL);
device_param->d_rules_c = hc_clCreateBuffer (device_param->context, CL_MEM_READ_ONLY, size_rules_c, NULL); // we need this for weak-hash-check even if the user has choosen for ex: -a 3
device_param->d_tmps = hc_clCreateBuffer (device_param->context, CL_MEM_READ_WRITE, size_tmps, NULL);
device_param->d_hooks = hc_clCreateBuffer (device_param->context, CL_MEM_READ_WRITE, size_hooks, NULL);
device_param->d_bitmap_s1_a = hc_clCreateBuffer (device_param->context, CL_MEM_READ_ONLY, bitmap_size, NULL);
@ -13842,7 +13700,6 @@ int main (int argc, char **argv)
run_kernel_bzero (device_param, device_param->d_pws_buf, size_pws);
run_kernel_bzero (device_param, device_param->d_pws_amp_buf, size_pws);
run_kernel_bzero (device_param, device_param->d_rules_c, size_rules_c);
run_kernel_bzero (device_param, device_param->d_tmps, size_tmps);
run_kernel_bzero (device_param, device_param->d_hooks, size_hooks);
run_kernel_bzero (device_param, device_param->d_plain_bufs, size_plains);
@ -13855,8 +13712,11 @@ int main (int argc, char **argv)
if (attack_kern == ATTACK_KERN_STRAIGHT)
{
device_param->d_rules = hc_clCreateBuffer (device_param->context, CL_MEM_READ_ONLY, size_rules, NULL);
device_param->d_rules_c = hc_clCreateBuffer (device_param->context, CL_MEM_READ_ONLY, size_rules_c, NULL);
hc_clEnqueueWriteBuffer (device_param->command_queue, device_param->d_rules, CL_TRUE, 0, size_rules, kernel_rules_buf, 0, NULL, NULL);
run_kernel_bzero (device_param, device_param->d_rules_c, size_rules_c);
}
else if (attack_kern == ATTACK_KERN_COMBI)
{
@ -14088,40 +13948,6 @@ int main (int argc, char **argv)
device_param->kernel3 = hc_clCreateKernel (device_param->program, kernel_name);
}
if (weak_hash_threshold)
{
if (opts_type & add_flag)
{
if (opti_type & OPTI_TYPE_SINGLE_HASH)
{
snprintf (kernel_name, sizeof (kernel_name) - 1, "m%05d_s%02d", kern_type, 4);
device_param->kernel_weak = hc_clCreateKernel (device_param->program_weak, kernel_name);
}
else
{
snprintf (kernel_name, sizeof (kernel_name) - 1, "m%05d_m%02d", kern_type, 4);
device_param->kernel_weak = hc_clCreateKernel (device_param->program_weak, kernel_name);
}
}
else
{
if (opti_type & OPTI_TYPE_SINGLE_HASH)
{
snprintf (kernel_name, sizeof (kernel_name) - 1, "m%05d_s%02d", kern_type, 4);
device_param->kernel_weak = hc_clCreateKernel (device_param->program, kernel_name);
}
else
{
snprintf (kernel_name, sizeof (kernel_name) - 1, "m%05d_m%02d", kern_type, 4);
device_param->kernel_weak = hc_clCreateKernel (device_param->program, kernel_name);
}
}
}
if (data.attack_mode == ATTACK_MODE_BF)
{
if (opts_type & OPTS_TYPE_PT_BITSLICE)
@ -14173,11 +13999,6 @@ int main (int argc, char **argv)
if (opts_type & OPTS_TYPE_HOOK12) hc_clSetKernelArg (device_param->kernel12, i, sizeof (cl_mem), device_param->kernel_params[i]);
if (opts_type & OPTS_TYPE_HOOK23) hc_clSetKernelArg (device_param->kernel23, i, sizeof (cl_mem), device_param->kernel_params[i]);
if (weak_hash_threshold)
{
hc_clSetKernelArg (device_param->kernel_weak, i, sizeof (cl_mem), device_param->kernel_params[i]);
}
}
for (uint i = 21; i <= 31; i++)
@ -14188,11 +14009,6 @@ int main (int argc, char **argv)
if (opts_type & OPTS_TYPE_HOOK12) hc_clSetKernelArg (device_param->kernel12, i, sizeof (cl_uint), device_param->kernel_params[i]);
if (opts_type & OPTS_TYPE_HOOK23) hc_clSetKernelArg (device_param->kernel23, i, sizeof (cl_uint), device_param->kernel_params[i]);
if (weak_hash_threshold)
{
hc_clSetKernelArg (device_param->kernel_weak, i, sizeof (cl_uint), device_param->kernel_params[i]);
}
}
if (attack_mode == ATTACK_MODE_BF)
@ -16494,12 +16310,10 @@ int main (int argc, char **argv)
if (device_param->kernel_tb) hc_clReleaseKernel (device_param->kernel_tb);
if (device_param->kernel_tm) hc_clReleaseKernel (device_param->kernel_tm);
if (device_param->kernel_amp) hc_clReleaseKernel (device_param->kernel_amp);
if (device_param->kernel_weak) hc_clReleaseKernel (device_param->kernel_weak);
if (device_param->program) hc_clReleaseProgram (device_param->program);
if (device_param->program_mp) hc_clReleaseProgram (device_param->program_mp);
if (device_param->program_amp) hc_clReleaseProgram (device_param->program_amp);
if (device_param->program_weak) hc_clReleaseProgram (device_param->program_weak);
if (device_param->command_queue) hc_clReleaseCommandQueue (device_param->command_queue);
if (device_param->context) hc_clReleaseContext (device_param->context);