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

Added self-test funcionality for OpenCL kernels on startup

Fixed a parser error for mode -m 9820 = MS Office <= 2003 $3, SHA1 + RC4, collider #2
This commit is contained in:
Jens Steube 2017-06-13 19:07:08 +02:00
parent e87fb31d3f
commit 08fc0ec1fb
13 changed files with 1468 additions and 120 deletions

View File

@ -1,5 +1,17 @@
* changes v3.6.0 -> xxx:
##
## Features
##
- Added self-test functionality for OpenCL kernels on startup
##
## Bugs
##
- Fixed a parser error for mode -m 9820 = MS Office <= 2003 $3, SHA1 + RC4, collider #2
##
## Improvements
##

View File

@ -22,6 +22,8 @@ int hashes_init_stage2 (hashcat_ctx_t *hashcat_ctx);
int hashes_init_stage3 (hashcat_ctx_t *hashcat_ctx);
int hashes_init_stage4 (hashcat_ctx_t *hashcat_ctx);
int hashes_init_selftest (hashcat_ctx_t *hashcat_ctx);
void hashes_destroy (hashcat_ctx_t *hashcat_ctx);
void hashes_logger (hashcat_ctx_t *hashcat_ctx);

View File

@ -1890,12 +1890,13 @@ void to_hccapx_t (hashcat_ctx_t *hashcat_ctx, hccapx_t *hccapx, const u32 salt_p
int ascii_digest (hashcat_ctx_t *hashcat_ctx, char *out_buf, const size_t out_len, const u32 salt_pos, const u32 digest_pos);
int hashconfig_init (hashcat_ctx_t *hashcat_ctx);
void hashconfig_destroy (hashcat_ctx_t *hashcat_ctx);
u32 hashconfig_get_kernel_threads (hashcat_ctx_t *hashcat_ctx, const hc_device_param_t *device_param);
u32 hashconfig_get_kernel_loops (hashcat_ctx_t *hashcat_ctx);
int hashconfig_general_defaults (hashcat_ctx_t *hashcat_ctx);
void hashconfig_benchmark_defaults (hashcat_ctx_t *hashcat_ctx, salt_t *salt, void *esalt, void *hook_salt);
const char *hashconfig_benchmark_mask (hashcat_ctx_t *hashcat_ctx);
int hashconfig_init (hashcat_ctx_t *hashcat_ctx);
void hashconfig_destroy (hashcat_ctx_t *hashcat_ctx);
u32 hashconfig_forced_kernel_threads (hashcat_ctx_t *hashcat_ctx);
u32 hashconfig_get_kernel_threads (hashcat_ctx_t *hashcat_ctx, const hc_device_param_t *device_param);
u32 hashconfig_get_kernel_loops (hashcat_ctx_t *hashcat_ctx);
int hashconfig_general_defaults (hashcat_ctx_t *hashcat_ctx);
void hashconfig_benchmark_defaults (hashcat_ctx_t *hashcat_ctx, salt_t *salt, void *esalt, void *hook_salt);
const char *hashconfig_benchmark_mask (hashcat_ctx_t *hashcat_ctx);
#endif // _INTERFACE_H

11
include/selftest.h Normal file
View File

@ -0,0 +1,11 @@
/**
* Author......: See docs/credits.txt
* License.....: MIT
*/
#ifndef _SELFTEST_H
#define _SELFTEST_H
void *thread_selftest (void *p);
#endif // _SELFTEST_H

View File

@ -129,12 +129,14 @@ typedef enum event_identifier
EVENT_POTFILE_NUM_CRACKED = 0x000000b3,
EVENT_POTFILE_REMOVE_PARSE_POST = 0x000000b4,
EVENT_POTFILE_REMOVE_PARSE_PRE = 0x000000b5,
EVENT_SET_KERNEL_POWER_FINAL = 0x000000c0,
EVENT_WEAK_HASH_POST = 0x000000d0,
EVENT_WEAK_HASH_PRE = 0x000000d1,
EVENT_WEAK_HASH_ALL_CRACKED = 0x000000d2,
EVENT_WORDLIST_CACHE_GENERATE = 0x000000e0,
EVENT_WORDLIST_CACHE_HIT = 0x000000e1,
EVENT_SELFTEST_FINISHED = 0x000000c0,
EVENT_SELFTEST_STARTING = 0x000000c1,
EVENT_SET_KERNEL_POWER_FINAL = 0x000000d0,
EVENT_WEAK_HASH_POST = 0x000000e0,
EVENT_WEAK_HASH_PRE = 0x000000e1,
EVENT_WEAK_HASH_ALL_CRACKED = 0x000000e2,
EVENT_WORDLIST_CACHE_GENERATE = 0x000000f0,
EVENT_WORDLIST_CACHE_HIT = 0x000000f1,
// there will be much more event types soon
@ -168,15 +170,16 @@ typedef enum status_rc
{
STATUS_INIT = 0,
STATUS_AUTOTUNE = 1,
STATUS_RUNNING = 2,
STATUS_PAUSED = 3,
STATUS_EXHAUSTED = 4,
STATUS_CRACKED = 5,
STATUS_ABORTED = 6,
STATUS_QUIT = 7,
STATUS_BYPASS = 8,
STATUS_ABORTED_CHECKPOINT = 9,
STATUS_ABORTED_RUNTIME = 10,
STATUS_SELFTEST = 2,
STATUS_RUNNING = 3,
STATUS_PAUSED = 4,
STATUS_EXHAUSTED = 5,
STATUS_CRACKED = 6,
STATUS_ABORTED = 7,
STATUS_QUIT = 8,
STATUS_BYPASS = 9,
STATUS_ABORTED_CHECKPOINT = 10,
STATUS_ABORTED_RUNTIME = 11,
} status_rc_t;
@ -790,6 +793,12 @@ typedef struct hashes
u8 *out_buf; // allocates [HCBUFSIZ_LARGE];
u8 *tmp_buf; // allocates [HCBUFSIZ_LARGE];
// selftest buffers
void *st_digests_buf;
salt_t *st_salts_buf;
void *st_esalts_buf;
} hashes_t;
struct hashconfig
@ -819,6 +828,9 @@ struct hashconfig
u32 pw_max;
int (*parse_func) (u8 *, u32, hash_t *, const struct hashconfig *);
char *st_hash;
char *st_pass;
};
typedef struct hashconfig hashconfig_t;
@ -954,6 +966,9 @@ typedef struct hc_device_param
size_t size_shown;
size_t size_results;
size_t size_plains;
size_t size_st_digests;
size_t size_st_salts;
size_t size_st_esalts;
FILE *combs_fp;
comb_t *combs_buf;
@ -1054,7 +1069,6 @@ typedef struct hc_device_param
cl_mem d_digests_shown;
cl_mem d_salt_bufs;
cl_mem d_esalt_bufs;
cl_mem d_bcrypt_bufs;
cl_mem d_tmps;
cl_mem d_hooks;
cl_mem d_result;
@ -1064,6 +1078,9 @@ typedef struct hc_device_param
cl_mem d_scryptV3_buf;
cl_mem d_root_css_buf;
cl_mem d_markov_css_buf;
cl_mem d_st_digests_buf;
cl_mem d_st_salts_buf;
cl_mem d_st_esalts_buf;
void *kernel_params[PARAMCNT];
void *kernel_params_mp[PARAMCNT];

View File

@ -274,7 +274,7 @@ LFLAGS_CROSS_WIN64 += -lpsapi
## Objects
##
OBJS_ALL := affinity autotune benchmark bitmap bitops combinator common convert cpt cpu_aes cpu_crc32 cpu_des cpu_md4 cpu_md5 cpu_sha1 cpu_sha256 debugfile dictstat dispatch dynloader event ext_ADL ext_nvapi ext_nvml ext_OpenCL ext_sysfs ext_xnvctrl ext_lzma lzma_sdk/Alloc lzma_sdk/Lzma2Dec lzma_sdk/LzmaDec filehandling folder hashcat hashes hlfmt hwmon induct interface locking logfile loopback memory monitor mpsp opencl outfile_check outfile pidfile potfile restore rp rp_cpu rp_kernel_on_cpu shared status stdout straight terminal thread timer tuningdb usage user_options weak_hash wordlist
OBJS_ALL := affinity autotune benchmark bitmap bitops combinator common convert cpt cpu_aes cpu_crc32 cpu_des cpu_md4 cpu_md5 cpu_sha1 cpu_sha256 debugfile dictstat dispatch dynloader event ext_ADL ext_nvapi ext_nvml ext_OpenCL ext_sysfs ext_xnvctrl ext_lzma lzma_sdk/Alloc lzma_sdk/Lzma2Dec lzma_sdk/LzmaDec filehandling folder hashcat hashes hlfmt hwmon induct interface locking logfile loopback memory monitor mpsp opencl outfile_check outfile pidfile potfile restore rp rp_cpu rp_kernel_on_cpu selftest shared status stdout straight terminal thread timer tuningdb usage user_options weak_hash wordlist
NATIVE_STATIC_OBJS := $(foreach OBJ,$(OBJS_ALL),obj/$(OBJ).NATIVE.STATIC.o)
NATIVE_SHARED_OBJS := $(foreach OBJ,$(OBJS_ALL),obj/$(OBJ).NATIVE.SHARED.o)

View File

@ -8,6 +8,26 @@
#include "memory.h"
#include "bitmap.h"
static void selftest_to_bitmap (const u32 dgst_shifts, char *digests_buf_ptr, const u32 dgst_pos0, const u32 dgst_pos1, const u32 dgst_pos2, const u32 dgst_pos3, const u32 bitmap_mask, u32 *bitmap_a, u32 *bitmap_b, u32 *bitmap_c, u32 *bitmap_d)
{
u32 *digest_ptr = (u32 *) digests_buf_ptr;
const u32 val0 = 1u << (digest_ptr[dgst_pos0] & 0x1f);
const u32 val1 = 1u << (digest_ptr[dgst_pos1] & 0x1f);
const u32 val2 = 1u << (digest_ptr[dgst_pos2] & 0x1f);
const u32 val3 = 1u << (digest_ptr[dgst_pos3] & 0x1f);
const u32 idx0 = (digest_ptr[dgst_pos0] >> dgst_shifts) & bitmap_mask;
const u32 idx1 = (digest_ptr[dgst_pos1] >> dgst_shifts) & bitmap_mask;
const u32 idx2 = (digest_ptr[dgst_pos2] >> dgst_shifts) & bitmap_mask;
const u32 idx3 = (digest_ptr[dgst_pos3] >> dgst_shifts) & bitmap_mask;
bitmap_a[idx0] |= val0;
bitmap_b[idx1] |= val1;
bitmap_c[idx2] |= val2;
bitmap_d[idx3] |= val3;
}
static u32 generate_bitmaps (const u32 digests_cnt, const u32 dgst_size, const u32 dgst_shifts, char *digests_buf_ptr, const u32 dgst_pos0, const u32 dgst_pos1, const u32 dgst_pos2, const u32 dgst_pos3, const u32 bitmap_mask, const u32 bitmap_size, u32 *bitmap_a, u32 *bitmap_b, u32 *bitmap_c, u32 *bitmap_d, const u64 collisions_max)
{
u64 collisions = 0;
@ -116,6 +136,12 @@ int bitmap_ctx_init (hashcat_ctx_t *hashcat_ctx)
generate_bitmaps (hashes->digests_cnt, hashconfig->dgst_size, bitmap_shift1, (char *) hashes->digests_buf, hashconfig->dgst_pos0, hashconfig->dgst_pos1, hashconfig->dgst_pos2, hashconfig->dgst_pos3, bitmap_mask, bitmap_size, bitmap_s1_a, bitmap_s1_b, bitmap_s1_c, bitmap_s1_d, -1ul);
generate_bitmaps (hashes->digests_cnt, hashconfig->dgst_size, bitmap_shift2, (char *) hashes->digests_buf, hashconfig->dgst_pos0, hashconfig->dgst_pos1, hashconfig->dgst_pos2, hashconfig->dgst_pos3, bitmap_mask, bitmap_size, bitmap_s2_a, bitmap_s2_b, bitmap_s2_c, bitmap_s2_d, -1ul);
if (hashconfig->st_hash != NULL)
{
selftest_to_bitmap (bitmap_shift1, (char *) hashes->st_digests_buf, hashconfig->dgst_pos0, hashconfig->dgst_pos1, hashconfig->dgst_pos2, hashconfig->dgst_pos3, bitmap_mask, bitmap_s1_a, bitmap_s1_b, bitmap_s1_c, bitmap_s1_d);
selftest_to_bitmap (bitmap_shift2, (char *) hashes->st_digests_buf, hashconfig->dgst_pos0, hashconfig->dgst_pos1, hashconfig->dgst_pos2, hashconfig->dgst_pos3, bitmap_mask, bitmap_s2_a, bitmap_s2_b, bitmap_s2_c, bitmap_s2_d);
}
bitmap_ctx->bitmap_bits = bitmap_bits;
bitmap_ctx->bitmap_nums = bitmap_nums;
bitmap_ctx->bitmap_size = bitmap_size;

View File

@ -43,6 +43,7 @@
#include "potfile.h"
#include "restore.h"
#include "rp.h"
#include "selftest.h"
#include "status.h"
#include "straight.h"
#include "tuningdb.h"
@ -159,15 +160,19 @@ static int inner2_loop (hashcat_ctx_t *hashcat_ctx)
opencl_ctx_devices_kernel_loops (hashcat_ctx);
/**
* create autotune threads
* prepare thread buffers
*/
EVENT (EVENT_AUTOTUNE_STARTING);
thread_param_t *threads_param = (thread_param_t *) hccalloc (opencl_ctx->devices_cnt, sizeof (thread_param_t));
hc_thread_t *c_threads = (hc_thread_t *) hccalloc (opencl_ctx->devices_cnt, sizeof (hc_thread_t));
/**
* create autotune threads
*/
EVENT (EVENT_AUTOTUNE_STARTING);
status_ctx->devices_status = STATUS_AUTOTUNE;
for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++)
@ -529,6 +534,14 @@ static int outer_loop (hashcat_ctx_t *hashcat_ctx)
if (rc_hashes_init_stage4 == -1) return -1;
/**
* load hashes, selftest
*/
const int rc_hashes_init_selftest = hashes_init_selftest (hashcat_ctx);
if (rc_hashes_init_selftest == -1) return -1;
/**
* Done loading hashes, log results
*/
@ -645,6 +658,38 @@ static int outer_loop (hashcat_ctx_t *hashcat_ctx)
EVENT (EVENT_OPENCL_SESSION_POST);
/**
* create self-test threads
*/
EVENT (EVENT_SELFTEST_STARTING);
thread_param_t *threads_param = (thread_param_t *) hccalloc (opencl_ctx->devices_cnt, sizeof (thread_param_t));
hc_thread_t *selftest_threads = (hc_thread_t *) hccalloc (opencl_ctx->devices_cnt, sizeof (hc_thread_t));
status_ctx->devices_status = STATUS_SELFTEST;
for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++)
{
thread_param_t *thread_param = threads_param + device_id;
thread_param->hashcat_ctx = hashcat_ctx;
thread_param->tid = device_id;
hc_thread_create (selftest_threads[device_id], thread_selftest, thread_param);
}
hc_thread_wait (opencl_ctx->devices_cnt, selftest_threads);
hcfree (threads_param);
hcfree (selftest_threads);
status_ctx->devices_status = STATUS_INIT;
EVENT (EVENT_SELFTEST_FINISHED);
/**
* weak hash check is the first to write to potfile, so open it for writing from here
*/

View File

@ -1515,11 +1515,62 @@ int hashes_init_stage4 (hashcat_ctx_t *hashcat_ctx)
return 0;
}
int hashes_init_selftest (hashcat_ctx_t *hashcat_ctx)
{
hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
hashes_t *hashes = hashcat_ctx->hashes;
if (hashconfig->st_hash == NULL) return 0;
void *st_digests_buf = NULL;
salt_t *st_salts_buf = NULL;
void *st_esalts_buf = NULL;
st_digests_buf = (void *) hccalloc (1, hashconfig->dgst_size);
st_salts_buf = (salt_t *) hccalloc (1, sizeof (salt_t));
if (hashconfig->esalt_size)
{
st_esalts_buf = (void *) hccalloc (1, hashconfig->esalt_size);
}
hash_t hash;
hash.digest = st_digests_buf;
hash.salt = st_salts_buf;
hash.esalt = st_esalts_buf;
hash.hook_salt = NULL;
hash.cracked = 0;
hash.hash_info = NULL;
hash.pw_buf = NULL;
hash.pw_len = 0;
const int parser_status = hashconfig->parse_func ((u8 *) hashconfig->st_hash, strlen (hashconfig->st_hash), &hash, hashconfig);
if (parser_status == PARSER_OK)
{
// nothing to do
}
else
{
event_log_error (hashcat_ctx, "Self-test Hash '%s': %s", hashconfig->st_hash, strparser (parser_status));
return -1;
}
hashes->st_digests_buf = st_digests_buf;
hashes->st_salts_buf = st_salts_buf;
hashes->st_esalts_buf = st_esalts_buf;
return 0;
}
void hashes_destroy (hashcat_ctx_t *hashcat_ctx)
{
hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
hashes_t *hashes = hashcat_ctx->hashes;
user_options_t *user_options = hashcat_ctx->user_options;
hashes_t *hashes = hashcat_ctx->hashes;
hcfree (hashes->digests_buf);
hcfree (hashes->digests_shown);
@ -1557,6 +1608,10 @@ void hashes_destroy (hashcat_ctx_t *hashcat_ctx)
hcfree (hashes->out_buf);
hcfree (hashes->tmp_buf);
hcfree (hashes->st_digests_buf);
hcfree (hashes->st_salts_buf);
hcfree (hashes->st_esalts_buf);
memset (hashes, 0, sizeof (hashes_t));
}

File diff suppressed because it is too large Load Diff

View File

@ -1371,17 +1371,19 @@ int run_kernel (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, con
int CL_rc;
CL_rc = hc_clSetKernelArg (hashcat_ctx, kernel, 24, sizeof (cl_uint), device_param->kernel_params[24]); if (CL_rc == -1) return -1;
CL_rc = hc_clSetKernelArg (hashcat_ctx, kernel, 25, sizeof (cl_uint), device_param->kernel_params[25]); if (CL_rc == -1) return -1;
CL_rc = hc_clSetKernelArg (hashcat_ctx, kernel, 26, sizeof (cl_uint), device_param->kernel_params[26]); if (CL_rc == -1) return -1;
CL_rc = hc_clSetKernelArg (hashcat_ctx, kernel, 27, sizeof (cl_uint), device_param->kernel_params[27]); if (CL_rc == -1) return -1;
CL_rc = hc_clSetKernelArg (hashcat_ctx, kernel, 28, sizeof (cl_uint), device_param->kernel_params[28]); if (CL_rc == -1) return -1;
CL_rc = hc_clSetKernelArg (hashcat_ctx, kernel, 29, sizeof (cl_uint), device_param->kernel_params[29]); if (CL_rc == -1) return -1;
CL_rc = hc_clSetKernelArg (hashcat_ctx, kernel, 30, sizeof (cl_uint), device_param->kernel_params[30]); if (CL_rc == -1) return -1;
CL_rc = hc_clSetKernelArg (hashcat_ctx, kernel, 31, sizeof (cl_uint), device_param->kernel_params[31]); if (CL_rc == -1) return -1;
CL_rc = hc_clSetKernelArg (hashcat_ctx, kernel, 32, sizeof (cl_uint), device_param->kernel_params[32]); if (CL_rc == -1) return -1;
CL_rc = hc_clSetKernelArg (hashcat_ctx, kernel, 33, sizeof (cl_uint), device_param->kernel_params[33]); if (CL_rc == -1) return -1;
CL_rc = hc_clSetKernelArg (hashcat_ctx, kernel, 34, sizeof (cl_uint), device_param->kernel_params[34]); if (CL_rc == -1) return -1;
for (u32 i = 0; i <= 23; i++)
{
CL_rc = hc_clSetKernelArg (hashcat_ctx, kernel, i, sizeof (cl_mem), device_param->kernel_params[i]);
if (CL_rc == -1) return -1;
}
for (u32 i = 24; i <= 34; i++)
{
CL_rc = hc_clSetKernelArg (hashcat_ctx, kernel, i, sizeof (cl_uint), device_param->kernel_params[i]);
if (CL_rc == -1) return -1;
}
cl_event event;
@ -3653,6 +3655,14 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx)
size_t size_bfs = KERNEL_BFS * sizeof (bf_t);
size_t size_tm = 32 * sizeof (bs_word_t);
size_t size_st_digests = 1 * hashconfig->dgst_size;
size_t size_st_salts = 1 * sizeof (salt_t);
size_t size_st_esalts = 1 * hashconfig->esalt_size;
device_param->size_st_digests = size_st_digests;
device_param->size_st_salts = size_st_salts;
device_param->size_st_esalts = size_st_esalts;
// scryptV stuff
u32 scrypt_tmp_size = 0;
@ -3760,7 +3770,10 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx)
+ size_salts
+ size_shown
+ size_tm
+ size_tmps;
+ size_tmps
+ size_st_digests
+ size_st_salts
+ size_st_esalts;
bool not_enough_memory = true;
@ -3891,7 +3904,10 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx)
+ size_scrypt4
+ size_shown
+ size_tm
+ size_tmps;
+ size_tmps
+ size_st_digests
+ size_st_salts
+ size_st_esalts;
if (size_total > device_param->device_global_mem) memory_limit_hit = 1;
@ -4526,18 +4542,19 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx)
CL_rc = hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_WRITE, size_scrypt4, NULL, &device_param->d_scryptV1_buf); if (CL_rc == -1) return -1;
CL_rc = hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_WRITE, size_scrypt4, NULL, &device_param->d_scryptV2_buf); if (CL_rc == -1) return -1;
CL_rc = hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_WRITE, size_scrypt4, NULL, &device_param->d_scryptV3_buf); if (CL_rc == -1) return -1;
CL_rc = hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, size_st_digests, NULL, &device_param->d_st_digests_buf); if (CL_rc == -1) return -1;
CL_rc = hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, size_st_salts, NULL, &device_param->d_st_salts_buf); if (CL_rc == -1) return -1;
CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_bitmap_s1_a, CL_TRUE, 0, bitmap_ctx->bitmap_size, bitmap_ctx->bitmap_s1_a, 0, NULL, NULL); if (CL_rc == -1) return -1;
CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_bitmap_s1_b, CL_TRUE, 0, bitmap_ctx->bitmap_size, bitmap_ctx->bitmap_s1_b, 0, NULL, NULL); if (CL_rc == -1) return -1;
CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_bitmap_s1_c, CL_TRUE, 0, bitmap_ctx->bitmap_size, bitmap_ctx->bitmap_s1_c, 0, NULL, NULL); if (CL_rc == -1) return -1;
CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_bitmap_s1_d, CL_TRUE, 0, bitmap_ctx->bitmap_size, bitmap_ctx->bitmap_s1_d, 0, NULL, NULL); if (CL_rc == -1) return -1;
CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_bitmap_s2_a, CL_TRUE, 0, bitmap_ctx->bitmap_size, bitmap_ctx->bitmap_s2_a, 0, NULL, NULL); if (CL_rc == -1) return -1;
CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_bitmap_s2_b, CL_TRUE, 0, bitmap_ctx->bitmap_size, bitmap_ctx->bitmap_s2_b, 0, NULL, NULL); if (CL_rc == -1) return -1;
CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_bitmap_s2_c, CL_TRUE, 0, bitmap_ctx->bitmap_size, bitmap_ctx->bitmap_s2_c, 0, NULL, NULL); if (CL_rc == -1) return -1;
CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_bitmap_s2_d, CL_TRUE, 0, bitmap_ctx->bitmap_size, bitmap_ctx->bitmap_s2_d, 0, NULL, NULL); if (CL_rc == -1) return -1;
CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_digests_buf, CL_TRUE, 0, size_digests, hashes->digests_buf, 0, NULL, NULL); if (CL_rc == -1) return -1;
CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_digests_shown, CL_TRUE, 0, size_shown, hashes->digests_shown, 0, NULL, NULL); if (CL_rc == -1) return -1;
CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_salt_bufs, CL_TRUE, 0, size_salts, hashes->salts_buf, 0, NULL, NULL); if (CL_rc == -1) return -1;
CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_bitmap_s1_a, CL_TRUE, 0, bitmap_ctx->bitmap_size, bitmap_ctx->bitmap_s1_a, 0, NULL, NULL); if (CL_rc == -1) return -1;
CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_bitmap_s1_b, CL_TRUE, 0, bitmap_ctx->bitmap_size, bitmap_ctx->bitmap_s1_b, 0, NULL, NULL); if (CL_rc == -1) return -1;
CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_bitmap_s1_c, CL_TRUE, 0, bitmap_ctx->bitmap_size, bitmap_ctx->bitmap_s1_c, 0, NULL, NULL); if (CL_rc == -1) return -1;
CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_bitmap_s1_d, CL_TRUE, 0, bitmap_ctx->bitmap_size, bitmap_ctx->bitmap_s1_d, 0, NULL, NULL); if (CL_rc == -1) return -1;
CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_bitmap_s2_a, CL_TRUE, 0, bitmap_ctx->bitmap_size, bitmap_ctx->bitmap_s2_a, 0, NULL, NULL); if (CL_rc == -1) return -1;
CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_bitmap_s2_b, CL_TRUE, 0, bitmap_ctx->bitmap_size, bitmap_ctx->bitmap_s2_b, 0, NULL, NULL); if (CL_rc == -1) return -1;
CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_bitmap_s2_c, CL_TRUE, 0, bitmap_ctx->bitmap_size, bitmap_ctx->bitmap_s2_c, 0, NULL, NULL); if (CL_rc == -1) return -1;
CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_bitmap_s2_d, CL_TRUE, 0, bitmap_ctx->bitmap_size, bitmap_ctx->bitmap_s2_d, 0, NULL, NULL); if (CL_rc == -1) return -1;
CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_digests_buf, CL_TRUE, 0, size_digests, hashes->digests_buf, 0, NULL, NULL); if (CL_rc == -1) return -1;
CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_salt_bufs, CL_TRUE, 0, size_salts, hashes->salts_buf, 0, NULL, NULL); if (CL_rc == -1) return -1;
/**
* special buffers
@ -4577,6 +4594,23 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx)
if (CL_rc == -1) return -1;
}
if (hashconfig->st_hash != NULL)
{
CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_st_digests_buf, CL_TRUE, 0, size_st_digests, hashes->st_digests_buf, 0, NULL, NULL); if (CL_rc == -1) return -1;
CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_st_salts_buf, CL_TRUE, 0, size_st_salts, hashes->st_salts_buf, 0, NULL, NULL); if (CL_rc == -1) return -1;
if (size_esalts)
{
CL_rc = hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, size_st_esalts, NULL, &device_param->d_st_esalts_buf);
if (CL_rc == -1) return -1;
CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_st_esalts_buf, CL_TRUE, 0, size_st_esalts, hashes->st_esalts_buf, 0, NULL, NULL);
if (CL_rc == -1) return -1;
}
}
/**
* main host data
*/
@ -4891,30 +4925,6 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx)
if (CL_rc == -1) return -1;
for (u32 i = 0; i <= 23; i++)
{
CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel1, i, sizeof (cl_mem), device_param->kernel_params[i]); if (CL_rc == -1) return -1;
CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel2, i, sizeof (cl_mem), device_param->kernel_params[i]); if (CL_rc == -1) return -1;
CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel3, i, sizeof (cl_mem), device_param->kernel_params[i]); if (CL_rc == -1) return -1;
if (hashconfig->opts_type & OPTS_TYPE_HOOK12) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel12, i, sizeof (cl_mem), device_param->kernel_params[i]); if (CL_rc == -1) return -1; }
if (hashconfig->opts_type & OPTS_TYPE_HOOK23) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel23, i, sizeof (cl_mem), device_param->kernel_params[i]); if (CL_rc == -1) return -1; }
if (hashconfig->opts_type & OPTS_TYPE_INIT2) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel_init2, i, sizeof (cl_mem), device_param->kernel_params[i]); if (CL_rc == -1) return -1; }
if (hashconfig->opts_type & OPTS_TYPE_LOOP2) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel_loop2, i, sizeof (cl_mem), device_param->kernel_params[i]); if (CL_rc == -1) return -1; }
}
for (u32 i = 24; i <= 34; i++)
{
CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel1, i, sizeof (cl_uint), device_param->kernel_params[i]); if (CL_rc == -1) return -1;
CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel2, i, sizeof (cl_uint), device_param->kernel_params[i]); if (CL_rc == -1) return -1;
CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel3, i, sizeof (cl_uint), device_param->kernel_params[i]); if (CL_rc == -1) return -1;
if (hashconfig->opts_type & OPTS_TYPE_HOOK12) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel12, i, sizeof (cl_uint), device_param->kernel_params[i]); if (CL_rc == -1) return -1; }
if (hashconfig->opts_type & OPTS_TYPE_HOOK23) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel23, i, sizeof (cl_uint), device_param->kernel_params[i]); if (CL_rc == -1) return -1; }
if (hashconfig->opts_type & OPTS_TYPE_INIT2) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel_init2, i, sizeof (cl_uint), device_param->kernel_params[i]); if (CL_rc == -1) return -1; }
if (hashconfig->opts_type & OPTS_TYPE_LOOP2) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel_loop2, i, sizeof (cl_uint), device_param->kernel_params[i]); if (CL_rc == -1) return -1; }
}
// GPU memset
CL_rc = hc_clCreateKernel (hashcat_ctx, device_param->program, "gpu_memset", &device_param->kernel_memset);
@ -5018,12 +5028,13 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx)
// zero some data buffers
CL_rc = run_kernel_bzero (hashcat_ctx, device_param, device_param->d_pws_buf, size_pws); if (CL_rc == -1) return -1;
CL_rc = run_kernel_bzero (hashcat_ctx, device_param, device_param->d_pws_amp_buf, size_pws); if (CL_rc == -1) return -1;
CL_rc = run_kernel_bzero (hashcat_ctx, device_param, device_param->d_tmps, size_tmps); if (CL_rc == -1) return -1;
CL_rc = run_kernel_bzero (hashcat_ctx, device_param, device_param->d_hooks, size_hooks); if (CL_rc == -1) return -1;
CL_rc = run_kernel_bzero (hashcat_ctx, device_param, device_param->d_plain_bufs, size_plains); if (CL_rc == -1) return -1;
CL_rc = run_kernel_bzero (hashcat_ctx, device_param, device_param->d_result, size_results); if (CL_rc == -1) return -1;
CL_rc = run_kernel_bzero (hashcat_ctx, device_param, device_param->d_pws_buf, device_param->size_pws); if (CL_rc == -1) return -1;
CL_rc = run_kernel_bzero (hashcat_ctx, device_param, device_param->d_pws_amp_buf, device_param->size_pws); if (CL_rc == -1) return -1;
CL_rc = run_kernel_bzero (hashcat_ctx, device_param, device_param->d_tmps, device_param->size_tmps); if (CL_rc == -1) return -1;
CL_rc = run_kernel_bzero (hashcat_ctx, device_param, device_param->d_hooks, device_param->size_hooks); if (CL_rc == -1) return -1;
CL_rc = run_kernel_bzero (hashcat_ctx, device_param, device_param->d_plain_bufs, device_param->size_plains); if (CL_rc == -1) return -1;
CL_rc = run_kernel_bzero (hashcat_ctx, device_param, device_param->d_digests_shown, device_param->size_shown); if (CL_rc == -1) return -1;
CL_rc = run_kernel_bzero (hashcat_ctx, device_param, device_param->d_result, device_param->size_results); if (CL_rc == -1) return -1;
/**
* special buffers
@ -5171,6 +5182,9 @@ void opencl_session_destroy (hashcat_ctx_t *hashcat_ctx)
if (device_param->d_root_css_buf) hc_clReleaseMemObject (hashcat_ctx, device_param->d_root_css_buf);
if (device_param->d_markov_css_buf) hc_clReleaseMemObject (hashcat_ctx, device_param->d_markov_css_buf);
if (device_param->d_tm_c) hc_clReleaseMemObject (hashcat_ctx, device_param->d_tm_c);
if (device_param->d_st_digests_buf) hc_clReleaseMemObject (hashcat_ctx, device_param->d_st_digests_buf);
if (device_param->d_st_salts_buf) hc_clReleaseMemObject (hashcat_ctx, device_param->d_st_salts_buf);
if (device_param->d_st_esalts_buf) hc_clReleaseMemObject (hashcat_ctx, device_param->d_st_esalts_buf);
if (device_param->kernel1) hc_clReleaseKernel (hashcat_ctx, device_param->kernel1);
if (device_param->kernel12) hc_clReleaseKernel (hashcat_ctx, device_param->kernel12);
@ -5229,6 +5243,9 @@ void opencl_session_destroy (hashcat_ctx_t *hashcat_ctx)
device_param->d_root_css_buf = NULL;
device_param->d_markov_css_buf = NULL;
device_param->d_tm_c = NULL;
device_param->d_st_digests_buf = NULL;
device_param->d_st_salts_buf = NULL;
device_param->d_st_esalts_buf = NULL;
device_param->kernel1 = NULL;
device_param->kernel12 = NULL;
device_param->kernel2 = NULL;
@ -5293,7 +5310,7 @@ void opencl_session_reset (hashcat_ctx_t *hashcat_ctx)
int opencl_session_update_combinator (hashcat_ctx_t *hashcat_ctx)
{
combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx;
hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
//hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx;
if (opencl_ctx->enabled == false) return 0;
@ -5308,6 +5325,7 @@ int opencl_session_update_combinator (hashcat_ctx_t *hashcat_ctx)
device_param->kernel_params_buf32[33] = combinator_ctx->combs_mode;
/*
int CL_rc;
CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel1, 33, sizeof (cl_uint), device_param->kernel_params[33]); if (CL_rc == -1) return -1;
@ -5318,17 +5336,20 @@ int opencl_session_update_combinator (hashcat_ctx_t *hashcat_ctx)
if (hashconfig->opts_type & OPTS_TYPE_HOOK23) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel23, 33, sizeof (cl_uint), device_param->kernel_params[33]); if (CL_rc == -1) return -1; }
if (hashconfig->opts_type & OPTS_TYPE_INIT2) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel_init2, 33, sizeof (cl_uint), device_param->kernel_params[33]); if (CL_rc == -1) return -1; }
if (hashconfig->opts_type & OPTS_TYPE_LOOP2) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel_loop2, 33, sizeof (cl_uint), device_param->kernel_params[33]); if (CL_rc == -1) return -1; }
*/
// kernel_params_amp
device_param->kernel_params_amp_buf32[5] = combinator_ctx->combs_mode;
/*
if (hashconfig->attack_exec == ATTACK_EXEC_OUTSIDE_KERNEL)
{
CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel_amp, 5, sizeof (cl_uint), device_param->kernel_params_amp[5]);
if (CL_rc == -1) return -1;
}
*/
}
return 0;

454
src/selftest.c Normal file
View File

@ -0,0 +1,454 @@
/**
* Author......: See docs/credits.txt
* License.....: MIT
*/
#include "common.h"
#include "types.h"
#include "event.h"
#include "bitops.h"
#include "convert.h"
#include "opencl.h"
#include "interface.h"
#include "thread.h"
#include "selftest.h"
static int selftest (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param)
{
hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
hashes_t *hashes = hashcat_ctx->hashes;
status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra;
cl_int CL_err;
int CL_rc;
if (hashconfig->st_hash == NULL) return 0;
// init : replace hashes with selftest hash
device_param->kernel_params[15] = &device_param->d_st_digests_buf;
device_param->kernel_params[17] = &device_param->d_st_salts_buf;
device_param->kernel_params[18] = &device_param->d_st_esalts_buf;
device_param->kernel_params_buf32[31] = 1;
device_param->kernel_params_buf32[32] = 0;
const u32 kernel_threads_by_wgs_kernel1_sav = device_param->kernel_threads_by_wgs_kernel1;
const u32 kernel_threads_by_wgs_kernel12_sav = device_param->kernel_threads_by_wgs_kernel12;
const u32 kernel_threads_by_wgs_kernel2_sav = device_param->kernel_threads_by_wgs_kernel2;
const u32 kernel_threads_by_wgs_kernel23_sav = device_param->kernel_threads_by_wgs_kernel23;
const u32 kernel_threads_by_wgs_kernel3_sav = device_param->kernel_threads_by_wgs_kernel3;
const u32 kernel_threads_by_wgs_kernel_init2_sav = device_param->kernel_threads_by_wgs_kernel_init2;
const u32 kernel_threads_by_wgs_kernel_loop2_sav = device_param->kernel_threads_by_wgs_kernel_loop2;
if (hashconfig_forced_kernel_threads (hashcat_ctx) == 0)
{
device_param->kernel_threads_by_wgs_kernel1 = 1;
device_param->kernel_threads_by_wgs_kernel12 = 1;
device_param->kernel_threads_by_wgs_kernel2 = 1;
device_param->kernel_threads_by_wgs_kernel23 = 1;
device_param->kernel_threads_by_wgs_kernel3 = 1;
device_param->kernel_threads_by_wgs_kernel_init2 = 1;
device_param->kernel_threads_by_wgs_kernel_loop2 = 1;
}
// password : move the known password into a fake buffer
u32 highest_pw_len = 0;
if (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL)
{
if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT)
{
device_param->kernel_params_buf32[30] = 1;
pw_t pw; memset (&pw, 0, sizeof (pw));
char *pw_ptr = (char *) &pw.i;
int pw_len = strlen (hashconfig->st_pass);
memcpy (pw_ptr, hashconfig->st_pass, pw_len);
pw.pw_len = pw_len;
CL_err = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_pws_buf, CL_TRUE, 0, 1 * sizeof (pw_t), &pw, 0, NULL, NULL);
if (CL_err != CL_SUCCESS) return -1;
}
else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI)
{
device_param->kernel_params_buf32[30] = 1;
device_param->kernel_params_buf32[33] = COMBINATOR_MODE_BASE_LEFT;
pw_t pw; memset (&pw, 0, sizeof (pw));
char *pw_ptr = (char *) &pw.i;
int pw_len = strlen (hashconfig->st_pass);
memcpy (pw_ptr, hashconfig->st_pass, pw_len - 1);
pw.pw_len = pw_len - 1;
comb_t comb; memset (&comb, 0, sizeof (comb));
char *comb_ptr = (char *) &comb.i;
memcpy (comb_ptr, hashconfig->st_pass + pw_len - 1, 1);
comb.pw_len = 1;
if (hashconfig->opts_type & OPTS_TYPE_PT_ADD01)
{
comb_ptr[comb.pw_len] = 0x01;
}
if (hashconfig->opts_type & OPTS_TYPE_PT_ADD80)
{
comb_ptr[comb.pw_len] = 0x80;
}
CL_err = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_combs_c, CL_TRUE, 0, 1 * sizeof (comb_t), &comb, 0, NULL, NULL);
if (CL_err != CL_SUCCESS) return -1;
CL_err = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_pws_buf, CL_TRUE, 0, 1 * sizeof (pw_t), &pw, 0, NULL, NULL);
if (CL_err != CL_SUCCESS) return -1;
}
else if (user_options_extra->attack_kern == ATTACK_KERN_BF)
{
device_param->kernel_params_buf32[30] = 1;
if (hashconfig->opts_type & OPTS_TYPE_PT_BITSLICE)
{
pw_t pw; memset (&pw, 0, sizeof (pw));
char *pw_ptr = (char *) &pw.i;
int pw_len = strlen (hashconfig->st_pass);
memcpy (pw_ptr, hashconfig->st_pass, pw_len);
if (hashconfig->opts_type & OPTS_TYPE_PT_UPPER)
{
uppercase ((u8 *) pw_ptr, pw_len);
}
pw.pw_len = pw_len;
CL_err = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_pws_buf, CL_TRUE, 0, 1 * sizeof (pw_t), &pw, 0, NULL, NULL);
if (CL_err != CL_SUCCESS) return -1;
}
else
{
bf_t bf; memset (&bf, 0, sizeof (bf));
char *bf_ptr = (char *) &bf.i;
memcpy (bf_ptr, hashconfig->st_pass, 1);
if (hashconfig->opts_type & OPTS_TYPE_PT_UTF16LE)
{
memset (bf_ptr, 0, 4);
for (int i = 0, j = 0; i < 1; i += 1, j += 2)
{
bf_ptr[j + 0] = hashconfig->st_pass[i];
bf_ptr[j + 1] = 0;
}
}
else if (hashconfig->opts_type & OPTS_TYPE_PT_UTF16BE)
{
memset (bf_ptr, 0, 4);
for (int i = 0, j = 0; i < 1; i += 1, j += 2)
{
bf_ptr[j + 0] = 0;
bf_ptr[j + 1] = hashconfig->st_pass[i];
}
}
if (hashconfig->opts_type & OPTS_TYPE_PT_UPPER)
{
uppercase ((u8 *) bf_ptr, 4);
}
if (hashconfig->opts_type & OPTS_TYPE_PT_GENERATE_BE)
{
bf.i = byte_swap_32 (bf.i);
}
CL_err = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_bfs_c, CL_TRUE, 0, 1 * sizeof (bf_t), &bf, 0, NULL, NULL);
if (CL_err != CL_SUCCESS) return -1;
pw_t pw; memset (&pw, 0, sizeof (pw));
char *pw_ptr = (char *) &pw.i;
int pw_len = strlen (hashconfig->st_pass);
memcpy (pw_ptr + 1, hashconfig->st_pass + 1, pw_len - 1);
int new_pass_len = pw_len;
if (hashconfig->opts_type & OPTS_TYPE_PT_UTF16LE)
{
memset (pw_ptr, 0, pw_len);
for (int i = 1, j = 2; i < new_pass_len; i += 1, j += 2)
{
pw_ptr[j + 0] = hashconfig->st_pass[i];
pw_ptr[j + 1] = 0;
}
new_pass_len *= 2;
}
else if (hashconfig->opts_type & OPTS_TYPE_PT_UTF16BE)
{
memset (pw_ptr, 0, pw_len);
for (int i = 1, j = 2; i < new_pass_len; i += 1, j += 2)
{
pw_ptr[j + 0] = 0;
pw_ptr[j + 1] = hashconfig->st_pass[i];
}
new_pass_len *= 2;
}
if (hashconfig->opts_type & OPTS_TYPE_PT_UPPER)
{
uppercase ((u8 *) pw_ptr, new_pass_len);
}
if (hashconfig->opti_type & OPTI_TYPE_SINGLE_HASH)
{
if (hashconfig->opti_type & OPTI_TYPE_APPENDED_SALT)
{
memcpy (pw_ptr + new_pass_len, (char *) hashes->st_salts_buf[0].salt_buf, 64 - new_pass_len);
new_pass_len += hashes->st_salts_buf[0].salt_len;
}
}
pw.pw_len = new_pass_len;
if (hashconfig->opts_type & OPTS_TYPE_PT_ADD01)
{
pw_ptr[new_pass_len] = 0x01;
}
if (hashconfig->opts_type & OPTS_TYPE_PT_ADD80)
{
pw_ptr[new_pass_len] = 0x80;
}
if (hashconfig->opts_type & OPTS_TYPE_PT_ADDBITS14)
{
pw.i[14] = new_pass_len * 8;
pw.i[15] = 0;
}
if (hashconfig->opts_type & OPTS_TYPE_PT_ADDBITS15)
{
pw.i[14] = 0;
pw.i[15] = new_pass_len * 8;
}
if (hashconfig->opts_type & OPTS_TYPE_PT_GENERATE_BE)
{
for (int i = 0; i < 14; i++) pw.i[i] = byte_swap_32 (pw.i[i]);
}
CL_err = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_pws_buf, CL_TRUE, 0, 1 * sizeof (pw_t), &pw, 0, NULL, NULL);
if (CL_err != CL_SUCCESS) return -1;
highest_pw_len = pw.pw_len;
}
}
}
else
{
pw_t pw; memset (&pw, 0, sizeof (pw));
char *pw_ptr = (char *) &pw.i;
int pw_len = strlen (hashconfig->st_pass);
memcpy (pw_ptr, hashconfig->st_pass, pw_len);
pw.pw_len = pw_len;
CL_err = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_pws_amp_buf, CL_TRUE, 0, 1 * sizeof (pw_t), &pw, 0, NULL, NULL);
if (CL_err != CL_SUCCESS) return -1;
}
// main : run the kernel
if (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL)
{
if (highest_pw_len < 16)
{
CL_rc = run_kernel (hashcat_ctx, device_param, KERN_RUN_1, 1, false, 0);
if (CL_rc == -1) return -1;
}
else if (highest_pw_len < 32)
{
CL_rc = run_kernel (hashcat_ctx, device_param, KERN_RUN_2, 1, false, 0);
if (CL_rc == -1) return -1;
}
else
{
CL_rc = run_kernel (hashcat_ctx, device_param, KERN_RUN_3, 1, false, 0);
if (CL_rc == -1) return -1;
}
}
else
{
// missing handling hooks
CL_rc = run_kernel (hashcat_ctx, device_param, KERN_RUN_1, 1, false, 0);
if (CL_rc == -1) return -1;
const u32 salt_pos = 0;
salt_t *salt_buf = &hashes->st_salts_buf[salt_pos];
const u32 kernel_loops_fixed = hashconfig_get_kernel_loops (hashcat_ctx);
const u32 loop_step = (kernel_loops_fixed) ? kernel_loops_fixed : 1;
const u32 iter = salt_buf->salt_iter;
for (u32 loop_pos = 0; loop_pos < iter; loop_pos += loop_step)
{
u32 loop_left = iter - loop_pos;
loop_left = MIN (loop_left, loop_step);
device_param->kernel_params_buf32[28] = loop_pos;
device_param->kernel_params_buf32[29] = loop_left;
CL_rc = run_kernel (hashcat_ctx, device_param, KERN_RUN_2, 1, false, 0);
if (CL_rc == -1) return -1;
}
CL_rc = run_kernel (hashcat_ctx, device_param, KERN_RUN_3, 1, false, 0);
if (CL_rc == -1) return -1;
}
// check : check if cracked
u32 num_cracked;
CL_err = hc_clEnqueueReadBuffer (hashcat_ctx, device_param->command_queue, device_param->d_result, CL_TRUE, 0, sizeof (u32), &num_cracked, 0, NULL, NULL);
if (CL_err != CL_SUCCESS) return -1;
// finish : cleanup and restore
device_param->kernel_threads_by_wgs_kernel1 = kernel_threads_by_wgs_kernel1_sav;
device_param->kernel_threads_by_wgs_kernel12 = kernel_threads_by_wgs_kernel12_sav;
device_param->kernel_threads_by_wgs_kernel2 = kernel_threads_by_wgs_kernel2_sav;
device_param->kernel_threads_by_wgs_kernel23 = kernel_threads_by_wgs_kernel23_sav;
device_param->kernel_threads_by_wgs_kernel3 = kernel_threads_by_wgs_kernel3_sav;
device_param->kernel_threads_by_wgs_kernel_init2 = kernel_threads_by_wgs_kernel_init2_sav;
device_param->kernel_threads_by_wgs_kernel_loop2 = kernel_threads_by_wgs_kernel_loop2_sav;
device_param->kernel_params_buf32[27] = 0;
device_param->kernel_params_buf32[28] = 0;
device_param->kernel_params_buf32[29] = 0;
device_param->kernel_params_buf32[30] = 0;
device_param->kernel_params_buf32[31] = 0;
device_param->kernel_params_buf32[32] = 0;
device_param->kernel_params_buf32[33] = 0;
device_param->kernel_params_buf32[34] = 0;
device_param->kernel_params[15] = &device_param->d_digests_buf;
device_param->kernel_params[17] = &device_param->d_salt_bufs;
device_param->kernel_params[18] = &device_param->d_esalt_bufs;
CL_rc = run_kernel_bzero (hashcat_ctx, device_param, device_param->d_pws_buf, device_param->size_pws); if (CL_rc == -1) return -1;
CL_rc = run_kernel_bzero (hashcat_ctx, device_param, device_param->d_pws_amp_buf, device_param->size_pws); if (CL_rc == -1) return -1;
CL_rc = run_kernel_bzero (hashcat_ctx, device_param, device_param->d_tmps, device_param->size_tmps); if (CL_rc == -1) return -1;
CL_rc = run_kernel_bzero (hashcat_ctx, device_param, device_param->d_hooks, device_param->size_hooks); if (CL_rc == -1) return -1;
CL_rc = run_kernel_bzero (hashcat_ctx, device_param, device_param->d_plain_bufs, device_param->size_plains); if (CL_rc == -1) return -1;
CL_rc = run_kernel_bzero (hashcat_ctx, device_param, device_param->d_digests_shown, device_param->size_shown); if (CL_rc == -1) return -1;
CL_rc = run_kernel_bzero (hashcat_ctx, device_param, device_param->d_result, device_param->size_results); if (CL_rc == -1) return -1;
if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT)
{
CL_rc = run_kernel_bzero (hashcat_ctx, device_param, device_param->d_rules_c, device_param->size_rules_c);
if (CL_rc == -1) return -1;
}
else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI)
{
CL_rc = run_kernel_bzero (hashcat_ctx, device_param, device_param->d_combs_c, device_param->size_combs);
if (CL_rc == -1) return -1;
}
else if (user_options_extra->attack_kern == ATTACK_KERN_BF)
{
CL_rc = run_kernel_bzero (hashcat_ctx, device_param, device_param->d_bfs_c, device_param->size_bfs);
if (CL_rc == -1) return -1;
}
// check return
if (num_cracked == 0)
{
hc_thread_mutex_lock (status_ctx->mux_display);
event_log_error (hashcat_ctx, "* Device #%u: ATTENTION! OpenCL kernel self-test failed.", device_param->device_id + 1);
event_log_warning (hashcat_ctx, "Your device driver installation is probably broken.");
event_log_warning (hashcat_ctx, "See also: https://hashcat.net/faq/wrongdriver");
event_log_warning (hashcat_ctx, NULL);
hc_thread_mutex_unlock (status_ctx->mux_display);
return -1;
}
return 0;
}
void *thread_selftest (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 == true) return NULL;
const int rc_selftest = selftest (hashcat_ctx, device_param);
if (rc_selftest == -1)
{
// we should do something here, tell hashcat main that autotune failed to abort
}
return NULL;
}

View File

@ -21,16 +21,17 @@
static const char ST_0000[] = "Initializing";
static const char ST_0001[] = "Autotuning";
static const char ST_0002[] = "Running";
static const char ST_0003[] = "Paused";
static const char ST_0004[] = "Exhausted";
static const char ST_0005[] = "Cracked";
static const char ST_0006[] = "Aborted";
static const char ST_0007[] = "Quit";
static const char ST_0008[] = "Bypass";
static const char ST_0009[] = "Aborted (Checkpoint)";
static const char ST_0010[] = "Aborted (Runtime)";
static const char ST_0011[] = "Running (Checkpoint Quit requested)";
static const char ST_0002[] = "Selftest";
static const char ST_0003[] = "Running";
static const char ST_0004[] = "Paused";
static const char ST_0005[] = "Exhausted";
static const char ST_0006[] = "Cracked";
static const char ST_0007[] = "Aborted";
static const char ST_0008[] = "Quit";
static const char ST_0009[] = "Bypass";
static const char ST_0010[] = "Aborted (Checkpoint)";
static const char ST_0011[] = "Aborted (Runtime)";
static const char ST_0012[] = "Running (Checkpoint Quit requested)";
static const char ST_9999[] = "Unknown! Bug!";
static const char UNITS[7] = { ' ', 'k', 'M', 'G', 'T', 'P', 'E' };
@ -204,7 +205,7 @@ char *status_get_status_string (const hashcat_ctx_t *hashcat_ctx)
{
if (status_ctx->checkpoint_shutdown == true)
{
return ((char *) ST_0011);
return ((char *) ST_0012);
}
}
@ -212,15 +213,16 @@ char *status_get_status_string (const hashcat_ctx_t *hashcat_ctx)
{
case STATUS_INIT: return ((char *) ST_0000);
case STATUS_AUTOTUNE: return ((char *) ST_0001);
case STATUS_RUNNING: return ((char *) ST_0002);
case STATUS_PAUSED: return ((char *) ST_0003);
case STATUS_EXHAUSTED: return ((char *) ST_0004);
case STATUS_CRACKED: return ((char *) ST_0005);
case STATUS_ABORTED: return ((char *) ST_0006);
case STATUS_QUIT: return ((char *) ST_0007);
case STATUS_BYPASS: return ((char *) ST_0008);
case STATUS_ABORTED_CHECKPOINT: return ((char *) ST_0009);
case STATUS_ABORTED_RUNTIME: return ((char *) ST_0010);
case STATUS_SELFTEST: return ((char *) ST_0002);
case STATUS_RUNNING: return ((char *) ST_0003);
case STATUS_PAUSED: return ((char *) ST_0004);
case STATUS_EXHAUSTED: return ((char *) ST_0005);
case STATUS_CRACKED: return ((char *) ST_0006);
case STATUS_ABORTED: return ((char *) ST_0007);
case STATUS_QUIT: return ((char *) ST_0008);
case STATUS_BYPASS: return ((char *) ST_0009);
case STATUS_ABORTED_CHECKPOINT: return ((char *) ST_0010);
case STATUS_ABORTED_RUNTIME: return ((char *) ST_0011);
}
return ((char *) ST_9999);