From 7009b6db0390b600084b37f4b87fbdbf9a07dd31 Mon Sep 17 00:00:00 2001 From: David Maciejak Date: Fri, 14 Jun 2019 13:33:11 +0800 Subject: [PATCH] Fix json output in case of connection error to the server --- hydra-redis.c | 10 +++++----- hydra.c | 13 +++++++++++-- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/hydra-redis.c b/hydra-redis.c index a2b9757..c230453 100644 --- a/hydra-redis.c +++ b/hydra-redis.c @@ -129,7 +129,7 @@ int32_t service_redis_init(char *ip, int32_t sp, unsigned char options, char *mi // performed once only. // return codes: // 0 - when the server is redis and it requires password - // 1 - when the server is not redis or when the server does not require password + // n - when the server is not redis or when the server does not require password int32_t sock = -1; int32_t myport = PORT_REDIS, mysslport = PORT_REDIS_SSL; @@ -151,7 +151,7 @@ int32_t service_redis_init(char *ip, int32_t sp, unsigned char options, char *mi printf("[VERBOSE] Initial redis password authentication test and response test ...\n"); if (sock < 0) { hydra_report(stderr, "[ERROR] Can not connect to port %d on the target\n", myport); - hydra_child_exit(1); + return 3; } // generating ping request as redis-cli if (debug) @@ -161,7 +161,7 @@ int32_t service_redis_init(char *ip, int32_t sp, unsigned char options, char *mi // $4 // ping if (hydra_send(sock, buffer, strlen(buffer), 0) < 0) { - return 1; + return 2; } buf = hydra_receive_line(sock); if (debug) @@ -170,13 +170,13 @@ int32_t service_redis_init(char *ip, int32_t sp, unsigned char options, char *mi if (strstr(buf, "+PONG") != NULL) { // the server does not require password hydra_report(stderr, "[!] The server %s does not require password.\n", hostname); free(buf); - return 1; + return 2; } // server response test if (strstr(buf, "-NOAUTH Authentication required") == NULL && strstr(buf, "-ERR operation not permitted") == NULL) { hydra_report(stderr, "[ERROR] The server is not redis, exit.\n"); free(buf); - return 1; + return 2; } if (verbose) printf("[VERBOSE] The redis server requires password.\n"); diff --git a/hydra.c b/hydra.c index a0735f0..288712b 100644 --- a/hydra.c +++ b/hydra.c @@ -1127,8 +1127,17 @@ void hydra_service_init(int32_t target_no) { else hydra_targets[target_no]->done = TARGET_ERROR; hydra_brains.finished++; - if (hydra_brains.targets == 1) + if (hydra_brains.targets == 1) { + if (hydra_brains.ofp != NULL && hydra_brains.ofp != stdout) { + if (hydra_options.outfile_format == FORMAT_JSONV1) { + char json_error[120]; + snprintf(json_error, sizeof(json_error), "[ERROR] unexpected result connecting to target %s port %d", hydra_address2string_beautiful(t->ip), t->port); + fprintf(hydra_brains.ofp, "\n\t],\n\"success\": false,\n\"errormessages\": [ \"%s\" ],\n\"quantityfound\": %lu }\n", json_error, hydra_brains.found); + } + fclose(hydra_brains.ofp); + } exit(-1); + } } } @@ -3741,7 +3750,7 @@ int main(int argc, char *argv[]) { for (head_no = 0; head_no < hydra_options.max_use; head_no++) { if (debug > 1 && hydra_heads[head_no]->active != HEAD_DISABLED) printf("[DEBUG] head_no[%d] to target_no %d active %d\n", head_no, hydra_heads[head_no]->target_no, hydra_heads[head_no]->active); - + switch (hydra_heads[head_no]->active) { case HEAD_DISABLED: break;