wifi dumping patch (prismdump like)
dmcnamee <[email protected]> Mon, 11 Nov 2002 15:15:54 -0600 (CST)
| Newsgroups | gmane.network.wireless.bsd.airtools |
|---|---|
| Message-ID | <[email protected]> |
I wrote this forever ago, and never released it. It writes wtap files out of packet captures (you can read them w/ ethereal). it is also available at http://lab.digitol.net/prism2dump-ptap.patch
prism2dump-ptap.patch
(text/plain, 6.8 KB)
diff -urNb prism2dump/Makefile.ptap prism2dump-ptap/Makefile.ptap --- prism2dump/Makefile.ptap Wed Dec 31 18:00:00 1969 +++ prism2dump-ptap/Makefile.ptap Thu Jun 6 20:13:00 2002 @@ -0,0 +1,33 @@ +WIRETAP_PATH=/usr/ports/net/ethereal/w-ethereal-0.9.3/build-i386/wiretap +WIRETAP_INCLUDE=-I /usr/ports/net/ethereal/w-ethereal-0.9.3/ethereal-0.9.3/wiretap +WIRETAP_LIB=/usr/ports/net/ethereal/w-ethereal-0.9.3/build-i386/wiretap/libwiretap.a +GLIB_CONFIG=/usr/local/bin/glib-config + +GLIB_INCLUDE=`$(GLIB_CONFIG) --cflags` +GLIB_LIB=`$(GLIB_CONFIG) --libs` + +CC = gcc +CFLAGS = -Wall -DPTAP $(WIRETAP_INCLUDE) $(GLIB_INCLUDE) +TARGET = prism2dump +LDFLAGS = -lpcap -lz -L$(WIRETAP_PATH) $(GLIB_LIB) +PREFIX = /usr/local +OBJS = prism2dump.o\ + misc.o\ + decode_80211.o\ + decode_data.o\ + decode_mgmt.o\ + decode_ctl.o\ + fields_80211.o\ + fields_data.o\ + fields_mgmt.o + +all: prism2dump + +prism2dump: $(OBJS) + $(CC) $(CFLAGS) -o $(TARGET) $(OBJS) $(WIRETAP_LIB) $(LDFLAGS) + +install: + install -m 700 -o root -g wheel $(TARGET) $(PREFIX)/bin + +clean: + rm -f *.o $(TARGET) diff -urNb prism2dump/README.ptap prism2dump-ptap/README.ptap --- prism2dump/README.ptap Wed Dec 31 18:00:00 1969 +++ prism2dump-ptap/README.ptap Thu Jun 6 20:35:41 2002 @@ -0,0 +1,25 @@ +PTAP Patch to allow wtap files of wireless traffic +================================================= +Written by spoonm <lab.digitol.net> +------------------------------------------------- + +Code/ideas/info from Jason Aras <[email protected]> +Thanks to h1kari for some help + + +To get this to work you must have wiretap (part of ethereal) built and have libwiretap available. Modify the Makefile.ptap to point to the locations of your files. + +To compile simply make -f Makefile.ptap + + +prism2dump -w filename + +This will write all of the wireless data to a wtap file, which can then be read by ethereal and other wtap compatible programs. + +This does not write a prismdump header like linux prismdump, but that isn't really important, it writes a 802.11 header with all the information you should need. + +prism2dump -d -w filename + +This will do the same thing as above, except it only logs data packets. +This is good if you are getting lost in management and control packets (beacons, etc). + diff -urNb prism2dump/prism2dump.c prism2dump-ptap/prism2dump.c --- prism2dump/prism2dump.c Tue Jan 22 17:14:53 2002 +++ prism2dump-ptap/prism2dump.c Thu Jun 6 21:26:25 2002 @@ -35,6 +35,13 @@ * THE POSSIBILITY OF SUCH DAMAGE. */ +/* + * PTAP Patch by spoonm <lab.digitol.net> + * + * Thanks to: + * Lots of code from / based on bsd@prismdump by Jason Aras <[email protected]> + */ + #include <stdio.h> #include <stdlib.h> #include <unistd.h> @@ -55,6 +62,21 @@ #include "frames.h" #include "prism2dump.h" +#ifdef PTAP + +#include <wtap.h> +#include <sys/stat.h> +#include <sys/resource.h> +#include <sys/time.h> +#include <fcntl.h> +#include <signal.h> + +char *dumpfilename; +wtap_dumper *dumpfile; +int fd, wtap_error, dataonly = 0; + +#endif + /* * structures */ @@ -63,11 +85,27 @@ void (*func)(struct wi_rx_frame *, u_char *); }; +void +sigint_handler(void) { + pcap_close(p); +#ifdef PTAP + if(dumpfilename) { + wtap_dump_close(dumpfile, &wtap_error); + close(fd); + } +#endif + printf("\n"); + exit(0); +} void usage(char *progname) { +#ifdef PTAP + fprintf(stderr, "usage: %s <device> [-p] [-v 0|1|2] || [-d] [-w wtapfile]\n", progname); +#else fprintf(stderr, "usage: %s <device> [-p] [-v 0|1|2]\n", progname); +#endif exit(2); } @@ -86,8 +124,11 @@ prism2 = 1; verbose = 2; - +#ifdef PTAP + while((c = getopt(argc, argv, "pv:dw:")) != -1) +#else while((c = getopt(argc, argv, "pv:")) != -1) +#endif { switch(c) { @@ -97,11 +138,20 @@ case 'v': verbose = atoi(optarg); break; +#ifdef PTAP + case 'd': + dataonly = 1; + break; + case 'w': + dumpfilename = optarg; + break; +#endif default: break; } } + signal(SIGINT, (void *)sigint_handler); startloop(); exit(0); } @@ -137,6 +187,12 @@ struct pcap_pkthdr h; struct wi_rx_frame *wi_h; +#ifdef PTAP + int payloadsize; + struct wtap_pkthdr packet_hdr_info; + char * dumpdata; +#endif + if((p = pcap_open_live(device, SNAPLEN, prism2 ? 0 : 1, TOMS, errbuf)) == NULL) { @@ -146,6 +202,26 @@ printf("prism2dump: listening on %s\n", device); +#ifdef PTAP + if(dumpfilename) { + + printf("Logging to: %s\n", dumpfilename); + + if(dataonly) + printf("Capturing Only Data Packets\n"); + + if((fd = open(dumpfilename, (O_WRONLY|O_CREAT), (S_IRUSR|S_IWUSR))) < 0) { + perror("can not open file name"); + exit(2); + } + + if((dumpfile = wtap_dump_fdopen(fd, WTAP_FILE_PCAP, WTAP_ENCAP_IEEE_802_11, 2344, &wtap_error)) == NULL) { + perror("cannot open the dump file"); + exit(2); + } + } +#endif + while(1) { if((buf = (u_char *)pcap_next(p, &h)) == NULL) @@ -156,6 +232,32 @@ if(le16toh(wi_h->wi_status) & WI_STAT_BADCRC) continue; +#ifdef PTAP + if(dumpfilename) { + if(dataonly && (wi_h->wi_frame_ctl & WI_FCTL_FTYPE) != WI_FTYPE_DATA) + continue; + + /* + * the wi_h->wi_dat_len was giving bad length values + * it seems that pcap's header is much more accurate + */ + + payloadsize = h.caplen - WI_RX_SIZE; + dumpdata = malloc(HDR_80211A3_SIZE + payloadsize); + memcpy(dumpdata, buf + HDR_HERMES_SIZE, HDR_80211A3_SIZE); + memcpy(dumpdata + HDR_80211A3_SIZE, buf + WI_RX_SIZE, payloadsize); + + packet_hdr_info.caplen = packet_hdr_info.len = HDR_80211A3_SIZE + payloadsize; + packet_hdr_info.pkt_encap = WTAP_ENCAP_IEEE_802_11; + gettimeofday(&packet_hdr_info.ts,NULL); + + wtap_dump(dumpfile, &packet_hdr_info, NULL, dumpdata, &wtap_error); + free(dumpdata); + printf("."); + fflush(stdout); + continue; + } +#endif if(verbose > 0) { diff -urNb prism2dump/prism2dump.h prism2dump-ptap/prism2dump.h --- prism2dump/prism2dump.h Sun Nov 25 17:22:42 2001 +++ prism2dump-ptap/prism2dump.h Thu Jun 6 20:10:48 2002 @@ -41,7 +41,9 @@ #define SNAPLEN 4096 #define TOMS 256 #define PROTO_PRE " " - +#define HDR_HERMES_SIZE 14 +#define HDR_80211A3_SIZE 24 +#define WI_RX_SIZE 60 /* * macros */ @@ -67,6 +69,7 @@ /* * prism2dump.c */ +void sigint_handler(void); void usage(char *); int main(int, char **); void startloop(void);