Tips:Hping3

From Wiki

Jump to: navigation, search
TIPS edit

FreeBSD vnode SambaHPing3 (patch)Fetchmail (POP3s)NetBSD pkgsrc under OSXSimple Bash Ad-hoc file sharing256 colors in Urxvt

Sadly, hping3 sources from hping.org cannot be compiled on Mac OSX, and have compilation warnings on Linux.

Working under :

  • MacOSX 32+64
  • FreeBSD 32+64
  • Linux 32+64

Should works :

  • NetBSD
  • OpenBSD
  • Solaris

This patch fix this behaviour providing a cleaner hping.

Installation

  1. Grab the latest sources hping3-20051105.tar.gz
  2. Download the following patch (direct link)
  3. Apply the patch.

References

File: hping3.patch

Files hping3-20051105/.ars.c.swp and hping3/.ars.c.swp differ
diff -Nup --exclude='*.o' hping3-20051105/.depend hping3/.depend
--- hping3-20051105/.depend     2005-11-05 11:31:42.000000000 +0100
+++ hping3/.depend      1970-01-01 01:00:00.000000000 +0100
@@ -1,87 +0,0 @@
-adbuf.o: adbuf.c adbuf.h
-antigetopt.o: antigetopt.c antigetopt.h
-apd.o: apd.c ars.h systype.h in.h bytesex.h adbuf.h fixtypes.h \
- hstring.h hex.h
-apdutils.o: apdutils.c
-ars.o: ars.c ars.h systype.h in.h bytesex.h adbuf.h fixtypes.h
-arsglue.o: arsglue.c ars.h systype.h in.h bytesex.h adbuf.h fixtypes.h
-binding.o: binding.c hping2.h byteorder.h systype.h fixtypes.h hcmp.h \
- globals.h
-byteorder.o: byteorder.c
-cksum.o: cksum.c hping2.h byteorder.h systype.h fixtypes.h hcmp.h \
- globals.h
-datafiller.o: datafiller.c hping2.h byteorder.h systype.h fixtypes.h \
- hcmp.h globals.h
-datahandler.o: datahandler.c hping2.h byteorder.h systype.h fixtypes.h \
- hcmp.h globals.h
-display_ipopt.o: display_ipopt.c hping2.h byteorder.h systype.h \
- fixtypes.h hcmp.h globals.h
-gentables.o: gentables.c sbignum.h fixtypes.h
-gethostname.o: gethostname.c
-getifname.o: getifname.c hping2.h byteorder.h systype.h fixtypes.h \
- hcmp.h globals.h
-getlhs.o: getlhs.c hping2.h byteorder.h systype.h fixtypes.h hcmp.h \
- globals.h
-getusec.o: getusec.c
-hex.o: hex.c
-hstring.o: hstring.c
-if_promisc.o: if_promisc.c hping2.h byteorder.h systype.h fixtypes.h \
- hcmp.h globals.h
-interface.o: interface.c
-ip_opt_build.o: ip_opt_build.c hping2.h byteorder.h systype.h \
- fixtypes.h hcmp.h globals.h
-libpcap_stuff.o: libpcap_stuff.c hping2.h byteorder.h systype.h \
- fixtypes.h hcmp.h globals.h
-listen.o: listen.c hping2.h byteorder.h systype.h fixtypes.h hcmp.h \
- globals.h
-logicmp.o: logicmp.c hping2.h byteorder.h systype.h fixtypes.h hcmp.h \
- globals.h
-main.o: main.c hping2.h byteorder.h systype.h fixtypes.h hcmp.h
-memlock.o: memlock.c
-memlockall.o: memlockall.c
-memstr.o: memstr.c
-memunlock.o: memunlock.c
-memunlockall.o: memunlockall.c
-opensockraw.o: opensockraw.c
-parseoptions.o: parseoptions.c antigetopt.h hping2.h byteorder.h \
- systype.h fixtypes.h hcmp.h globals.h
-random.o: random.c fixtypes.h
-rapd.o: rapd.c ars.h systype.h in.h bytesex.h adbuf.h fixtypes.h
-relid.o: relid.c hping2.h byteorder.h systype.h fixtypes.h hcmp.h \
- globals.h
-resolve.o: resolve.c
-rtt.o: rtt.c hping2.h byteorder.h systype.h fixtypes.h hcmp.h \
- globals.h
-sbignum-tables.o: sbignum-tables.c sbignum-tables.h sbignum.h \
- fixtypes.h
-sbignum.o: sbignum.c sbignum.h fixtypes.h sbignum-tables.h
-scan.o: scan.c hping2.h byteorder.h systype.h fixtypes.h hcmp.h \
- globals.h hstring.h
-script.o: script.c
-send.o: send.c hping2.h byteorder.h systype.h fixtypes.h hcmp.h \
- globals.h
-sendhcmp.o: sendhcmp.c hping2.h byteorder.h systype.h fixtypes.h \
- hcmp.h globals.h
-sendicmp.o: sendicmp.c hping2.h byteorder.h systype.h fixtypes.h \
- hcmp.h globals.h
-sendip.o: sendip.c hping2.h byteorder.h systype.h fixtypes.h hcmp.h \
- globals.h
-sendip_handler.o: sendip_handler.c hping2.h byteorder.h systype.h \
- fixtypes.h hcmp.h globals.h
-sendrawip.o: sendrawip.c hping2.h byteorder.h systype.h fixtypes.h \
- hcmp.h globals.h
-sendtcp.o: sendtcp.c hping2.h byteorder.h systype.h fixtypes.h hcmp.h \
- globals.h
-sendudp.o: sendudp.c hping2.h byteorder.h systype.h fixtypes.h hcmp.h \
- globals.h
-signal.o: signal.c
-sockopt.o: sockopt.c
-split.o: split.c ars.h systype.h in.h bytesex.h adbuf.h fixtypes.h
-statistics.o: statistics.c hping2.h byteorder.h systype.h fixtypes.h \
- hcmp.h globals.h
-strlcpy.o: strlcpy.c
-usage.o: usage.c
-version.o: version.c release.h hping2.h byteorder.h systype.h \
- fixtypes.h hcmp.h
-waitpacket.o: waitpacket.c hping2.h byteorder.h systype.h fixtypes.h \
- hcmp.h globals.h
Common subdirectories: hping3-20051105/.svn and hping3/.svn
Common subdirectories: hping3-20051105/CVS and hping3/CVS
diff -Nup --exclude='*.o' hping3-20051105/Makefile hping3/Makefile
--- hping3-20051105/Makefile    2005-11-05 11:31:41.000000000 +0100
+++ hping3/Makefile     1970-01-01 01:00:00.000000000 +0100
@@ -1,92 +0,0 @@
-# $smu-mark$
-# $name: Makefile.in$
-# $author: Salvatore Sanfilippo 'antirez'$
-# $copyright: Copyright (C) 1999 by Salvatore Sanfilippo$
-# $license: This software is under GPL version 2 of license$
-# $date: Sun Jul 25 17:56:15 MET DST 1999$
-# $rev: 3$
-
-CC= gcc
-AR=/usr/bin/ar
-RANLIB=/usr/bin/ranlib
-CCOPT= -O2 -Wall  -I/usr/include/tcl8.4 -DUSE_TCL
-DEBUG= -g
-#uncomment the following if you need libpcap based build under linux
-#(not raccomanded)
-COMPILE_TIME=
-INSTALL_MANPATH=/usr/local/man
-PCAP=-lpcap
-
-ARSOBJ = ars.o apd.o split.o rapd.o
-
-OBJ=   main.o getifname.o getlhs.o \
-       parseoptions.o datafiller.o \
-       datahandler.o gethostname.o \
-       binding.o getusec.o opensockraw.o \
-       logicmp.o waitpacket.o resolve.o \
-       sendip.o sendicmp.o sendudp.o \
-       sendtcp.o cksum.o statistics.o \
-       usage.o version.o antigetopt.o \
-       sockopt.o listen.o \
-       sendhcmp.o memstr.o rtt.o \
-       relid.o sendip_handler.o \
-       libpcap_stuff.o memlockall.o memunlockall.o \
-       memlock.o memunlock.o ip_opt_build.o \
-       display_ipopt.o sendrawip.o signal.o send.o \
-       strlcpy.o arsglue.o random.o scan.o \
-       hstring.o script.o interface.o \
-       adbuf.o hex.o apdutils.o sbignum.o \
-       sbignum-tables.o $(ARSOBJ)
-
-all: .depend hping3
-
-dep: .depend
-.depend:
-       @echo Making dependences
-       @$(CC) -MM *.c > .depend
-
-libars.a: $(ARSOBJ)
-       $(AR) rc $@ $^
-       $(RANLIB) $@
-
-hping3: byteorder.h $(OBJ)
-       $(CC) -o hping3 $(CCOPT) $(DEBUG) $(OBJ) -L/usr/local/lib $(PCAP)  -ltcl8.4 -lm -lpthread
-       @echo
-       ./hping3 -v
-       @echo "use \`make strip' to strip hping3 binary"
-       @echo "use \`make install' to install hping3"
-
-hping3-static: byteorder.h $(OBJ)
-       $(CC) -static -o hping3-static $(CCOPT) $(DEBUG) $(OBJ) -L/usr/local/lib $(PCAP)  -ltcl8.4 -lm -lpthread -ldl
-
-byteorder.h:
-       ./configure
-
-.c.o:
-       $(CC) -c $(CCOPT) $(DEBUG) $(COMPILE_TIME) $<
-
-clean:
-       rm -rf hping3 *.o libars.a
-
-distclean:
-       rm -rf hping3 *.o byteorder byteorder.h systype.h Makefile libars.a .depend
-
-install: hping3
-       cp -f hping3 /usr/sbin/
-       chmod 755 /usr/sbin/hping3
-       ln -s /usr/sbin/hping3 /usr/sbin/hping
-       ln -s /usr/sbin/hping3 /usr/sbin/hping2
-       @if [ -d ${INSTALL_MANPATH}/man8 ]; then \
-               cp ./docs/hping3.8 ${INSTALL_MANPATH}/man8; \
-               chmod 644 ${INSTALL_MANPATH}/man8/hping3.8; \
-       else \
-               echo "@@@@@@ WARNING @@@@@@"; \
-               echo "Can't install the man page: ${INSTALL_MANPATH}/man8 does not exist"; \
-       fi
-
-strip: hping3
-       @ls -l ./hping3
-       strip hping3
-       @ls -l ./hping3
-
-include .depend
diff -Nup --exclude='*.o' hping3-20051105/Makefile.in hping3/Makefile.in
--- hping3-20051105/Makefile.in 2004-04-10 01:38:56.000000000 +0200
+++ hping3/Makefile.in  2009-11-15 22:24:31.000000000 +0100
@@ -74,8 +74,8 @@ distclean:
 install: hping3
        cp -f hping3 /usr/sbin/
        chmod 755 /usr/sbin/hping3
-       ln -s /usr/sbin/hping3 /usr/sbin/hping
-       ln -s /usr/sbin/hping3 /usr/sbin/hping2
+       ln -fs /usr/sbin/hping3 /usr/sbin/hping
+       ln -fs /usr/sbin/hping3 /usr/sbin/hping2
        @if [ -d ${INSTALL_MANPATH}/man8 ]; then \
                cp ./docs/hping3.8 ${INSTALL_MANPATH}/man8; \
                chmod 644 ${INSTALL_MANPATH}/man8/hping3.8; \
Common subdirectories: hping3-20051105/RFCs and hping3/RFCs
diff -Nup --exclude='*.o' hping3-20051105/adbuf.c hping3/adbuf.c
--- hping3-20051105/adbuf.c     2003-08-31 19:24:00.000000000 +0200
+++ hping3/adbuf.c      2009-11-15 22:24:31.000000000 +0100
@@ -127,7 +127,7 @@ int adbuf_addchar(struct adbuf *b, int c
        if (adbuf_ptr(b) == NULL)
                return 1; /* bad buffer in input */
        if (b->left >= 2) {
-               unsigned char *p = b->buf + adbuf_used(b);
+               unsigned char *p = (unsigned char *) (b->buf + adbuf_used(b));
 
                *p = c;
                *(p+1) = '\0';
diff -Nup --exclude='*.o' hping3-20051105/apd.c hping3/apd.c
--- hping3-20051105/apd.c       2003-09-07 13:21:18.000000000 +0200
+++ hping3/apd.c        2009-11-15 22:24:31.000000000 +0100
@@ -786,7 +786,7 @@ static int hextab[256];
 static int hextab_initialized = 0;
 static char *hexdig = "0123456789abcdef";
 
-static char *ars_decode_hex(struct ars_packet *pkt, char *s, int *blen)
+static unsigned char *ars_decode_hex(struct ars_packet *pkt, char *s, int *blen)
 {
        int len = strlen(s), i;
        unsigned char *d, *saved;
@@ -823,7 +823,7 @@ static char *ars_decode_hex(struct ars_p
        return saved;
 }
 
-static char *ars_decode_string(struct ars_packet *pkt, char *s, int *blen)
+static unsigned char *ars_decode_string(struct ars_packet *pkt, char *s, int *blen)
 {
        int l = strlen(s), i;
        int bl = 0;
@@ -875,7 +875,7 @@ int ars_d_set_data(struct ars_packet *pk
                        return -ARS_OK;
                return ars_push_data(pkt, layer, buffer, n_read);
        } else if (strcasecmp(f, "str") == 0) {
-               char *binary;
+               unsigned char *binary;
                int err, blen;
 
                binary = ars_decode_string(pkt, v, &blen);
@@ -885,7 +885,7 @@ int ars_d_set_data(struct ars_packet *pk
                free(binary);
                return err;
        } else if (strcasecmp(f, "hex") == 0) {
-               char *binary;
+               unsigned char *binary;
                int err, blen;
 
                binary = ars_decode_hex(pkt, v, &blen);
diff -Nup --exclude='*.o' hping3-20051105/ars.c hping3/ars.c
--- hping3-20051105/ars.c       2004-04-14 14:30:18.000000000 +0200
+++ hping3/ars.c        2009-11-15 22:24:31.000000000 +0100
@@ -482,7 +482,7 @@ u_int16_t ars_multi_cksum(struct mc_cont
                sum += (sum >> 16);
                return (u_int16_t) ~sum;
        } else {
-               assert("else reached in ars_multi_cksum()" == "");
+               assert("else reached in ars_multi_cksum()");
        }
        return 0; /* unreached, here to prevent warnings */
 }
@@ -914,7 +914,7 @@ int ars_bsd_fix(struct ars_packet *pkt,
                return -ARS_INVALID;
        }
        ip = (struct ars_iphdr*) packet;
-#if defined OSTYPE_FREEBSD || defined OSTYPE_NETBSD || defined OSTYPE_BSDI
+#if defined OSTYPE_DARWIN || defined OSTYPE_FREEBSD || defined OSTYPE_NETBSD || defined OSTYPE_BSDI
        ip->tot_len = ntohs(ip->tot_len);
        ip->frag_off = ntohs(ip->frag_off);
 #endif
Files hping3-20051105/byteorder and hping3/byteorder differ
diff -Nup --exclude='*.o' hping3-20051105/byteorder.c hping3/byteorder.c
--- hping3-20051105/byteorder.c 2003-09-01 02:22:06.000000000 +0200
+++ hping3/byteorder.c  2009-11-15 22:24:31.000000000 +0100
@@ -68,7 +68,7 @@ int main(int argc, char **argv)
        }
 
        if (debug) {
-               printf("sizeof(unsigned int) = %d\n", sizeof(unsigned int));
+               printf("sizeof(unsigned int) = %ld\n", sizeof(unsigned int));
                printf("unsigned int test = 1;\n");
                printf("in memory as: ");
                for (j = 0; j < sizeof(unsigned int); j++)
diff -Nup --exclude='*.o' hping3-20051105/bytesex.h hping3/bytesex.h
--- hping3-20051105/bytesex.h   2003-08-31 19:23:48.000000000 +0200
+++ hping3/bytesex.h    2009-11-15 22:24:31.000000000 +0100
@@ -9,7 +9,8 @@
 
 #if    defined(__i386__) \
        || defined(__alpha__) \
-       || (defined(__mips__) && (defined(MIPSEL) || defined (__MIPSEL__)))
+       || (defined(__mips__) && (defined(MIPSEL) || defined (__MIPSEL__))) \
+       || defined(__x86_64__)
 #define BYTE_ORDER_LITTLE_ENDIAN
 #elif  defined(__mc68000__) \
        || defined (__sparc__) \
diff -Nup --exclude='*.o' hping3-20051105/configure hping3/configure
--- hping3-20051105/configure   2004-06-04 08:39:10.000000000 +0200
+++ hping3/configure    2009-11-15 22:42:32.000000000 +0100
@@ -76,7 +76,7 @@ do
                fi
        done
 done
-if [ -f $TCLSH ]
+if [ -f "$TCLSH" ]
 then
        TCL_VER=`echo puts \\$tcl_version | $TCLSH -`
        USE_TCL='-DUSE_TCL'
@@ -91,14 +91,20 @@ then
        then
                TCL_INC="-I/usr/local/include/tcl${TCL_VER}"
        else
+               # On ne devrai jamais passer ici
                USE_TCL=""
                TCL_LIB=""
                echo "==> WARNING: no Tcl header files found!"
        fi
+else
+       USE_TCL=""
+       TCL_LIB=""
+       echo "==> WARNING: no Tcl header files found!"
 fi
-if [ -n $USE_TCL ]
+
+if [ -n "$USE_TCL" ]
 then
-       LIBPOSTFIX=`ls -1 /usr/local/lib/ /usr/lib | grep 'libtcl[0-9]' | grep so | sed -e 's/\.so.*//g' -e 's/libtcl//g' | sort -r | head -1`
+       LIBPOSTFIX=`ls -1 /usr/local/lib/ /usr/lib | grep 'libtcl[0-9]' | grep so | sed "s/libtcl\(.*\)\.so.*/\1/g" |  sort -r | head -1`
        TCL_LIB="-ltcl${LIBPOSTFIX} -lm -lpthread"
 fi
 
Common subdirectories: hping3-20051105/docs and hping3/docs
diff -Nup --exclude='*.o' hping3-20051105/getifname.c hping3/getifname.c
--- hping3-20051105/getifname.c 2003-10-22 12:41:00.000000000 +0200
+++ hping3/getifname.c  2009-11-15 22:24:31.000000000 +0100
@@ -59,7 +59,7 @@ int get_if_name(void)
                        known_output_if = 1;
                        if (opt_debug)
                                printf("DEBUG: Output interface address: %s\n",
-                                       inet_ntoa(sa.sin_addr));
+                                       inet_ntoa(output_if_addr.sin_addr));
                } else {
                        fprintf(stderr, "Warning: Unable to guess the output "
                                        "interface\n");
@@ -315,7 +315,8 @@ int get_if_name(void)
  * to the OS routing table. Derived from R.Stevens */
 int get_output_if(struct sockaddr_in *dest, struct sockaddr_in *ifip)
 {
-       int sock_rt, len, on=1;
+       int sock_rt,  on=1;
+       unsigned int len;
        struct sockaddr_in iface_out;
 
        memset(&iface_out, 0, sizeof(iface_out));
Files hping3-20051105/hping3-20051105.tar.gz and hping3/hping3-20051105.tar.gz differ
Common subdirectories: hping3-20051105/img and hping3/img
Common subdirectories: hping3-20051105/lib and hping3/lib
diff -Nup --exclude='*.o' hping3-20051105/libpcap_stuff.c hping3/libpcap_stuff.c
--- hping3-20051105/libpcap_stuff.c     2004-04-10 01:38:56.000000000 +0200
+++ hping3/libpcap_stuff.c      2009-11-15 22:24:31.000000000 +0100
@@ -16,9 +16,12 @@
 #include <string.h>
 #include <stdlib.h>
 #include <sys/ioctl.h>
+#ifdef OSTYPE_LINUX
+ #include <pcap-bpf.h>
+#else
+ #include <net/bpf.h>
+#endif
 #include <pcap.h>
-#include <net/bpf.h>
-
 #include "globals.h"
 
 int open_pcap()
@@ -51,7 +54,7 @@ int close_pcap()
 
 int pcap_recv(char *packet, unsigned int size)
 {
-        char *p = NULL;
+        unsigned char *p = NULL;
         int pcapsize;
 
        if (opt_debug)
diff -Nup --exclude='*.o' hping3-20051105/scan.c hping3/scan.c
--- hping3-20051105/scan.c      2003-10-22 12:41:00.000000000 +0200
+++ hping3/scan.c       2009-11-15 22:24:31.000000000 +0100
@@ -356,7 +356,7 @@ static void sender(struct portinfo *pi)
 static void receiver(struct portinfo *pi, int childpid)
 {
        struct myiphdr ip;
-       char packet[IP_MAX_SIZE+linkhdr_size];
+       unsigned char packet[IP_MAX_SIZE+linkhdr_size];
 
        while(1)
        {
@@ -456,7 +456,8 @@ static void receiver(struct portinfo *pi
                                continue;
                        /* time to copy headers in a safe place */
                        p = packet+linkhdr_size+iphdrlen;
-                       memcpy(&icmp, p, sizeof(subtcp));
+                       //memcpy(&icmp, p, sizeof(subtcp));
+                       memcpy(&icmp, p, sizeof(p));
                        p += sizeof(icmp);
                        memcpy(&subip, p, sizeof(ip));
                        p += sizeof(ip);
diff -Nup --exclude='*.o' hping3-20051105/script.c hping3/script.c
--- hping3-20051105/script.c    2004-05-29 08:48:13.000000000 +0200
+++ hping3/script.c     2009-11-15 22:24:31.000000000 +0100
@@ -10,6 +10,8 @@
 
 #ifdef USE_TCL
 
+#include "systype.h"
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -23,8 +25,12 @@
 #include <sched.h>
 
 #include <sys/ioctl.h>
+#ifdef OSTYPE_LINUX
+ #include <pcap-bpf.h>
+#else
+ #include <net/bpf.h>
+#endif
 #include <pcap.h>
-#include <net/bpf.h>
 
 #include "release.h"
 #include "hping2.h"
@@ -262,7 +268,7 @@ static int HpingSendRawCmd(ClientData cl
 #define APD_MAX_LEN (65536*2+4096)
 char *GetPacketDescription(char *data, int len, int hexdata)
 {
-       unsigned char *p = (char*)data;
+       unsigned char *p = (unsigned char*)data;
        struct ars_packet pkt;
        char *d = malloc(APD_MAX_LEN);
        char *ret;
diff -Nup --exclude='*.o' hping3-20051105/sendip.c hping3/sendip.c
--- hping3-20051105/sendip.c    2004-04-10 01:38:56.000000000 +0200
+++ hping3/sendip.c     2009-11-15 22:24:31.000000000 +0100
@@ -48,9 +48,10 @@ void send_ip (char* src, char *dst, char
        ip->ihl         = (IPHDR_SIZE + optlen + 3) >> 2;
        ip->tos         = ip_tos;
 
-#if defined OSTYPE_FREEBSD || defined OSTYPE_NETBSD || defined OSTYPE_BSDI
+#if defined OSTYPE_DARWIN || defined OSTYPE_FREEBSD || defined OSTYPE_NETBSD || defined OSTYPE_BSDI
 /* FreeBSD */
 /* NetBSD */
+/* Darwin */
        ip->tot_len     = packetsize;
 #else
 /* Linux */
@@ -73,9 +74,10 @@ void send_ip (char* src, char *dst, char
                        htons((unsigned short) src_id);
        }
 
-#if defined OSTYPE_FREEBSD || defined OSTYPE_NETBSD | defined OSTYPE_BSDI
+#if defined OSTYPE_DARWIN || defined OSTYPE_FREEBSD || defined OSTYPE_NETBSD || defined OSTYPE_BSDI
 /* FreeBSD */
 /* NetBSD */
+/* Darwin */
        ip->frag_off    |= more_fragments;
        ip->frag_off    |= fragoff >> 3;
 #else
diff -Nup --exclude='*.o' hping3-20051105/systype.h hping3/systype.h
--- hping3-20051105/systype.h   2005-11-05 11:31:41.000000000 +0100
+++ hping3/systype.h    1970-01-01 01:00:00.000000000 +0100
@@ -1,6 +0,0 @@
-#ifndef __SYSTYPE_H
-#define __SYSTYPE_H
-
-#define OSTYPE_LINUX
-
-#endif /* SYSTYPE_H */
Personal tools