Skip to content

Commit

Permalink
add gzip support for login and password files
Browse files Browse the repository at this point in the history
* module hydra-teamspeak.c modified, because of
  conflict of crc32 with zlib crc32
  • Loading branch information
renatoalencar committed Jul 1, 2015
1 parent adec22c commit 1aeda50
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 6 deletions.
20 changes: 20 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions crc32.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -101,3 +103,5 @@ unsigned int crc32(const void *buf, unsigned int size) {

return crc ^ ~0U;
}

#endif
2 changes: 2 additions & 0 deletions crc32.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include <sys/types.h>

#ifndef HAVE_ZLIB
unsigned int crc32(const void *buf, unsigned int size);
#endif

#endif
9 changes: 9 additions & 0 deletions hydra-teamspeak.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#include "hydra-mod.h"

#ifdef HAVE_ZLIB
#include <zlib.h>
#else
#include "crc32.h"
#endif

/*
Expand Down Expand Up @@ -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;
Expand Down
38 changes: 32 additions & 6 deletions hydra.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*
* License: GNU AFFERO GENERAL PUBLIC LICENSE v3.0, see LICENSE file
*/

#include "hydra.h"
#include "bfg.h"

Expand Down Expand Up @@ -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) {
Expand All @@ -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';
Expand Down Expand Up @@ -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() {
Expand Down
4 changes: 4 additions & 0 deletions hydra.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
#include <libssh/libssh.h>
#endif

#ifdef HAVE_ZLIB
#include <zlib.h>
#endif

#define OPTION_SSL 1

#define PORT_NOPORT -1
Expand Down

0 comments on commit 1aeda50

Please sign in to comment.