Prepare for hashcat_ctx_run_session()

pull/544/head
jsteube 8 years ago
parent 742b9c8404
commit 0179097a53

@ -6,9 +6,10 @@
#ifndef _HASHCAT_H
#define _HASHCAT_H
int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_folder, int argc, char **argv, const int comptime);
int hashcat_ctx_init (hashcat_ctx_t *hashcat_ctx, void (*event) (const u32, struct hashcat_ctx *, const void *, const size_t));
void hashcat_ctx_destroy (hashcat_ctx_t *hashcat_ctx);
char *hashcat_ctx_last_error (hashcat_ctx_t *hashcat_ctx);
int hashcat_ctx_run_session (hashcat_ctx_t *hashcat_ctx);
int hashcat_ctx_init (hashcat_ctx_t *hashcat_ctx, void (*event) (const u32, struct hashcat_ctx *, const void *, const size_t), char *install_folder, char *shared_folder, int argc, char **argv, const int comptime);
int hashcat_ctx_alloc (hashcat_ctx_t *hashcat_ctx);
void hashcat_ctx_destroy (hashcat_ctx_t *hashcat_ctx);
#endif // _HASHCAT_H

@ -82,9 +82,9 @@ typedef enum event_identifier
EVENT_LOG_ERROR = 0x00000003,
EVENT_WELCOME_SCREEN = 0x00000011,
EVENT_GOODBYE_SCREEN = 0x00000012,
EVENT_OUTERLOOP_STARTING = 0x00000031,
EVENT_OUTERLOOP_MAINSCREEN = 0x00000032,
EVENT_OUTERLOOP_FINISHED = 0x00000033,
EVENT_SESSION_STARTING = 0x00000031,
EVENT_SESSION_MAINSCREEN = 0x00000032,
EVENT_SESSION_FINISHED = 0x00000033,
EVENT_INNERLOOP1_STARTING = 0x00000041,
EVENT_INNERLOOP1_FINISHED = 0x00000042,
EVENT_INNERLOOP2_STARTING = 0x00000051,
@ -1339,7 +1339,6 @@ typedef struct status_ctx
* thread control
*/
bool run_main_level1;
bool run_main_level2;
bool run_main_level3;
bool run_thread_level1;

@ -52,81 +52,6 @@
#include "weak_hash.h"
#include "wordlist.h"
extern const u32 DEFAULT_BENCHMARK_ALGORITHMS_CNT;
extern const u32 DEFAULT_BENCHMARK_ALGORITHMS_BUF[];
int hashcat_ctx_init (hashcat_ctx_t *hashcat_ctx, void (*event) (const u32, struct hashcat_ctx *, const void *, const size_t))
{
if (event == NULL)
{
fprintf (stderr, "Event callback function is mandatory\n");
return -1;
}
hashcat_ctx->event = event;
hashcat_ctx->bitmap_ctx = (bitmap_ctx_t *) hcmalloc (hashcat_ctx, sizeof (bitmap_ctx_t)); VERIFY_PTR (hashcat_ctx->bitmap_ctx);
hashcat_ctx->combinator_ctx = (combinator_ctx_t *) hcmalloc (hashcat_ctx, sizeof (combinator_ctx_t)); VERIFY_PTR (hashcat_ctx->combinator_ctx);
hashcat_ctx->cpt_ctx = (cpt_ctx_t *) hcmalloc (hashcat_ctx, sizeof (cpt_ctx_t)); VERIFY_PTR (hashcat_ctx->cpt_ctx);
hashcat_ctx->debugfile_ctx = (debugfile_ctx_t *) hcmalloc (hashcat_ctx, sizeof (debugfile_ctx_t)); VERIFY_PTR (hashcat_ctx->debugfile_ctx);
hashcat_ctx->dictstat_ctx = (dictstat_ctx_t *) hcmalloc (hashcat_ctx, sizeof (dictstat_ctx_t)); VERIFY_PTR (hashcat_ctx->dictstat_ctx);
hashcat_ctx->event_ctx = (event_ctx_t *) hcmalloc (hashcat_ctx, sizeof (event_ctx_t)); VERIFY_PTR (hashcat_ctx->event_ctx);
hashcat_ctx->folder_config = (folder_config_t *) hcmalloc (hashcat_ctx, sizeof (folder_config_t)); VERIFY_PTR (hashcat_ctx->folder_config);
hashcat_ctx->hashcat_user = (hashcat_user_t *) hcmalloc (hashcat_ctx, sizeof (hashcat_user_t)); VERIFY_PTR (hashcat_ctx->hashcat_user);
hashcat_ctx->hashconfig = (hashconfig_t *) hcmalloc (hashcat_ctx, sizeof (hashconfig_t)); VERIFY_PTR (hashcat_ctx->hashconfig);
hashcat_ctx->hashes = (hashes_t *) hcmalloc (hashcat_ctx, sizeof (hashes_t)); VERIFY_PTR (hashcat_ctx->hashes);
hashcat_ctx->hwmon_ctx = (hwmon_ctx_t *) hcmalloc (hashcat_ctx, sizeof (hwmon_ctx_t)); VERIFY_PTR (hashcat_ctx->hwmon_ctx);
hashcat_ctx->induct_ctx = (induct_ctx_t *) hcmalloc (hashcat_ctx, sizeof (induct_ctx_t)); VERIFY_PTR (hashcat_ctx->induct_ctx);
hashcat_ctx->logfile_ctx = (logfile_ctx_t *) hcmalloc (hashcat_ctx, sizeof (logfile_ctx_t)); VERIFY_PTR (hashcat_ctx->logfile_ctx);
hashcat_ctx->loopback_ctx = (loopback_ctx_t *) hcmalloc (hashcat_ctx, sizeof (loopback_ctx_t)); VERIFY_PTR (hashcat_ctx->loopback_ctx);
hashcat_ctx->mask_ctx = (mask_ctx_t *) hcmalloc (hashcat_ctx, sizeof (mask_ctx_t)); VERIFY_PTR (hashcat_ctx->mask_ctx);
hashcat_ctx->opencl_ctx = (opencl_ctx_t *) hcmalloc (hashcat_ctx, sizeof (opencl_ctx_t)); VERIFY_PTR (hashcat_ctx->opencl_ctx);
hashcat_ctx->outcheck_ctx = (outcheck_ctx_t *) hcmalloc (hashcat_ctx, sizeof (outcheck_ctx_t)); VERIFY_PTR (hashcat_ctx->outcheck_ctx);
hashcat_ctx->outfile_ctx = (outfile_ctx_t *) hcmalloc (hashcat_ctx, sizeof (outfile_ctx_t)); VERIFY_PTR (hashcat_ctx->outfile_ctx);
hashcat_ctx->potfile_ctx = (potfile_ctx_t *) hcmalloc (hashcat_ctx, sizeof (potfile_ctx_t)); VERIFY_PTR (hashcat_ctx->potfile_ctx);
hashcat_ctx->restore_ctx = (restore_ctx_t *) hcmalloc (hashcat_ctx, sizeof (restore_ctx_t)); VERIFY_PTR (hashcat_ctx->restore_ctx);
hashcat_ctx->status_ctx = (status_ctx_t *) hcmalloc (hashcat_ctx, sizeof (status_ctx_t)); VERIFY_PTR (hashcat_ctx->status_ctx);
hashcat_ctx->straight_ctx = (straight_ctx_t *) hcmalloc (hashcat_ctx, sizeof (straight_ctx_t)); VERIFY_PTR (hashcat_ctx->straight_ctx);
hashcat_ctx->tuning_db = (tuning_db_t *) hcmalloc (hashcat_ctx, sizeof (tuning_db_t)); VERIFY_PTR (hashcat_ctx->tuning_db);
hashcat_ctx->user_options_extra = (user_options_extra_t *) hcmalloc (hashcat_ctx, sizeof (user_options_extra_t)); VERIFY_PTR (hashcat_ctx->user_options_extra);
hashcat_ctx->user_options = (user_options_t *) hcmalloc (hashcat_ctx, sizeof (user_options_t)); VERIFY_PTR (hashcat_ctx->user_options);
hashcat_ctx->wl_data = (wl_data_t *) hcmalloc (hashcat_ctx, sizeof (wl_data_t)); VERIFY_PTR (hashcat_ctx->wl_data);
return 0;
}
void hashcat_ctx_destroy (hashcat_ctx_t *hashcat_ctx)
{
hcfree (hashcat_ctx->bitmap_ctx);
hcfree (hashcat_ctx->combinator_ctx);
hcfree (hashcat_ctx->cpt_ctx);
hcfree (hashcat_ctx->debugfile_ctx);
hcfree (hashcat_ctx->dictstat_ctx);
hcfree (hashcat_ctx->event_ctx);
hcfree (hashcat_ctx->folder_config);
hcfree (hashcat_ctx->hashconfig);
hcfree (hashcat_ctx->hashes);
hcfree (hashcat_ctx->hwmon_ctx);
hcfree (hashcat_ctx->induct_ctx);
hcfree (hashcat_ctx->logfile_ctx);
hcfree (hashcat_ctx->loopback_ctx);
hcfree (hashcat_ctx->mask_ctx);
hcfree (hashcat_ctx->opencl_ctx);
hcfree (hashcat_ctx->outcheck_ctx);
hcfree (hashcat_ctx->outfile_ctx);
hcfree (hashcat_ctx->potfile_ctx);
hcfree (hashcat_ctx->restore_ctx);
hcfree (hashcat_ctx->status_ctx);
hcfree (hashcat_ctx->straight_ctx);
hcfree (hashcat_ctx->tuning_db);
hcfree (hashcat_ctx->user_options_extra);
hcfree (hashcat_ctx->user_options);
hcfree (hashcat_ctx->wl_data);
memset (hashcat_ctx, 0, sizeof (hashcat_ctx_t));
}
// inner2_loop iterates through wordlists, then calls kernel execution
static int inner2_loop (hashcat_ctx_t *hashcat_ctx)
@ -140,7 +65,6 @@ static int inner2_loop (hashcat_ctx_t *hashcat_ctx)
user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra;
user_options_t *user_options = hashcat_ctx->user_options;
//status_ctx->run_main_level1 = true;
//status_ctx->run_main_level2 = true;
//status_ctx->run_main_level3 = true;
status_ctx->run_thread_level1 = true;
@ -390,7 +314,6 @@ static int inner1_loop (hashcat_ctx_t *hashcat_ctx)
status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx;
//status_ctx->run_main_level1 = true;
//status_ctx->run_main_level2 = true;
status_ctx->run_main_level3 = true;
status_ctx->run_thread_level1 = true;
@ -431,10 +354,16 @@ static int inner1_loop (hashcat_ctx_t *hashcat_ctx)
return 0;
}
// outer_loop iterates through hash_modes (in benchmark mode)
// also initializes stuff that depend on hash mode
char *hashcat_ctx_last_error (hashcat_ctx_t *hashcat_ctx)
{
event_ctx_t *event_ctx = hashcat_ctx->event_ctx;
return event_ctx->msg_buf;
}
static int outer_loop (hashcat_ctx_t *hashcat_ctx)
// hashcat_ctx_run_session also initializes stuff that depend on hash mode
int hashcat_ctx_run_session (hashcat_ctx_t *hashcat_ctx)
{
hashes_t *hashes = hashcat_ctx->hashes;
mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx;
@ -447,7 +376,6 @@ static int outer_loop (hashcat_ctx_t *hashcat_ctx)
status_ctx->devices_status = STATUS_INIT;
//status_ctx->run_main_level1 = true;
status_ctx->run_main_level2 = true;
status_ctx->run_main_level3 = true;
status_ctx->run_thread_level1 = true;
@ -655,7 +583,7 @@ static int outer_loop (hashcat_ctx_t *hashcat_ctx)
* main screen
*/
EVENT (EVENT_OUTERLOOP_MAINSCREEN);
EVENT (EVENT_SESSION_MAINSCREEN);
/**
* inform the user
@ -740,6 +668,8 @@ static int outer_loop (hashcat_ctx_t *hashcat_ctx)
EVENT (EVENT_INNERLOOP1_STARTING);
int rc_inner1_loop = -1;
if (mask_ctx->masks_cnt)
{
restore_data_t *rd = restore_ctx->rd;
@ -755,20 +685,20 @@ static int outer_loop (hashcat_ctx_t *hashcat_ctx)
mask_ctx->masks_pos = masks_pos;
const int rc_inner1_loop = inner1_loop (hashcat_ctx);
rc_inner1_loop = inner1_loop (hashcat_ctx);
if (rc_inner1_loop == -1) return -1;
if (rc_inner1_loop == -1) break;
if (status_ctx->run_main_level2 == false) break;
}
}
else
{
const int rc_inner1_loop = inner1_loop (hashcat_ctx);
if (rc_inner1_loop == -1) return -1;
rc_inner1_loop = inner1_loop (hashcat_ctx);
}
EVENT (EVENT_INNERLOOP1_FINISHED);
// wait for inner threads
status_ctx->shutdown_inner = true;
@ -780,8 +710,6 @@ static int outer_loop (hashcat_ctx_t *hashcat_ctx)
hcfree (inner_threads);
EVENT (EVENT_INNERLOOP1_FINISHED);
// finalize potfile
potfile_write_close (hashcat_ctx);
@ -810,15 +738,38 @@ static int outer_loop (hashcat_ctx_t *hashcat_ctx)
cpt_ctx_destroy (hashcat_ctx);
return 0;
// something for the user
if (rc_inner1_loop == 0)
{
if (status_ctx->devices_status == STATUS_ABORTED) rc_inner1_loop = 2;
if (status_ctx->devices_status == STATUS_QUIT) rc_inner1_loop = 2;
if (status_ctx->devices_status == STATUS_EXHAUSTED) rc_inner1_loop = 1;
if (status_ctx->devices_status == STATUS_CRACKED) rc_inner1_loop = 0;
}
return rc_inner1_loop;
}
int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_folder, int argc, char **argv, const int comptime)
// hashcat_ctx_init initializes opencl, sensors, everything that can be reused if we want to run hashcat multiple times
int hashcat_ctx_init (hashcat_ctx_t *hashcat_ctx, void (*event) (const u32, struct hashcat_ctx *, const void *, const size_t), char *install_folder, char *shared_folder, int argc, char **argv, const int comptime)
{
if (event == NULL)
{
fprintf (stderr, "Event callback function is mandatory\n");
return -1;
}
hashcat_ctx->event = event;
logfile_ctx_t *logfile_ctx = hashcat_ctx->logfile_ctx;
status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
user_options_t *user_options = hashcat_ctx->user_options;
time (&status_ctx->proc_start);
/**
* event init (needed for logging so should be first)
*/
@ -827,6 +778,10 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_fold
if (rc_event_init == -1) return -1;
// say hello to user
EVENT (EVENT_WELCOME_SCREEN);
/**
* status init
*/
@ -835,8 +790,6 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_fold
if (rc_status_init == -1) return -1;
EVENT (EVENT_WELCOME_SCREEN);
/**
* folder
*/
@ -853,14 +806,6 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_fold
if (rc_restore_init == -1) return -1;
/**
* process user input
*/
user_options_preprocess (hashcat_ctx);
user_options_extra_init (hashcat_ctx);
/**
* logfile
*/
@ -873,6 +818,14 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_fold
logfile_top_msg ("START");
/**
* final process user input (argc/argv related)
*/
user_options_preprocess (hashcat_ctx);
user_options_extra_init (hashcat_ctx);
// add all user options to logfile in case we want to debug some user session
user_options_logger (hashcat_ctx);
@ -942,7 +895,7 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_fold
/**
* potfile init
* this is only setting path because potfile can be used in read and write mode depending on user options
* plus it depends on hash_mode, so we continue using it in outer_loop
* plus it depends on hash_mode, so we continue using it in hashcat_ctx_run_session
*/
const int rc_potfile_init = potfile_init (hashcat_ctx);
@ -999,51 +952,62 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_fold
if (rc_hwmon_init == -1) return -1;
return 0;
}
int hashcat_ctx_alloc (hashcat_ctx_t *hashcat_ctx)
{
/**
* outer loop
* allocate main work objects
*/
EVENT (EVENT_OUTERLOOP_STARTING);
int rc_final = -1;
if (user_options->benchmark == true)
{
user_options->quiet = true;
hashcat_ctx->bitmap_ctx = (bitmap_ctx_t *) hcmalloc (hashcat_ctx, sizeof (bitmap_ctx_t)); VERIFY_PTR (hashcat_ctx->bitmap_ctx);
hashcat_ctx->combinator_ctx = (combinator_ctx_t *) hcmalloc (hashcat_ctx, sizeof (combinator_ctx_t)); VERIFY_PTR (hashcat_ctx->combinator_ctx);
hashcat_ctx->cpt_ctx = (cpt_ctx_t *) hcmalloc (hashcat_ctx, sizeof (cpt_ctx_t)); VERIFY_PTR (hashcat_ctx->cpt_ctx);
hashcat_ctx->debugfile_ctx = (debugfile_ctx_t *) hcmalloc (hashcat_ctx, sizeof (debugfile_ctx_t)); VERIFY_PTR (hashcat_ctx->debugfile_ctx);
hashcat_ctx->dictstat_ctx = (dictstat_ctx_t *) hcmalloc (hashcat_ctx, sizeof (dictstat_ctx_t)); VERIFY_PTR (hashcat_ctx->dictstat_ctx);
hashcat_ctx->event_ctx = (event_ctx_t *) hcmalloc (hashcat_ctx, sizeof (event_ctx_t)); VERIFY_PTR (hashcat_ctx->event_ctx);
hashcat_ctx->folder_config = (folder_config_t *) hcmalloc (hashcat_ctx, sizeof (folder_config_t)); VERIFY_PTR (hashcat_ctx->folder_config);
hashcat_ctx->hashcat_user = (hashcat_user_t *) hcmalloc (hashcat_ctx, sizeof (hashcat_user_t)); VERIFY_PTR (hashcat_ctx->hashcat_user);
hashcat_ctx->hashconfig = (hashconfig_t *) hcmalloc (hashcat_ctx, sizeof (hashconfig_t)); VERIFY_PTR (hashcat_ctx->hashconfig);
hashcat_ctx->hashes = (hashes_t *) hcmalloc (hashcat_ctx, sizeof (hashes_t)); VERIFY_PTR (hashcat_ctx->hashes);
hashcat_ctx->hwmon_ctx = (hwmon_ctx_t *) hcmalloc (hashcat_ctx, sizeof (hwmon_ctx_t)); VERIFY_PTR (hashcat_ctx->hwmon_ctx);
hashcat_ctx->induct_ctx = (induct_ctx_t *) hcmalloc (hashcat_ctx, sizeof (induct_ctx_t)); VERIFY_PTR (hashcat_ctx->induct_ctx);
hashcat_ctx->logfile_ctx = (logfile_ctx_t *) hcmalloc (hashcat_ctx, sizeof (logfile_ctx_t)); VERIFY_PTR (hashcat_ctx->logfile_ctx);
hashcat_ctx->loopback_ctx = (loopback_ctx_t *) hcmalloc (hashcat_ctx, sizeof (loopback_ctx_t)); VERIFY_PTR (hashcat_ctx->loopback_ctx);
hashcat_ctx->mask_ctx = (mask_ctx_t *) hcmalloc (hashcat_ctx, sizeof (mask_ctx_t)); VERIFY_PTR (hashcat_ctx->mask_ctx);
hashcat_ctx->opencl_ctx = (opencl_ctx_t *) hcmalloc (hashcat_ctx, sizeof (opencl_ctx_t)); VERIFY_PTR (hashcat_ctx->opencl_ctx);
hashcat_ctx->outcheck_ctx = (outcheck_ctx_t *) hcmalloc (hashcat_ctx, sizeof (outcheck_ctx_t)); VERIFY_PTR (hashcat_ctx->outcheck_ctx);
hashcat_ctx->outfile_ctx = (outfile_ctx_t *) hcmalloc (hashcat_ctx, sizeof (outfile_ctx_t)); VERIFY_PTR (hashcat_ctx->outfile_ctx);
hashcat_ctx->potfile_ctx = (potfile_ctx_t *) hcmalloc (hashcat_ctx, sizeof (potfile_ctx_t)); VERIFY_PTR (hashcat_ctx->potfile_ctx);
hashcat_ctx->restore_ctx = (restore_ctx_t *) hcmalloc (hashcat_ctx, sizeof (restore_ctx_t)); VERIFY_PTR (hashcat_ctx->restore_ctx);
hashcat_ctx->status_ctx = (status_ctx_t *) hcmalloc (hashcat_ctx, sizeof (status_ctx_t)); VERIFY_PTR (hashcat_ctx->status_ctx);
hashcat_ctx->straight_ctx = (straight_ctx_t *) hcmalloc (hashcat_ctx, sizeof (straight_ctx_t)); VERIFY_PTR (hashcat_ctx->straight_ctx);
hashcat_ctx->tuning_db = (tuning_db_t *) hcmalloc (hashcat_ctx, sizeof (tuning_db_t)); VERIFY_PTR (hashcat_ctx->tuning_db);
hashcat_ctx->user_options_extra = (user_options_extra_t *) hcmalloc (hashcat_ctx, sizeof (user_options_extra_t)); VERIFY_PTR (hashcat_ctx->user_options_extra);
hashcat_ctx->user_options = (user_options_t *) hcmalloc (hashcat_ctx, sizeof (user_options_t)); VERIFY_PTR (hashcat_ctx->user_options);
hashcat_ctx->wl_data = (wl_data_t *) hcmalloc (hashcat_ctx, sizeof (wl_data_t)); VERIFY_PTR (hashcat_ctx->wl_data);
if (user_options->hash_mode_chgd == true)
{
rc_final = outer_loop (hashcat_ctx);
return 0;
}
if (rc_final == -1) myabort (hashcat_ctx);
}
else
{
for (u32 algorithm_pos = 0; algorithm_pos < DEFAULT_BENCHMARK_ALGORITHMS_CNT; algorithm_pos++)
{
user_options->hash_mode = DEFAULT_BENCHMARK_ALGORITHMS_BUF[algorithm_pos];
void hashcat_ctx_destroy (hashcat_ctx_t *hashcat_ctx)
{
// final logfile entry
rc_final = outer_loop (hashcat_ctx);
logfile_ctx_t *logfile_ctx = hashcat_ctx->logfile_ctx;
status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
if (rc_final == -1) myabort (hashcat_ctx);
time (&status_ctx->proc_stop);
if (status_ctx->run_main_level1 == false) break;
}
}
}
else
{
rc_final = outer_loop (hashcat_ctx);
logfile_top_uint (status_ctx->proc_start);
logfile_top_uint (status_ctx->proc_stop);
if (rc_final == -1) myabort (hashcat_ctx);
}
logfile_top_msg ("STOP");
EVENT (EVENT_OUTERLOOP_FINISHED);
// say goodbye to user
if (user_options->benchmark == true)
{
user_options->quiet = false;
}
EVENT (EVENT_GOODBYE_SCREEN);
// if exhausted or cracked, unlink the restore file
@ -1053,19 +1017,8 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_fold
dictstat_write (hashcat_ctx);
// final logfile entry
time (&status_ctx->proc_stop);
logfile_top_uint (status_ctx->proc_start);
logfile_top_uint (status_ctx->proc_stop);
logfile_top_msg ("STOP");
// free memory
EVENT (EVENT_GOODBYE_SCREEN);
logfile_destroy (hashcat_ctx);
debugfile_destroy (hashcat_ctx);
@ -1098,19 +1051,35 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_fold
user_options_destroy (hashcat_ctx);
if (rc_final == 0)
{
if (status_ctx->devices_status == STATUS_ABORTED) rc_final = 2;
if (status_ctx->devices_status == STATUS_QUIT) rc_final = 2;
if (status_ctx->devices_status == STATUS_EXHAUSTED) rc_final = 1;
if (status_ctx->devices_status == STATUS_CRACKED) rc_final = 0;
}
event_ctx_destroy (hashcat_ctx);
status_ctx_destroy (hashcat_ctx);
// done
hcfree (hashcat_ctx->bitmap_ctx);
hcfree (hashcat_ctx->combinator_ctx);
hcfree (hashcat_ctx->cpt_ctx);
hcfree (hashcat_ctx->debugfile_ctx);
hcfree (hashcat_ctx->dictstat_ctx);
hcfree (hashcat_ctx->event_ctx);
hcfree (hashcat_ctx->folder_config);
hcfree (hashcat_ctx->hashconfig);
hcfree (hashcat_ctx->hashes);
hcfree (hashcat_ctx->hwmon_ctx);
hcfree (hashcat_ctx->induct_ctx);
hcfree (hashcat_ctx->logfile_ctx);
hcfree (hashcat_ctx->loopback_ctx);
hcfree (hashcat_ctx->mask_ctx);
hcfree (hashcat_ctx->opencl_ctx);
hcfree (hashcat_ctx->outcheck_ctx);
hcfree (hashcat_ctx->outfile_ctx);
hcfree (hashcat_ctx->potfile_ctx);
hcfree (hashcat_ctx->restore_ctx);
hcfree (hashcat_ctx->status_ctx);
hcfree (hashcat_ctx->straight_ctx);
hcfree (hashcat_ctx->tuning_db);
hcfree (hashcat_ctx->user_options_extra);
hcfree (hashcat_ctx->user_options);
hcfree (hashcat_ctx->wl_data);
return rc_final;
memset (hashcat_ctx, 0, sizeof (hashcat_ctx_t));
}

@ -6,6 +6,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <assert.h>
#include "common.h"
#include "types.h"
@ -17,8 +18,12 @@
#include "thread.h"
#include "status.h"
#include "interface.h"
#include "benchmark.h"
#include "event.h"
extern const u32 DEFAULT_BENCHMARK_ALGORITHMS_CNT;
extern const u32 DEFAULT_BENCHMARK_ALGORITHMS_BUF[];
static void main_log (hashcat_ctx_t *hashcat_ctx, FILE *fp)
{
event_ctx_t *event_ctx = hashcat_ctx->event_ctx;
@ -117,7 +122,7 @@ static void main_goodbye_screen (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_
goodbye_screen (hashcat_ctx, status_ctx->proc_start, status_ctx->proc_stop);
}
static void main_outerloop_starting (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len)
static void main_session_starting (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len)
{
const user_options_t *user_options = hashcat_ctx->user_options;
const user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra;
@ -148,7 +153,7 @@ static void main_outerloop_starting (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MA
}
}
static void main_outerloop_finished (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len)
static void main_session_finished (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len)
{
hashcat_user_t *hashcat_user = hashcat_ctx->hashcat_user;
status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
@ -167,6 +172,90 @@ static void main_outerloop_finished (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MA
hashcat_user->outer_threads_cnt = 0;
}
static void main_session_mainscreen (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len)
{
const bitmap_ctx_t *bitmap_ctx = hashcat_ctx->bitmap_ctx;
const hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
const hashes_t *hashes = hashcat_ctx->hashes;
const hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx;
const straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx;
const user_options_t *user_options = hashcat_ctx->user_options;
/**
* In benchmark-mode, inform user which algorithm is checked
*/
if (user_options->benchmark == true)
{
if (user_options->machine_readable == false)
{
char *hash_type = strhashtype (hashconfig->hash_mode); // not a bug
event_log_info (hashcat_ctx, "Hashtype: %s", hash_type);
event_log_info (hashcat_ctx, "");
}
}
if (user_options->quiet == true) return;
event_log_info (hashcat_ctx, "Hashes: %u digests; %u unique digests, %u unique salts", hashes->hashes_cnt_orig, hashes->digests_cnt, hashes->salts_cnt);
event_log_info (hashcat_ctx, "Bitmaps: %u bits, %u entries, 0x%08x mask, %u bytes, %u/%u rotates", bitmap_ctx->bitmap_bits, bitmap_ctx->bitmap_nums, bitmap_ctx->bitmap_mask, bitmap_ctx->bitmap_size, bitmap_ctx->bitmap_shift1, bitmap_ctx->bitmap_shift2);
if (user_options->attack_mode == ATTACK_MODE_STRAIGHT)
{
event_log_info (hashcat_ctx, "Rules: %u", straight_ctx->kernel_rules_cnt);
}
if (user_options->quiet == false) event_log_info (hashcat_ctx, "");
if (hashconfig->opti_type)
{
event_log_info (hashcat_ctx, "Applicable Optimizers:");
for (u32 i = 0; i < 32; i++)
{
const u32 opti_bit = 1u << i;
if (hashconfig->opti_type & opti_bit) event_log_info (hashcat_ctx, "* %s", stroptitype (opti_bit));
}
}
event_log_info (hashcat_ctx, "");
/**
* Watchdog and Temperature balance
*/
if (hwmon_ctx->enabled == false && user_options->gpu_temp_disable == false)
{
event_log_info (hashcat_ctx, "Watchdog: Hardware Monitoring Interface not found on your system");
}
if (hwmon_ctx->enabled == true && user_options->gpu_temp_abort > 0)
{
event_log_info (hashcat_ctx, "Watchdog: Temperature abort trigger set to %uc", user_options->gpu_temp_abort);
}
else
{
event_log_info (hashcat_ctx, "Watchdog: Temperature abort trigger disabled");
}
if (hwmon_ctx->enabled == true && user_options->gpu_temp_retain > 0)
{
event_log_info (hashcat_ctx, "Watchdog: Temperature retain trigger set to %uc", user_options->gpu_temp_retain);
}
else
{
event_log_info (hashcat_ctx, "Watchdog: Temperature retain trigger disabled");
}
event_log_info (hashcat_ctx, "");
#if defined (DEBUG)
if (user_options->benchmark == true) event_log_info (hashcat_ctx, "Hashmode: %d", hashconfig->hash_mode);
#endif
}
static void main_cracker_starting (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len)
{
const user_options_t *user_options = hashcat_ctx->user_options;
@ -302,90 +391,6 @@ static void main_potfile_all_cracked (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, M
event_log_info (hashcat_ctx, "");
}
static void main_outerloop_mainscreen (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len)
{
const bitmap_ctx_t *bitmap_ctx = hashcat_ctx->bitmap_ctx;
const hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
const hashes_t *hashes = hashcat_ctx->hashes;
const hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx;
const straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx;
const user_options_t *user_options = hashcat_ctx->user_options;
/**
* In benchmark-mode, inform user which algorithm is checked
*/
if (user_options->benchmark == true)
{
if (user_options->machine_readable == false)
{
char *hash_type = strhashtype (hashconfig->hash_mode); // not a bug
event_log_info (hashcat_ctx, "Hashtype: %s", hash_type);
event_log_info (hashcat_ctx, "");
}
}
if (user_options->quiet == true) return;
event_log_info (hashcat_ctx, "Hashes: %u digests; %u unique digests, %u unique salts", hashes->hashes_cnt_orig, hashes->digests_cnt, hashes->salts_cnt);
event_log_info (hashcat_ctx, "Bitmaps: %u bits, %u entries, 0x%08x mask, %u bytes, %u/%u rotates", bitmap_ctx->bitmap_bits, bitmap_ctx->bitmap_nums, bitmap_ctx->bitmap_mask, bitmap_ctx->bitmap_size, bitmap_ctx->bitmap_shift1, bitmap_ctx->bitmap_shift2);
if (user_options->attack_mode == ATTACK_MODE_STRAIGHT)
{
event_log_info (hashcat_ctx, "Rules: %u", straight_ctx->kernel_rules_cnt);
}
if (user_options->quiet == false) event_log_info (hashcat_ctx, "");
if (hashconfig->opti_type)
{
event_log_info (hashcat_ctx, "Applicable Optimizers:");
for (u32 i = 0; i < 32; i++)
{
const u32 opti_bit = 1u << i;
if (hashconfig->opti_type & opti_bit) event_log_info (hashcat_ctx, "* %s", stroptitype (opti_bit));
}
}
event_log_info (hashcat_ctx, "");
/**
* Watchdog and Temperature balance
*/
if (hwmon_ctx->enabled == false && user_options->gpu_temp_disable == false)
{
event_log_info (hashcat_ctx, "Watchdog: Hardware Monitoring Interface not found on your system");
}
if (hwmon_ctx->enabled == true && user_options->gpu_temp_abort > 0)
{
event_log_info (hashcat_ctx, "Watchdog: Temperature abort trigger set to %uc", user_options->gpu_temp_abort);
}
else
{
event_log_info (hashcat_ctx, "Watchdog: Temperature abort trigger disabled");
}
if (hwmon_ctx->enabled == true && user_options->gpu_temp_retain > 0)
{
event_log_info (hashcat_ctx, "Watchdog: Temperature retain trigger set to %uc", user_options->gpu_temp_retain);
}
else
{
event_log_info (hashcat_ctx, "Watchdog: Temperature retain trigger disabled");
}
event_log_info (hashcat_ctx, "");
#if defined (DEBUG)
if (user_options->benchmark == true) event_log_info (hashcat_ctx, "Hashmode: %d", hashconfig->hash_mode);
#endif
}
static void main_opencl_session_pre (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len)
{
const user_options_t *user_options = hashcat_ctx->user_options;
@ -463,9 +468,9 @@ void event (const u32 id, hashcat_ctx_t *hashcat_ctx, const void *buf, const siz
case EVENT_LOG_ERROR: main_log_error (hashcat_ctx, buf, len); break;
case EVENT_WELCOME_SCREEN: main_welcome_screen (hashcat_ctx, buf, len); break;
case EVENT_GOODBYE_SCREEN: main_goodbye_screen (hashcat_ctx, buf, len); break;
case EVENT_OUTERLOOP_STARTING: main_outerloop_starting (hashcat_ctx, buf, len); break;
case EVENT_OUTERLOOP_FINISHED: main_outerloop_finished (hashcat_ctx, buf, len); break;
case EVENT_OUTERLOOP_MAINSCREEN: main_outerloop_mainscreen (hashcat_ctx, buf, len); break;
case EVENT_SESSION_STARTING: main_session_starting (hashcat_ctx, buf, len); break;
case EVENT_SESSION_FINISHED: main_session_finished (hashcat_ctx, buf, len); break;
case EVENT_SESSION_MAINSCREEN: main_session_mainscreen (hashcat_ctx, buf, len); break;
case EVENT_CRACKER_STARTING: main_cracker_starting (hashcat_ctx, buf, len); break;
case EVENT_CRACKER_FINISHED: main_cracker_finished (hashcat_ctx, buf, len); break;
case EVENT_CRACKER_HASH_CRACKED: main_cracker_hash_cracked (hashcat_ctx, buf, len); break;
@ -486,14 +491,6 @@ void event (const u32 id, hashcat_ctx_t *hashcat_ctx, const void *buf, const siz
int main (int argc, char **argv)
{
// hashcat main context
hashcat_ctx_t *hashcat_ctx = (hashcat_ctx_t *) malloc (sizeof (hashcat_ctx_t)); VERIFY_PTR (hashcat_ctx);
const int rc_hashcat_init = hashcat_ctx_init (hashcat_ctx, event);
if (rc_hashcat_init == -1) return -1;
// install and shared folder need to be set to recognize "make install" use
char *install_folder = NULL;
@ -507,7 +504,17 @@ int main (int argc, char **argv)
shared_folder = SHARED_FOLDER;
#endif
// initialize the user options with some defaults (you can override them later)
// hashcat main context
hashcat_ctx_t *hashcat_ctx = (hashcat_ctx_t *) malloc (sizeof (hashcat_ctx_t));
assert (hashcat_ctx);
const int rc_hashcat_alloc = hashcat_ctx_alloc (hashcat_ctx);
if (rc_hashcat_alloc == -1) return -1;
// initialize the user options with some defaults
const int rc_options_init = user_options_init (hashcat_ctx);
@ -541,11 +548,55 @@ int main (int argc, char **argv)
return 0;
}
// initialize hashcat and check for errors
const int rc_hashcat_init = hashcat_ctx_init (hashcat_ctx, event, install_folder, shared_folder, argc, argv, COMPTIME);
if (rc_hashcat_init == -1)
{
hashcat_ctx_destroy (hashcat_ctx);
free (hashcat_ctx);
return -1;
}
// now run hashcat
const int rc_hashcat = hashcat (hashcat_ctx, install_folder, shared_folder, argc, argv, COMPTIME);
EVENT (EVENT_SESSION_STARTING);
int rc_hashcat = -1;
if (user_options->benchmark == true)
{
user_options->quiet = true;
if (user_options->hash_mode_chgd == true)
{
rc_hashcat = hashcat_ctx_run_session (hashcat_ctx);
}
else
{
for (u32 algorithm_pos = 0; algorithm_pos < DEFAULT_BENCHMARK_ALGORITHMS_CNT; algorithm_pos++)
{
user_options->hash_mode = DEFAULT_BENCHMARK_ALGORITHMS_BUF[algorithm_pos];
rc_hashcat = hashcat_ctx_run_session (hashcat_ctx);
if (rc_hashcat == -1) break;
}
}
user_options->quiet = false;
}
else
{
rc_hashcat = hashcat_ctx_run_session (hashcat_ctx);
}
EVENT (EVENT_SESSION_FINISHED);
// finished with hashcat, clean up
// clean up
hashcat_ctx_destroy (hashcat_ctx);

@ -32,30 +32,30 @@ void event (const u32 id, hashcat_ctx_t *hashcat_ctx, const void *buf, const siz
int main ()
{
// hashcat main context
// hashcat context
hashcat_ctx_t *hashcat_ctx = (hashcat_ctx_t *) malloc (sizeof (hashcat_ctx_t));
assert (hashcat_ctx);
const int rc_hashcat_init = hashcat_ctx_init (hashcat_ctx, event);
const int rc_hashcat_alloc = hashcat_ctx_alloc (hashcat_ctx);
if (rc_hashcat_init == -1) return -1;
if (rc_hashcat_alloc == -1) return -1;
// this is a bit ugly, but it's the example you're looking for
// initialize the user options with some defaults (you can override them later) ...
char *hash = "8743b52063cd84097a65d1633f5c74f5";
char *mask = "?l?l?l?l?l?l?l";
const int rc_options_init = user_options_init (hashcat_ctx);
char *hc_argv[] = { hash, mask, NULL };
if (rc_options_init == -1) return -1;
// initialize the user options with some defaults (you can override them later)
// hashcat session
const int rc_options_init = user_options_init (hashcat_ctx);
char *hash = "8743b52063cd84097a65d1633f5c74f5";
char *mask = "?l?l?l?l?l?l?l";
if (rc_options_init == -1) return -1;
char *hc_argv[] = { hash, mask, NULL };
// your own stuff
// ... and add your own stuff
user_options_t *user_options = hashcat_ctx->user_options;
@ -67,21 +67,36 @@ int main ()
user_options->hash_mode = 0; // MD5
user_options->workload_profile = 3;
// now run hashcat
// initialize hashcat and check for errors
const int rc_hashcat = hashcat (hashcat_ctx, NULL, NULL, 0, NULL, 0);
const int rc_hashcat_init = hashcat_ctx_init (hashcat_ctx, event, NULL, NULL, 0, NULL, 0);
if (rc_hashcat == 0)
if (rc_hashcat_init == -1)
{
const char *error = hashcat_ctx_last_error (hashcat_ctx);
fprintf (stderr, "%s\n", error);
return -1;
}
// now run hashcat and check for errors
const int rc_session = hashcat_ctx_run_session (hashcat_ctx);
if (rc_session == 0)
{
puts ("YAY, all hashes cracked!!");
}
else if (rc_hashcat == -1)
else if (rc_session == -1)
{
event_ctx_t *event_ctx = hashcat_ctx->event_ctx;
const char *error = hashcat_ctx_last_error (hashcat_ctx);
fprintf (stderr, "%s\n", event_ctx->msg_buf);
fprintf (stderr, "%s\n", error);
}
// clean up
hashcat_ctx_destroy (hashcat_ctx);
free (hashcat_ctx);

@ -367,7 +367,6 @@ void stop_at_checkpoint (hashcat_ctx_t *hashcat_ctx)
if ((status_ctx->run_thread_level1 == true) && (status_ctx->run_thread_level2 == true))
{
status_ctx->run_main_level1 = false;
status_ctx->run_main_level2 = false;
status_ctx->run_main_level3 = false;
status_ctx->run_thread_level1 = false;
@ -377,7 +376,6 @@ void stop_at_checkpoint (hashcat_ctx_t *hashcat_ctx)
}
else
{
status_ctx->run_main_level1 = true;
status_ctx->run_main_level2 = true;
status_ctx->run_main_level3 = true;
status_ctx->run_thread_level1 = true;

@ -444,9 +444,9 @@ void status_display (hashcat_ctx_t *hashcat_ctx)
if (mask_ctx->masks_cnt > 1)
{
const int maks_pos_done = ((status_ctx->devices_status == STATUS_EXHAUSTED) && (status_ctx->run_main_level1 == true)) ? 1 : 0;
const int mask_pos_done = ((status_ctx->devices_status == STATUS_EXHAUSTED) && (status_ctx->run_main_level2 == true)) ? 1 : 0;
double mask_percentage = (double) (mask_ctx->masks_pos + maks_pos_done) / (double) mask_ctx->masks_cnt;
double mask_percentage = (double) (mask_ctx->masks_pos + mask_pos_done) / (double) mask_ctx->masks_cnt;
tmp_len += snprintf (tmp_buf + tmp_len, sizeof (tmp_buf) - tmp_len, " (%.02f%%)", mask_percentage * 100);
}
@ -1026,7 +1026,7 @@ void status_display (hashcat_ctx_t *hashcat_ctx)
}
}
if (status_ctx->run_main_level1 == false) return;
if (status_ctx->run_main_level2 == false) return;
for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++)
{
@ -1383,7 +1383,6 @@ int status_ctx_init (hashcat_ctx_t *hashcat_ctx)
status_ctx->devices_status = STATUS_INIT;
status_ctx->run_main_level1 = true;
status_ctx->run_main_level2 = true;
status_ctx->run_main_level3 = true;
status_ctx->run_thread_level1 = true;

@ -124,7 +124,6 @@ void mycracked (hashcat_ctx_t *hashcat_ctx)
status_ctx->devices_status = STATUS_CRACKED;
status_ctx->run_main_level1 = false;
status_ctx->run_main_level2 = false;
status_ctx->run_main_level3 = false;
status_ctx->run_thread_level1 = false;
@ -140,7 +139,6 @@ void myabort (hashcat_ctx_t *hashcat_ctx)
status_ctx->devices_status = STATUS_ABORTED;
status_ctx->run_main_level1 = false;
status_ctx->run_main_level2 = false;
status_ctx->run_main_level3 = false;
status_ctx->run_thread_level1 = false;
@ -155,7 +153,6 @@ void myquit (hashcat_ctx_t *hashcat_ctx)
status_ctx->devices_status = STATUS_QUIT;
status_ctx->run_main_level1 = false;
status_ctx->run_main_level2 = false;
status_ctx->run_main_level3 = false;
status_ctx->run_thread_level1 = false;
@ -170,7 +167,6 @@ void bypass (hashcat_ctx_t *hashcat_ctx)
status_ctx->devices_status = STATUS_BYPASS;
status_ctx->run_main_level1 = true;
status_ctx->run_main_level2 = true;
status_ctx->run_main_level3 = true;
status_ctx->run_thread_level1 = false;

Loading…
Cancel
Save