-rw-r--r-- | noncore/net/wellenreiter/daemon/source/Makefile | 7 | ||||
-rw-r--r-- | noncore/net/wellenreiter/daemon/source/TODO | 1 | ||||
-rw-r--r-- | noncore/net/wellenreiter/daemon/source/cardmode.cc | 3 | ||||
-rw-r--r-- | noncore/net/wellenreiter/daemon/source/cardmode.hh | 4 | ||||
-rw-r--r-- | noncore/net/wellenreiter/daemon/source/daemon.cc | 50 | ||||
-rw-r--r-- | noncore/net/wellenreiter/daemon/source/sniffer.cc | 41 | ||||
-rw-r--r-- | noncore/net/wellenreiter/daemon/source/sniffer.hh | 8 |
7 files changed, 38 insertions, 76 deletions
diff --git a/noncore/net/wellenreiter/daemon/source/Makefile b/noncore/net/wellenreiter/daemon/source/Makefile index bcbc799..f3f41f0 100644 --- a/noncore/net/wellenreiter/daemon/source/Makefile +++ b/noncore/net/wellenreiter/daemon/source/Makefile | |||
@@ -8,3 +8,3 @@ LDFLAGS = | |||
8 | LIBS = -lpcap ../../libwellenreiter/source/libwellenreiter.a | 8 | LIBS = -lpcap ../../libwellenreiter/source/libwellenreiter.a |
9 | OBJ = daemon.o | 9 | OBJ = daemon.o cardmode.o sniffer.o |
10 | 10 | ||
@@ -22,7 +22,2 @@ wellenreiterd: $(OBJ) | |||
22 | 22 | ||
23 | sniffer: sniffer.o cardmode.o | ||
24 | $(CPP) $(OPTIMFLAGS) $(WARNFLAGS) sniffer.o cardmode.o $(LDFLAGS) $(LIBS) -o $@ | ||
25 | @echo Build sniffer | ||
26 | |||
27 | |||
28 | clean distclean realclean: | 23 | clean distclean realclean: |
diff --git a/noncore/net/wellenreiter/daemon/source/TODO b/noncore/net/wellenreiter/daemon/source/TODO index 39b1a05..2d72ab7 100644 --- a/noncore/net/wellenreiter/daemon/source/TODO +++ b/noncore/net/wellenreiter/daemon/source/TODO | |||
@@ -2,3 +2,2 @@ implement communication protocol | |||
2 | security analysis | 2 | security analysis |
3 | implement sniffer (last step) | ||
4 | security analysis | 3 | security analysis |
diff --git a/noncore/net/wellenreiter/daemon/source/cardmode.cc b/noncore/net/wellenreiter/daemon/source/cardmode.cc index f84ce23..8069edc 100644 --- a/noncore/net/wellenreiter/daemon/source/cardmode.cc +++ b/noncore/net/wellenreiter/daemon/source/cardmode.cc | |||
@@ -2,2 +2,3 @@ | |||
2 | 2 | ||
3 | #include "config.hh" | ||
3 | #include "cardmode.hh" | 4 | #include "cardmode.hh" |
@@ -18,3 +19,3 @@ int card_into_monitormode (char *device, int cardtype) | |||
18 | return 0; | 19 | return 0; |
19 | } | 20 | } |
20 | 21 | ||
diff --git a/noncore/net/wellenreiter/daemon/source/cardmode.hh b/noncore/net/wellenreiter/daemon/source/cardmode.hh index 87284a1..ecc97b1 100644 --- a/noncore/net/wellenreiter/daemon/source/cardmode.hh +++ b/noncore/net/wellenreiter/daemon/source/cardmode.hh | |||
@@ -15,4 +15,2 @@ | |||
15 | 15 | ||
16 | #endif /* CARDMODE_HH */ | ||
17 | |||
18 | /* Defines, used for the card setup */ | 16 | /* Defines, used for the card setup */ |
@@ -35,2 +33,2 @@ int card_set_promisc_up (char * device); | |||
35 | 33 | ||
36 | 34 | #endif /* CARDMODE_HH */ | |
diff --git a/noncore/net/wellenreiter/daemon/source/daemon.cc b/noncore/net/wellenreiter/daemon/source/daemon.cc index b3a37b6..1f9e98a 100644 --- a/noncore/net/wellenreiter/daemon/source/daemon.cc +++ b/noncore/net/wellenreiter/daemon/source/daemon.cc | |||
@@ -8,2 +8,4 @@ | |||
8 | #include "daemon.hh" | 8 | #include "daemon.hh" |
9 | #include "cardmode.hh" | ||
10 | #include "sniffer.hh" | ||
9 | 11 | ||
@@ -12,4 +14,3 @@ int main(int argc, char **argv) | |||
12 | { | 14 | { |
13 | int sock, maxfd, guiport=GUIPORT; | 15 | int sock, maxfd; |
14 | char guihost[]="127.0.0.1"; | ||
15 | struct sockaddr_in *cliaddr; | 16 | struct sockaddr_in *cliaddr; |
@@ -17,3 +18,7 @@ int main(int argc, char **argv) | |||
17 | char buffer[128]; | 18 | char buffer[128]; |
18 | FILE *fp=stdin; /* Will be replaced with sniffer */ | 19 | pcap_t *handletopcap; /* The handle to the libpcap */ |
20 | char errbuf[PCAP_ERRBUF_SIZE]; /* The errorbuffer of libpacap */ | ||
21 | struct pcap_pkthdr header; /* The packet header from pcap*/ | ||
22 | const u_char *packet; /* The actual packet content*/ | ||
23 | |||
19 | fd_set rset; | 24 | fd_set rset; |
@@ -22,2 +27,15 @@ int main(int argc, char **argv) | |||
22 | 27 | ||
28 | /* will be replaced soon, just for max because max is lazy :-) */ | ||
29 | if(card_into_monitormode (SNIFFER_DEVICE, CARD_TYPE_NG) < 0) | ||
30 | { | ||
31 | fprintf(stderr, "Cannot set card into mon mode, aborting\n"); | ||
32 | exit(-1); | ||
33 | } | ||
34 | |||
35 | /* opening the pcap for sniffing */ | ||
36 | handletopcap = pcap_open_live(SNIFFER_DEVICE, BUFSIZ, 1, 1000, errbuf); | ||
37 | #ifdef HAVE_PCAP_NONBLOCK | ||
38 | pcap_setnonblock(handletopcap, 1, errstr); | ||
39 | #endif | ||
40 | |||
23 | /* Setup socket for incoming commands */ | 41 | /* Setup socket for incoming commands */ |
@@ -38,4 +56,4 @@ int main(int argc, char **argv) | |||
38 | FD_SET(sock, &rset); | 56 | FD_SET(sock, &rset); |
39 | FD_SET(fileno(fp), &rset); | 57 | FD_SET(pcap_fileno(handletopcap), &rset); |
40 | maxfd=sock+fileno(fp)+1; | 58 | maxfd=sock + pcap_fileno(handletopcap) + 1; |
41 | if(select(maxfd, &rset, NULL, NULL, NULL) < 0) | 59 | if(select(maxfd, &rset, NULL, NULL, NULL) < 0) |
@@ -57,4 +75,4 @@ int main(int argc, char **argv) | |||
57 | 75 | ||
58 | /* Pass string to analyze function */ | 76 | /* will be passed to analyze function */ |
59 | // sendcomm(guihost, guiport, buffer); | 77 | fprintf(stderr, "Received command: %s\n", buffer); |
60 | 78 | ||
@@ -62,15 +80,11 @@ int main(int argc, char **argv) | |||
62 | 80 | ||
63 | /* Will be replaced with sniffer ... later */ | 81 | /* Pcap stuff */ |
64 | if(FD_ISSET(fileno(fp), &rset)) | 82 | if(FD_ISSET(pcap_fileno(handletopcap), &rset)) |
65 | { | 83 | { |
66 | memset(buffer, 0, sizeof(buffer)); | ||
67 | if(fgets(buffer, sizeof(buffer) - 1, fp) == NULL) | ||
68 | { | ||
69 | wl_logerr("Cannot read from stdin: %s", strerror(errno)); | ||
70 | break; | ||
71 | } | ||
72 | wl_loginfo("Sending command to '%s': %s", GUIADDR, buffer); | ||
73 | 84 | ||
74 | /* Send string to GUI */ | 85 | /* Grab one single packet */ |
75 | sendcomm(guihost, guiport, "%d: %s", 1234, buffer); | 86 | packet = pcap_next(handletopcap, &header); |
87 | |||
88 | /* process the packet */ | ||
89 | process_packets(NULL,&header,*&packet); | ||
76 | 90 | ||
diff --git a/noncore/net/wellenreiter/daemon/source/sniffer.cc b/noncore/net/wellenreiter/daemon/source/sniffer.cc index be64d67..66d5b6f 100644 --- a/noncore/net/wellenreiter/daemon/source/sniffer.cc +++ b/noncore/net/wellenreiter/daemon/source/sniffer.cc | |||
@@ -14,41 +14,2 @@ | |||
14 | 14 | ||
15 | int main(void) | ||
16 | { | ||
17 | if(card_into_monitormode (SNIFFER_DEVICE, CARD_TYPE_NG) < 0) | ||
18 | return 0; | ||
19 | start_sniffing (SNIFFER_DEVICE); | ||
20 | |||
21 | return 1; | ||
22 | } | ||
23 | |||
24 | int start_sniffing (char * device) | ||
25 | { | ||
26 | |||
27 | pcap_t *handletopcap; /* The handle to the libpcap */ | ||
28 | char errbuf[PCAP_ERRBUF_SIZE]; /* The errorbuffer of libpacap */ | ||
29 | struct pcap_pkthdr header; /* The packet header from pcap*/ | ||
30 | const u_char *packet; /* The actual packet content*/ | ||
31 | |||
32 | /* opening the pcap for sniffing */ | ||
33 | handletopcap = pcap_open_live(device, BUFSIZ, 1, 1000, errbuf); | ||
34 | |||
35 | #ifdef HAVE_PCAP_NONBLOCK | ||
36 | pcap_setnonblock(handletopcap, 1, errstr); | ||
37 | #endif | ||
38 | /*start scanning */ | ||
39 | //pcap_loop(handletopcap,-1,process_packets,NULL); | ||
40 | /* Loope endless */ | ||
41 | while(1) | ||
42 | { | ||
43 | /* Grab one single packet */ | ||
44 | packet = pcap_next(handletopcap, &header); | ||
45 | |||
46 | /* process the packet */ | ||
47 | process_packets(NULL,&header,*&packet); | ||
48 | } | ||
49 | |||
50 | printf("\nDone processing packets... wheew!\n"); | ||
51 | return 1; | ||
52 | } | ||
53 | |||
54 | void process_packets(u_char *useless,const struct pcap_pkthdr* pkthdr,const u_char* packet) | 15 | void process_packets(u_char *useless,const struct pcap_pkthdr* pkthdr,const u_char* packet) |
@@ -300,3 +261,3 @@ int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo) | |||
300 | 261 | ||
301 | static int GetHeaderLength(u_int16_t fc) | 262 | int GetHeaderLength(u_int16_t fc) |
302 | { | 263 | { |
diff --git a/noncore/net/wellenreiter/daemon/source/sniffer.hh b/noncore/net/wellenreiter/daemon/source/sniffer.hh index d262353..7e1e3be 100644 --- a/noncore/net/wellenreiter/daemon/source/sniffer.hh +++ b/noncore/net/wellenreiter/daemon/source/sniffer.hh | |||
@@ -15,6 +15,4 @@ | |||
15 | 15 | ||
16 | |||
17 | #define NONBROADCASTING "non-broadcasting" | 16 | #define NONBROADCASTING "non-broadcasting" |
18 | 17 | ||
19 | |||
20 | /* holds all the interresting data */ | 18 | /* holds all the interresting data */ |
@@ -38,6 +36,2 @@ struct packetinfo | |||
38 | 36 | ||
39 | |||
40 | /* Prototypes */ | ||
41 | int sniffer(void); | ||
42 | int start_sniffing (char * device); | ||
43 | void process_packets(u_char *useless,const struct pcap_pkthdr* pkthdr,const u_char* packet); | 37 | void process_packets(u_char *useless,const struct pcap_pkthdr* pkthdr,const u_char* packet); |
@@ -47,3 +41,3 @@ int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo); | |||
47 | 41 | ||
48 | static int GetHeaderLength(u_int16_t fc); | 42 | int GetHeaderLength(u_int16_t fc); |
49 | 43 | ||