2016-09-15 02:29:22 +00:00
|
|
|
/**
|
|
|
|
* Author......: See docs/credits.txt
|
|
|
|
* License.....: MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "types.h"
|
2016-11-20 15:13:42 +00:00
|
|
|
#include "convert.h"
|
|
|
|
#include "event.h"
|
2016-09-15 02:29:22 +00:00
|
|
|
#include "memory.h"
|
|
|
|
#include "opencl.h"
|
|
|
|
#include "wordlist.h"
|
|
|
|
#include "shared.h"
|
2016-11-20 15:13:42 +00:00
|
|
|
#include "thread.h"
|
|
|
|
#include "filehandling.h"
|
|
|
|
#include "rp_cpu.h"
|
2016-09-15 02:29:22 +00:00
|
|
|
#include "dispatch.h"
|
|
|
|
|
2016-10-20 19:27:42 +00:00
|
|
|
static u64 get_lowest_words_done (const hashcat_ctx_t *hashcat_ctx)
|
|
|
|
{
|
|
|
|
const opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx;
|
|
|
|
|
|
|
|
u64 words_cur = 0xffffffffffffffff;
|
|
|
|
|
|
|
|
for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++)
|
|
|
|
{
|
|
|
|
hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id];
|
|
|
|
|
2016-11-18 09:09:03 +00:00
|
|
|
if (device_param->skipped == true) continue;
|
2016-10-20 19:27:42 +00:00
|
|
|
|
|
|
|
const u64 words_done = device_param->words_done;
|
|
|
|
|
|
|
|
if (words_done < words_cur) words_cur = words_done;
|
|
|
|
}
|
|
|
|
|
|
|
|
// It's possible that a device's workload isn't finished right after a restore-case.
|
|
|
|
// In that case, this function would return 0 and overwrite the real restore point
|
|
|
|
|
|
|
|
const status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
|
|
|
|
|
|
|
|
if (words_cur < status_ctx->words_cur) words_cur = status_ctx->words_cur;
|
|
|
|
|
|
|
|
return words_cur;
|
|
|
|
}
|
|
|
|
|
2016-10-07 20:25:52 +00:00
|
|
|
static int set_kernel_power_final (hashcat_ctx_t *hashcat_ctx, const u32 kernel_power_final)
|
2016-09-15 02:29:22 +00:00
|
|
|
{
|
2016-10-08 21:16:40 +00:00
|
|
|
EVENT (EVENT_SET_KERNEL_POWER_FINAL);
|
2016-09-15 02:29:22 +00:00
|
|
|
|
2016-10-07 20:25:52 +00:00
|
|
|
opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx;
|
2016-09-15 02:29:22 +00:00
|
|
|
|
2016-09-28 09:49:08 +00:00
|
|
|
opencl_ctx->kernel_power_final = kernel_power_final;
|
2016-10-07 20:25:52 +00:00
|
|
|
|
|
|
|
return 0;
|
2016-09-15 02:29:22 +00:00
|
|
|
}
|
|
|
|
|
2016-09-28 09:49:08 +00:00
|
|
|
static u32 get_power (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param)
|
2016-09-15 02:29:22 +00:00
|
|
|
{
|
2016-09-28 09:49:08 +00:00
|
|
|
const u64 kernel_power_final = opencl_ctx->kernel_power_final;
|
2016-09-15 02:29:22 +00:00
|
|
|
|
|
|
|
if (kernel_power_final)
|
|
|
|
{
|
2016-09-28 09:49:08 +00:00
|
|
|
const double device_factor = (double) device_param->hardware_power / opencl_ctx->hardware_power_all;
|
2016-09-15 02:29:22 +00:00
|
|
|
|
|
|
|
const u64 words_left_device = (u64) CEIL (kernel_power_final * device_factor);
|
|
|
|
|
|
|
|
// work should be at least the hardware power available without any accelerator
|
|
|
|
|
|
|
|
const u64 work = MAX (words_left_device, device_param->hardware_power);
|
|
|
|
|
|
|
|
return work;
|
|
|
|
}
|
|
|
|
|
|
|
|
return device_param->kernel_power;
|
|
|
|
}
|
|
|
|
|
2016-10-20 19:27:42 +00:00
|
|
|
static u32 get_work (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, const u32 max)
|
2016-09-15 02:29:22 +00:00
|
|
|
{
|
2016-10-07 20:25:52 +00:00
|
|
|
opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx;
|
|
|
|
status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
|
|
|
|
user_options_t *user_options = hashcat_ctx->user_options;
|
|
|
|
|
2016-09-29 21:49:33 +00:00
|
|
|
hc_thread_mutex_lock (status_ctx->mux_dispatcher);
|
2016-09-15 02:29:22 +00:00
|
|
|
|
2016-10-20 19:27:42 +00:00
|
|
|
const u64 words_off = status_ctx->words_off;
|
2016-09-29 21:49:33 +00:00
|
|
|
const u64 words_base = (user_options->limit == 0) ? status_ctx->words_base : MIN (user_options->limit, status_ctx->words_base);
|
2016-09-15 02:29:22 +00:00
|
|
|
|
2016-10-20 19:27:42 +00:00
|
|
|
device_param->words_off = words_off;
|
2016-09-15 02:29:22 +00:00
|
|
|
|
2016-09-28 09:49:08 +00:00
|
|
|
const u64 kernel_power_all = opencl_ctx->kernel_power_all;
|
2016-09-15 02:29:22 +00:00
|
|
|
|
2016-10-20 19:27:42 +00:00
|
|
|
const u64 words_left = words_base - words_off;
|
2016-09-15 02:29:22 +00:00
|
|
|
|
|
|
|
if (words_left < kernel_power_all)
|
|
|
|
{
|
2016-09-28 09:49:08 +00:00
|
|
|
if (opencl_ctx->kernel_power_final == 0)
|
2016-09-15 02:29:22 +00:00
|
|
|
{
|
2016-10-07 20:25:52 +00:00
|
|
|
set_kernel_power_final (hashcat_ctx, words_left);
|
2016-09-15 02:29:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-28 09:49:08 +00:00
|
|
|
const u32 kernel_power = get_power (opencl_ctx, device_param);
|
2016-09-15 02:29:22 +00:00
|
|
|
|
2016-10-04 09:22:08 +00:00
|
|
|
u32 work = MIN (words_left, kernel_power);
|
2016-09-15 02:29:22 +00:00
|
|
|
|
|
|
|
work = MIN (work, max);
|
|
|
|
|
2016-10-20 19:27:42 +00:00
|
|
|
status_ctx->words_off += work;
|
2016-09-15 02:29:22 +00:00
|
|
|
|
2016-09-29 21:49:33 +00:00
|
|
|
hc_thread_mutex_unlock (status_ctx->mux_dispatcher);
|
2016-09-15 02:29:22 +00:00
|
|
|
|
|
|
|
return work;
|
|
|
|
}
|
|
|
|
|
2016-10-13 08:07:04 +00:00
|
|
|
static int calc_stdin (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param)
|
2016-09-15 02:29:22 +00:00
|
|
|
{
|
2016-09-30 20:52:44 +00:00
|
|
|
user_options_t *user_options = hashcat_ctx->user_options;
|
|
|
|
user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra;
|
|
|
|
hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
|
|
|
|
hashes_t *hashes = hashcat_ctx->hashes;
|
|
|
|
straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx;
|
|
|
|
status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
|
2016-09-15 02:29:22 +00:00
|
|
|
|
2016-11-20 21:54:52 +00:00
|
|
|
char *buf = (char *) hcmalloc (HCBUFSIZ_LARGE);
|
2016-09-15 02:29:22 +00:00
|
|
|
|
2017-04-14 14:36:28 +00:00
|
|
|
bool iconv_enabled = false;
|
|
|
|
|
|
|
|
iconv_t iconv_ctx;
|
|
|
|
|
|
|
|
char *iconv_tmp = NULL;
|
|
|
|
|
|
|
|
if (strcmp (user_options->encoding_from, user_options->encoding_to))
|
|
|
|
{
|
|
|
|
iconv_enabled = true;
|
|
|
|
|
|
|
|
iconv_ctx = iconv_open (user_options->encoding_to, user_options->encoding_from);
|
|
|
|
|
|
|
|
if (iconv_ctx == (iconv_t) -1) return -1;
|
|
|
|
|
|
|
|
iconv_tmp = (char *) hcmalloc (HCBUFSIZ_TINY);
|
|
|
|
}
|
2016-09-15 02:29:22 +00:00
|
|
|
|
2016-09-29 21:25:29 +00:00
|
|
|
while (status_ctx->run_thread_level1 == true)
|
2016-09-15 02:29:22 +00:00
|
|
|
{
|
2016-09-29 21:49:33 +00:00
|
|
|
hc_thread_mutex_lock (status_ctx->mux_dispatcher);
|
2016-09-15 02:29:22 +00:00
|
|
|
|
|
|
|
if (feof (stdin) != 0)
|
|
|
|
{
|
2016-09-29 21:49:33 +00:00
|
|
|
hc_thread_mutex_unlock (status_ctx->mux_dispatcher);
|
2016-09-15 02:29:22 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-11-16 12:24:41 +00:00
|
|
|
u32 words_extra_total = 0;
|
2016-11-09 01:02:11 +00:00
|
|
|
|
2016-11-16 12:24:41 +00:00
|
|
|
while (device_param->pws_cnt < device_param->kernel_power)
|
2016-09-15 02:29:22 +00:00
|
|
|
{
|
|
|
|
char *line_buf = fgets (buf, HCBUFSIZ_LARGE - 1, stdin);
|
|
|
|
|
|
|
|
if (line_buf == NULL) break;
|
|
|
|
|
2017-04-14 14:36:28 +00:00
|
|
|
size_t line_len = in_superchop (line_buf);
|
2016-09-15 02:29:22 +00:00
|
|
|
|
2016-10-06 14:16:56 +00:00
|
|
|
line_len = convert_from_hex (hashcat_ctx, line_buf, line_len);
|
2016-09-15 02:29:22 +00:00
|
|
|
|
2017-04-14 14:36:28 +00:00
|
|
|
// do the on-the-fly encoding
|
|
|
|
|
|
|
|
if (iconv_enabled == true)
|
|
|
|
{
|
|
|
|
char *iconv_ptr = iconv_tmp;
|
|
|
|
size_t iconv_sz = HCBUFSIZ_TINY;
|
|
|
|
|
|
|
|
const size_t iconv_rc = iconv (iconv_ctx, &line_buf, &line_len, &iconv_ptr, &iconv_sz);
|
|
|
|
|
2017-06-29 10:19:05 +00:00
|
|
|
if (iconv_rc == (size_t) -1) continue;
|
|
|
|
|
|
|
|
line_buf = iconv_tmp;
|
|
|
|
line_len = HCBUFSIZ_TINY - iconv_sz;
|
2017-04-14 14:36:28 +00:00
|
|
|
}
|
|
|
|
|
2016-09-15 02:29:22 +00:00
|
|
|
// post-process rule engine
|
|
|
|
|
2017-02-14 14:09:01 +00:00
|
|
|
char rule_buf_out[BLOCK_SIZE];
|
2017-02-14 13:27:08 +00:00
|
|
|
|
2016-09-30 16:09:29 +00:00
|
|
|
if (run_rule_engine ((int) user_options_extra->rule_len_l, user_options->rule_buf_l))
|
2016-09-15 02:29:22 +00:00
|
|
|
{
|
2017-06-29 10:19:05 +00:00
|
|
|
if (line_len >= BLOCK_SIZE) continue;
|
|
|
|
|
2017-02-14 14:09:01 +00:00
|
|
|
memset (rule_buf_out, 0, sizeof (rule_buf_out));
|
|
|
|
|
2017-06-29 10:19:05 +00:00
|
|
|
const int rule_len_out = _old_apply_rule (user_options->rule_buf_l, (int) user_options_extra->rule_len_l, line_buf, (int) line_len, rule_buf_out);
|
2016-09-15 02:29:22 +00:00
|
|
|
|
|
|
|
if (rule_len_out < 0) continue;
|
|
|
|
|
|
|
|
line_buf = rule_buf_out;
|
2017-06-29 10:19:05 +00:00
|
|
|
line_len = (size_t) rule_len_out;
|
2016-09-15 02:29:22 +00:00
|
|
|
}
|
|
|
|
|
2017-06-29 10:19:05 +00:00
|
|
|
if (line_len >= PW_MAX) continue;
|
2016-09-15 02:29:22 +00:00
|
|
|
|
|
|
|
// hmm that's always the case, or?
|
|
|
|
|
2017-04-14 14:36:28 +00:00
|
|
|
const u32 attack_kern = user_options_extra->attack_kern;
|
|
|
|
|
2016-09-15 02:29:22 +00:00
|
|
|
if (attack_kern == ATTACK_KERN_STRAIGHT)
|
|
|
|
{
|
2016-09-28 11:51:00 +00:00
|
|
|
if ((line_len < hashconfig->pw_min) || (line_len > hashconfig->pw_max))
|
2016-09-15 02:29:22 +00:00
|
|
|
{
|
2016-11-16 12:24:41 +00:00
|
|
|
words_extra_total++;
|
2016-09-15 02:29:22 +00:00
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-30 16:09:29 +00:00
|
|
|
pw_add (device_param, (u8 *) line_buf, (int) line_len);
|
2016-09-15 02:29:22 +00:00
|
|
|
|
2016-09-29 21:25:29 +00:00
|
|
|
while (status_ctx->run_thread_level1 == false) break;
|
2016-09-15 02:29:22 +00:00
|
|
|
}
|
|
|
|
|
2016-09-29 21:49:33 +00:00
|
|
|
hc_thread_mutex_unlock (status_ctx->mux_dispatcher);
|
2016-09-15 02:29:22 +00:00
|
|
|
|
2016-11-16 12:24:41 +00:00
|
|
|
if (words_extra_total > 0)
|
2016-11-09 01:02:11 +00:00
|
|
|
{
|
|
|
|
hc_thread_mutex_lock (status_ctx->mux_counter);
|
|
|
|
|
|
|
|
for (u32 salt_pos = 0; salt_pos < hashes->salts_cnt; salt_pos++)
|
|
|
|
{
|
2016-11-16 12:24:41 +00:00
|
|
|
status_ctx->words_progress_rejected[salt_pos] += words_extra_total * straight_ctx->kernel_rules_cnt;
|
2016-11-09 01:02:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
hc_thread_mutex_unlock (status_ctx->mux_counter);
|
|
|
|
}
|
|
|
|
|
2016-11-16 12:24:41 +00:00
|
|
|
if (status_ctx->run_thread_level1 == false) break;
|
2016-09-15 02:29:22 +00:00
|
|
|
|
2016-11-16 12:24:41 +00:00
|
|
|
if (device_param->pws_cnt == 0) break;
|
2016-10-15 17:44:31 +00:00
|
|
|
|
2016-11-16 12:24:41 +00:00
|
|
|
// flush
|
2016-10-15 17:44:31 +00:00
|
|
|
|
2016-11-16 12:24:41 +00:00
|
|
|
int CL_rc;
|
2016-10-15 17:44:31 +00:00
|
|
|
|
2016-11-16 12:24:41 +00:00
|
|
|
CL_rc = run_copy (hashcat_ctx, device_param, device_param->pws_cnt);
|
2016-09-15 02:29:22 +00:00
|
|
|
|
2017-02-14 13:02:18 +00:00
|
|
|
if (CL_rc == -1)
|
|
|
|
{
|
|
|
|
hcfree (buf);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
2016-09-15 02:29:22 +00:00
|
|
|
|
2016-11-16 12:24:41 +00:00
|
|
|
CL_rc = run_cracker (hashcat_ctx, device_param, device_param->pws_cnt);
|
2016-10-15 17:44:31 +00:00
|
|
|
|
2017-02-14 13:02:18 +00:00
|
|
|
if (CL_rc == -1)
|
|
|
|
{
|
|
|
|
hcfree (buf);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
2016-10-15 17:44:31 +00:00
|
|
|
|
2016-11-16 12:24:41 +00:00
|
|
|
device_param->pws_cnt = 0;
|
2016-10-14 19:38:52 +00:00
|
|
|
|
|
|
|
if (status_ctx->run_thread_level1 == false) break;
|
|
|
|
|
|
|
|
if (user_options->speed_only == true) break;
|
2016-09-15 02:29:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
device_param->kernel_accel = 0;
|
|
|
|
device_param->kernel_loops = 0;
|
|
|
|
|
2017-04-14 14:36:28 +00:00
|
|
|
if (iconv_enabled == true)
|
|
|
|
{
|
|
|
|
iconv_close (iconv_ctx);
|
|
|
|
|
|
|
|
iconv_enabled = false;
|
|
|
|
|
|
|
|
hcfree (iconv_tmp);
|
|
|
|
}
|
|
|
|
|
2016-10-10 09:03:11 +00:00
|
|
|
hcfree (buf);
|
2016-10-13 08:07:04 +00:00
|
|
|
|
|
|
|
return 0;
|
2016-09-15 02:29:22 +00:00
|
|
|
}
|
|
|
|
|
2016-09-30 20:52:44 +00:00
|
|
|
void *thread_calc_stdin (void *p)
|
2016-09-15 02:29:22 +00:00
|
|
|
{
|
2016-09-30 20:52:44 +00:00
|
|
|
thread_param_t *thread_param = (thread_param_t *) p;
|
|
|
|
|
|
|
|
hashcat_ctx_t *hashcat_ctx = thread_param->hashcat_ctx;
|
|
|
|
|
|
|
|
opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx;
|
|
|
|
|
|
|
|
if (opencl_ctx->enabled == false) return NULL;
|
|
|
|
|
|
|
|
hc_device_param_t *device_param = opencl_ctx->devices_param + thread_param->tid;
|
2016-09-15 02:29:22 +00:00
|
|
|
|
|
|
|
if (device_param->skipped) return NULL;
|
|
|
|
|
2016-10-13 08:07:04 +00:00
|
|
|
calc_stdin (hashcat_ctx, device_param); // we should check the RC here
|
2016-09-30 20:52:44 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-10-13 08:07:04 +00:00
|
|
|
static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param)
|
2016-09-30 20:52:44 +00:00
|
|
|
{
|
|
|
|
user_options_t *user_options = hashcat_ctx->user_options;
|
|
|
|
user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra;
|
|
|
|
hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
|
|
|
|
hashes_t *hashes = hashcat_ctx->hashes;
|
|
|
|
straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx;
|
|
|
|
combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx;
|
|
|
|
status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
|
2016-09-15 02:29:22 +00:00
|
|
|
|
2016-10-04 09:22:08 +00:00
|
|
|
const u32 attack_mode = user_options->attack_mode;
|
|
|
|
const u32 attack_kern = user_options_extra->attack_kern;
|
2016-09-15 02:29:22 +00:00
|
|
|
|
|
|
|
if (attack_mode == ATTACK_MODE_BF)
|
|
|
|
{
|
2016-09-29 21:25:29 +00:00
|
|
|
while (status_ctx->run_thread_level1 == true)
|
2016-09-15 02:29:22 +00:00
|
|
|
{
|
2016-10-07 20:25:52 +00:00
|
|
|
const u32 work = get_work (hashcat_ctx, device_param, -1u);
|
2016-09-15 02:29:22 +00:00
|
|
|
|
|
|
|
if (work == 0) break;
|
|
|
|
|
|
|
|
const u64 words_off = device_param->words_off;
|
|
|
|
const u64 words_fin = words_off + work;
|
|
|
|
|
2016-11-16 12:24:41 +00:00
|
|
|
device_param->pws_cnt = work;
|
2016-09-15 02:29:22 +00:00
|
|
|
|
2016-11-16 12:24:41 +00:00
|
|
|
int CL_rc;
|
2016-10-15 17:44:31 +00:00
|
|
|
|
2016-11-16 12:24:41 +00:00
|
|
|
CL_rc = run_copy (hashcat_ctx, device_param, device_param->pws_cnt);
|
2016-10-15 17:44:31 +00:00
|
|
|
|
2016-11-16 12:24:41 +00:00
|
|
|
if (CL_rc == -1) return -1;
|
2016-09-15 02:29:22 +00:00
|
|
|
|
2016-11-16 12:24:41 +00:00
|
|
|
CL_rc = run_cracker (hashcat_ctx, device_param, device_param->pws_cnt);
|
2016-10-15 17:44:31 +00:00
|
|
|
|
2016-11-16 12:24:41 +00:00
|
|
|
if (CL_rc == -1) return -1;
|
2016-09-15 02:29:22 +00:00
|
|
|
|
2016-11-16 12:24:41 +00:00
|
|
|
device_param->pws_cnt = 0;
|
2016-09-15 02:29:22 +00:00
|
|
|
|
2016-10-14 19:38:52 +00:00
|
|
|
if (user_options->speed_only == true) break;
|
2016-09-15 02:29:22 +00:00
|
|
|
|
2016-10-20 20:14:54 +00:00
|
|
|
if (status_ctx->run_thread_level2 == true)
|
|
|
|
{
|
|
|
|
device_param->words_done = words_fin;
|
2016-10-20 19:27:42 +00:00
|
|
|
|
2016-10-20 20:14:54 +00:00
|
|
|
status_ctx->words_cur = get_lowest_words_done (hashcat_ctx);
|
|
|
|
}
|
2016-10-20 19:27:42 +00:00
|
|
|
|
|
|
|
if (status_ctx->run_thread_level1 == false) break;
|
2016-09-15 02:29:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-09-29 12:46:51 +00:00
|
|
|
char *dictfile = straight_ctx->dict;
|
2016-09-15 02:29:22 +00:00
|
|
|
|
|
|
|
if (attack_mode == ATTACK_MODE_COMBI)
|
|
|
|
{
|
2016-09-29 12:46:51 +00:00
|
|
|
if (combinator_ctx->combs_mode == COMBINATOR_MODE_BASE_LEFT)
|
2016-09-15 02:29:22 +00:00
|
|
|
{
|
2016-09-29 12:46:51 +00:00
|
|
|
dictfile = combinator_ctx->dict1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dictfile = combinator_ctx->dict2;
|
2016-09-15 02:29:22 +00:00
|
|
|
}
|
|
|
|
|
2016-10-04 09:22:08 +00:00
|
|
|
const u32 combs_mode = combinator_ctx->combs_mode;
|
2016-09-15 02:29:22 +00:00
|
|
|
|
|
|
|
if (combs_mode == COMBINATOR_MODE_BASE_LEFT)
|
|
|
|
{
|
2016-09-29 12:46:51 +00:00
|
|
|
const char *dictfilec = combinator_ctx->dict2;
|
2016-09-15 02:29:22 +00:00
|
|
|
|
|
|
|
FILE *combs_fp = fopen (dictfilec, "rb");
|
|
|
|
|
|
|
|
if (combs_fp == NULL)
|
|
|
|
{
|
2017-02-04 01:53:50 +00:00
|
|
|
event_log_error (hashcat_ctx, "%s: %s", combinator_ctx->dict2, strerror (errno));
|
2016-09-15 02:29:22 +00:00
|
|
|
|
2016-10-13 08:07:04 +00:00
|
|
|
return -1;
|
2016-09-15 02:29:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
device_param->combs_fp = combs_fp;
|
|
|
|
}
|
|
|
|
else if (combs_mode == COMBINATOR_MODE_BASE_RIGHT)
|
|
|
|
{
|
2016-09-29 12:46:51 +00:00
|
|
|
const char *dictfilec = combinator_ctx->dict1;
|
2016-09-15 02:29:22 +00:00
|
|
|
|
|
|
|
FILE *combs_fp = fopen (dictfilec, "rb");
|
|
|
|
|
|
|
|
if (combs_fp == NULL)
|
|
|
|
{
|
2017-02-04 01:53:50 +00:00
|
|
|
event_log_error (hashcat_ctx, "%s: %s", dictfilec, strerror (errno));
|
2016-09-15 02:29:22 +00:00
|
|
|
|
2016-10-13 08:07:04 +00:00
|
|
|
return -1;
|
2016-09-15 02:29:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
device_param->combs_fp = combs_fp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-14 13:02:18 +00:00
|
|
|
FILE *fd = fopen (dictfile, "rb");
|
|
|
|
|
|
|
|
if (fd == NULL)
|
|
|
|
{
|
|
|
|
event_log_error (hashcat_ctx, "%s: %s", dictfile, strerror (errno));
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-11-20 21:54:52 +00:00
|
|
|
hashcat_ctx_t *hashcat_ctx_tmp = (hashcat_ctx_t *) hcmalloc (sizeof (hashcat_ctx_t));
|
2016-10-06 14:16:56 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
hashcat_ctx_tmp->bitmap_ctx = hashcat_ctx->bitmap_ctx;
|
|
|
|
hashcat_ctx_tmp->combinator_ctx = hashcat_ctx->combinator_ctx;
|
|
|
|
hashcat_ctx_tmp->cpt_ctx = hashcat_ctx->cpt_ctx;
|
|
|
|
hashcat_ctx_tmp->debugfile_ctx = hashcat_ctx->debugfile_ctx;
|
|
|
|
hashcat_ctx_tmp->dictstat_ctx = hashcat_ctx->dictstat_ctx;
|
|
|
|
hashcat_ctx_tmp->folder_config = hashcat_ctx->folder_config;
|
|
|
|
hashcat_ctx_tmp->hashconfig = hashcat_ctx->hashconfig;
|
|
|
|
hashcat_ctx_tmp->hashes = hashcat_ctx->hashes;
|
|
|
|
hashcat_ctx_tmp->hwmon_ctx = hashcat_ctx->hwmon_ctx;
|
|
|
|
hashcat_ctx_tmp->induct_ctx = hashcat_ctx->induct_ctx;
|
|
|
|
hashcat_ctx_tmp->logfile_ctx = hashcat_ctx->logfile_ctx;
|
|
|
|
hashcat_ctx_tmp->loopback_ctx = hashcat_ctx->loopback_ctx;
|
|
|
|
hashcat_ctx_tmp->mask_ctx = hashcat_ctx->mask_ctx;
|
|
|
|
hashcat_ctx_tmp->opencl_ctx = hashcat_ctx->opencl_ctx;
|
|
|
|
hashcat_ctx_tmp->outcheck_ctx = hashcat_ctx->outcheck_ctx;
|
|
|
|
hashcat_ctx_tmp->outfile_ctx = hashcat_ctx->outfile_ctx;
|
|
|
|
hashcat_ctx_tmp->potfile_ctx = hashcat_ctx->potfile_ctx;
|
|
|
|
hashcat_ctx_tmp->restore_ctx = hashcat_ctx->restore_ctx;
|
|
|
|
hashcat_ctx_tmp->status_ctx = hashcat_ctx->status_ctx;
|
|
|
|
hashcat_ctx_tmp->straight_ctx = hashcat_ctx->straight_ctx;
|
|
|
|
hashcat_ctx_tmp->tuning_db = hashcat_ctx->tuning_db;
|
|
|
|
hashcat_ctx_tmp->user_options_extra = hashcat_ctx->user_options_extra;
|
|
|
|
hashcat_ctx_tmp->user_options = hashcat_ctx->user_options;
|
|
|
|
*/
|
|
|
|
|
|
|
|
memcpy (hashcat_ctx_tmp, hashcat_ctx, sizeof (hashcat_ctx_t)); // yes we actually want to copy these pointers
|
|
|
|
|
2016-11-20 21:54:52 +00:00
|
|
|
hashcat_ctx_tmp->wl_data = (wl_data_t *) hcmalloc (sizeof (wl_data_t));
|
2016-10-13 08:07:04 +00:00
|
|
|
|
|
|
|
const int rc_wl_data_init = wl_data_init (hashcat_ctx_tmp);
|
2016-10-06 14:16:56 +00:00
|
|
|
|
2016-10-30 15:08:41 +00:00
|
|
|
if (rc_wl_data_init == -1)
|
|
|
|
{
|
2017-02-14 13:02:18 +00:00
|
|
|
if (attack_mode == ATTACK_MODE_COMBI) fclose (device_param->combs_fp);
|
|
|
|
|
2016-10-30 15:08:41 +00:00
|
|
|
fclose (fd);
|
|
|
|
|
2017-02-14 13:02:18 +00:00
|
|
|
hcfree (hashcat_ctx_tmp->wl_data);
|
|
|
|
|
|
|
|
hcfree (hashcat_ctx_tmp);
|
|
|
|
|
2016-10-30 15:08:41 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2016-09-15 02:29:22 +00:00
|
|
|
|
|
|
|
u64 words_cur = 0;
|
|
|
|
|
2016-09-29 21:25:29 +00:00
|
|
|
while (status_ctx->run_thread_level1 == true)
|
2016-09-15 02:29:22 +00:00
|
|
|
{
|
|
|
|
u64 words_off = 0;
|
|
|
|
u64 words_fin = 0;
|
|
|
|
|
2016-10-20 19:27:42 +00:00
|
|
|
u32 words_extra = -1u;
|
2016-09-15 02:29:22 +00:00
|
|
|
|
2016-11-09 01:02:11 +00:00
|
|
|
u32 words_extra_total = 0;
|
|
|
|
|
2016-10-20 19:27:42 +00:00
|
|
|
while (words_extra)
|
2016-09-15 02:29:22 +00:00
|
|
|
{
|
2016-10-20 19:27:42 +00:00
|
|
|
const u32 work = get_work (hashcat_ctx, device_param, words_extra);
|
2016-09-15 02:29:22 +00:00
|
|
|
|
|
|
|
if (work == 0) break;
|
|
|
|
|
2016-10-20 19:27:42 +00:00
|
|
|
words_extra = 0;
|
2016-09-15 02:29:22 +00:00
|
|
|
|
|
|
|
words_off = device_param->words_off;
|
|
|
|
words_fin = words_off + work;
|
|
|
|
|
|
|
|
char *line_buf;
|
2016-10-04 09:22:08 +00:00
|
|
|
u32 line_len;
|
2016-09-15 02:29:22 +00:00
|
|
|
|
2017-02-14 14:09:01 +00:00
|
|
|
char rule_buf_out[BLOCK_SIZE];
|
|
|
|
|
2016-10-06 14:16:56 +00:00
|
|
|
for ( ; words_cur < words_off; words_cur++) get_next_word (hashcat_ctx_tmp, fd, &line_buf, &line_len);
|
2016-09-15 02:29:22 +00:00
|
|
|
|
|
|
|
for ( ; words_cur < words_fin; words_cur++)
|
|
|
|
{
|
2016-10-06 14:16:56 +00:00
|
|
|
get_next_word (hashcat_ctx_tmp, fd, &line_buf, &line_len);
|
2016-09-15 02:29:22 +00:00
|
|
|
|
2016-10-06 14:16:56 +00:00
|
|
|
line_len = convert_from_hex (hashcat_ctx, line_buf, line_len);
|
2016-09-15 02:29:22 +00:00
|
|
|
|
|
|
|
// post-process rule engine
|
|
|
|
|
2016-09-30 16:09:29 +00:00
|
|
|
if (run_rule_engine ((int) user_options_extra->rule_len_l, user_options->rule_buf_l))
|
2016-09-15 02:29:22 +00:00
|
|
|
{
|
2017-06-29 10:19:05 +00:00
|
|
|
if (line_len >= BLOCK_SIZE) continue;
|
2017-02-14 14:09:01 +00:00
|
|
|
|
2017-06-29 10:19:05 +00:00
|
|
|
memset (rule_buf_out, 0, sizeof (rule_buf_out));
|
2016-09-15 02:29:22 +00:00
|
|
|
|
2017-06-29 10:19:05 +00:00
|
|
|
const int rule_len_out = _old_apply_rule (user_options->rule_buf_l, (int) user_options_extra->rule_len_l, line_buf, (int) line_len, rule_buf_out);
|
2016-09-15 02:29:22 +00:00
|
|
|
|
|
|
|
if (rule_len_out < 0) continue;
|
|
|
|
|
|
|
|
line_buf = rule_buf_out;
|
2016-09-30 16:09:29 +00:00
|
|
|
line_len = (u32) rule_len_out;
|
2016-09-15 02:29:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (attack_kern == ATTACK_KERN_STRAIGHT)
|
|
|
|
{
|
2016-09-28 11:51:00 +00:00
|
|
|
if ((line_len < hashconfig->pw_min) || (line_len > hashconfig->pw_max))
|
2016-09-15 02:29:22 +00:00
|
|
|
{
|
2016-10-20 19:27:42 +00:00
|
|
|
words_extra++;
|
2016-09-15 02:29:22 +00:00
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (attack_kern == ATTACK_KERN_COMBI)
|
|
|
|
{
|
2016-09-28 11:51:00 +00:00
|
|
|
// do not check if minimum restriction is satisfied (line_len >= hashconfig->pw_min) here
|
2016-09-15 02:29:22 +00:00
|
|
|
// since we still need to combine the plains
|
|
|
|
|
2016-09-28 11:51:00 +00:00
|
|
|
if (line_len > hashconfig->pw_max)
|
2016-09-15 02:29:22 +00:00
|
|
|
{
|
2016-10-20 19:27:42 +00:00
|
|
|
words_extra++;
|
2016-09-15 02:29:22 +00:00
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-30 16:09:29 +00:00
|
|
|
pw_add (device_param, (u8 *) line_buf, (int) line_len);
|
2016-09-15 02:29:22 +00:00
|
|
|
|
2016-09-29 21:25:29 +00:00
|
|
|
if (status_ctx->run_thread_level1 == false) break;
|
2016-09-15 02:29:22 +00:00
|
|
|
}
|
|
|
|
|
2016-11-09 01:02:11 +00:00
|
|
|
words_extra_total += words_extra;
|
|
|
|
|
2016-09-29 21:25:29 +00:00
|
|
|
if (status_ctx->run_thread_level1 == false) break;
|
2016-09-15 02:29:22 +00:00
|
|
|
}
|
|
|
|
|
2016-09-29 21:25:29 +00:00
|
|
|
if (status_ctx->run_thread_level1 == false) break;
|
2016-09-15 02:29:22 +00:00
|
|
|
|
2016-11-09 01:02:11 +00:00
|
|
|
if (words_extra_total > 0)
|
|
|
|
{
|
|
|
|
hc_thread_mutex_lock (status_ctx->mux_counter);
|
|
|
|
|
|
|
|
for (u32 salt_pos = 0; salt_pos < hashes->salts_cnt; salt_pos++)
|
|
|
|
{
|
|
|
|
status_ctx->words_progress_rejected[salt_pos] += words_extra_total * straight_ctx->kernel_rules_cnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
hc_thread_mutex_unlock (status_ctx->mux_counter);
|
|
|
|
}
|
|
|
|
|
2016-09-15 02:29:22 +00:00
|
|
|
//
|
|
|
|
// flush
|
|
|
|
//
|
|
|
|
|
2016-10-04 09:22:08 +00:00
|
|
|
const u32 pws_cnt = device_param->pws_cnt;
|
2016-09-15 02:29:22 +00:00
|
|
|
|
|
|
|
if (pws_cnt)
|
|
|
|
{
|
2016-10-15 17:44:31 +00:00
|
|
|
int CL_rc;
|
|
|
|
|
|
|
|
CL_rc = run_copy (hashcat_ctx, device_param, pws_cnt);
|
|
|
|
|
2017-02-14 13:02:18 +00:00
|
|
|
if (CL_rc == -1)
|
|
|
|
{
|
|
|
|
if (attack_mode == ATTACK_MODE_COMBI) fclose (device_param->combs_fp);
|
|
|
|
|
|
|
|
fclose (fd);
|
|
|
|
|
|
|
|
hcfree (hashcat_ctx_tmp->wl_data);
|
|
|
|
|
|
|
|
hcfree (hashcat_ctx_tmp);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
2016-09-15 02:29:22 +00:00
|
|
|
|
2016-10-15 17:44:31 +00:00
|
|
|
CL_rc = run_cracker (hashcat_ctx, device_param, pws_cnt);
|
|
|
|
|
2017-02-14 13:02:18 +00:00
|
|
|
if (CL_rc == -1)
|
|
|
|
{
|
|
|
|
if (attack_mode == ATTACK_MODE_COMBI) fclose (device_param->combs_fp);
|
|
|
|
|
|
|
|
fclose (fd);
|
|
|
|
|
|
|
|
hcfree (hashcat_ctx_tmp->wl_data);
|
|
|
|
|
|
|
|
hcfree (hashcat_ctx_tmp);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
2016-09-15 02:29:22 +00:00
|
|
|
|
|
|
|
device_param->pws_cnt = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
still required?
|
|
|
|
if (attack_kern == ATTACK_KERN_STRAIGHT)
|
|
|
|
{
|
2016-10-15 17:44:31 +00:00
|
|
|
CL_rc = run_kernel_bzero (device_param, device_param->d_rules_c, device_param->size_rules_c);
|
|
|
|
|
2017-02-14 13:02:18 +00:00
|
|
|
if (CL_rc == -1)
|
|
|
|
{
|
|
|
|
if (attack_mode == ATTACK_MODE_COMBI) fclose (device_param->combs_fp);
|
|
|
|
|
|
|
|
fclose (fd);
|
|
|
|
|
|
|
|
hcfree (hashcat_ctx_tmp->wl_data);
|
|
|
|
|
|
|
|
hcfree (hashcat_ctx_tmp);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
2016-09-15 02:29:22 +00:00
|
|
|
}
|
|
|
|
else if (attack_kern == ATTACK_KERN_COMBI)
|
|
|
|
{
|
2016-10-15 17:44:31 +00:00
|
|
|
CL_rc = run_kernel_bzero (device_param, device_param->d_combs_c, device_param->size_combs);
|
|
|
|
|
2017-02-14 13:02:18 +00:00
|
|
|
if (CL_rc == -1)
|
|
|
|
{
|
|
|
|
if (attack_mode == ATTACK_MODE_COMBI) fclose (device_param->combs_fp);
|
|
|
|
|
|
|
|
fclose (fd);
|
|
|
|
|
|
|
|
hcfree (hashcat_ctx_tmp->wl_data);
|
|
|
|
|
|
|
|
hcfree (hashcat_ctx_tmp);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
2016-09-15 02:29:22 +00:00
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2016-10-14 19:38:52 +00:00
|
|
|
if (user_options->speed_only == true) break;
|
|
|
|
|
2016-10-20 20:14:54 +00:00
|
|
|
if (status_ctx->run_thread_level2 == true)
|
|
|
|
{
|
|
|
|
device_param->words_done = words_fin;
|
2016-10-20 19:27:42 +00:00
|
|
|
|
2016-10-20 20:14:54 +00:00
|
|
|
status_ctx->words_cur = get_lowest_words_done (hashcat_ctx);
|
|
|
|
}
|
2016-10-20 19:27:42 +00:00
|
|
|
|
2016-09-29 21:25:29 +00:00
|
|
|
if (status_ctx->run_thread_level1 == false) break;
|
2016-09-15 02:29:22 +00:00
|
|
|
|
|
|
|
if (words_fin == 0) break;
|
|
|
|
}
|
|
|
|
|
2017-02-14 13:02:18 +00:00
|
|
|
if (attack_mode == ATTACK_MODE_COMBI) fclose (device_param->combs_fp);
|
|
|
|
|
|
|
|
fclose (fd);
|
2016-09-15 02:29:22 +00:00
|
|
|
|
2016-10-06 14:16:56 +00:00
|
|
|
wl_data_destroy (hashcat_ctx_tmp);
|
|
|
|
|
2016-10-10 09:03:11 +00:00
|
|
|
hcfree (hashcat_ctx_tmp->wl_data);
|
2016-10-06 14:16:56 +00:00
|
|
|
|
2016-10-10 09:03:11 +00:00
|
|
|
hcfree (hashcat_ctx_tmp);
|
2016-09-15 02:29:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
device_param->kernel_accel = 0;
|
|
|
|
device_param->kernel_loops = 0;
|
2016-10-13 08:07:04 +00:00
|
|
|
|
|
|
|
return 0;
|
2016-09-30 20:52:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void *thread_calc (void *p)
|
|
|
|
{
|
|
|
|
thread_param_t *thread_param = (thread_param_t *) p;
|
|
|
|
|
|
|
|
hashcat_ctx_t *hashcat_ctx = thread_param->hashcat_ctx;
|
|
|
|
|
|
|
|
opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx;
|
|
|
|
|
|
|
|
if (opencl_ctx->enabled == false) return NULL;
|
|
|
|
|
|
|
|
hc_device_param_t *device_param = opencl_ctx->devices_param + thread_param->tid;
|
|
|
|
|
|
|
|
if (device_param->skipped) return NULL;
|
|
|
|
|
2016-10-13 08:07:04 +00:00
|
|
|
calc (hashcat_ctx, device_param); // we should check the RC here
|
2016-09-15 02:29:22 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|