From: hackbard Date: Wed, 1 Jun 2005 15:42:08 +0000 (+0000) Subject: commit soon and often .. (nothing working by now ;) X-Git-Url: https://hackdaworld.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c9575c4e105d074120e573587cbf7e7de9a0b5ab;p=my-code%2Fhdw-sniff.git commit soon and often .. (nothing working by now ;) --- diff --git a/Makefile b/Makefile index 0503908..80353ae 100644 --- a/Makefile +++ b/Makefile @@ -1,28 +1,29 @@ -# Makefile of hdw-sniff +# hdw-sniff Makefile, created Fri May 27 20:42:55 CEST 2005 INCLUDEDIR = /usr/include - CFLAGS = -DDEBUG -O3 -Wall -LIBS = -lpcap +LIBS = -lm -lncurses -lpcap + +OBJS = network.o event.o list.o display.o input.o +OBJS2 = hdw-sniff -API_OBJS = network.o event.o input.o display.o audio.o +links: + ln -sf ../api/network/network.{c,h} . + ln -sf ../api/event/event.{c,h} . + ln -sf ../api/list/list.{c,h} . + ln -sf ../api/display/display.{c,h} . + ln -sf ../api/input/input.{c,h} . -api: links $(API_OBJS) +hdw-sniff: links $(OBJS) + $(CC) $(CFLAGS) -o $@ $(OBJS) main.c parse.c $(LIBS) -hdw-sniff: $(API_OBJS) - $(CC) $(CFLAGS) -o $@ $(API_OBJS) hdw-sniff.c $(LIBS) all: hdw-sniff clean: - rm -f $(API_OBJS) {event,input,display,audio,network,list}.{c,h} - rm -f hdw-sniff - -links: - ln -sf ../api/event/event.{c,h} . - ln -sf ../api/input/input.{c,h} . - ln -sf ../api/display/display.{c,h} . - ln -sf ../api/audio/audio.{c,h} . - ln -sf ../api/network/network.{c,h} . - ln -sf ../api/list/list.{c,h} . + rm -f $(OBJS) $(OBJS2) remake: clean all + +install: + mkdir -p /usr/bin + cp hdw-sniff /usr/bin diff --git a/main.c b/main.c index a0f5575..2c5a41f 100644 --- a/main.c +++ b/main.c @@ -1,39 +1,101 @@ /* * main.c - main hdw-sniff * - * Copyright (C) 2004 hackbard@hackdaworld.dyndns.org + * Copyright (C) 2004/05 hackbard@hackdaworld.org * */ #include "main.h" -void parse_package(unsigned char *ptr,const struct pcap_pkthdr *pcap_header,const unsigned char *package); +// void parse_package(unsigned char *ptr,const struct pcap_pkthdr *pcap_header,const unsigned char *package); /* functions */ -int get_user_event(t_info *info) { - char event; - if(read(0,&event,1)!=1) { - perror("reading user interaction failed"); - return -23; +int display_console(t_info *info,char *string) { + + int x,y; + t_display *display; + + display=(t_display *)&(info->display); + + x=display->max_x-1; + y=display->max_y-1; + + display_line(display,0,0,2,0,'-'); + display_string(display,4,0,"essid",5); + display_line(display,10,0,x,0,'-'); + + //display_line(display,0,0,0,y,'|'); + //display_line(display,x,0,x,y,'|'); + + display_line(display,0,y-1,x,y-1,'-'); + + display_draw(display); + + return 23; +} + +int noop(t_input *input,void *ptr) { + + return 23; +} + +int get_user_interaction(t_info *info) { + + char *string; + + string=(char *)malloc(info->display.max_x*sizeof(char)); + + input_get_event(&(info->input),noop,info); + + /* + if(info->input.content[0]=='h') { + display_console(info,"hdw-sniff help:"); + display_console(info,"h - print this help"); + display_console(info,"x - enable/disable hex output"); + display_console(info,"a - enable/disable ascii output"); + display_console(info,"q - quit"); + display_console(info,"console navigation: arrow up/down"); + display_console(info,"network list navigation: page up/down"); } - printf("user event: %c ",event); - if(event=='h') { - info->mode^=MODE_HEXOUT; - printf("- hex output: %c\n",info->mode&MODE_HEXOUT?'a':'n'); + */ + + if(info->input.content[0]=='x') { + info->mode^=MODE_HEXOUT; + display_console(info,"toggled hex output"); } - if(event=='a') { - info->mode^=MODE_ASCIIOUT; - printf("- ascii output: %c\n",info->mode&MODE_ASCIIOUT?'a':'n'); + + else if(info->input.content[0]=='a') { + info->mode^=MODE_ASCIIOUT; + display_console(info,"toggled ascii output"); } - if(event=='q') { - info->mode|=MODE_QUIT; - printf("- shutting down!\n"); + + else if(info->input.content[0]=='q') { + event_stop(&(info->event)); + display_console(info,"quit!"); + } + + else { + snprintf(string,info->display.max_x,"unknown event (%x)", + info->input.content[0]); + display_console(info,string); } return 23; } +int react_on_event(t_event *event,void *ptr) { + + t_info *info; + + info=(t_info *)ptr; + + if(event_check(event,0)==E_FD_YES) get_user_interaction(info); + else pcap_dispatch(info->pcap_handle,-1,parse_package,(u_char *)ptr); + + return 23; +} + int usage(void) { puts("usage: hdw-sniff "); puts("\toptions:"); @@ -43,11 +105,16 @@ int usage(void) { puts("\t\t-k \t(string)"); puts("\t\t-h \tdisplay this help message"); puts(""); + + return 23; } -int hop_channel(t_info *info) { +int hop_channel(t_event *event,void *ptr) { struct iwreq iwreq; + t_info *info; + + info=(t_info *)ptr; if(info->current_channel>=CHANNEL_MAX) info->current_channel=1; memset(&iwreq,0,sizeof(iwreq)); @@ -67,8 +134,7 @@ int main(int argc, char **argv) { t_info info; int pcap_fd; - fd_set fds; - struct timeval hop_f; + int logfd; int i; char sys_call[MAX_SYSCALL_CHARS]; char pcap_error[PCAP_ERRBUF_SIZE]; @@ -130,6 +196,9 @@ int main(int argc, char **argv) { puts("setting up device ..."); system(sys_call); + // todo + logfd=open("/tmp/hdw-sniff.log",O_WRONLY|O_CREAT); + /* pcap */ if((info.pcap_handle=pcap_open_live(info.device,BUFSIZ,1,-1,pcap_error))==NULL) { @@ -142,31 +211,30 @@ int main(int argc, char **argv) { /* socket fd for channel hopping */ info.channel_hop_fd=socket(AF_INET,SOCK_DGRAM,0); - /* parse packages until user breaks */ - while(!(info.mode&MODE_QUIT)) - { - /* watch pcap_fd and stdin (reading) */ - FD_ZERO(&fds); - FD_SET(pcap_fd,&fds); - FD_SET(0,&fds); - hop_f.tv_sec=HOP_SEC; - hop_f.tv_usec=HOP_USEC; - - if(select(pcap_fd+1,&fds,NULL,NULL,&hop_f)) { - if(FD_ISSET(0,&fds)) - get_user_event(&info); - else if(FD_ISSET(pcap_fd,&fds)) - pcap_dispatch(info.pcap_handle,-1,parse_package,(unsigned char *)&info); - else - hop_channel(&info); - } - } + display_init(&(info.display),logfd); + + input_init(&(info.input),logfd); + //input.mode=CONTENT_BUFFER; + input_ios_init(&info.input); + event_init(&(info.event),logfd); + event_set_timeout(&(info.event),HOP_SEC,HOP_USEC); + + event_math(0,&(info.event),READ,ADD); + event_math(pcap_fd,&(info.event),READ,ADD); + + display_console(&info,"foo"); + + event_start(&(info.event),&info,react_on_event,hop_channel); + + input_shutdown(&(info.input)); + display_shutdown(&(info.display)); + puts(""); puts(""); - puts("thanks for using hdw-sniff (C) 2005 hackbard"); + puts("thanks for using hdw-sniff (C) 2004/05 hackbard"); puts(""); - puts("bugreports: hackbard@hackdaworld.dyndns.org"); + puts("bugreports: hackbard@hackdaworld.org"); return 23; diff --git a/main.h b/main.h index 4e5259c..0a39b7b 100644 --- a/main.h +++ b/main.h @@ -28,8 +28,12 @@ #include "parse.h" +#include "event.h" +#include "display.h" +#include "input.h" + #define SYSCALL_MAX 32 -#define CHANNEL_MAX 13 +#define CHANNEL_MAX 12 #define MAX_DEV_CHARS 6 #define MAX_SYSCALL_CHARS 64 @@ -47,6 +51,9 @@ /* type definitions */ typedef struct s_info { + t_event event; + t_display display; + t_input input; int count; /* count packages */ unsigned char mode; /* monitoring/managed mode */ char device[MAX_DEV_CHARS]; /* sniffed devie */ @@ -56,12 +63,11 @@ typedef struct s_info { int channel_hop_fd; char key[13]; /* wep key */ pcap_t *pcap_handle; + t_data data; + int view_table; } t_info; - /* function prototypes */ -int usage(void); -int get_user_event(t_info *info); -int hop_channel(t_info *info); +void parse_package(unsigned char *ptr,const struct pcap_pkthdr *pcap_header,const unsigned char *package); #endif diff --git a/parse.h b/parse.h index 228a67e..1bf727e 100644 --- a/parse.h +++ b/parse.h @@ -1,8 +1,14 @@ -/* function prototypes */ +/* parse.h */ #ifndef PARSE_H #define PARSE_H -// void parse_package(unsigned char *ptr,const struct pcap_pkthdr *pcap_header,const unsigned char *package); +typedef struct s_data { + unsigned char **package; + int p_count; + +} t_data; + +/* function prototypes */ #endif