1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-11-23 00:28:11 +00:00

Revert "Prepare for hashcat_ctx_run_session()"

This reverts commit 0179097a53.
This commit is contained in:
jsteube 2016-10-14 19:25:13 +02:00
parent 0179097a53
commit 056083fdba
8 changed files with 292 additions and 320 deletions

View File

@ -6,10 +6,9 @@
#ifndef _HASHCAT_H
#define _HASHCAT_H
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);
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);
#endif // _HASHCAT_H

View File

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

View File

@ -52,6 +52,81 @@
#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)
@ -65,6 +140,7 @@ 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;
@ -314,6 +390,7 @@ 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;
@ -354,16 +431,10 @@ static int inner1_loop (hashcat_ctx_t *hashcat_ctx)
return 0;
}
char *hashcat_ctx_last_error (hashcat_ctx_t *hashcat_ctx)
{
event_ctx_t *event_ctx = hashcat_ctx->event_ctx;
// outer_loop iterates through hash_modes (in benchmark mode)
// also initializes stuff that depend on hash mode
return event_ctx->msg_buf;
}
// hashcat_ctx_run_session also initializes stuff that depend on hash mode
int hashcat_ctx_run_session (hashcat_ctx_t *hashcat_ctx)
static int outer_loop (hashcat_ctx_t *hashcat_ctx)
{
hashes_t *hashes = hashcat_ctx->hashes;
mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx;
@ -376,6 +447,7 @@ int hashcat_ctx_run_session (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;
@ -583,7 +655,7 @@ int hashcat_ctx_run_session (hashcat_ctx_t *hashcat_ctx)
* main screen
*/
EVENT (EVENT_SESSION_MAINSCREEN);
EVENT (EVENT_OUTERLOOP_MAINSCREEN);
/**
* inform the user
@ -668,8 +740,6 @@ int hashcat_ctx_run_session (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;
@ -685,19 +755,19 @@ int hashcat_ctx_run_session (hashcat_ctx_t *hashcat_ctx)
mask_ctx->masks_pos = masks_pos;
rc_inner1_loop = inner1_loop (hashcat_ctx);
const int rc_inner1_loop = inner1_loop (hashcat_ctx);
if (rc_inner1_loop == -1) break;
if (rc_inner1_loop == -1) return -1;
if (status_ctx->run_main_level2 == false) break;
}
}
else
{
rc_inner1_loop = inner1_loop (hashcat_ctx);
}
const int rc_inner1_loop = inner1_loop (hashcat_ctx);
EVENT (EVENT_INNERLOOP1_FINISHED);
if (rc_inner1_loop == -1) return -1;
}
// wait for inner threads
@ -710,6 +780,8 @@ int hashcat_ctx_run_session (hashcat_ctx_t *hashcat_ctx)
hcfree (inner_threads);
EVENT (EVENT_INNERLOOP1_FINISHED);
// finalize potfile
potfile_write_close (hashcat_ctx);
@ -738,38 +810,15 @@ int hashcat_ctx_run_session (hashcat_ctx_t *hashcat_ctx)
cpt_ctx_destroy (hashcat_ctx);
// 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 0;
}
return rc_inner1_loop;
}
// 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)
int hashcat (hashcat_ctx_t *hashcat_ctx, 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)
*/
@ -778,10 +827,6 @@ int hashcat_ctx_init (hashcat_ctx_t *hashcat_ctx, void (*event) (const u32, stru
if (rc_event_init == -1) return -1;
// say hello to user
EVENT (EVENT_WELCOME_SCREEN);
/**
* status init
*/
@ -790,6 +835,8 @@ int hashcat_ctx_init (hashcat_ctx_t *hashcat_ctx, void (*event) (const u32, stru
if (rc_status_init == -1) return -1;
EVENT (EVENT_WELCOME_SCREEN);
/**
* folder
*/
@ -806,6 +853,14 @@ int hashcat_ctx_init (hashcat_ctx_t *hashcat_ctx, void (*event) (const u32, stru
if (rc_restore_init == -1) return -1;
/**
* process user input
*/
user_options_preprocess (hashcat_ctx);
user_options_extra_init (hashcat_ctx);
/**
* logfile
*/
@ -818,14 +873,6 @@ int hashcat_ctx_init (hashcat_ctx_t *hashcat_ctx, void (*event) (const u32, stru
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);
@ -895,7 +942,7 @@ int hashcat_ctx_init (hashcat_ctx_t *hashcat_ctx, void (*event) (const u32, stru
/**
* 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 hashcat_ctx_run_session
* plus it depends on hash_mode, so we continue using it in outer_loop
*/
const int rc_potfile_init = potfile_init (hashcat_ctx);
@ -952,62 +999,51 @@ int hashcat_ctx_init (hashcat_ctx_t *hashcat_ctx, void (*event) (const u32, stru
if (rc_hwmon_init == -1) return -1;
return 0;
}
int hashcat_ctx_alloc (hashcat_ctx_t *hashcat_ctx)
{
/**
* allocate main work objects
* outer loop
*/
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);
EVENT (EVENT_OUTERLOOP_STARTING);
return 0;
int rc_final = -1;
if (user_options->benchmark == true)
{
user_options->quiet = true;
if (user_options->hash_mode_chgd == true)
{
rc_final = outer_loop (hashcat_ctx);
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];
rc_final = outer_loop (hashcat_ctx);
if (rc_final == -1) myabort (hashcat_ctx);
if (status_ctx->run_main_level1 == false) break;
}
}
}
else
{
rc_final = outer_loop (hashcat_ctx);
if (rc_final == -1) myabort (hashcat_ctx);
}
void hashcat_ctx_destroy (hashcat_ctx_t *hashcat_ctx)
EVENT (EVENT_OUTERLOOP_FINISHED);
if (user_options->benchmark == true)
{
// final logfile entry
logfile_ctx_t *logfile_ctx = hashcat_ctx->logfile_ctx;
status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
time (&status_ctx->proc_stop);
logfile_top_uint (status_ctx->proc_start);
logfile_top_uint (status_ctx->proc_stop);
logfile_top_msg ("STOP");
// say goodbye to user
EVENT (EVENT_GOODBYE_SCREEN);
user_options->quiet = false;
}
// if exhausted or cracked, unlink the restore file
@ -1017,8 +1053,19 @@ void hashcat_ctx_destroy (hashcat_ctx_t *hashcat_ctx)
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);
@ -1051,35 +1098,19 @@ void hashcat_ctx_destroy (hashcat_ctx_t *hashcat_ctx)
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);
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);
// done
memset (hashcat_ctx, 0, sizeof (hashcat_ctx_t));
return rc_final;
}

View File

@ -6,7 +6,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <assert.h>
#include "common.h"
#include "types.h"
@ -18,12 +17,8 @@
#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;
@ -122,7 +117,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_session_starting (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len)
static void main_outerloop_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;
@ -153,7 +148,7 @@ static void main_session_starting (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYB
}
}
static void main_session_finished (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len)
static void main_outerloop_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;
@ -172,90 +167,6 @@ static void main_session_finished (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYB
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;
@ -391,6 +302,90 @@ 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;
@ -468,9 +463,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_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_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_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;
@ -491,6 +486,14 @@ 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;
@ -504,17 +507,7 @@ int main (int argc, char **argv)
shared_folder = SHARED_FOLDER;
#endif
// 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
// initialize the user options with some defaults (you can override them later)
const int rc_options_init = user_options_init (hashcat_ctx);
@ -548,55 +541,11 @@ 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
EVENT (EVENT_SESSION_STARTING);
const int rc_hashcat = hashcat (hashcat_ctx, install_folder, shared_folder, argc, argv, COMPTIME);
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);
// clean up
// finished with hashcat, clean up
hashcat_ctx_destroy (hashcat_ctx);

View File

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

View File

@ -367,6 +367,7 @@ 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;
@ -376,6 +377,7 @@ 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;

View File

@ -444,9 +444,9 @@ void status_display (hashcat_ctx_t *hashcat_ctx)
if (mask_ctx->masks_cnt > 1)
{
const int mask_pos_done = ((status_ctx->devices_status == STATUS_EXHAUSTED) && (status_ctx->run_main_level2 == true)) ? 1 : 0;
const int maks_pos_done = ((status_ctx->devices_status == STATUS_EXHAUSTED) && (status_ctx->run_main_level1 == true)) ? 1 : 0;
double mask_percentage = (double) (mask_ctx->masks_pos + mask_pos_done) / (double) mask_ctx->masks_cnt;
double mask_percentage = (double) (mask_ctx->masks_pos + maks_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_level2 == false) return;
if (status_ctx->run_main_level1 == false) return;
for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++)
{
@ -1383,6 +1383,7 @@ 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;

View File

@ -124,6 +124,7 @@ 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;
@ -139,6 +140,7 @@ 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;
@ -153,6 +155,7 @@ 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;
@ -167,6 +170,7 @@ 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;