From 386efb7fb5e2cf0cc26eb759a1a63380d1857926 Mon Sep 17 00:00:00 2001 From: jsteube Date: Wed, 12 Oct 2016 11:27:10 +0200 Subject: [PATCH] Make use of EVENT_CRACKER_HASH_CRACKED, do not print a cracked hash to stdout directly, let the client do it --- include/event.h | 6 +- include/hashcat.h | 2 +- include/outfile.h | 2 +- include/types.h | 2 +- src/event.c | 6 +- src/hashcat.c | 2 +- src/hashes.c | 6 +- src/main.c | 188 +++++++++++++++++----------------------------- src/outfile.c | 27 +++---- src/potfile.c | 24 +++++- 10 files changed, 112 insertions(+), 153 deletions(-) diff --git a/include/event.h b/include/event.h index f3c8d42f9..cac3d15e1 100644 --- a/include/event.h +++ b/include/event.h @@ -9,10 +9,10 @@ #include #include -int event_call (const u32 id, hashcat_ctx_t *hashcat_ctx, const void *buf, const size_t len); +void event_call (const u32 id, hashcat_ctx_t *hashcat_ctx, const void *buf, const size_t len); -#define EVENT(id) { const int rc_event = event_call ((id), hashcat_ctx, NULL, 0); if (rc_event == -1) return -1; } -#define EVENT_DATA(id,buf,len) { const int rc_event = event_call ((id), hashcat_ctx, (buf), (len)); if (rc_event == -1) return -1; } +#define EVENT(id) event_call ((id), hashcat_ctx, NULL, 0) +#define EVENT_DATA(id,buf,len) event_call ((id), hashcat_ctx, (buf), (len)) size_t event_log_info_nn (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...); size_t event_log_warning_nn (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...); diff --git a/include/hashcat.h b/include/hashcat.h index 0e01c74d6..3953cecd0 100644 --- a/include/hashcat.h +++ b/include/hashcat.h @@ -8,7 +8,7 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_folder, int argc, char **argv, const int comptime); -void hashcat_ctx_init (hashcat_ctx_t *hashcat_ctx, int (*event) (const u32, struct hashcat_ctx *, const void *, const size_t)); +void 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 diff --git a/include/outfile.h b/include/outfile.h index af88cb4fc..965c95da1 100644 --- a/include/outfile.h +++ b/include/outfile.h @@ -18,7 +18,7 @@ int outfile_init (hashcat_ctx_t *hashcat_ctx); void outfile_destroy (hashcat_ctx_t *hashcat_ctx); int outfile_write_open (hashcat_ctx_t *hashcat_ctx); void outfile_write_close (hashcat_ctx_t *hashcat_ctx); -void outfile_write (hashcat_ctx_t *hashcat_ctx, const char *out_buf, const unsigned char *plain_ptr, const u32 plain_len, const u64 crackpos, const unsigned char *username, const u32 user_len); +int outfile_write (hashcat_ctx_t *hashcat_ctx, const char *out_buf, const unsigned char *plain_ptr, const u32 plain_len, const u64 crackpos, const unsigned char *username, const u32 user_len, char tmp_buf[HCBUFSIZ_LARGE]); int outfile_and_hashfile (hashcat_ctx_t *hashcat_ctx); #endif // _OUTFILE_H diff --git a/include/types.h b/include/types.h index 5ed9149d7..936c1e06c 100644 --- a/include/types.h +++ b/include/types.h @@ -1435,7 +1435,7 @@ typedef struct hashcat_ctx user_options_t *user_options; wl_data_t *wl_data; - int (*event) (const u32, struct hashcat_ctx *, const void *, const size_t); + void (*event) (const u32, struct hashcat_ctx *, const void *, const size_t); } hashcat_ctx_t; diff --git a/src/event.c b/src/event.c index 60a1fd672..63195d520 100644 --- a/src/event.c +++ b/src/event.c @@ -8,7 +8,7 @@ #include "thread.h" #include "event.h" -int event_call (const u32 id, hashcat_ctx_t *hashcat_ctx, const void *buf, const size_t len) +void event_call (const u32 id, hashcat_ctx_t *hashcat_ctx, const void *buf, const size_t len) { bool need_mux = true; @@ -26,7 +26,7 @@ int event_call (const u32 id, hashcat_ctx_t *hashcat_ctx, const void *buf, const hc_thread_mutex_lock (event_ctx->mux_event); } - const int rc = hashcat_ctx->event (id, hashcat_ctx, buf, len); + hashcat_ctx->event (id, hashcat_ctx, buf, len); if (need_mux == true) { @@ -34,8 +34,6 @@ int event_call (const u32 id, hashcat_ctx_t *hashcat_ctx, const void *buf, const hc_thread_mutex_unlock (event_ctx->mux_event); } - - return rc; } static int event_log (const char *fmt, va_list ap, char *s, const size_t sz) diff --git a/src/hashcat.c b/src/hashcat.c index 15832edb7..c3aff6a30 100644 --- a/src/hashcat.c +++ b/src/hashcat.c @@ -55,7 +55,7 @@ extern const u32 DEFAULT_BENCHMARK_ALGORITHMS_CNT; extern const u32 DEFAULT_BENCHMARK_ALGORITHMS_BUF[]; -void hashcat_ctx_init (hashcat_ctx_t *hashcat_ctx, int (*event) (const u32, struct hashcat_ctx *, const void *, const size_t)) +void hashcat_ctx_init (hashcat_ctx_t *hashcat_ctx, void (*event) (const u32, struct hashcat_ctx *, const void *, const size_t)) { if (event == NULL) { diff --git a/src/hashes.c b/src/hashes.c index 496f25174..b70af831f 100644 --- a/src/hashes.c +++ b/src/hashes.c @@ -272,10 +272,14 @@ void check_hash (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, pl if (outfile_ctx->filename == NULL) if (user_options->quiet == false) clear_prompt (); - outfile_write (hashcat_ctx, out_buf, plain_ptr, plain_len, crackpos, NULL, 0); + char tmp_buf[HCBUFSIZ_LARGE]; + + const int tmp_len = outfile_write (hashcat_ctx, out_buf, plain_ptr, plain_len, crackpos, NULL, 0, tmp_buf); outfile_write_close (hashcat_ctx); + EVENT_DATA (EVENT_CRACKER_HASH_CRACKED, tmp_buf, tmp_len); + if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) { if ((status_ctx->devices_status != STATUS_CRACKED) && (user_options->status != true)) diff --git a/src/main.c b/src/main.c index 88ef3ba8a..d062d9141 100644 --- a/src/main.c +++ b/src/main.c @@ -60,36 +60,30 @@ static void main_log (hashcat_ctx_t *hashcat_ctx, const char *buf, const size_t fflush (fp); } -static int main_log_info (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +static void main_log_info (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) { main_log (hashcat_ctx, buf, len, stdout); - - return 0; } -static int main_log_warning (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +static void main_log_warning (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) { static const char PREFIX_WARNING[] = "WARNING: "; fwrite (PREFIX_WARNING, sizeof (PREFIX_WARNING), 1, stdout); main_log (hashcat_ctx, buf, len, stdout); - - return 0; } -static int main_log_error (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +static void main_log_error (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) { static const char PREFIX_ERROR[] = "ERROR: "; fwrite (PREFIX_ERROR, sizeof (PREFIX_ERROR), 1, stderr); main_log (hashcat_ctx, buf, len, stderr); - - return 0; } -static int main_welcome_screen (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +static void main_welcome_screen (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) { // sets dos window size (windows only) @@ -100,22 +94,18 @@ static int main_welcome_screen (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_U const status_ctx_t *status_ctx = hashcat_ctx->status_ctx; welcome_screen (hashcat_ctx, status_ctx->proc_start, VERSION_TAG); - - return 0; } -static int main_goodbye_screen (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +static void main_goodbye_screen (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) { // Inform user we're done const status_ctx_t *status_ctx = hashcat_ctx->status_ctx; goodbye_screen (hashcat_ctx, status_ctx->proc_start, status_ctx->proc_stop); - - return 0; } -static int main_outerloop_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; @@ -144,11 +134,9 @@ static int main_outerloop_starting (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAY hashcat_user->outer_threads_cnt++; } } - - return 0; } -static int main_outerloop_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; @@ -165,16 +153,14 @@ static int main_outerloop_finished (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAY hcfree (hashcat_user->outer_threads); hashcat_user->outer_threads_cnt = 0; - - return 0; } -static int main_cracker_starting (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +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; const user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; - if (user_options->quiet == true) return 0; + if (user_options->quiet == true) return; // Tell the user we're about to start @@ -190,11 +176,9 @@ static int main_cracker_starting (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE event_log_info (hashcat_ctx, "Starting attack in stdin mode..."); event_log_info (hashcat_ctx, ""); } - - return 0; } -static int main_cracker_finished (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +static void main_cracker_finished (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) { const hashes_t *hashes = hashcat_ctx->hashes; const user_options_t *user_options = hashcat_ctx->user_options; @@ -232,62 +216,52 @@ static int main_cracker_finished (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE } } } - - return 0; } -static int main_cracker_hash_cracked (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +static void main_cracker_hash_cracked (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) { - const hashes_t *hashes = hashcat_ctx->hashes; - const user_options_t *user_options = hashcat_ctx->user_options; + outfile_ctx_t *outfile_ctx = hashcat_ctx->outfile_ctx; - if (hashes == NULL) hashes = NULL; - if (user_options == NULL) user_options = NULL; + if (outfile_ctx->fp != NULL) return; // cracked hash was not written to an outfile - return 0; + fwrite (buf, len, 1, stdout); + fwrite (EOL, sizeof (EOL), 1, stdout); } -static int main_calculated_words_base (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +static void main_calculated_words_base (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) { const status_ctx_t *status_ctx = hashcat_ctx->status_ctx; const user_options_t *user_options = hashcat_ctx->user_options; - if (user_options->keyspace == true) - { - event_log_info (hashcat_ctx, "%" PRIu64 "", status_ctx->words_base); - } + if (user_options->keyspace == false) return; - return 0; + event_log_info (hashcat_ctx, "%" PRIu64 "", status_ctx->words_base); } -static int main_potfile_remove_parse_pre (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +static void main_potfile_remove_parse_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; - if (user_options->quiet == true) return 0; + if (user_options->quiet == true) return; event_log_info_nn (hashcat_ctx, "Comparing hashes with potfile entries..."); - - return 0; } -static int main_potfile_remove_parse_post (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +static void main_potfile_remove_parse_post (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 0; + if (user_options->quiet == true) return; event_log_info_nn (hashcat_ctx, "Compared hashes with potfile entries..."); - - return 0; } -static int main_potfile_num_cracked (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +static void main_potfile_num_cracked (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 hashes_t *hashes = hashcat_ctx->hashes; - if (user_options->quiet == true) return 0; + if (user_options->quiet == true) return; const int potfile_remove_cracks = hashes->digests_done; @@ -304,23 +278,19 @@ static int main_potfile_num_cracked (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MA event_log_info (hashcat_ctx, ""); } } - - return 0; } -static int main_potfile_all_cracked (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +static void main_potfile_all_cracked (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 0; + if (user_options->quiet == true) return; event_log_info (hashcat_ctx, "INFO: All hashes found in potfile! You can use --show to display them."); event_log_info (hashcat_ctx, ""); - - return 0; } -static int main_outerloop_mainscreen (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +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; @@ -344,7 +314,7 @@ static int main_outerloop_mainscreen (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, M } } - if (user_options->quiet == true) return 0; + 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); @@ -402,81 +372,67 @@ static int main_outerloop_mainscreen (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, M #if defined (DEBUG) if (user_options->benchmark == true) event_log_info (hashcat_ctx, "Hashmode: %d", hashconfig->hash_mode); #endif - - return 0; } -static int main_opencl_session_pre (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +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; - if (user_options->quiet == true) return 0; + if (user_options->quiet == true) return; event_log_info_nn (hashcat_ctx, "Initializing device kernels and memory..."); - - return 0; } -static int main_opencl_session_post (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +static void main_opencl_session_post (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 0; + if (user_options->quiet == true) return; event_log_info_nn (hashcat_ctx, "Initialized device kernels and memory..."); - - return 0; } -static int main_weak_hash_pre (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +static void main_weak_hash_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; - if (user_options->quiet == true) return 0; + if (user_options->quiet == true) return; event_log_info_nn (hashcat_ctx, "Checking for weak hashes..."); - - return 0; } -static int main_weak_hash_post (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +static void main_weak_hash_post (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 0; + if (user_options->quiet == true) return; event_log_info_nn (hashcat_ctx, "Checked for weak hashes..."); - - return 0; } -static int main_bitmap_init_pre (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +static void main_bitmap_init_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; - if (user_options->quiet == true) return 0; + if (user_options->quiet == true) return; event_log_info_nn (hashcat_ctx, "Generating bitmap tables..."); - - return 0; } -static int main_bitmap_init_post (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +static void main_bitmap_init_post (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 0; + if (user_options->quiet == true) return; event_log_info_nn (hashcat_ctx, "Generated bitmap tables..."); - - return 0; } -static int main_set_kernel_power_final (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +static void main_set_kernel_power_final (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 0; + if (user_options->quiet == true) return; clear_prompt (); @@ -484,55 +440,45 @@ static int main_set_kernel_power_final (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, event_log_info (hashcat_ctx, ""); send_prompt (); - - return 0; } -int event (const u32 id, hashcat_ctx_t *hashcat_ctx, const void *buf, const size_t len) +void event (const u32 id, hashcat_ctx_t *hashcat_ctx, const void *buf, const size_t len) { - int rc = 0; - switch (id) { - case EVENT_LOG_INFO: rc = main_log_info (hashcat_ctx, buf, len); break; - case EVENT_LOG_WARNING: rc = main_log_warning (hashcat_ctx, buf, len); break; - case EVENT_LOG_ERROR: rc = main_log_error (hashcat_ctx, buf, len); break; - case EVENT_WELCOME_SCREEN: rc = main_welcome_screen (hashcat_ctx, buf, len); break; - case EVENT_GOODBYE_SCREEN: rc = main_goodbye_screen (hashcat_ctx, buf, len); break; - case EVENT_OUTERLOOP_STARTING: rc = main_outerloop_starting (hashcat_ctx, buf, len); break; - case EVENT_OUTERLOOP_FINISHED: rc = main_outerloop_finished (hashcat_ctx, buf, len); break; - case EVENT_OUTERLOOP_MAINSCREEN: rc = main_outerloop_mainscreen (hashcat_ctx, buf, len); break; - case EVENT_CRACKER_STARTING: rc = main_cracker_starting (hashcat_ctx, buf, len); break; - case EVENT_CRACKER_FINISHED: rc = main_cracker_finished (hashcat_ctx, buf, len); break; - case EVENT_CRACKER_HASH_CRACKED: rc = main_cracker_hash_cracked (hashcat_ctx, buf, len); break; - case EVENT_CALCULATED_WORDS_BASE: rc = main_calculated_words_base (hashcat_ctx, buf, len); break; - case EVENT_POTFILE_REMOVE_PARSE_PRE: rc = main_potfile_remove_parse_pre (hashcat_ctx, buf, len); break; - case EVENT_POTFILE_REMOVE_PARSE_POST: rc = main_potfile_remove_parse_post (hashcat_ctx, buf, len); break; - case EVENT_POTFILE_NUM_CRACKED: rc = main_potfile_num_cracked (hashcat_ctx, buf, len); break; - case EVENT_POTFILE_ALL_CRACKED: rc = main_potfile_all_cracked (hashcat_ctx, buf, len); break; - case EVENT_OPENCL_SESSION_PRE: rc = main_opencl_session_pre (hashcat_ctx, buf, len); break; - case EVENT_OPENCL_SESSION_POST: rc = main_opencl_session_post (hashcat_ctx, buf, len); break; - case EVENT_BITMAP_INIT_PRE: rc = main_bitmap_init_pre (hashcat_ctx, buf, len); break; - case EVENT_BITMAP_INIT_POST: rc = main_bitmap_init_post (hashcat_ctx, buf, len); break; - case EVENT_WEAK_HASH_PRE: rc = main_weak_hash_pre (hashcat_ctx, buf, len); break; - case EVENT_WEAK_HASH_POST: rc = main_weak_hash_post (hashcat_ctx, buf, len); break; - case EVENT_SET_KERNEL_POWER_FINAL: rc = main_set_kernel_power_final (hashcat_ctx, buf, len); break; + case EVENT_LOG_INFO: main_log_info (hashcat_ctx, buf, len); break; + case EVENT_LOG_WARNING: main_log_warning (hashcat_ctx, buf, len); break; + 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_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; + case EVENT_CALCULATED_WORDS_BASE: main_calculated_words_base (hashcat_ctx, buf, len); break; + case EVENT_POTFILE_REMOVE_PARSE_PRE: main_potfile_remove_parse_pre (hashcat_ctx, buf, len); break; + case EVENT_POTFILE_REMOVE_PARSE_POST: main_potfile_remove_parse_post (hashcat_ctx, buf, len); break; + case EVENT_POTFILE_NUM_CRACKED: main_potfile_num_cracked (hashcat_ctx, buf, len); break; + case EVENT_POTFILE_ALL_CRACKED: main_potfile_all_cracked (hashcat_ctx, buf, len); break; + case EVENT_OPENCL_SESSION_PRE: main_opencl_session_pre (hashcat_ctx, buf, len); break; + case EVENT_OPENCL_SESSION_POST: main_opencl_session_post (hashcat_ctx, buf, len); break; + case EVENT_BITMAP_INIT_PRE: main_bitmap_init_pre (hashcat_ctx, buf, len); break; + case EVENT_BITMAP_INIT_POST: main_bitmap_init_post (hashcat_ctx, buf, len); break; + case EVENT_WEAK_HASH_PRE: main_weak_hash_pre (hashcat_ctx, buf, len); break; + case EVENT_WEAK_HASH_POST: main_weak_hash_post (hashcat_ctx, buf, len); break; + case EVENT_SET_KERNEL_POWER_FINAL: main_set_kernel_power_final (hashcat_ctx, buf, len); break; } - - return rc; } #else -int event (const u32 id, hashcat_ctx_t *hashcat_ctx, const void *buf, const size_t len) +void event (const u32 id, hashcat_ctx_t *hashcat_ctx, const void *buf, const size_t len) { - int rc = 0; - switch (id) { } - - return rc; } #endif diff --git a/src/outfile.c b/src/outfile.c index 29f13cacd..afb568be1 100644 --- a/src/outfile.c +++ b/src/outfile.c @@ -262,17 +262,8 @@ int outfile_init (hashcat_ctx_t *hashcat_ctx) outfile_ctx_t *outfile_ctx = hashcat_ctx->outfile_ctx; user_options_t *user_options = hashcat_ctx->user_options; - if (user_options->outfile == NULL) - { - outfile_ctx->fp = stdout; - outfile_ctx->filename = NULL; - } - else - { - outfile_ctx->fp = NULL; - outfile_ctx->filename = user_options->outfile; - } - + outfile_ctx->fp = NULL; + outfile_ctx->filename = user_options->outfile; outfile_ctx->outfile_format = user_options->outfile_format; outfile_ctx->outfile_autohex = user_options->outfile_autohex; @@ -312,18 +303,17 @@ void outfile_write_close (hashcat_ctx_t *hashcat_ctx) { outfile_ctx_t *outfile_ctx = hashcat_ctx->outfile_ctx; - if (outfile_ctx->fp == stdout) return; + if (outfile_ctx->fp == NULL) return; fclose (outfile_ctx->fp); } -void outfile_write (hashcat_ctx_t *hashcat_ctx, const char *out_buf, const unsigned char *plain_ptr, const u32 plain_len, const u64 crackpos, const unsigned char *username, const u32 user_len) +int outfile_write (hashcat_ctx_t *hashcat_ctx, const char *out_buf, const unsigned char *plain_ptr, const u32 plain_len, const u64 crackpos, const unsigned char *username, const u32 user_len, char tmp_buf[HCBUFSIZ_LARGE]) { const hashconfig_t *hashconfig = hashcat_ctx->hashconfig; const outfile_ctx_t *outfile_ctx = hashcat_ctx->outfile_ctx; - char tmp_buf[HCBUFSIZ_LARGE]; - int tmp_len = 0; + int tmp_len = 0; if (outfile_ctx->outfile_format & OUTFILE_FMT_HASH) { @@ -412,7 +402,12 @@ void outfile_write (hashcat_ctx_t *hashcat_ctx, const char *out_buf, const unsig tmp_buf[tmp_len] = 0; - fprintf (outfile_ctx->fp, "%s" EOL, tmp_buf); + if (outfile_ctx->fp) + { + fprintf (outfile_ctx->fp, "%s" EOL, tmp_buf); + } + + return tmp_len; } int outfile_and_hashfile (hashcat_ctx_t *hashcat_ctx) diff --git a/src/potfile.c b/src/potfile.c index 39f5d40e9..80603c80e 100644 --- a/src/potfile.c +++ b/src/potfile.c @@ -523,7 +523,11 @@ void potfile_show_request (hashcat_ctx_t *hashcat_ctx, char *input_buf, int inpu // do output the line - outfile_write (hashcat_ctx, input_buf, (const unsigned char *) pot_ptr->plain_buf, pot_ptr->plain_len, 0, username, user_len); + char tmp_buf[HCBUFSIZ_LARGE]; + + const int tmp_len = outfile_write (hashcat_ctx, input_buf, (const unsigned char *) pot_ptr->plain_buf, pot_ptr->plain_len, 0, username, user_len, tmp_buf); + + EVENT_DATA (EVENT_CRACKER_HASH_CRACKED, tmp_buf, tmp_len); } } @@ -546,7 +550,11 @@ void potfile_left_request (hashcat_ctx_t *hashcat_ctx, char *input_buf, int inpu input_buf[input_len] = 0; - outfile_write (hashcat_ctx, input_buf, NULL, 0, 0, NULL, 0); + char tmp_buf[HCBUFSIZ_LARGE]; + + const int tmp_len = outfile_write (hashcat_ctx, input_buf, NULL, 0, 0, NULL, 0, tmp_buf); + + EVENT_DATA (EVENT_CRACKER_HASH_CRACKED, tmp_buf, tmp_len); } } @@ -667,7 +675,11 @@ void potfile_show_request_lm (hashcat_ctx_t *hashcat_ctx, char *input_buf, int i // do output the line - outfile_write (hashcat_ctx, input_buf, (unsigned char *) pot_ptr.plain_buf, pot_ptr.plain_len, 0, username, user_len); + char tmp_buf[HCBUFSIZ_LARGE]; + + const int tmp_len = outfile_write (hashcat_ctx, input_buf, (unsigned char *) pot_ptr.plain_buf, pot_ptr.plain_len, 0, username, user_len, tmp_buf); + + EVENT_DATA (EVENT_CRACKER_HASH_CRACKED, tmp_buf, tmp_len); if (weak_hash_found == 1) hcfree (pot_right_ptr); @@ -753,7 +765,11 @@ void potfile_left_request_lm (hashcat_ctx_t *hashcat_ctx, char *input_buf, int i hash_output[user_len + 16] = 0; } - outfile_write (hashcat_ctx, hash_output, NULL, 0, 0, NULL, 0); + char tmp_buf[HCBUFSIZ_LARGE]; + + const int tmp_len = outfile_write (hashcat_ctx, hash_output, NULL, 0, 0, NULL, 0, tmp_buf); + + EVENT_DATA (EVENT_CRACKER_HASH_CRACKED, tmp_buf, tmp_len); hcfree (hash_output);