mirror of
https://github.com/vanhauser-thc/thc-hydra.git
synced 2025-07-05 20:41:39 -07:00
Fix json output in case of connection error to the server
This commit is contained in:
parent
4130079209
commit
7009b6db03
2 changed files with 16 additions and 7 deletions
|
@ -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");
|
||||
|
|
13
hydra.c
13
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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue