summaryrefslogtreecommitdiff
path: root/noncore/net/wellenreiter
Unidiff
Diffstat (limited to 'noncore/net/wellenreiter') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/wellenreiter/daemon/source/Makefile5
-rw-r--r--noncore/net/wellenreiter/daemon/source/cardmode.cc89
-rw-r--r--noncore/net/wellenreiter/daemon/source/cardmode.hh36
-rw-r--r--noncore/net/wellenreiter/daemon/source/sniffer.cc95
-rw-r--r--noncore/net/wellenreiter/daemon/source/sniffer.hh13
5 files changed, 137 insertions, 101 deletions
diff --git a/noncore/net/wellenreiter/daemon/source/Makefile b/noncore/net/wellenreiter/daemon/source/Makefile
index f6efa3d..bcbc799 100644
--- a/noncore/net/wellenreiter/daemon/source/Makefile
+++ b/noncore/net/wellenreiter/daemon/source/Makefile
@@ -22,2 +22,7 @@ wellenreiterd: $(OBJ)
22 22
23sniffer: sniffer.o cardmode.o
24 $(CPP) $(OPTIMFLAGS) $(WARNFLAGS) sniffer.o cardmode.o $(LDFLAGS) $(LIBS) -o $@
25 @echo Build sniffer
26
27
23clean distclean realclean: 28clean distclean realclean:
diff --git a/noncore/net/wellenreiter/daemon/source/cardmode.cc b/noncore/net/wellenreiter/daemon/source/cardmode.cc
new file mode 100644
index 0000000..ae32af4
--- a/dev/null
+++ b/noncore/net/wellenreiter/daemon/source/cardmode.cc
@@ -0,0 +1,89 @@
1/* $Id$ */
2
3#include "cardmode.hh"
4
5int card_into_monitormode (char *device, int cardtype)
6{
7
8 int datalink; /* used for getting the pcap datalink type */
9 char CiscoRFMON[35] = "/proc/driver/aironet/";
10 FILE *CISCO_CONFIG_FILE;
11 char errbuf[PCAP_ERRBUF_SIZE];
12 pcap_t *handle;
13
14 /* Checks if we have a device to sniff on */
15 if(device == NULL)
16 {
17 printf ("Fatal error i did not have any interfaces to sniff on\n");
18 return 0;
19 }
20
21 /* Setting the prmiscous and up flag to the interface */
22 if (card_set_promisc_up (device) == 0)
23 {
24 printf ("Interface flags correctly set using ifconfig\n");
25 }
26
27 /* Check the cardtype and executes the commands to go into monitor mode */
28 if (cardtype == CARD_TYPE_CISCO) /* I got a cisco card */
29 {
30 /* bring the sniffer into rfmon mode */
31 snprintf(CiscoRFMON, sizeof(CiscoRFMON),DEFAULT_PATH, device);
32 CISCO_CONFIG_FILE = fopen(CiscoRFMON,"w");
33 fputs ("Mode: r",CISCO_CONFIG_FILE);
34 fputs ("Mode: y",CISCO_CONFIG_FILE);
35 fputs ("XmitPower: 1",CISCO_CONFIG_FILE);
36 fclose(CISCO_CONFIG_FILE);
37 }
38 else if (cardtype == CARD_TYPE_NG)
39 {
40 char wlanngcmd[62];
41 snprintf(wlanngcmd, sizeof(wlanngcmd),"%s %s lnxreq_wlansniff channel=1 enable=true",WLANCTL_PATH,device);
42 if (system (wlanngcmd) != 0)
43 {
44 printf ("\n Fatal error could not set %s in raw mode, check cardtype\n",device);
45 return 0;
46 }
47 }
48 else if (cardtype == CARD_TYPE_HOSTAP)
49 {
50 printf ("Got a host-ap card, nothing is implemented now\n");
51 }
52
53
54 /* Check the interface if it is in the correct raw mode */
55 handle = pcap_open_live(device, BUFSIZ, 1, 0, errbuf);
56
57 /* getting the datalink type */
58 datalink = pcap_datalink(handle);
59
60 if (datalink == DLT_IEEE802_11) /* Rawmode is IEEE802_11 */
61 {
62 printf ("Your successfully listen on %s in 802.11 raw mode\n",device);
63 pcap_close(handle);
64 return 0;
65
66 }
67 else
68 {
69 printf ("Fatal error, cannot continue, your interface %s does not work in the correct 802.11 raw mode, check you driver please\n",device);
70 pcap_close(handle);
71 return 0;
72 }
73}
74
75
76
77int card_set_promisc_up (char * device)
78{
79 int ret;
80 char ifconfigcmd[32];
81 snprintf(ifconfigcmd,sizeof(ifconfigcmd),SBIN_PATH, device);
82 ret = system (ifconfigcmd);
83 if (ret > 0)
84 {
85 printf ("\nFatal error, could not execute %s please check your card,binary location and permission\n",ifconfigcmd);
86 return 0;
87 }
88 return 1;
89}
diff --git a/noncore/net/wellenreiter/daemon/source/cardmode.hh b/noncore/net/wellenreiter/daemon/source/cardmode.hh
new file mode 100644
index 0000000..87284a1
--- a/dev/null
+++ b/noncore/net/wellenreiter/daemon/source/cardmode.hh
@@ -0,0 +1,36 @@
1/* $Id$ */
2
3#ifndef CARDMODE_HH
4#define CARDMODE_HH
5
6#include <string.h>
7#include <stdio.h>
8#include <stdlib.h>
9#include <pcap.h>
10#include <errno.h>
11#include <sys/socket.h>
12#include <netinet/in.h>
13#include <arpa/inet.h>
14#include <net/bpf.h>
15
16#endif /* CARDMODE_HH */
17
18/* Defines, used for the card setup */
19#define DEFAULT_PATH "/proc/driver/aironet/%s/Config"
20 #define CARD_TYPE_CISCO1
21 #define CARD_TYPE_NG2
22 #define CARD_TYPE_HOSTAP3
23
24/* only for now, until we have the daemon running */
25/*the config file should provide these information */
26 #define SNIFFER_DEVICE "wlan0"
27#define CARD_TYPE CARD_TYPE_CISCO
28 #define SBIN_PATH"/sbin/ifconfig %s promisc up"
29#define WLANCTL_PATH "/sbin/wlanctl-ng"
30
31/* Prototypes */
32
33int card_into_monitormode (char * device, int cardtype);
34int card_set_promisc_up (char * device);
35
36
diff --git a/noncore/net/wellenreiter/daemon/source/sniffer.cc b/noncore/net/wellenreiter/daemon/source/sniffer.cc
index c837505..65c8579 100644
--- a/noncore/net/wellenreiter/daemon/source/sniffer.cc
+++ b/noncore/net/wellenreiter/daemon/source/sniffer.cc
@@ -9,2 +9,3 @@
9#include "config.hh" 9#include "config.hh"
10#include "cardmode.hh"
10#include "sniffer.hh" 11#include "sniffer.hh"
@@ -13,3 +14,3 @@
13 14
14int sniffer(void) 15int main(void)
15 { 16 {
@@ -22,86 +23,2 @@ int sniffer(void)
22 23
23int card_into_monitormode (char *device, int cardtype)
24{
25
26 int datalink; /* used for getting the pcap datalink type */
27 char CiscoRFMON[35] = "/proc/driver/aironet/";
28 FILE *CISCO_CONFIG_FILE;
29 char errbuf[PCAP_ERRBUF_SIZE];
30 pcap_t *handle;
31
32 /* Checks if we have a device to sniff on */
33 if(device == NULL)
34 {
35 printf ("Fatal error i did not have any interfaces to sniff on\n");
36 return 0;
37 }
38
39 /* Setting the prmiscous and up flag to the interface */
40 if (card_set_promisc_up (device) == 0)
41 {
42 printf ("Interface flags correctly set using ifconfig\n");
43 }
44
45 /* Check the cardtype and executes the commands to go into monitor mode */
46 if (cardtype == CARD_TYPE_CISCO) /* I got a cisco card */
47 {
48 /* bring the sniffer into rfmon mode */
49 snprintf(CiscoRFMON, sizeof(CiscoRFMON),DEFAULT_PATH, device);
50 CISCO_CONFIG_FILE = fopen(CiscoRFMON,"w");
51 fputs ("Mode: r",CISCO_CONFIG_FILE);
52 fputs ("Mode: y",CISCO_CONFIG_FILE);
53 fputs ("XmitPower: 1",CISCO_CONFIG_FILE);
54 fclose(CISCO_CONFIG_FILE);
55 }
56 else if (cardtype == CARD_TYPE_NG)
57 {
58 char wlanngcmd[62];
59 snprintf(wlanngcmd, sizeof(wlanngcmd),"%s %s lnxreq_wlansniff channel=1 enable=true",WLANCTL_PATH,device);
60 if (system (wlanngcmd) != 0)
61 {
62 printf ("\n Fatal error could not set %s in raw mode, check cardtype\n",device);
63 return 0;
64 }
65 }
66 else if (cardtype == CARD_TYPE_HOSTAP)
67 {
68 printf ("Got a host-ap card, nothing is implemented now\n");
69 }
70
71
72 /* Check the interface if it is in the correct raw mode */
73 handle = pcap_open_live(device, BUFSIZ, 1, 0, errbuf);
74
75 /* getting the datalink type */
76 datalink = pcap_datalink(handle);
77
78 if (datalink == DLT_IEEE802_11) /* Rawmode is IEEE802_11 */
79 {
80 printf ("Your successfully listen on %s in 802.11 raw mode\n",device);
81 pcap_close(handle);
82 return 0;
83
84 }
85 else
86 {
87 printf ("Fatal error, cannot continue, your interface %s does not work in the correct 802.11 raw mode, check you driver please\n",device);
88 pcap_close(handle);
89 return 0;
90 }
91}
92
93int card_set_promisc_up (char * device)
94{
95 int ret;
96 char ifconfigcmd[32];
97 snprintf(ifconfigcmd,sizeof(ifconfigcmd),SBIN_PATH, device);
98 ret = system (ifconfigcmd);
99 if (ret > 0)
100 {
101 printf ("\nFatal error, could not execute %s please check your card,binary location and permission\n",ifconfigcmd);
102 return 0;
103 }
104 return 1;
105}
106
107int start_sniffing (char * device) 24int start_sniffing (char * device)
@@ -115,3 +32,2 @@ int start_sniffing (char * device)
115 32
116 /* Next few lines a taken out of kismet */
117 #ifdef HAVE_PCAP_NONBLOCK 33 #ifdef HAVE_PCAP_NONBLOCK
@@ -119,3 +35,2 @@ int start_sniffing (char * device)
119 #endif 35 #endif
120
121 /*start scanning */ 36 /*start scanning */
@@ -141,2 +56,3 @@ void process_packets(u_char *useless,const struct pcap_pkthdr* pkthdr,const u_ch
141 pinfoptr->pktlen = pkthdr->len; 56 pinfoptr->pktlen = pkthdr->len;
57
142 if (caplen < IEEE802_11_FC_LEN) 58 if (caplen < IEEE802_11_FC_LEN)
@@ -184,2 +100,3 @@ void process_packets(u_char *useless,const struct pcap_pkthdr* pkthdr,const u_ch
184 { 100 {
101 printf ("\n\tOn network : %s",pinfoptr->ssid);
185 if (!strcmp(pinfoptr->desthwaddr,"ff:ff:ff:ff:ff:ff") == 0) 102 if (!strcmp(pinfoptr->desthwaddr,"ff:ff:ff:ff:ff:ff") == 0)
@@ -191,2 +108,3 @@ void process_packets(u_char *useless,const struct pcap_pkthdr* pkthdr,const u_ch
191 } 108 }
109
192 if (pinfoptr->cap_ESS == pinfoptr->cap_IBSS) 110 if (pinfoptr->cap_ESS == pinfoptr->cap_IBSS)
@@ -330,2 +248,3 @@ int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo)
330 break; 248 break;
249
331 case E_CHALLENGE: 250 case E_CHALLENGE:
@@ -366,3 +285,3 @@ int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo)
366 } /* end of for loop */ 285 } /* end of for loop */
367 return 1; 286 return 0;
368 287
diff --git a/noncore/net/wellenreiter/daemon/source/sniffer.hh b/noncore/net/wellenreiter/daemon/source/sniffer.hh
index 7f45be6..d262353 100644
--- a/noncore/net/wellenreiter/daemon/source/sniffer.hh
+++ b/noncore/net/wellenreiter/daemon/source/sniffer.hh
@@ -15,6 +15,2 @@
15 15
16#define DEFAULT_PATH "/proc/driver/aironet/%s/Config"
17 #define CARD_TYPE_CISCO1
18 #define CARD_TYPE_NG2
19 #define CARD_TYPE_HOSTAP3
20 16
@@ -22,8 +18,2 @@
22 18
23/* only for now, until we have the daemon running */
24/*the config file should provide these information */
25 #define SNIFFER_DEVICE "wlan0"
26#define CARD_TYPE CARD_TYPE_CISCO
27 #define SBIN_PATH"/sbin/ifconfig %s promisc up"
28#define WLANCTL_PATH "/sbin/wlanctl-ng"
29 19
@@ -50,6 +40,3 @@ struct packetinfo
50/* Prototypes */ 40/* Prototypes */
51
52int sniffer(void); 41int sniffer(void);
53int card_into_monitormode (char * device, int cardtype);
54int card_set_promisc_up (char * device);
55int start_sniffing (char * device); 42int start_sniffing (char * device);