From 1bc659fa450df2108ab59b085e75564b7ac19995 Mon Sep 17 00:00:00 2001 From: hackbard Date: Thu, 27 Mar 2003 15:53:12 +0000 Subject: [PATCH] moved old stuff to old/, added new stuff --- main.c | 129 +++++++++++++++++++++++++++++++ main.h | 37 +++++++++ Makefile => old/Makefile | 0 hdw-sniff.c => old/hdw-sniff.c | 0 hdw-sniff.h => old/hdw-sniff.h | 0 hdw_outlib.c => old/hdw_outlib.c | 0 hdw_outlib.h => old/hdw_outlib.h | 0 ieee80211.h => old/ieee80211.h | 0 ieee802_11.h => old/ieee802_11.h | 0 list.c => old/list.c | 0 list.h => old/list.h | 0 parse.c | 25 ++++++ 12 files changed, 191 insertions(+) create mode 100644 main.c create mode 100644 main.h rename Makefile => old/Makefile (100%) rename hdw-sniff.c => old/hdw-sniff.c (100%) rename hdw-sniff.h => old/hdw-sniff.h (100%) rename hdw_outlib.c => old/hdw_outlib.c (100%) rename hdw_outlib.h => old/hdw_outlib.h (100%) rename ieee80211.h => old/ieee80211.h (100%) rename ieee802_11.h => old/ieee802_11.h (100%) rename list.c => old/list.c (100%) rename list.h => old/list.h (100%) create mode 100644 parse.c diff --git a/main.c b/main.c new file mode 100644 index 0000000..2926a76 --- /dev/null +++ b/main.c @@ -0,0 +1,129 @@ +/* + * main.c - main hdw-sniff + * + * author: hackbard@hackdaworld.dyndns.org + * + */ + +#include +#include "main.h" + +/* functions */ +int usage(void) +{ + puts("usage: hdw-sniff "); + puts("\toptions:\t-m \t1 monitoring, 2 managed"); + puts("\t\t-d \twlan0,eth0"); + puts("\t\t-l "); + puts("\t\t-h \tdisplay this help message"); + return -23; +} + +int hop_channel(info_struct *info) +{ + struct iwreq iwreq; + if(info->current_channel>=CHANNEL_MAX) info->current_channel=1; + memset(&iwreq,0,sizeof(iwreq)); + strcpy(iwreq.ifr_name,info->device); + iwreq.u.freq.e=0; + iwreq.u.freq.m=info->current_channel; + if(ioctl(info->channel_hop_fd,SIOCSIWFREQ,&iwreq)<0) + { + puts("unable to hop channel"); + perror("ioctl"); + return -23; + } + ++(info->current_channel; + return 23; +} + +int main(int argc, char **argv) +{ + /* local variables */ + char pcap_error[PCAP_ERRBUF_SIZE]; + char sys_call[SYSCALL_MAX]; + + int pcap_fd,channel_hop_fd;; + int i; + + fd_set pcap_fd_set; + struct timeval pcap_fd_set_tv; + + struct info_struct info; + + + memset(&info,0,sizeof(struct info_struct)); + /* default values */ + info.caps=0; + info.logfile_fd=0; + info.quit=0; + + /* parse arguments */ + for(i=1;i %s\n",argv[i+1]); + else + puts("warning: can't write to logfile."); + ++i; + break; + case 'd': + strncpy(info.device,argv[i+1],MAX_DEV_CHARS); + ++i; + break; + } + } else usage(); + } + + /* setting up device */ + if((info.caps&CAP_MODE_MASK)==MONITORING_MODE) + { + sprintf(sys_call,"iwpriv %s monitor %d",info.device,IWPRIV_M_MODE); + system(sys_call); + puts("set monitoring mode ..."); + } + sprintf(sys_call,"ifconfig %s up",info.device); + system(sys_call); + puts("device up ..."); + + /* pcap */ + if((info.pcap_handle=pcap_open_live(info.device,BUFSIZ,1,-1,pcap_error))==NULL) + { + printf("%s: %s\n",argv[0],pcap_error); + return -23; + } + pcap_fd=pcap_fileno(pcap_handle); + /* -> non blocking? */ + + info.channel_hop_fd=socket(AF_INET,SOCK_DGRAM,0); + /* socket fd for channel hopping */ + + /* watch pcap_fd for reading */ + FD_ZERO(&pcap_fd); + FD_SET(pcap_fd,&pcap_fd_set); + fd_set_tv.tv_sec=PCAP_SELECT_SEC; + pcap_fd_set_tv.tv_usec=PCAP_SELECT_USEC; + + /* parse packages until user breaks */ + while(!(info.caps&CAP_QUIT_MASK)) + { + if(select(pcap_fd+1,&pcap_fd_set,NULL,NULL,&pcap_fd_set_tv)) + pcap_dispatch(pcap_handle,-1,parse_package,(unsigned char *)&info); + else + hop_channel(&info); + } + + puts("bugreports: hackbard@hackdaworld.dyndns.org"); + return 23; +} diff --git a/main.h b/main.h new file mode 100644 index 0000000..4d9b7b6 --- /dev/null +++ b/main.h @@ -0,0 +1,37 @@ +/* + * main.h - main header file + * + * author: hackbard@hackdaworld.dyndns.org + * + */ + +#include + + +#define SYSCALL_MAX 32 +#define MAX_DEV_CHARS 6 +#define PCAP_SELECT_SEC 0 +#define PCAP_SELECT_USEC 200000 + +#define CAP_MODE_MASK 0x01 +#define CAP_QUIT_MASK 0x02 + +#define MONITORING_MODE 0x01 +#define MANAGED_MODE 0x00 +#define QUIT_MODE 0x02 + +#define IWPRIV_M_MODE 3 + + +/* typedefinitions */ +struct info_struct +{ + unsigned char caps; /* capabilities */ + int logfile_fd; /* file descriptof for logfile */ + char device[MAX_DEV_CHARS]; /* sniffed devie */ + int channel_hop_fd; /* fd for channel hopping */ +}; + + +/* function prototypes */ +int usage(void); diff --git a/Makefile b/old/Makefile similarity index 100% rename from Makefile rename to old/Makefile diff --git a/hdw-sniff.c b/old/hdw-sniff.c similarity index 100% rename from hdw-sniff.c rename to old/hdw-sniff.c diff --git a/hdw-sniff.h b/old/hdw-sniff.h similarity index 100% rename from hdw-sniff.h rename to old/hdw-sniff.h diff --git a/hdw_outlib.c b/old/hdw_outlib.c similarity index 100% rename from hdw_outlib.c rename to old/hdw_outlib.c diff --git a/hdw_outlib.h b/old/hdw_outlib.h similarity index 100% rename from hdw_outlib.h rename to old/hdw_outlib.h diff --git a/ieee80211.h b/old/ieee80211.h similarity index 100% rename from ieee80211.h rename to old/ieee80211.h diff --git a/ieee802_11.h b/old/ieee802_11.h similarity index 100% rename from ieee802_11.h rename to old/ieee802_11.h diff --git a/list.c b/old/list.c similarity index 100% rename from list.c rename to old/list.c diff --git a/list.h b/old/list.h similarity index 100% rename from list.h rename to old/list.h diff --git a/parse.c b/parse.c new file mode 100644 index 0000000..70d15c9 --- /dev/null +++ b/parse.c @@ -0,0 +1,25 @@ +/* + * parse.c - parsing of pcap packages + * + * author: hackbard@hackdaworld.dyndns.org + * + */ + +#include "parse.h" +#include "802.11b.h" +#include "main.h" +#include "parse.h" + + +int parse_package(unsigned char *info,const struct pcap_pkthdr *pcap_hdr,cont unsigned char *package) +{ + if(info->caps&MONITORING_MODE) + { + struct linux_wlan_ng_prism_hdr *prism_hdr; + + prism_hdr=(struct linux_wlan_ng_prism_hdr *)package; + + + + +} -- 2.20.1