From 1aeda5001cfc30b6d941ad50b6b085c017323e1f Mon Sep 17 00:00:00 2001 From: Renato Alencar Date: Wed, 1 Jul 2015 11:00:17 -0300 Subject: [PATCH] add gzip support for login and password files * module hydra-teamspeak.c modified, because of conflict of crc32 with zlib crc32 --- configure | 20 ++++++++++++++++++++ crc32.c | 4 ++++ crc32.h | 2 ++ hydra-teamspeak.c | 9 +++++++++ hydra.c | 38 ++++++++++++++++++++++++++++++++------ hydra.h | 4 ++++ 6 files changed, 71 insertions(+), 6 deletions(-) diff --git a/configure b/configure index dd3f35f..8980e24 100755 --- a/configure +++ b/configure @@ -126,6 +126,19 @@ INCDIRS="/usr/include /usr/local/include /opt/include /opt/local/include" STRIP="strip" echo +echo "Checking for zlib (libz.so, zlib.h) ..." +for i in $INCDIRS; do + if [ -f "$i/zlib.h" ]; then + HAVE_ZLIB="y" + fi +done + +if [ -n "$HAVE_ZLIB" ]; then + echo " ... found" +else + echo " ... zlib not found, gzip support disabled" +fi + echo "Checking for openssl (libssl, libcrypto, ssl.h, sha.h) ..." if [ "X" != "X$DEBUG" ]; then echo DEBUG: SSL_LIB=$LIBDIRS `ls -d /*ssl /usr/*ssl /opt/*ssl /usr/local/*ssl /opt/local/*ssl /*ssl/lib /usr/*ssl/lib /opt/*ssl/lib /usr/local/*ssl/lib /opt/local/*ssl/lib 2> /dev/null` @@ -1023,6 +1036,10 @@ fi if [ -n "$RSA" ]; then XDEFINES="$XDEFINES -DNO_RSA_LEGACY" fi +if [ -n "$HAVE_ZLIB" ]; then + XDEFINES="$XDEFINES -DHAVE_ZLIB" +fi + OLDPATH="" for i in $SSL_PATH $FIREBIRD_PATH $WORACLE_LIB_PATH $PCRE_PATH $IDN_PATH $CRYPTO_PATH $SSH_PATH $NSL_PATH $SOCKET_PATH $RESOLV_PATH $SAPR3_PATH $POSTGRES_PATH $SVN_PATH $NCP_PATH $CURSES_PATH $ORACLE_PATH $AFP_PATH $MYSQL_PATH; do if [ "$OLDPATH" = "$i" ]; then @@ -1077,6 +1094,9 @@ fi if [ -n "$ORACLE_IPATH" ]; then XIPATHS="$XIPATHS -I$ORACLE_IPATH" fi +if [ -n "$HAVE_ZLIB" ]; then + XLIBS="$XLIBS -lz" +fi if [ -n "$CURSES_PATH" ]; then XLIBS="$XLIBS -lcurses" fi diff --git a/crc32.c b/crc32.c index 2dc37cb..44bd6ce 100644 --- a/crc32.c +++ b/crc32.c @@ -89,6 +89,8 @@ unsigned int crc32_tab[] = { 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d }; +#ifndef HAVE_ZLIB + unsigned int crc32(const void *buf, unsigned int size) { const unsigned char *p; unsigned int crc; @@ -101,3 +103,5 @@ unsigned int crc32(const void *buf, unsigned int size) { return crc ^ ~0U; } + +#endif diff --git a/crc32.h b/crc32.h index 9555e0f..cfd45cb 100644 --- a/crc32.h +++ b/crc32.h @@ -3,6 +3,8 @@ #include +#ifndef HAVE_ZLIB unsigned int crc32(const void *buf, unsigned int size); +#endif #endif diff --git a/hydra-teamspeak.c b/hydra-teamspeak.c index 32b06f2..45b041a 100644 --- a/hydra-teamspeak.c +++ b/hydra-teamspeak.c @@ -1,5 +1,10 @@ #include "hydra-mod.h" + +#ifdef HAVE_ZLIB +#include +#else #include "crc32.h" +#endif /* @@ -65,7 +70,11 @@ int start_teamspeak(int s, char *ip, int port, unsigned char options, char *misc teamspeak.loginlen = 0; strcpy((char *) &teamspeak.login, ""); +#ifdef HAVE_ZLIB + teamspeak.crc = crc32(0L, &teamspeak, sizeof(struct team_speak)); +#else teamspeak.crc = crc32(&teamspeak, sizeof(struct team_speak)); +#endif if (hydra_send(s, (char *) &teamspeak, sizeof(struct team_speak), 0) < 0) { return 3; diff --git a/hydra.c b/hydra.c index a9a813c..e54c054 100644 --- a/hydra.c +++ b/hydra.c @@ -7,7 +7,6 @@ * * License: GNU AFFERO GENERAL PUBLIC LICENSE v3.0, see LICENSE file */ - #include "hydra.h" #include "bfg.h" @@ -1000,14 +999,27 @@ void kill_children(int signo) { exit(0); } -unsigned long int countlines(FILE * fp, int colonmode) { +unsigned long int countlines(FILE * fd, int colonmode) { size_t lines = 0; char *buf = malloc(MAXLINESIZE); int only_one_empty_line = 0; - struct stat st; +#ifdef HAVE_ZLIB + gzFile fp = gzdopen(fileno(fd), "r"); +#else + FILE *fp = fd; +#endif + + size_of_data = 0; + +#ifdef HAVE_ZLIB + while (!gzeof(fp)) { + if (gzgets(fp, buf, MAXLINESIZE) != NULL) { +#else while (!feof(fp)) { if (fgets(buf, MAXLINESIZE, fp) != NULL) { +#endif + size_of_data += strlen(buf); if (buf[0] != 0) { if (buf[0] == '\r' || buf[0] == '\n') { if (only_one_empty_line == 0) { @@ -1020,20 +1032,30 @@ unsigned long int countlines(FILE * fp, int colonmode) { } } } +#ifdef HAVE_ZLIB + gzrewind(fp); +#else rewind(fp); +#endif free(buf); - (void) fstat(fileno(fp), &st); - size_of_data = st.st_size + 1; return lines; } -void fill_mem(char *ptr, FILE * fp, int colonmode) { +void fill_mem(char *ptr, FILE * fd, int colonmode) { char tmp[MAXBUF + 4] = "", *ptr2; unsigned int len; int only_one_empty_line = 0; +#ifdef HAVE_ZLIB + gzFile fp = gzdopen(fileno(fd), "r"); + + while (!gzeof(fp)) { + if (gzgets(fp, tmp, MAXLINESIZE) != NULL) { +#else + FILE *fp = fd; while (!feof(fp)) { if (fgets(tmp, MAXLINESIZE, fp) != NULL) { +#endif if (tmp[0] != 0) { if (tmp[strlen(tmp) - 1] == '\n') tmp[strlen(tmp) - 1] = '\0'; @@ -1069,7 +1091,11 @@ void fill_mem(char *ptr, FILE * fp, int colonmode) { } } } +#ifdef HAVE_ZLIB + gzclose(fp); +#else fclose(fp); +#endif } char *hydra_build_time() { diff --git a/hydra.h b/hydra.h index 7c51717..2d15f38 100644 --- a/hydra.h +++ b/hydra.h @@ -35,6 +35,10 @@ #include #endif +#ifdef HAVE_ZLIB +#include +#endif + #define OPTION_SSL 1 #define PORT_NOPORT -1