1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-12-23 07:08:19 +00:00

Merge pull request #1719 from philsmd/master

stdin: add read timeout checks (abort if no input for a long time)
This commit is contained in:
Jens Steube 2018-10-17 11:27:04 +02:00 committed by GitHub
commit ab46265f5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 61 additions and 0 deletions

View File

@ -36,6 +36,7 @@
- Increased the maximum size of edata2 in Kerberos 5 TGS-REP etype 23
- Allow hashfile for -m 16800 to be used with -m 16801
- Make the masks parser more restrictive by rejecting a single '?' at the end of the mask (use ?? instead)
- Add a periodic check for read timeouts in stdin/pipe mode and abort if no input was provided
##
## Bugs

View File

@ -6,6 +6,9 @@
#ifndef _MONITOR_H
#define _MONITOR_H
#define STDIN_TIMEOUT_MIN 20 // warn after no input from stdin for x seconds
#define STDIN_TIMEOUT_MAX 120 // abort after no input from stdin for x seconds
int get_runtime_left (const hashcat_ctx_t *hashcat_ctx);
HC_API_CALL void *thread_monitor (void *p);

View File

@ -120,6 +120,8 @@ typedef enum event_identifier
EVENT_MONITOR_THROTTLE2 = 0x00000084,
EVENT_MONITOR_THROTTLE3 = 0x00000085,
EVENT_MONITOR_PERFORMANCE_HINT = 0x00000086,
EVENT_MONITOR_NOINPUT_HINT = 0x00000087,
EVENT_MONITOR_NOINPUT_ABORT = 0x00000088,
EVENT_OPENCL_SESSION_POST = 0x00000090,
EVENT_OPENCL_SESSION_PRE = 0x00000091,
EVENT_OUTERLOOP_FINISHED = 0x000000a0,
@ -2022,6 +2024,12 @@ typedef struct status_ctx
double msec_paused; // timer on current dict
/**
* read timeouts
*/
u32 stdin_read_timeout_cnt;
} status_ctx_t;
typedef struct hashcat_user

View File

@ -179,9 +179,13 @@ static int calc_stdin (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_par
{
if (status_ctx->run_thread_level1 == false) break;
status_ctx->stdin_read_timeout_cnt++;
continue;
}
status_ctx->stdin_read_timeout_cnt = 0;
char *line_buf = fgets (buf, HCBUFSIZ_LARGE - 1, stdin);
if (line_buf == NULL) break;
@ -343,9 +347,13 @@ static int calc_stdin (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_par
{
if (status_ctx->run_thread_level1 == false) break;
status_ctx->stdin_read_timeout_cnt++;
continue;
}
status_ctx->stdin_read_timeout_cnt = 0;
char *line_buf = fgets (buf, HCBUFSIZ_LARGE - 1, stdin);
if (line_buf == NULL) break;

View File

@ -700,6 +700,24 @@ static void main_monitor_performance_hint (MAYBE_UNUSED hashcat_ctx_t *hashcat_c
}
}
static void main_monitor_noinput_hint (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;
if (user_options->quiet == true) return;
event_log_advice (hashcat_ctx, "ATTENTION! Read timeout in stdin mode. The password candidates input is too slow:");
event_log_advice (hashcat_ctx, "* Are you sure that you are using the correct attack mode (--attack-mode or -a)?");
event_log_advice (hashcat_ctx, "* Are you sure that you want to use input from standard input (stdin)?");
event_log_advice (hashcat_ctx, "* If so, are you sure that the input from stdin (the pipe) is working correctly and is fast enough?");
event_log_advice (hashcat_ctx, NULL);
}
static void main_monitor_noinput_abort (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len)
{
event_log_error (hashcat_ctx, "No password candidates received in stdin mode, aborting...");
}
static void main_monitor_temp_abort (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;
@ -952,6 +970,8 @@ static void event (const u32 id, hashcat_ctx_t *hashcat_ctx, const void *buf, co
case EVENT_MONITOR_THROTTLE2: main_monitor_throttle2 (hashcat_ctx, buf, len); break;
case EVENT_MONITOR_THROTTLE3: main_monitor_throttle3 (hashcat_ctx, buf, len); break;
case EVENT_MONITOR_PERFORMANCE_HINT: main_monitor_performance_hint (hashcat_ctx, buf, len); break;
case EVENT_MONITOR_NOINPUT_HINT: main_monitor_noinput_hint (hashcat_ctx, buf, len); break;
case EVENT_MONITOR_NOINPUT_ABORT: main_monitor_noinput_abort (hashcat_ctx, buf, len); break;
case EVENT_OPENCL_SESSION_POST: main_opencl_session_post (hashcat_ctx, buf, len); break;
case EVENT_OPENCL_SESSION_PRE: main_opencl_session_pre (hashcat_ctx, buf, len); break;
case EVENT_OUTERLOOP_FINISHED: main_outerloop_finished (hashcat_ctx, buf, len); break;

View File

@ -282,6 +282,27 @@ static int monitor (hashcat_ctx_t *hashcat_ctx)
if (performance_warnings == 10) EVENT_DATA (EVENT_MONITOR_PERFORMANCE_HINT, NULL, 0);
}
}
// stdin read timeout check
if (status_ctx->stdin_read_timeout_cnt >= STDIN_TIMEOUT_MIN)
{
if (status_ctx->stdin_read_timeout_cnt >= STDIN_TIMEOUT_MAX)
{
EVENT_DATA (EVENT_MONITOR_NOINPUT_ABORT, NULL, 0);
myabort (hashcat_ctx);
status_ctx->shutdown_inner = true;
break;
}
if ((status_ctx->stdin_read_timeout_cnt % STDIN_TIMEOUT_MIN) == 0)
{
EVENT_DATA (EVENT_MONITOR_NOINPUT_HINT, NULL, 0);
}
}
}
// final round of save_hash