summaryrefslogtreecommitdiff
path: root/noncore
authormjm <mjm>2002-11-23 21:42:41 (UTC)
committer mjm <mjm>2002-11-23 21:42:41 (UTC)
commitc93ded2c1256817b9c974c792cd143315b98fff7 (patch) (unidiff)
tree7de5b3fc8eee930f72c4e3ef662f48948a60d935 /noncore
parent4e24ece4607d3b2f9e3252fa561fabaa9cdddd63 (diff)
downloadopie-c93ded2c1256817b9c974c792cd143315b98fff7.zip
opie-c93ded2c1256817b9c974c792cd143315b98fff7.tar.gz
opie-c93ded2c1256817b9c974c792cd143315b98fff7.tar.bz2
implemented sniffer function in daemon.cc
Diffstat (limited to 'noncore') (more/less context) (show 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.cc1
-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, 37 insertions, 75 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
@@ -3,13 +3,13 @@
3 CPP = g++ 3 CPP = g++
4 4
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
14%.o : %.cc 14%.o : %.cc
15 $(CPP) $(WARNFLAGS) $(OPTIMFLAGS) -c $< -o $@ 15 $(CPP) $(WARNFLAGS) $(OPTIMFLAGS) -c $< -o $@
@@ -17,17 +17,12 @@ OBJ = daemon.o
17 all:wellenreiterd 17 all:wellenreiterd
18 18
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
32 daemon.o:config.hh 27 daemon.o:config.hh
33 28
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,8 +1,9 @@
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{
7 8
8 int datalink; /* used for getting the pcap datalink type */ 9 int datalink; /* used for getting the pcap datalink type */
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
@@ -10,14 +10,12 @@
10#include <errno.h> 10#include <errno.h>
11#include <sys/socket.h> 11#include <sys/socket.h>
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
22 #define CARD_TYPE_HOSTAP3 20 #define CARD_TYPE_HOSTAP3
23 21
@@ -30,7 +28,7 @@
30 28
31/* Prototypes */ 29/* Prototypes */
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
@@ -3,26 +3,44 @@
3 * 3 *
4 * $Id$ 4 * $Id$
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");
27 exit(-1); 45 exit(-1);
28 } 46 }
@@ -33,14 +51,14 @@ int main(int argc, char **argv)
33 /* Start main loop */ 51 /* Start main loop */
34 wl_loginfo("Starting main loop"); 52 wl_loginfo("Starting main loop");
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;
45 } 63 }
46 64
@@ -52,30 +70,26 @@ int main(int argc, char **argv)
52 { 70 {
53 wl_logerr("Cannot read from socket: %s", strerror(errno)); 71 wl_logerr("Cannot read from socket: %s", strerror(errno));
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);
80 exit(0); 94 exit(0);
81} 95}
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
@@ -9,51 +9,12 @@
9#include "config.hh" 9#include "config.hh"
10#include "cardmode.hh" 10#include "cardmode.hh"
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;
58 u_int16_t fc; 19 u_int16_t fc;
59 u_int HEADER_LENGTH; 20 u_int HEADER_LENGTH;
@@ -295,13 +256,13 @@ int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo)
295 } /* end of for loop */ 256 } /* end of for loop */
296 return 0; 257 return 0;
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)) {
306 case T_MGMT: 267 case T_MGMT:
307 iLength = MGMT_HEADER_LEN; 268 iLength = MGMT_HEADER_LEN;
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
@@ -10,16 +10,14 @@
10#include <errno.h> 10#include <errno.h>
11#include <sys/socket.h> 11#include <sys/socket.h>
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;
24 int pktlen; 22 int pktlen;
25 int fctype; 23 int fctype;
@@ -33,22 +31,18 @@ struct packetinfo
33 char desthwaddr[sizeof("00:00:00:00:00:00")]; 31 char desthwaddr[sizeof("00:00:00:00:00:00")];
34 char sndhwaddr[sizeof("00:00:00:00:00:00")]; 32 char sndhwaddr[sizeof("00:00:00:00:00:00")];
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 *
53 * The "snapend - (l) <= snapend" checks to make sure "l" isn't so large 47 * The "snapend - (l) <= snapend" checks to make sure "l" isn't so large
54 * that "snapend - (l)" underflows. 48 * that "snapend - (l)" underflows.