From 34131739fe844a85e0df77e2febfebae9c0878bb Mon Sep 17 00:00:00 2001 From: Diadlo Date: Mon, 17 Apr 2017 22:34:04 +0300 Subject: [PATCH 1/3] Remove comparing unsigned value with zero --- hydra.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hydra.c b/hydra.c index 5f1ccac..a338026 100644 --- a/hydra.c +++ b/hydra.c @@ -4151,7 +4151,7 @@ int main(int argc, char *argv[]) { hydra_brains.sent, // tries (long unsigned int) ((elapsed_status - starttime) / 3600), // hours (long unsigned int) (((elapsed_status - starttime) % 3600) / 60), // minutes - (hydra_brains.todo_all + total_redo_count) - hydra_brains.sent <= 0 ? 1 : (hydra_brains.todo_all + total_redo_count) - hydra_brains.sent, // left todo + (hydra_brains.todo_all + total_redo_count) - hydra_brains.sent, // left todo (long unsigned int) (((double) (hydra_brains.todo_all + total_redo_count) - hydra_brains.sent) / ((double) hydra_brains.sent / (elapsed_status - starttime)) ) / 3600, // hours (((long unsigned int) (((double) (hydra_brains.todo_all + total_redo_count) - hydra_brains.sent) / ((double) hydra_brains.sent / (elapsed_status - starttime)) From c760e7e5c5bbe75957e4a4003a14a1bee3a9c86c Mon Sep 17 00:00:00 2001 From: Diadlo Date: Mon, 17 Apr 2017 22:41:12 +0300 Subject: [PATCH 2/3] Fix size of pointer instead of size of data --- hydra-ncp.c | 2 +- hydra.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/hydra-ncp.c b/hydra-ncp.c index 7573e35..f4bc62f 100644 --- a/hydra-ncp.c +++ b/hydra-ncp.c @@ -65,7 +65,7 @@ int start_ncp(int s, char *ip, int port, unsigned char options, char *miscptr, F } memset(context, 0, sizeof(context)); strncpy(context, login, strlen(login)); - strncpy(context + strlen(login), miscptr, sizeof(miscptr) + 1); + strncpy(context + strlen(login), miscptr, sizeof(char) + 1); login = context; } } diff --git a/hydra.c b/hydra.c index a338026..098dfeb 100644 --- a/hydra.c +++ b/hydra.c @@ -3512,7 +3512,7 @@ int main(int argc, char *argv[]) { exit(-1); } // if (countinfile > 60) fprintf(stderr, "[WARNING] the -M option is not working correctly at the moment for target lists > 60!\n"); - hydra_targets = malloc(sizeof(hydra_targets) * (countservers + 2) + 8); + hydra_targets = malloc(sizeof(hydra_target*) * (countservers + 2) + 8); if (hydra_targets == NULL) bail("Could not allocate enough memory for target data"); sizeinfile = size_of_data; @@ -3600,7 +3600,7 @@ int main(int argc, char *argv[]) { four_from = (addr4 & l); l = 1 << (32 - k); hydra_brains.targets = countservers = l; - hydra_targets = malloc(sizeof(hydra_targets) * (l + 2) + 8); + hydra_targets = malloc(sizeof(hydra_target*) * (l + 2) + 8); if (hydra_targets == NULL) bail("Could not allocate enough memory for target data"); i = 0; @@ -3864,7 +3864,7 @@ int main(int argc, char *argv[]) { #endif if (hydra_options.restore == 0) { - hydra_heads = malloc(sizeof(hydra_heads) * hydra_options.max_use); + hydra_heads = malloc(sizeof(hydra_head*) * hydra_options.max_use); target_no = 0; for (i = 0; i < hydra_options.max_use; i++) { hydra_heads[i] = malloc(sizeof(hydra_head)); From 1bf376baa3e5c4e4ed63abbb97629d38c8ec2e0c Mon Sep 17 00:00:00 2001 From: Diadlo Date: Mon, 17 Apr 2017 23:14:21 +0300 Subject: [PATCH 3/3] Refactor hydra_debug function --- hydra.c | 71 ++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 47 insertions(+), 24 deletions(-) diff --git a/hydra.c b/hydra.c index 098dfeb..88ed522 100644 --- a/hydra.c +++ b/hydra.c @@ -660,42 +660,65 @@ void module_usage() { exit(0); } +#define STR_NULL(s) ((s) == NULL ? "(null)" : (s)) + void hydra_debug(int force, char *string) { - int i, active = 0, inactive = 0; + int active = 0; + int inactive = 0; + int i; if (!debug && !force) return; printf("[DEBUG] Code: %s Time: %lu\n", string, (unsigned long int) time(NULL)); printf("[DEBUG] Options: mode %d ssl %d restore %d showAttempt %d tasks %d max_use %d tnp %d tpsal %d tprl %d exit_found %d miscptr %s service %s\n", - hydra_options.mode, hydra_options.ssl, hydra_options.restore, hydra_options.showAttempt, hydra_options.tasks, hydra_options.max_use, - hydra_options.try_null_password, hydra_options.try_password_same_as_login, hydra_options.try_password_reverse_login, hydra_options.exit_found, - hydra_options.miscptr == NULL ? "(null)" : hydra_options.miscptr, hydra_options.service); + hydra_options.mode, hydra_options.ssl, hydra_options.restore, + hydra_options.showAttempt, hydra_options.tasks, hydra_options.max_use, + hydra_options.try_null_password, hydra_options.try_password_same_as_login, + hydra_options.try_password_reverse_login, hydra_options.exit_found, + STR_NULL(hydra_options.miscptr), hydra_options.service); + printf("[DEBUG] Brains: active %d targets %d finished %d todo_all %lu todo %lu sent %lu found %lu countlogin %lu sizelogin %lu countpass %lu sizepass %lu\n", - hydra_brains.active, hydra_brains.targets, hydra_brains.finished, hydra_brains.todo_all + total_redo_count, hydra_brains.todo, hydra_brains.sent, hydra_brains.found, - (unsigned long int) hydra_brains.countlogin, (unsigned long int) hydra_brains.sizelogin, (unsigned long int) hydra_brains.countpass, + hydra_brains.active, hydra_brains.targets, hydra_brains.finished, + hydra_brains.todo_all + total_redo_count, hydra_brains.todo, + hydra_brains.sent, hydra_brains.found, + (unsigned long int) hydra_brains.countlogin, + (unsigned long int) hydra_brains.sizelogin, + (unsigned long int) hydra_brains.countpass, (unsigned long int) hydra_brains.sizepass); - for (i = 0; i < hydra_brains.targets; i++) + + for (i = 0; i < hydra_brains.targets; i++) { + hydra_target* target = hydra_targets[i]; printf ("[DEBUG] Target %d - target %s ip %s login_no %lu pass_no %lu sent %lu pass_state %d redo_state %d (%d redos) use_count %d failed %d done %d fail_count %d login_ptr %s pass_ptr %s\n", - i, hydra_targets[i]->target == NULL ? "(null)" : hydra_targets[i]->target, hydra_address2string(hydra_targets[i]->ip), hydra_targets[i]->login_no, - hydra_targets[i]->pass_no, hydra_targets[i]->sent, hydra_targets[i]->pass_state, hydra_targets[i]->redo_state, hydra_targets[i]->redo, hydra_targets[i]->use_count, hydra_targets[i]->failed, hydra_targets[i]->done, - hydra_targets[i]->fail_count, hydra_targets[i]->login_ptr == NULL ? "(null)" : hydra_targets[i]->login_ptr, - hydra_targets[i]->pass_ptr == NULL ? "(null)" : hydra_targets[i]->pass_ptr); - if (hydra_heads != NULL) { - for (i = 0; i < hydra_options.max_use; i++) - if (hydra_heads[i]->active >= 0) { - printf("[DEBUG] Task %d - pid %d active %d redo %d current_login_ptr %s current_pass_ptr %s\n", - i, (int) hydra_heads[i]->pid, hydra_heads[i]->active, hydra_heads[i]->redo, - hydra_heads[i]->current_login_ptr == NULL ? "(null)" : hydra_heads[i]->current_login_ptr, - hydra_heads[i]->current_pass_ptr == NULL ? "(null)" : hydra_heads[i]->current_pass_ptr); - if (hydra_heads[i]->active == 0) - inactive++; - else - active++; - } - printf("[DEBUG] Tasks %d inactive %d active\n", inactive, active); + i, STR_NULL(target->target), hydra_address2string(target->ip), + target->login_no, target->pass_no, target->sent, + target->pass_state, target->redo_state, target->redo, + target->use_count, target->failed, target->done, + target->fail_count, + STR_NULL(target->login_ptr), + STR_NULL(target->pass_ptr)); } + + if (hydra_heads == NULL) { + return + } + + for (i = 0; i < hydra_options.max_use; i++) { + if (hydra_heads[i]->active >= 0) { + printf("[DEBUG] Task %d - pid %d active %d redo %d current_login_ptr %s current_pass_ptr %s\n", + i, (int) hydra_heads[i]->pid, + hydra_heads[i]->active, + hydra_heads[i]->redo, + STR_NULL(hydra_heads[i]->current_login_ptr), + STR_NULL(hydra_heads[i]->current_pass_ptr)); + if (hydra_heads[i]->active == 0) + inactive++; + else + active++; + } + } + printf("[DEBUG] Tasks %d inactive %d active\n", inactive, active); } void bail(char *text) {