2016-09-11 11:42:19 +02:00
|
|
|
/**
|
2016-09-11 22:20:15 +02:00
|
|
|
* Author......: See docs/credits.txt
|
2016-09-11 11:42:19 +02:00
|
|
|
* License.....: MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common.h"
|
2016-09-12 12:59:40 +02:00
|
|
|
#include "types.h"
|
2016-10-09 22:41:55 +02:00
|
|
|
#include "event.h"
|
2016-09-30 12:46:33 +02:00
|
|
|
#include "timer.h"
|
2016-09-20 13:18:47 +02:00
|
|
|
#include "thread.h"
|
2016-09-12 12:59:40 +02:00
|
|
|
|
2016-09-30 22:52:44 +02:00
|
|
|
/*
|
2016-09-12 12:59:40 +02:00
|
|
|
#if defined (_WIN)
|
|
|
|
|
|
|
|
BOOL WINAPI sigHandler_default (DWORD sig)
|
|
|
|
{
|
|
|
|
switch (sig)
|
|
|
|
{
|
|
|
|
case CTRL_CLOSE_EVENT:
|
|
|
|
|
2016-09-30 22:52:44 +02:00
|
|
|
*
|
2016-09-12 12:59:40 +02:00
|
|
|
* special case see: https://stackoverflow.com/questions/3640633/c-setconsolectrlhandler-routine-issue/5610042#5610042
|
|
|
|
* if the user interacts w/ the user-interface (GUI/cmd), we need to do the finalization job within this signal handler
|
|
|
|
* function otherwise it is too late (e.g. after returning from this function)
|
2016-09-30 22:52:44 +02:00
|
|
|
*
|
2016-09-12 12:59:40 +02:00
|
|
|
|
2016-09-30 22:52:44 +02:00
|
|
|
myabort (hashcat_ctx->status_ctx);
|
2016-09-12 12:59:40 +02:00
|
|
|
|
|
|
|
SetConsoleCtrlHandler (NULL, TRUE);
|
|
|
|
|
2017-09-23 22:02:34 +02:00
|
|
|
sleep (10);
|
2016-09-12 12:59:40 +02:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case CTRL_C_EVENT:
|
|
|
|
case CTRL_LOGOFF_EVENT:
|
|
|
|
case CTRL_SHUTDOWN_EVENT:
|
|
|
|
|
2016-09-30 22:52:44 +02:00
|
|
|
myabort (hashcat_ctx->status_ctx);
|
2016-09-12 12:59:40 +02:00
|
|
|
|
|
|
|
SetConsoleCtrlHandler (NULL, TRUE);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WINAPI sigHandler_benchmark (DWORD sig)
|
|
|
|
{
|
|
|
|
switch (sig)
|
|
|
|
{
|
|
|
|
case CTRL_CLOSE_EVENT:
|
|
|
|
|
2016-09-30 22:52:44 +02:00
|
|
|
myquit (hashcat_ctx->status_ctx);
|
2016-09-12 12:59:40 +02:00
|
|
|
|
|
|
|
SetConsoleCtrlHandler (NULL, TRUE);
|
|
|
|
|
2017-09-23 22:02:34 +02:00
|
|
|
sleep (10);
|
2016-09-12 12:59:40 +02:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case CTRL_C_EVENT:
|
|
|
|
case CTRL_LOGOFF_EVENT:
|
|
|
|
case CTRL_SHUTDOWN_EVENT:
|
|
|
|
|
2016-09-30 22:52:44 +02:00
|
|
|
myquit (hashcat_ctx->status_ctx);
|
2016-09-12 12:59:40 +02:00
|
|
|
|
|
|
|
SetConsoleCtrlHandler (NULL, TRUE);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void hc_signal (BOOL WINAPI (callback) (DWORD))
|
|
|
|
{
|
|
|
|
if (callback == NULL)
|
|
|
|
{
|
|
|
|
SetConsoleCtrlHandler ((PHANDLER_ROUTINE) callback, FALSE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetConsoleCtrlHandler ((PHANDLER_ROUTINE) callback, TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
void sigHandler_default (int sig)
|
|
|
|
{
|
2016-09-30 22:52:44 +02:00
|
|
|
myabort (hashcat_ctx->status_ctx);
|
2016-09-12 12:59:40 +02:00
|
|
|
|
|
|
|
signal (sig, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void sigHandler_benchmark (int sig)
|
|
|
|
{
|
2016-09-30 22:52:44 +02:00
|
|
|
myquit (hashcat_ctx->status_ctx);
|
2016-09-12 12:59:40 +02:00
|
|
|
|
|
|
|
signal (sig, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void hc_signal (void (callback) (int))
|
|
|
|
{
|
|
|
|
if (callback == NULL) callback = SIG_DFL;
|
|
|
|
|
|
|
|
signal (SIGINT, callback);
|
|
|
|
signal (SIGTERM, callback);
|
|
|
|
signal (SIGABRT, callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2016-09-30 22:52:44 +02:00
|
|
|
*/
|
2016-09-12 12:59:40 +02:00
|
|
|
|
2016-10-16 19:32:43 +02:00
|
|
|
int mycracked (hashcat_ctx_t *hashcat_ctx)
|
2016-09-19 15:52:01 +02:00
|
|
|
{
|
2016-10-09 22:41:55 +02:00
|
|
|
status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
|
|
|
|
|
2016-09-29 23:25:29 +02:00
|
|
|
status_ctx->devices_status = STATUS_CRACKED;
|
2016-09-19 15:52:01 +02:00
|
|
|
|
2016-10-14 19:25:13 +02:00
|
|
|
status_ctx->run_main_level1 = false;
|
2016-09-29 23:25:29 +02:00
|
|
|
status_ctx->run_main_level2 = false;
|
|
|
|
status_ctx->run_main_level3 = false;
|
|
|
|
status_ctx->run_thread_level1 = false;
|
|
|
|
status_ctx->run_thread_level2 = false;
|
2016-10-16 19:32:43 +02:00
|
|
|
|
|
|
|
return 0;
|
2016-09-19 15:52:01 +02:00
|
|
|
}
|
|
|
|
|
2017-01-06 08:45:40 +01:00
|
|
|
int myabort_checkpoint (hashcat_ctx_t *hashcat_ctx)
|
|
|
|
{
|
|
|
|
status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
|
|
|
|
|
|
|
|
status_ctx->devices_status = STATUS_ABORTED_CHECKPOINT;
|
|
|
|
|
|
|
|
status_ctx->run_main_level1 = false;
|
|
|
|
status_ctx->run_main_level2 = false;
|
|
|
|
status_ctx->run_main_level3 = false;
|
|
|
|
status_ctx->run_thread_level1 = false;
|
|
|
|
status_ctx->run_thread_level2 = false;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-05-05 22:53:04 +02:00
|
|
|
int myabort_finish (hashcat_ctx_t *hashcat_ctx)
|
|
|
|
{
|
|
|
|
status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
|
|
|
|
|
|
|
|
status_ctx->devices_status = STATUS_ABORTED_FINISH;
|
|
|
|
|
|
|
|
status_ctx->run_main_level1 = false;
|
|
|
|
status_ctx->run_main_level2 = false;
|
|
|
|
status_ctx->run_main_level3 = false;
|
|
|
|
status_ctx->run_thread_level1 = false;
|
|
|
|
status_ctx->run_thread_level2 = false;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-01-06 08:45:40 +01:00
|
|
|
int myabort_runtime (hashcat_ctx_t *hashcat_ctx)
|
|
|
|
{
|
|
|
|
status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
|
|
|
|
|
|
|
|
status_ctx->devices_status = STATUS_ABORTED_RUNTIME;
|
|
|
|
|
|
|
|
status_ctx->run_main_level1 = false;
|
|
|
|
status_ctx->run_main_level2 = false;
|
|
|
|
status_ctx->run_main_level3 = false;
|
|
|
|
status_ctx->run_thread_level1 = false;
|
|
|
|
status_ctx->run_thread_level2 = false;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-10-16 19:32:43 +02:00
|
|
|
int myabort (hashcat_ctx_t *hashcat_ctx)
|
2016-09-12 12:59:40 +02:00
|
|
|
{
|
2016-10-09 22:41:55 +02:00
|
|
|
status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
|
|
|
|
|
2016-09-30 13:40:43 +02:00
|
|
|
//those checks create problems in benchmark mode, it's simply too short of a timeframe where it's running as STATUS_RUNNING
|
2016-10-16 19:32:43 +02:00
|
|
|
// not sure if this is still valid, but abort is also called by gpu temp monitor
|
2016-09-30 13:40:43 +02:00
|
|
|
//if (status_ctx->devices_status != STATUS_RUNNING) return;
|
2016-09-19 15:52:01 +02:00
|
|
|
|
2016-09-29 23:25:29 +02:00
|
|
|
status_ctx->devices_status = STATUS_ABORTED;
|
2016-09-19 15:52:01 +02:00
|
|
|
|
2016-10-14 19:25:13 +02:00
|
|
|
status_ctx->run_main_level1 = false;
|
2016-09-29 23:25:29 +02:00
|
|
|
status_ctx->run_main_level2 = false;
|
|
|
|
status_ctx->run_main_level3 = false;
|
|
|
|
status_ctx->run_thread_level1 = false;
|
|
|
|
status_ctx->run_thread_level2 = false;
|
2016-10-16 19:32:43 +02:00
|
|
|
|
|
|
|
return 0;
|
2016-09-12 12:59:40 +02:00
|
|
|
}
|
|
|
|
|
2016-10-16 19:32:43 +02:00
|
|
|
int myquit (hashcat_ctx_t *hashcat_ctx)
|
2016-09-12 12:59:40 +02:00
|
|
|
{
|
2016-10-09 22:41:55 +02:00
|
|
|
status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
|
|
|
|
|
2016-10-30 16:05:00 +01:00
|
|
|
if (status_ctx->devices_status != STATUS_RUNNING && status_ctx->devices_status != STATUS_PAUSED) return -1;
|
2016-09-19 15:52:01 +02:00
|
|
|
|
2016-09-29 23:25:29 +02:00
|
|
|
status_ctx->devices_status = STATUS_QUIT;
|
2016-09-19 15:52:01 +02:00
|
|
|
|
2016-10-14 19:25:13 +02:00
|
|
|
status_ctx->run_main_level1 = false;
|
2016-09-29 23:25:29 +02:00
|
|
|
status_ctx->run_main_level2 = false;
|
|
|
|
status_ctx->run_main_level3 = false;
|
|
|
|
status_ctx->run_thread_level1 = false;
|
|
|
|
status_ctx->run_thread_level2 = false;
|
2016-10-16 19:32:43 +02:00
|
|
|
|
|
|
|
return 0;
|
2016-09-19 15:52:01 +02:00
|
|
|
}
|
|
|
|
|
2016-10-16 19:32:43 +02:00
|
|
|
int bypass (hashcat_ctx_t *hashcat_ctx)
|
2016-09-19 15:52:01 +02:00
|
|
|
{
|
2016-10-09 22:41:55 +02:00
|
|
|
status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
|
|
|
|
|
2016-10-16 19:32:43 +02:00
|
|
|
if (status_ctx->devices_status != STATUS_RUNNING) return -1;
|
2016-09-19 15:52:01 +02:00
|
|
|
|
2016-09-29 23:25:29 +02:00
|
|
|
status_ctx->devices_status = STATUS_BYPASS;
|
2016-09-19 15:52:01 +02:00
|
|
|
|
2016-10-14 19:25:13 +02:00
|
|
|
status_ctx->run_main_level1 = true;
|
2016-09-29 23:25:29 +02:00
|
|
|
status_ctx->run_main_level2 = true;
|
|
|
|
status_ctx->run_main_level3 = true;
|
|
|
|
status_ctx->run_thread_level1 = false;
|
|
|
|
status_ctx->run_thread_level2 = false;
|
2016-10-16 19:32:43 +02:00
|
|
|
|
2021-05-05 22:53:04 +02:00
|
|
|
status_ctx->checkpoint_shutdown = false;
|
|
|
|
status_ctx->finish_shutdown = false;
|
|
|
|
|
2016-10-16 19:32:43 +02:00
|
|
|
return 0;
|
2016-09-12 12:59:40 +02:00
|
|
|
}
|
2016-09-14 20:22:38 +02:00
|
|
|
|
2016-10-16 19:32:43 +02:00
|
|
|
int SuspendThreads (hashcat_ctx_t *hashcat_ctx)
|
2016-09-14 20:22:38 +02:00
|
|
|
{
|
2016-10-09 22:41:55 +02:00
|
|
|
status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
|
|
|
|
|
2016-10-16 19:32:43 +02:00
|
|
|
if (status_ctx->devices_status != STATUS_RUNNING) return -1;
|
2016-09-14 20:22:38 +02:00
|
|
|
|
2016-09-29 23:49:33 +02:00
|
|
|
hc_timer_set (&status_ctx->timer_paused);
|
2016-09-14 20:22:38 +02:00
|
|
|
|
2016-09-29 23:25:29 +02:00
|
|
|
status_ctx->devices_status = STATUS_PAUSED;
|
2016-10-16 19:32:43 +02:00
|
|
|
|
|
|
|
return 0;
|
2016-09-14 20:22:38 +02:00
|
|
|
}
|
|
|
|
|
2016-10-16 19:32:43 +02:00
|
|
|
int ResumeThreads (hashcat_ctx_t *hashcat_ctx)
|
2016-09-14 20:22:38 +02:00
|
|
|
{
|
2016-10-09 22:41:55 +02:00
|
|
|
status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
|
|
|
|
|
2016-10-16 19:32:43 +02:00
|
|
|
if (status_ctx->devices_status != STATUS_PAUSED) return -1;
|
2016-09-14 20:22:38 +02:00
|
|
|
|
2016-10-17 13:44:07 +02:00
|
|
|
const double msec_paused = hc_timer_get (status_ctx->timer_paused);
|
2016-09-14 20:22:38 +02:00
|
|
|
|
2016-10-17 13:44:07 +02:00
|
|
|
status_ctx->msec_paused += msec_paused;
|
2016-09-14 20:22:38 +02:00
|
|
|
|
2016-09-29 23:25:29 +02:00
|
|
|
status_ctx->devices_status = STATUS_RUNNING;
|
2016-10-16 19:32:43 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int stop_at_checkpoint (hashcat_ctx_t *hashcat_ctx)
|
|
|
|
{
|
2021-05-05 22:53:04 +02:00
|
|
|
status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
|
2016-10-16 19:32:43 +02:00
|
|
|
|
|
|
|
if (status_ctx->devices_status != STATUS_RUNNING) return -1;
|
|
|
|
|
|
|
|
// this feature only makes sense if --restore-disable was not specified
|
|
|
|
|
|
|
|
restore_ctx_t *restore_ctx = hashcat_ctx->restore_ctx;
|
|
|
|
|
|
|
|
if (restore_ctx->enabled == false)
|
|
|
|
{
|
2017-04-02 09:50:06 +02:00
|
|
|
event_log_warning (hashcat_ctx, "This feature is disabled when --restore-disable is specified.");
|
2016-10-16 19:32:43 +02:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enable or Disable
|
|
|
|
|
2016-10-23 13:38:41 +02:00
|
|
|
if (status_ctx->checkpoint_shutdown == false)
|
2016-10-16 19:32:43 +02:00
|
|
|
{
|
2016-10-23 13:38:41 +02:00
|
|
|
status_ctx->checkpoint_shutdown = true;
|
|
|
|
|
2016-10-16 19:32:43 +02:00
|
|
|
status_ctx->run_main_level1 = false;
|
|
|
|
status_ctx->run_main_level2 = false;
|
|
|
|
status_ctx->run_main_level3 = false;
|
|
|
|
status_ctx->run_thread_level1 = false;
|
|
|
|
status_ctx->run_thread_level2 = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-10-23 13:38:41 +02:00
|
|
|
status_ctx->checkpoint_shutdown = false;
|
|
|
|
|
2016-10-16 19:32:43 +02:00
|
|
|
status_ctx->run_main_level1 = true;
|
|
|
|
status_ctx->run_main_level2 = true;
|
|
|
|
status_ctx->run_main_level3 = true;
|
|
|
|
status_ctx->run_thread_level1 = true;
|
|
|
|
status_ctx->run_thread_level2 = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2016-09-14 20:22:38 +02:00
|
|
|
}
|
2021-05-05 22:53:04 +02:00
|
|
|
|
|
|
|
int finish_after_attack (hashcat_ctx_t *hashcat_ctx)
|
|
|
|
{
|
|
|
|
status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
|
|
|
|
|
|
|
|
if (status_ctx->devices_status != STATUS_RUNNING) return -1;
|
|
|
|
|
|
|
|
// Enable or Disable
|
|
|
|
|
|
|
|
if (status_ctx->finish_shutdown == false)
|
|
|
|
{
|
|
|
|
status_ctx->finish_shutdown = true;
|
|
|
|
|
|
|
|
status_ctx->run_main_level1 = false;
|
|
|
|
status_ctx->run_main_level2 = false;
|
|
|
|
status_ctx->run_main_level3 = false;
|
|
|
|
status_ctx->run_thread_level1 = true;
|
|
|
|
status_ctx->run_thread_level2 = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
status_ctx->finish_shutdown = false;
|
|
|
|
|
|
|
|
status_ctx->run_main_level1 = true;
|
|
|
|
status_ctx->run_main_level2 = true;
|
|
|
|
status_ctx->run_main_level3 = true;
|
|
|
|
status_ctx->run_thread_level1 = true;
|
|
|
|
status_ctx->run_thread_level2 = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|