summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/wellenreiter/daemon/source/Makefile7
-rw-r--r--noncore/net/wellenreiter/daemon/source/TODO1
-rw-r--r--noncore/net/wellenreiter/daemon/source/cardmode.cc3
-rw-r--r--noncore/net/wellenreiter/daemon/source/cardmode.hh4
-rw-r--r--noncore/net/wellenreiter/daemon/source/daemon.cc50
-rw-r--r--noncore/net/wellenreiter/daemon/source/sniffer.cc41
-rw-r--r--noncore/net/wellenreiter/daemon/source/sniffer.hh8
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
@@ -5,9 +5,9 @@ CPP = g++
5 OPTIMFLAGS= -g 5 OPTIMFLAGS= -g
6 WARNFLAGS= -Wall -pedantic -DDEBUG 6 WARNFLAGS= -Wall -pedantic -DDEBUG
7 LDFLAGS = 7 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
11.SUFFIXES: 11.SUFFIXES:
12 .PHONY: all wellenreiterd clean distclean realclean 12 .PHONY: all wellenreiterd clean distclean realclean
13 13
@@ -19,13 +19,8 @@ all: wellenreiterd
19 wellenreiterd:$(OBJ) 19 wellenreiterd:$(OBJ)
20 $(CPP) $(OPTIMFLAGS) $(WARNFLAGS) $(OBJ) $(LDFLAGS) $(LIBS) -o $@ 20 $(CPP) $(OPTIMFLAGS) $(WARNFLAGS) $(OBJ) $(LDFLAGS) $(LIBS) -o $@
21 @echo Build wellenreiterd 21 @echo Build wellenreiterd
22 22
23sniffer: sniffer.o cardmode.o
24 $(CPP) $(OPTIMFLAGS) $(WARNFLAGS) sniffer.o cardmode.o $(LDFLAGS) $(LIBS) -o $@
25 @echo Build sniffer
26
27
28clean distclean realclean: 23clean distclean realclean:
29 @rm -rf wellenreiterd *~ *.o 24 @rm -rf wellenreiterd *~ *.o
30 @echo All dependent files have been removed. 25 @echo All dependent files have been removed.
31 26
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
@@ -1,5 +1,4 @@
1implement communication protocol 1implement communication protocol
2security analysis 2security analysis
3implement sniffer (last step)
4security analysis 3security analysis
5code cleanup \ No newline at end of file 4code cleanup \ No newline at end of file
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
@@ -1,6 +1,7 @@
1/* $Id$ */ 1/* $Id$ */
2 2
3#include "config.hh"
3#include "cardmode.hh" 4#include "cardmode.hh"
4 5
5int card_into_monitormode (char *device, int cardtype) 6int card_into_monitormode (char *device, int cardtype)
6{ 7{
@@ -15,9 +16,9 @@ int card_into_monitormode (char *device, int cardtype)
15 if(device == NULL) 16 if(device == NULL)
16 { 17 {
17 printf ("Fatal error i did not have any interfaces to sniff on\n"); 18 printf ("Fatal error i did not have any interfaces to sniff on\n");
18 return 0; 19 return 0;
19 } 20 }
20 21
21 /* Setting the prmiscous and up flag to the interface */ 22 /* Setting the prmiscous and up flag to the interface */
22 if (card_set_promisc_up (device) == 0) 23 if (card_set_promisc_up (device) == 0)
23 { 24 {
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
@@ -12,10 +12,8 @@
12#include <netinet/in.h> 12#include <netinet/in.h>
13#include <arpa/inet.h> 13#include <arpa/inet.h>
14#include <net/bpf.h> 14#include <net/bpf.h>
15 15
16#endif /* CARDMODE_HH */
17
18/* Defines, used for the card setup */ 16/* Defines, used for the card setup */
19#define DEFAULT_PATH "/proc/driver/aironet/%s/Config" 17#define DEFAULT_PATH "/proc/driver/aironet/%s/Config"
20 #define CARD_TYPE_CISCO1 18 #define CARD_TYPE_CISCO1
21 #define CARD_TYPE_NG2 19 #define CARD_TYPE_NG2
@@ -32,5 +30,5 @@
32 30
33int card_into_monitormode (char * device, int cardtype); 31int card_into_monitormode (char * device, int cardtype);
34int card_set_promisc_up (char * device); 32int 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
@@ -5,22 +5,40 @@
5 */ 5 */
6 6
7#include "config.hh" 7#include "config.hh"
8#include "daemon.hh" 8#include "daemon.hh"
9#include "cardmode.hh"
10#include "sniffer.hh"
9 11
10/* Main function of wellenreiterd */ 12/* Main function of wellenreiterd */
11int main(int argc, char **argv) 13int 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;
16 socklen_t len=sizeof(struct sockaddr); 17 socklen_t len=sizeof(struct sockaddr);
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;
20 25
21 fprintf(stderr, "wellenreiterd %s\n\n", VERSION); 26 fprintf(stderr, "wellenreiterd %s\n\n", VERSION);
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 */
24 if((sock=commsock(DAEMONADDR, DAEMONPORT)) < 0) 42 if((sock=commsock(DAEMONADDR, DAEMONPORT)) < 0)
25 { 43 {
26 wl_logerr("Cannot setup socket"); 44 wl_logerr("Cannot setup socket");
@@ -35,10 +53,10 @@ int main(int argc, char **argv)
35 while(1) 53 while(1)
36 { 54 {
37 55
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)
42 { 60 {
43 wl_logerr("Error calling select: %s", strerror(errno)); 61 wl_logerr("Error calling select: %s", strerror(errno));
44 break; 62 break;
@@ -54,26 +72,22 @@ int main(int argc, char **argv)
54 break; 72 break;
55 } 73 }
56 wl_loginfo("Received command from '%s': %s", inet_ntoa(cliaddr->sin_addr), buffer); 74 wl_loginfo("Received command from '%s': %s", inet_ntoa(cliaddr->sin_addr), buffer);
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
61 } 79 }
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
77 } 91 }
78 } 92 }
79 close(sock); 93 close(sock);
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
@@ -11,47 +11,8 @@
11#include "sniffer.hh" 11#include "sniffer.hh"
12#include "ieee802_11.hh" 12#include "ieee802_11.hh"
13#include "extract.hh" 13#include "extract.hh"
14 14
15int 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
24int 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
54void process_packets(u_char *useless,const struct pcap_pkthdr* pkthdr,const u_char* packet) 15void process_packets(u_char *useless,const struct pcap_pkthdr* pkthdr,const u_char* packet)
55{ 16{
56 u_int caplen = pkthdr->caplen; 17 u_int caplen = pkthdr->caplen;
57 u_int length = pkthdr->len; 18 u_int length = pkthdr->len;
@@ -297,9 +258,9 @@ int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo)
297 258
298} /* End of handle_beacon */ 259} /* End of handle_beacon */
299 260
300 261
301static int GetHeaderLength(u_int16_t fc) 262int GetHeaderLength(u_int16_t fc)
302{ 263{
303 int iLength=0; 264 int iLength=0;
304 265
305 switch (FC_TYPE(fc)) { 266 switch (FC_TYPE(fc)) {
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
@@ -12,12 +12,10 @@
12#include <netinet/in.h> 12#include <netinet/in.h>
13#include <arpa/inet.h> 13#include <arpa/inet.h>
14#include <net/bpf.h> 14#include <net/bpf.h>
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 */
21struct packetinfo 19struct packetinfo
22{ 20{
23 int isvalid; 21 int isvalid;
@@ -35,18 +33,14 @@ struct packetinfo
35 char *ssid; 33 char *ssid;
36 int ssid_len; 34 int ssid_len;
37}; 35};
38 36
39
40/* Prototypes */
41int sniffer(void);
42int start_sniffing (char * device);
43void process_packets(u_char *useless,const struct pcap_pkthdr* pkthdr,const u_char* packet); 37void process_packets(u_char *useless,const struct pcap_pkthdr* pkthdr,const u_char* packet);
44int decode_80211b_hdr(const u_char *p,struct packetinfo *ppinfo); 38int decode_80211b_hdr(const u_char *p,struct packetinfo *ppinfo);
45void etheraddr_string(register const u_char *ep,char * text); 39void etheraddr_string(register const u_char *ep,char * text);
46int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo); 40int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo);
47 41
48static int GetHeaderLength(u_int16_t fc); 42int GetHeaderLength(u_int16_t fc);
49 43
50/* 44/*
51 * True if "l" bytes of "var" were captured. 45 * True if "l" bytes of "var" were captured.
52 * 46 *