From 4ab31cd18e8e35257e47efd90d67f9969f9f7c98 Mon Sep 17 00:00:00 2001 From: van Hauser Date: Thu, 6 Jul 2017 22:34:55 +0200 Subject: [PATCH] ipv6 pretty print --- hydra-firebird.c | 1 - hydra-http-proxy-urlenum.c | 4 ++-- hydra-mod.c | 23 +++++++++++++++++++++++ hydra-postgres.c | 1 - hydra-ssh.c | 8 ++++---- hydra-svn.c | 5 +---- hydra.c | 3 ++- 7 files changed, 32 insertions(+), 13 deletions(-) diff --git a/hydra-firebird.c b/hydra-firebird.c index fbcad69..1b5228b 100644 --- a/hydra-firebird.c +++ b/hydra-firebird.c @@ -1,4 +1,3 @@ - /* Firebird Support - by David Maciejak @ GMAIL dot com diff --git a/hydra-http-proxy-urlenum.c b/hydra-http-proxy-urlenum.c index ae6097f..5abaaea 100644 --- a/hydra-http-proxy-urlenum.c +++ b/hydra-http-proxy-urlenum.c @@ -210,8 +210,8 @@ int32_t start_http_proxy_urlenum(int32_t s, char *ip, int32_t port, unsigned cha if (*ptr == '2' || (*ptr == '3' && (*(ptr + 2) == '1' || *(ptr + 2) == '2')) || strncmp(ptr, "404", 4) == 0 || strncmp(ptr, "403", 4) == 0) { hydra_report_found_host(port, ip, "http-proxy", fp); if (fp != stdout) - fprintf(fp, "[%d][http-proxy-urlenum] host: %s url: %s\n", port, hydra_address2string(ip), url); - printf("[%d][http-proxy-urlenum] host: %s url: %s\n", port, hydra_address2string(ip), url); + fprintf(fp, "[%d][http-proxy-urlenum] host: %s url: %s\n", port, hydra_address2string_beautiful(ip), url); + printf("[%d][http-proxy-urlenum] host: %s url: %s\n", port, hydra_address2string_beautiful(ip), url); hydra_completed_pair_found(); } else { if (strncmp(ptr, "407", 3) == 0 /*|| strncmp(ptr, "401", 3) == 0 */ ) { diff --git a/hydra-mod.c b/hydra-mod.c index b87a07c..2f86963 100644 --- a/hydra-mod.c +++ b/hydra-mod.c @@ -1208,6 +1208,29 @@ char *hydra_address2string(char *address) { struct sockaddr_in target; struct sockaddr_in6 target6; + if (address[0] == 4) { + memcpy(&target.sin_addr.s_addr, &address[1], 4); + return inet_ntoa((struct in_addr) target.sin_addr); + } else +#ifdef AF_INET6 + if (address[0] == 16) { + memcpy(&target6.sin6_addr, &address[1], 16); + inet_ntop(AF_INET6, &target6.sin6_addr, ipstring, sizeof(ipstring)); + return ipstring; + } else +#endif + { + if (debug) + fprintf(stderr, "[ERROR] unknown address string size!\n"); + return NULL; + } + return NULL; // not reached +} + +char *hydra_address2string_beautiful(char *address) { + struct sockaddr_in target; + struct sockaddr_in6 target6; + if (address[0] == 4) { memcpy(&target.sin_addr.s_addr, &address[1], 4); return inet_ntoa((struct in_addr) target.sin_addr); diff --git a/hydra-postgres.c b/hydra-postgres.c index d27a78b..0be1363 100644 --- a/hydra-postgres.c +++ b/hydra-postgres.c @@ -1,4 +1,3 @@ - /* * PostgresSQL Support - by Diaul (at) devilopers.org * diff --git a/hydra-ssh.c b/hydra-ssh.c index e0a67b1..0834713 100644 --- a/hydra-ssh.c +++ b/hydra-ssh.c @@ -172,7 +172,7 @@ int32_t service_ssh_init(char *ip, int32_t sp, unsigned char options, char *misc ssh_session session = ssh_new(); if (verbose || debug) - printf("[INFO] Testing if password authentication is supported by ssh://%s@%s:%d\n", miscptr == NULL ? "hydra" : miscptr, hydra_address2string(ip), port); + printf("[INFO] Testing if password authentication is supported by ssh://%s@%s:%d\n", miscptr == NULL ? "hydra" : miscptr, hydra_address2string_beautiful(ip), port); ssh_options_set(session, SSH_OPTIONS_PORT, &port); ssh_options_set(session, SSH_OPTIONS_HOST, hydra_address2string(ip)); if (miscptr == NULL) @@ -182,7 +182,7 @@ int32_t service_ssh_init(char *ip, int32_t sp, unsigned char options, char *misc ssh_options_set(session, SSH_OPTIONS_COMPRESSION_C_S, "none"); ssh_options_set(session, SSH_OPTIONS_COMPRESSION_S_C, "none"); if (ssh_connect(session) != 0) { - fprintf(stderr, "[ERROR] could not connect to ssh://%s:%d - %s\n", hydra_address2string(ip), port, ssh_get_error(session)); + fprintf(stderr, "[ERROR] could not connect to ssh://%s:%d - %s\n", hydra_address2string_beautiful(ip), port, ssh_get_error(session)); return 2; } rc = ssh_userauth_none(session, NULL); @@ -193,11 +193,11 @@ int32_t service_ssh_init(char *ip, int32_t sp, unsigned char options, char *misc if ((method & SSH_AUTH_METHOD_INTERACTIVE) || (method & SSH_AUTH_METHOD_PASSWORD)) { if (verbose || debug) - printf("[INFO] Successful, password authentication is supported by ssh://%s:%d\n", hydra_address2string(ip), port); + printf("[INFO] Successful, password authentication is supported by ssh://%s:%d\n", hydra_address2string_beautiful(ip), port); return 0; } - fprintf(stderr, "[ERROR] target ssh://%s:%d/ does not support password authentication.\n", hydra_address2string(ip), port); + fprintf(stderr, "[ERROR] target ssh://%s:%d/ does not support password authentication.\n", hydra_address2string_beautiful(ip), port); return 1; #else return 0; diff --git a/hydra-svn.c b/hydra-svn.c index 11ed2f9..cdee8ec 100644 --- a/hydra-svn.c +++ b/hydra-svn.c @@ -103,10 +103,7 @@ int32_t start_svn(int32_t s, char *ip, int32_t port, unsigned char options, char svn_auth_open(&ctx->auth_baton, providers, pool); revision.kind = svn_opt_revision_head; - if (ipv6) - snprintf(URL, sizeof(URL), "svn://[%s]:%d/%s", hydra_address2string(ip), port, URLBRANCH); - else - snprintf(URL, sizeof(URL), "svn://%s:%d/%s", hydra_address2string(ip), port, URLBRANCH); + snprintf(URL, sizeof(URL), "svn://%s:%d/%s", hydra_address2string_beautiful(ip), port, URLBRANCH); dirents = SVN_DIRENT_KIND; canonical = svn_uri_canonicalize(URL, pool); //err = svn_client_list2(canonical, &revision, &revision, svn_depth_unknown, dirents, FALSE, print_dirdummy, NULL, ctx, pool); diff --git a/hydra.c b/hydra.c index 1ec958f..c335e2b 100644 --- a/hydra.c +++ b/hydra.c @@ -211,6 +211,7 @@ extern char *hydra_strcasestr(const char *haystack, const char *needle); extern void hydra_tobase64(unsigned char *buf, int32_t buflen, int32_t bufsize); extern char *hydra_string_replace(const char *string, const char *substr, const char *replacement); extern char *hydra_address2string(char *address); +extern char *hydra_address2string_beautiful(char *address); extern int32_t colored_output; extern char quiet; extern int32_t do_retry; @@ -638,7 +639,7 @@ void hydra_debug(int32_t force, char *string) { hydra_target* target = hydra_targets[i]; printf ("[DEBUG] Target %d - target %s ip %s login_no %llu pass_no %llu sent %llu 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, STR_NULL(target->target), hydra_address2string(target->ip), + i, STR_NULL(target->target), hydra_address2string_beautiful(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,