Diffstat (limited to 'noncore/net/wellenreiter/daemon/source/sniffer.cc') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/wellenreiter/daemon/source/sniffer.cc | 95 |
1 files changed, 7 insertions, 88 deletions
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 | |||
@@ -4,123 +4,38 @@ | |||
4 | * able driver and not with wifi stuff. | 4 | * able driver and not with wifi stuff. |
5 | * | 5 | * |
6 | * $Id$ | 6 | * $Id$ |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "config.hh" | 9 | #include "config.hh" |
10 | #include "cardmode.hh" | ||
10 | #include "sniffer.hh" | 11 | #include "sniffer.hh" |
11 | #include "ieee802_11.hh" | 12 | #include "ieee802_11.hh" |
12 | #include "extract.hh" | 13 | #include "extract.hh" |
13 | 14 | ||
14 | int sniffer(void) | 15 | int main(void) |
15 | { | 16 | { |
16 | if(card_into_monitormode (SNIFFER_DEVICE, CARD_TYPE_NG) < 0) | 17 | if(card_into_monitormode (SNIFFER_DEVICE, CARD_TYPE_NG) < 0) |
17 | return 0; | 18 | return 0; |
18 | start_sniffing (SNIFFER_DEVICE); | 19 | start_sniffing (SNIFFER_DEVICE); |
19 | 20 | ||
20 | return 1; | 21 | return 1; |
21 | } | 22 | } |
22 | 23 | ||
23 | int 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 | |||
93 | int 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 | |||
107 | int start_sniffing (char * device) | 24 | int start_sniffing (char * device) |
108 | { | 25 | { |
109 | 26 | ||
110 | pcap_t *handletopcap; | 27 | pcap_t *handletopcap; |
111 | char errbuf[PCAP_ERRBUF_SIZE]; | 28 | char errbuf[PCAP_ERRBUF_SIZE]; |
112 | 29 | ||
113 | /* opening the pcap for sniffing */ | 30 | /* opening the pcap for sniffing */ |
114 | handletopcap = pcap_open_live(device, BUFSIZ, 1, 1000, errbuf); | 31 | handletopcap = pcap_open_live(device, BUFSIZ, 1, 1000, errbuf); |
115 | 32 | ||
116 | /* Next few lines a taken out of kismet */ | ||
117 | #ifdef HAVE_PCAP_NONBLOCK | 33 | #ifdef HAVE_PCAP_NONBLOCK |
118 | pcap_setnonblock(handletopcap, 1, errstr); | 34 | pcap_setnonblock(handletopcap, 1, errstr); |
119 | #endif | 35 | #endif |
120 | |||
121 | /*start scanning */ | 36 | /*start scanning */ |
122 | pcap_loop(handletopcap,-1,process_packets,NULL); | 37 | pcap_loop(handletopcap,-1,process_packets,NULL); |
123 | 38 | ||
124 | printf("\nDone processing packets... wheew!\n"); | 39 | printf("\nDone processing packets... wheew!\n"); |
125 | return 1; | 40 | return 1; |
126 | } | 41 | } |
@@ -136,12 +51,13 @@ void process_packets(u_char *useless,const struct pcap_pkthdr* pkthdr,const u_ch | |||
136 | struct packetinfo pinfo; | 51 | struct packetinfo pinfo; |
137 | struct packetinfo *pinfoptr; | 52 | struct packetinfo *pinfoptr; |
138 | pinfoptr=&pinfo; | 53 | pinfoptr=&pinfo; |
139 | 54 | ||
140 | pinfoptr->isvalid = 0; | 55 | pinfoptr->isvalid = 0; |
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) |
143 | { | 59 | { |
144 | /* This is a garbage packet, because is does not long enough | 60 | /* This is a garbage packet, because is does not long enough |
145 | to hold a 802.11b header */ | 61 | to hold a 802.11b header */ |
146 | pinfoptr->isvalid = 0; | 62 | pinfoptr->isvalid = 0; |
147 | return; | 63 | return; |
@@ -179,19 +95,21 @@ void process_packets(u_char *useless,const struct pcap_pkthdr* pkthdr,const u_ch | |||
179 | case T_MGMT: | 95 | case T_MGMT: |
180 | switch (FC_SUBTYPE(fc)) | 96 | switch (FC_SUBTYPE(fc)) |
181 | { /* Is it a beacon frame? */ | 97 | { /* Is it a beacon frame? */ |
182 | case ST_BEACON: | 98 | case ST_BEACON: |
183 | if (handle_beacon(fc, packet,pinfoptr) ==0) | 99 | if (handle_beacon(fc, packet,pinfoptr) ==0) |
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) |
186 | { | 103 | { |
187 | /* Every beacon must have the broadcast as destination | 104 | /* Every beacon must have the broadcast as destination |
188 | so it must be a shitti packet */ | 105 | so it must be a shitti packet */ |
189 | pinfoptr->isvalid = 0; | 106 | pinfoptr->isvalid = 0; |
190 | return; | 107 | return; |
191 | } | 108 | } |
109 | |||
192 | if (pinfoptr->cap_ESS == pinfoptr->cap_IBSS) | 110 | if (pinfoptr->cap_ESS == pinfoptr->cap_IBSS) |
193 | { | 111 | { |
194 | /* Only one of both are possible, so must be | 112 | /* Only one of both are possible, so must be |
195 | a noise packet, if this comes up */ | 113 | a noise packet, if this comes up */ |
196 | pinfoptr->isvalid = 0; | 114 | pinfoptr->isvalid = 0; |
197 | return; | 115 | return; |
@@ -325,12 +243,13 @@ int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo) | |||
325 | { | 243 | { |
326 | ppinfo->ssid = (char *)pbody.ssid.ssid; | 244 | ppinfo->ssid = (char *)pbody.ssid.ssid; |
327 | } | 245 | } |
328 | ppinfo->ssid_len = pbody.ssid.length; | 246 | ppinfo->ssid_len = pbody.ssid.length; |
329 | } | 247 | } |
330 | break; | 248 | break; |
249 | |||
331 | case E_CHALLENGE: | 250 | case E_CHALLENGE: |
332 | memcpy(&(pbody.challenge),p+offset,2); offset += 2; | 251 | memcpy(&(pbody.challenge),p+offset,2); offset += 2; |
333 | if (pbody.challenge.length > 0) | 252 | if (pbody.challenge.length > 0) |
334 | { | 253 | { |
335 | memcpy(&(pbody.challenge.text),p+offset,pbody.challenge.length); offset += pbody.challenge.length; | 254 | memcpy(&(pbody.challenge.text),p+offset,pbody.challenge.length); offset += pbody.challenge.length; |
336 | pbody.challenge.text[pbody.challenge.length]='\0'; | 255 | pbody.challenge.text[pbody.challenge.length]='\0'; |
@@ -361,13 +280,13 @@ int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo) | |||
361 | default: | 280 | default: |
362 | 281 | ||
363 | offset+= *(p+offset+1) + 2; | 282 | offset+= *(p+offset+1) + 2; |
364 | break; | 283 | break; |
365 | } /* end of switch*/ | 284 | } /* end of switch*/ |
366 | } /* end of for loop */ | 285 | } /* end of for loop */ |
367 | return 1; | 286 | return 0; |
368 | 287 | ||
369 | } /* End of handle_beacon */ | 288 | } /* End of handle_beacon */ |
370 | 289 | ||
371 | 290 | ||
372 | static int GetHeaderLength(u_int16_t fc) | 291 | static int GetHeaderLength(u_int16_t fc) |
373 | { | 292 | { |