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 | 308 |
1 files changed, 0 insertions, 308 deletions
diff --git a/noncore/net/wellenreiter/daemon/source/sniffer.cc b/noncore/net/wellenreiter/daemon/source/sniffer.cc deleted file mode 100644 index 66d5b6f..0000000 --- a/noncore/net/wellenreiter/daemon/source/sniffer.cc +++ b/dev/null | |||
@@ -1,308 +0,0 @@ | |||
1 | /* | ||
2 | * rfmon mode sniffer | ||
3 | * This works only with cisco wireless cards with an rfmon | ||
4 | * able driver and not with wifi stuff. | ||
5 | * | ||
6 | * $Id$ | ||
7 | */ | ||
8 | |||
9 | #include "config.hh" | ||
10 | #include "cardmode.hh" | ||
11 | #include "sniffer.hh" | ||
12 | #include "ieee802_11.hh" | ||
13 | #include "extract.hh" | ||
14 | |||
15 | void process_packets(u_char *useless,const struct pcap_pkthdr* pkthdr,const u_char* packet) | ||
16 | { | ||
17 | u_int caplen = pkthdr->caplen; | ||
18 | u_int length = pkthdr->len; | ||
19 | u_int16_t fc; | ||
20 | u_int HEADER_LENGTH; | ||
21 | |||
22 | /* pinfo holds all interresting information for us */ | ||
23 | struct packetinfo pinfo; | ||
24 | struct packetinfo *pinfoptr; | ||
25 | pinfoptr=&pinfo; | ||
26 | |||
27 | pinfoptr->isvalid = 0; | ||
28 | pinfoptr->pktlen = pkthdr->len; | ||
29 | |||
30 | if (caplen < IEEE802_11_FC_LEN) | ||
31 | { | ||
32 | /* This is a garbage packet, because is does not long enough | ||
33 | to hold a 802.11b header */ | ||
34 | pinfoptr->isvalid = 0; | ||
35 | return; | ||
36 | } | ||
37 | |||
38 | /* Gets the framecontrol bits (2bytes long) */ | ||
39 | fc = EXTRACT_LE_16BITS(packet); | ||
40 | |||
41 | HEADER_LENGTH = GetHeaderLength(fc); | ||
42 | |||
43 | if (caplen < HEADER_LENGTH) | ||
44 | { | ||
45 | /* This is a garbage packet, because it is not long enough | ||
46 | to hold a correct header of its type */ | ||
47 | pinfoptr->isvalid = 0; | ||
48 | return; | ||
49 | } | ||
50 | |||
51 | /* Decode 802.11b header out of the packet */ | ||
52 | if (decode_80211b_hdr(packet,pinfoptr) == 0) | ||
53 | { | ||
54 | /* Justification of the ofset to further process the packet */ | ||
55 | length -= HEADER_LENGTH; | ||
56 | caplen -= HEADER_LENGTH; | ||
57 | packet += HEADER_LENGTH; | ||
58 | } | ||
59 | else | ||
60 | { /* Something is wrong,could not be a correct packet */ | ||
61 | return; | ||
62 | } | ||
63 | |||
64 | switch (FC_TYPE(fc)) | ||
65 | { | ||
66 | /* Is it a managemnet frame? */ | ||
67 | case T_MGMT: | ||
68 | switch (FC_SUBTYPE(fc)) | ||
69 | { /* Is it a beacon frame? */ | ||
70 | case ST_BEACON: | ||
71 | if (handle_beacon(fc, packet,pinfoptr) ==0) | ||
72 | { | ||
73 | if (!strcmp(pinfoptr->desthwaddr,"ff:ff:ff:ff:ff:ff") == 0) | ||
74 | { | ||
75 | /* Every beacon must have the broadcast as destination | ||
76 | so it must be a shitti packet */ | ||
77 | pinfoptr->isvalid = 0; | ||
78 | return; | ||
79 | } | ||
80 | |||
81 | if (pinfoptr->cap_ESS == pinfoptr->cap_IBSS) | ||
82 | { | ||
83 | /* Only one of both are possible, so must be | ||
84 | a noise packet, if this comes up */ | ||
85 | pinfoptr->isvalid = 0; | ||
86 | return; | ||
87 | } | ||
88 | if (pinfoptr->channel < 1 || pinfoptr->channel > 14) | ||
89 | { | ||
90 | /* Only channels between 1 and 14 are possible | ||
91 | others must be noise packets */ | ||
92 | pinfoptr->isvalid = 0; | ||
93 | return; | ||
94 | } | ||
95 | |||
96 | /* Here should be the infos to the gui issued */ | ||
97 | if (pinfoptr->cap_ESS == 1 &&pinfoptr->cap_IBSS ==0) | ||
98 | { | ||
99 | printf ("\nHave found an accesspoint:"); | ||
100 | } | ||
101 | else if(pinfoptr->cap_ESS == 0 && pinfoptr->cap_IBSS == 1) | ||
102 | { | ||
103 | printf ("\nHave found an AD-HOC station:"); | ||
104 | |||
105 | } | ||
106 | if (strcmp (pinfoptr->ssid,NONBROADCASTING) ==0) | ||
107 | { | ||
108 | printf ("\n\tOn a non-broadcasting network"); | ||
109 | } | ||
110 | else | ||
111 | { | ||
112 | printf ("\n\tOn network : %s",pinfoptr->ssid); | ||
113 | } | ||
114 | printf ("\n\tLen SSID : %d",pinfoptr->ssid_len); | ||
115 | printf ("\n\tOn Channel : %d",pinfoptr->channel); | ||
116 | printf ("\n\tEncryption : %s", pinfoptr->cap_WEP ? "ON" : "OFF"); | ||
117 | printf ("\n\tMacaddress : %s",pinfoptr->sndhwaddr); | ||
118 | printf ("\n\tBssid : %s",pinfoptr->bssid); | ||
119 | printf ("\n\tDest : %s\n",pinfoptr->desthwaddr); | ||
120 | } | ||
121 | break; | ||
122 | default: | ||
123 | printf("Unknown IEEE802.11 frame subtype (%d)",FC_SUBTYPE(fc)); | ||
124 | break; | ||
125 | } /* End of switch over different mgt frame types */ | ||
126 | |||
127 | break; | ||
128 | case T_CTRL: | ||
129 | //decode_control_frames(fc, packet); | ||
130 | printf ("Its a control frame"); | ||
131 | break; | ||
132 | case T_DATA: | ||
133 | //decode_data_frames(fc, packet); | ||
134 | printf ("Its a date frame"); | ||
135 | break; | ||
136 | default: | ||
137 | printf("Unknown IEEE802.11 frame type (%d)",FC_TYPE(fc)); | ||
138 | break; | ||
139 | } | ||
140 | } | ||
141 | |||
142 | |||
143 | /* This decodes the 802.11b frame header out of the 802.11b packet | ||
144 | all the infos is placed into the packetinfo structure */ | ||
145 | int decode_80211b_hdr(const u_char *p,struct packetinfo *ppinfo) | ||
146 | { | ||
147 | const struct mgmt_header_t *mgthdr = (const struct mgmt_header_t *) p; | ||
148 | ppinfo->fcsubtype = FC_SUBTYPE(mgthdr->fc); | ||
149 | |||
150 | /* Get the sender, bssid and dest mac address */ | ||
151 | etheraddr_string(mgthdr->bssid,ppinfo->bssid); | ||
152 | etheraddr_string(mgthdr->da,ppinfo->desthwaddr); | ||
153 | etheraddr_string(mgthdr->sa,ppinfo->sndhwaddr); | ||
154 | ppinfo->fc_wep = FC_WEP(mgthdr->fc); | ||
155 | return 0; | ||
156 | } | ||
157 | |||
158 | |||
159 | void etheraddr_string(register const u_char *ep,char * text) | ||
160 | { | ||
161 | static char hex[] = "0123456789abcdef"; | ||
162 | register u_int i, j; | ||
163 | register char *cp; | ||
164 | char buf[sizeof("00:00:00:00:00:00")]; | ||
165 | cp = buf; | ||
166 | if ((j = *ep >> 4) != 0) | ||
167 | *cp++ = hex[j]; | ||
168 | *cp++ = hex[*ep++ & 0xf]; | ||
169 | for (i = 5; (int)--i >= 0;) { | ||
170 | *cp++ = ':'; | ||
171 | if ((j = *ep >> 4) != 0) | ||
172 | *cp++ = hex[j]; | ||
173 | *cp++ = hex[*ep++ & 0xf]; | ||
174 | } | ||
175 | *cp = '\0'; | ||
176 | strcpy(text,buf); | ||
177 | } | ||
178 | |||
179 | int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo) | ||
180 | { | ||
181 | struct mgmt_body_t pbody; | ||
182 | int offset = 0; | ||
183 | |||
184 | /* Get the static informations out of the packet */ | ||
185 | memset(&pbody, 0, sizeof(pbody)); | ||
186 | memcpy(&pbody.timestamp, p, 8); | ||
187 | offset += 8; | ||
188 | pbody.beacon_interval = EXTRACT_LE_16BITS(p+offset); | ||
189 | offset += 2; | ||
190 | pbody.capability_info = EXTRACT_LE_16BITS(p+offset); | ||
191 | offset += 2; | ||
192 | |||
193 | /* Gets the different flags out of the capabilities */ | ||
194 | ppinfo->cap_ESS = CAPABILITY_ESS(pbody.capability_info); | ||
195 | ppinfo->cap_IBSS = CAPABILITY_IBSS(pbody.capability_info); | ||
196 | ppinfo->cap_WEP = CAPABILITY_PRIVACY(pbody.capability_info); | ||
197 | |||
198 | /* Gets the tagged elements out of the packets */ | ||
199 | while (offset + 1 < ppinfo->pktlen) | ||
200 | { | ||
201 | switch (*(p + offset)) | ||
202 | { | ||
203 | case E_SSID: | ||
204 | memcpy(&(pbody.ssid),p+offset,2); offset += 2; | ||
205 | if (pbody.ssid.length > 0) | ||
206 | { | ||
207 | memcpy(&(pbody.ssid.ssid),p+offset,pbody.ssid.length); offset += pbody.ssid.length; | ||
208 | pbody.ssid.ssid[pbody.ssid.length]='\0'; | ||
209 | if (strcmp((char *)pbody.ssid.ssid,"")==0) | ||
210 | { | ||
211 | ppinfo->ssid = NONBROADCASTING; | ||
212 | } | ||
213 | else | ||
214 | { | ||
215 | ppinfo->ssid = (char *)pbody.ssid.ssid; | ||
216 | } | ||
217 | ppinfo->ssid_len = pbody.ssid.length; | ||
218 | } | ||
219 | break; | ||
220 | |||
221 | case E_CHALLENGE: | ||
222 | memcpy(&(pbody.challenge),p+offset,2); offset += 2; | ||
223 | if (pbody.challenge.length > 0) | ||
224 | { | ||
225 | memcpy(&(pbody.challenge.text),p+offset,pbody.challenge.length); offset += pbody.challenge.length; | ||
226 | pbody.challenge.text[pbody.challenge.length]='\0'; | ||
227 | } | ||
228 | break; | ||
229 | case E_RATES: | ||
230 | memcpy(&(pbody.rates),p+offset,2); offset += 2; | ||
231 | if (pbody.rates.length > 0) { | ||
232 | memcpy(&(pbody.rates.rate),p+offset,pbody.rates.length); offset += pbody.rates.length; | ||
233 | } | ||
234 | break; | ||
235 | case E_DS: | ||
236 | memcpy(&(pbody.ds),p+offset,3); offset +=3; | ||
237 | ppinfo->channel = pbody.ds.channel; | ||
238 | break; | ||
239 | case E_CF: | ||
240 | memcpy(&(pbody.cf),p+offset,8); offset +=8; | ||
241 | break; | ||
242 | case E_TIM: | ||
243 | memcpy(&(pbody.tim),p+offset,2); offset +=2; | ||
244 | memcpy(&(pbody.tim.count),p+offset,3); offset +=3; | ||
245 | if ((pbody.tim.length -3) > 0) | ||
246 | { | ||
247 | memcpy((pbody.tim.bitmap),p+(pbody.tim.length -3),(pbody.tim.length -3)); | ||
248 | offset += pbody.tim.length -3; | ||
249 | } | ||
250 | break; | ||
251 | default: | ||
252 | |||
253 | offset+= *(p+offset+1) + 2; | ||
254 | break; | ||
255 | } /* end of switch*/ | ||
256 | } /* end of for loop */ | ||
257 | return 0; | ||
258 | |||
259 | } /* End of handle_beacon */ | ||
260 | |||
261 | |||
262 | int GetHeaderLength(u_int16_t fc) | ||
263 | { | ||
264 | int iLength=0; | ||
265 | |||
266 | switch (FC_TYPE(fc)) { | ||
267 | case T_MGMT: | ||
268 | iLength = MGMT_HEADER_LEN; | ||
269 | break; | ||
270 | case T_CTRL: | ||
271 | switch (FC_SUBTYPE(fc)) { | ||
272 | case CTRL_PS_POLL: | ||
273 | iLength = CTRL_PS_POLL_LEN; | ||
274 | break; | ||
275 | case CTRL_RTS: | ||
276 | iLength = CTRL_RTS_LEN; | ||
277 | break; | ||
278 | case CTRL_CTS: | ||
279 | iLength = CTRL_CTS_LEN; | ||
280 | break; | ||
281 | case CTRL_ACK: | ||
282 | iLength = CTRL_ACK_LEN; | ||
283 | break; | ||
284 | case CTRL_CF_END: | ||
285 | iLength = CTRL_END_LEN; | ||
286 | break; | ||
287 | case CTRL_END_ACK: | ||
288 | iLength = CTRL_END_ACK_LEN; | ||
289 | break; | ||
290 | default: | ||
291 | iLength = 0; | ||
292 | break; | ||
293 | } | ||
294 | break; | ||
295 | case T_DATA: | ||
296 | if (FC_TO_DS(fc) && FC_FROM_DS(fc)) | ||
297 | iLength = 30; | ||
298 | else | ||
299 | iLength = 24; | ||
300 | break; | ||
301 | default: | ||
302 | printf("unknown IEEE802.11 frame type (%d)", | ||
303 | FC_TYPE(fc)); | ||
304 | break; | ||
305 | } | ||
306 | |||
307 | return iLength; | ||
308 | } | ||