From c191ef245532c978ebdfbcb25056500fab9eb638 Mon Sep 17 00:00:00 2001 From: hackbard Date: Thu, 2 Jun 2005 17:39:23 +0000 Subject: [PATCH] beacon work ... --- main.c | 28 ++++++++++++++++++---------- main.h | 2 +- parse.c | 27 +++++++++++++++++++++++---- parse.h | 13 +++++++++++++ 4 files changed, 55 insertions(+), 15 deletions(-) diff --git a/main.c b/main.c index 8004e9e..1ed6040 100644 --- a/main.c +++ b/main.c @@ -23,7 +23,13 @@ int display_console(t_info *info,char *string) { display_line(display,0,0,2,0,'-'); display_string(display,4,0,"sta",3); - display_line(display,8,0,x,0,'-'); + display_line(display,8,0,12,0,'-'); + + display_string(display,13,0,"bssid",5); + display_line(display,19,0,23,0,'-'); + + display_string(display,24,0,"M",1); + display_line(display,26,0,x,0,'-'); //display_line(display,0,0,0,y,'|'); //display_line(display,x,0,x,y,'|'); @@ -117,7 +123,8 @@ int hop_channel(t_event *event,void *ptr) { info=(t_info *)ptr; - if(info->current_channel>=CHANNEL_MAX) info->current_channel=1; + if((info->current_channel>CHANNEL_MAX)|(info->current_channel==0)) + info->current_channel=1; memset(&iwreq,0,sizeof(iwreq)); strcpy(iwreq.ifr_name,info->device); iwreq.u.freq.e=0; @@ -127,8 +134,9 @@ int hop_channel(t_event *event,void *ptr) { perror("ioctl"); return -23; } - ++(info->current_channel); - return 23; + ++(info->current_channel); + + return 23; } int main(int argc, char **argv) { @@ -201,11 +209,12 @@ int main(int argc, char **argv) { system(sys_call); if(info.log_fd==0) { - if((info.log_fd=open("/tmp/hdw-sniff.log",O_RDWR|O_CREAT))!=0) - puts("using logfile /tmp/hdw-sniff.log ..."); - else { - puts("failed to open logfile ..."); - return -23; + if((info.log_fd=open("/tmp/hdw-sniff.log",O_RDWR|O_CREAT))!=0) + puts("using logfile /tmp/hdw-sniff.log ..."); + else { + puts("failed to open logfile ..."); + return -23; + } } /* pcap */ @@ -248,5 +257,4 @@ int main(int argc, char **argv) { puts("bugreports: hackbard@hackdaworld.org"); return 23; - } diff --git a/main.h b/main.h index b44ce38..754c5f8 100644 --- a/main.h +++ b/main.h @@ -34,7 +34,7 @@ #include "list.h" #define SYSCALL_MAX 32 -#define CHANNEL_MAX 12 +#define CHANNEL_MAX 13 #define MAX_DEV_CHARS 6 #define MAX_SYSCALL_CHARS 64 diff --git a/parse.c b/parse.c index cac3821..b325728 100644 --- a/parse.c +++ b/parse.c @@ -6,7 +6,6 @@ */ #include "parse.h" -//#include "802.11b.h" #include "main.h" /* all the parsing stuff will go here @@ -19,12 +18,19 @@ void parse_package(unsigned char *ptr,const struct pcap_pkthdr *pcap_header,cons t_info *info; int i; t_sta new_sta; + t_frame4_hdr *f4hdr; + t_frame3_hdr *f3hdr; + t_frame2_hdr *f2hdr; + t_frame1_hdr *f1hdr; + t_beacon_fb *beacon_fb; int ret; info=(t_info *)ptr; info->count++; + memset(&new_sta,0,sizeof(t_sta)); + if(info->dump_fd!=0) { ret=write(info->dump_fd,pcap_header,sizeof(struct pcap_pkthdr)); if(ret!=sizeof(struct pcap_pkthdr)) @@ -37,9 +43,22 @@ void parse_package(unsigned char *ptr,const struct pcap_pkthdr *pcap_header,cons /* maybe there is offset to the actual ieee802.11 frame, for example prism header ... */ - /* debug log */ - dprintf(info->log_fd,"new package -> %02x/n",package[0]); + if(FCTL_TYPE(package[0])==FCTL_TYPE_MGMT) { + if(FCTL_STYPE(package[0])==FCTL_STYPE_BEACON) + f3hdr=(t_frame3_hdr *)package; + beacon_fb=(t_beacon_fb *)package+sizeof(t_frame3_hdr); + dprintf(info->log_fd,"beacon: "); + for(i=0;ilog_fd,"%02x ",*((f3hdr->addr2)+i)); + dprintf(info->log_fd," essid: "); + for(i=0;issid_length;i++) + dprintf(info->log_fd,"%c ",(beacon_fb->ssid)+i); + dprintf(info->log_fd,"\n"); + } - /* go on parsing frame ctl header here ... */ + else { + dprintf(info->log_fd,"other: "); + for(i=0;i<16;i++) dprintf(info->log_fd,"%02x ",package[i]); + dprintf(info->log_fd,"\n"); + } } diff --git a/parse.h b/parse.h index a657833..96eca6d 100644 --- a/parse.h +++ b/parse.h @@ -6,6 +6,7 @@ /* ieee802.11 stuff */ +typedef unsigned long long int u64; typedef unsigned int u32; typedef unsigned short int u16; typedef unsigned char u8; @@ -90,6 +91,18 @@ typedef struct s_frame1_hdr { #define FCTL_STYPE_CFPOLL 0x6 #define FCTL_STYPE_CFACKPOLL 0x7 +typedef struct s_beacon_fb { + u64 timestamp; + u16 beacon_int; + u16 cap_info; + u8 ssid_element_id; + u8 ssid_length; + u32 ssid; + u8 srates_element_id; + u8 srates_element_length; + u8 rest; /* go on here ... */ +} __attribute__ ((packed)) t_beacon_fb; + /* hdw-sniff stuff */ -- 2.20.1