00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <include.h>
00029 #include <src/analyse.h>
00030 #include <src/interface.h>
00031 #include <src/crt_io.h>
00032 #include <src/conversion.h>
00033 #include <src/manuf.h>
00034 #include <src/airjack.h>
00035 #include <src/functions.h>
00036
00037
00038 void LogPutSSID_byAddMAc(UINT8 AddMac[WLAN_ADDR_LEN], char *SSID);
00039 void LogPutSSID_byBSSID(UINT8 BSSID[WLAN_ADDR_LEN], char *SSID);
00040 void CalculCoef(UINT32 X[HISTORY_SIZE],
00041 UINT32 Y[HISTORY_SIZE], float *a, float *b);
00042 char DetermineCryptType(UINT8 hasWep, UINT8 hasWPA, UINT8 hasTKIP,
00043 UINT8 hasCCMP, UINT8 hasWPAPSK, UINT8 hasWPA2PSK);
00044
00045 const char svnid[] = "@(#) $Id: analyse.c 178 2007-08-11 16:57:24Z poggij $";
00046
00047 UINT16 NumberOfDetectedClient = 0;
00048 ClientInfo_t ClientInfo[MAX_NUMBER_OF_DETECTED_CLIENT];
00049
00050
00051 extern WINDOW *Panel_WND, *RealTime_WND;
00052 extern ScanResult_t Res;
00053 extern Statistics_t Stats;
00054 extern UINT8 ids_warning;
00055 extern ConfigStruct config;
00056
00057 #ifdef WITH_THREAD
00058 extern pthread_mutex_t screen_mutex;
00059 #endif
00060
00061 const UINT8 BroadcastMAC[WLAN_ADDR_LEN] =
00062 { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
00063
00064 enum CRYPT_TYPE {
00065 CRYPT_TYPE_CLEAR = 0,
00066 CRYPT_TYPE_WEP,
00067 CRYPT_TYPE_WPA,
00068 CRYPT_TYPE_TKIP,
00069 CRYPT_TYPE_CCMP,
00070 CRYPT_TYPE_PSK1,
00071 CRYPT_TYPE_PSK2
00072 };
00073
00074 const char CryptTypeASCII[] = {
00075 [CRYPT_TYPE_CLEAR] = ' ',
00076 [CRYPT_TYPE_WEP] = 'w',
00077 [CRYPT_TYPE_WPA] = 'W',
00078 [CRYPT_TYPE_TKIP] = 'T',
00079 [CRYPT_TYPE_CCMP] = 'C',
00080 [CRYPT_TYPE_PSK1] = 'p',
00081 [CRYPT_TYPE_PSK2] = 'P'
00082 };
00083
00084 #define WPA_OUI "\x00\x50\xF2"
00085 #define RSN_OUI "\x00\x0F\xAC"
00086 #define WME_OUI "\x00\x50\xF2"
00087
00088
00089
00090
00091
00092
00093
00094 UINT8
00095 CompareAddMac(UINT8 AddMac1[WLAN_ADDR_LEN], UINT8 AddMac2[WLAN_ADDR_LEN])
00096 {
00097 return (((UINT8) AddMac1[0] == (UINT8) AddMac2[0]) &&
00098 ((UINT8) AddMac1[1] == (UINT8) AddMac2[1]) &&
00099 ((UINT8) AddMac1[2] == (UINT8) AddMac2[2]) &&
00100 ((UINT8) AddMac1[3] == (UINT8) AddMac2[3]) &&
00101 ((UINT8) AddMac1[4] == (UINT8) AddMac2[4]) &&
00102 ((UINT8) AddMac1[5] == (UINT8) AddMac2[5]));
00103 }
00104
00105
00106
00107
00108 UINT8 AddMacIsBroadcast(UINT8 AddMac1[WLAN_ADDR_LEN])
00109 {
00110 return (((UINT8) AddMac1[0] == 0xFF) &&
00111 ((UINT8) AddMac1[1] == 0xFF) &&
00112 ((UINT8) AddMac1[2] == 0xFF) &&
00113 ((UINT8) AddMac1[3] == 0xFF) &&
00114 ((UINT8) AddMac1[4] == 0xFF) && ((UINT8) AddMac1[5] == 0xFF));
00115 }
00116
00118 UINT8 AddMacIsNULL(UINT8 AddMac1[WLAN_ADDR_LEN])
00119 {
00120 return (((UINT8) AddMac1[0] == 0x00) &&
00121 ((UINT8) AddMac1[1] == 0x00) &&
00122 ((UINT8) AddMac1[2] == 0x00) &&
00123 ((UINT8) AddMac1[3] == 0x00) &&
00124 ((UINT8) AddMac1[4] == 0x00) && ((UINT8) AddMac1[5] == 0x00));
00125 }
00126
00127
00128
00129
00130 void ResetAllDetectedClient(void)
00131 {
00132 register UINT16 i;
00133
00134 for (i = 0; i < NumberOfDetectedClient; i++) {
00135 memset(&ClientInfo[i], 0, sizeof(ClientInfo_t));
00136 }
00137 NumberOfDetectedClient = 0;
00138 }
00139
00140
00141
00142
00143
00144
00145
00146 void LogPutSN(UINT8 AddMac[WLAN_ADDR_LEN], UINT32 SN)
00147 {
00148 register UINT16 i, j;
00149
00150 for (i = 0; i < NumberOfDetectedClient; i++) {
00151 if (CompareAddMac(ClientInfo[i].AddMac, AddMac)) {
00152
00153 for (j = (HISTORY_SIZE - 1); j != 0; j--) {
00154 ClientInfo[i].SN[j] = ClientInfo[i].SN[j - 1];
00155 }
00156
00157 ClientInfo[i].SN[0] = SN;
00158
00159
00160 if (ClientInfo[i].SNMax < SN) {
00161 ClientInfo[i].SNMax = SN;
00162 } else if ((ClientInfo[i].SNMin > SN)
00163 || (ClientInfo[i].SNMin == 0)) {
00164 ClientInfo[i].SNMin = SN;
00165 }
00166
00167 UINT32 summe = 0;
00168 for (j = 0; j < 4; j++) {
00169 summe += ClientInfo[i].SN[j];
00170 }
00171 ClientInfo[i].SNMed = (summe / HISTORY_SIZE);
00172
00173
00174 break;
00175 }
00176 }
00177 }
00178
00179
00180
00181
00182 void LogPutRate(UINT8 AddMac[WLAN_ADDR_LEN], UINT8 Rate)
00183 {
00184 register UINT16 i;
00185
00186 for (i = 0; i < NumberOfDetectedClient; i++) {
00187 if (CompareAddMac(ClientInfo[i].AddMac, AddMac)) {
00188 if (ClientInfo[i].RateMax < Rate)
00189 ClientInfo[i].RateMax = Rate;
00190 else if ((ClientInfo[i].RateMin > Rate)
00191 || (ClientInfo[i].RateMin == 0))
00192 ClientInfo[i].RateMin = Rate;
00193 break;
00194 }
00195 }
00196 }
00197
00198
00199
00200
00201 void LogPutMaxSpeed(UINT8 AddMac[WLAN_ADDR_LEN], UINT8 Rate)
00202 {
00203 register UINT16 i;
00204
00205 for (i = 0; i < NumberOfDetectedClient; i++) {
00206 if (CompareAddMac(ClientInfo[i].AddMac, AddMac)) {
00207 ClientInfo[i].MaxSpeed = Rate;
00208 }
00209 }
00210 }
00211
00212 void LogDetectedClient(UINT8 AddMac[WLAN_ADDR_LEN])
00213 {
00214 register UINT16 i;
00215 UINT8 Founded = 0;
00216
00217 if (NumberOfDetectedClient >= MAX_NUMBER_OF_DETECTED_CLIENT) {
00218 warning("Maximum of host is detected : %d.\n",
00219 MAX_NUMBER_OF_DETECTED_CLIENT);
00220 return;
00221 }
00222
00223 if (AddMacIsBroadcast(AddMac)) {
00224 Founded = 2;
00225
00226 }
00227
00228 for (i = 0; i < NumberOfDetectedClient; i++) {
00229 if (CompareAddMac(ClientInfo[i].AddMac, AddMac)) {
00230 Founded = 1;
00231
00232 break;
00233 }
00234 }
00235 if (!Founded) {
00236 debug(1,
00237 "New client found (%02X:%02X:%02X:%02X:%02X:%02X)\n",
00238 AddMac[0], AddMac[1], AddMac[2], AddMac[3],
00239 AddMac[4], AddMac[5]);
00240
00241 memset(&ClientInfo[NumberOfDetectedClient], 0, sizeof(ClientInfo_t));
00242 memcpy(&ClientInfo[NumberOfDetectedClient].AddMac, AddMac,
00243 WLAN_ADDR_LEN);
00244 memcpy(&ClientInfo[NumberOfDetectedClient].Manuf,
00245 AddMacToManufName(ClientInfo[i].AddMac), MANUF_MAXSTRINGLENGTH);
00246 memcpy(&ClientInfo[NumberOfDetectedClient].Model,
00247 AddMacToManufModel(ClientInfo[i].AddMac),
00248 MANUF_MAXSTRINGLENGTH);
00249 NumberOfDetectedClient++;
00250 }
00251 }
00252
00253
00254
00255
00256 void LogPutBSSID(UINT8 AddMac[WLAN_ADDR_LEN], UINT8 BSSID[WLAN_ADDR_LEN])
00257 {
00258 register UINT16 i;
00259
00260
00261 if (AddMacIsBroadcast(BSSID) == 0) {
00262 for (i = 0; i < NumberOfDetectedClient; i++) {
00263 if (CompareAddMac(ClientInfo[i].AddMac, AddMac)) {
00264 memcpy(&ClientInfo[i].BSSID, BSSID, WLAN_ADDR_LEN);
00265 break;
00266 }
00267 }
00268 }
00269 }
00270
00271 void LogPutDS(UINT8 AddMac[WLAN_ADDR_LEN])
00272 {
00273 register UINT16 i;
00274
00275 for (i = 0; i < NumberOfDetectedClient; i++) {
00276 if (CompareAddMac(ClientInfo[i].AddMac, AddMac)) {
00277 ClientInfo[i].IsDS = 1;
00278 break;
00279 }
00280 }
00281 }
00282
00283
00284
00285
00286 void LogPutWep(UINT8 BSSID[WLAN_ADDR_LEN], UINT8 hasWep, UINT8 hasWPA)
00287 {
00288 register UINT16 i;
00289
00290 for (i = 0; i < NumberOfDetectedClient; i++) {
00291 if (CompareAddMac(ClientInfo[i].BSSID, BSSID)) {
00292 ClientInfo[i].hasWep = hasWep;
00293 ClientInfo[i].hasWPA = hasWPA;
00294 }
00295 }
00296 }
00297
00298 void LogPutChannel_byAddMac(UINT8 AddMac[WLAN_ADDR_LEN], UINT8 Channel)
00299 {
00300 register UINT16 i;
00301
00302 for (i = 0; i < NumberOfDetectedClient; i++) {
00303 if (CompareAddMac(ClientInfo[i].AddMac, AddMac)) {
00304 ClientInfo[i].Channel = Channel;
00305 break;
00306 }
00307 }
00308 }
00309
00310
00311 void LogPutChannel_byBSSID(UINT8 BSSID[WLAN_ADDR_LEN], UINT8 Channel)
00312 {
00313 register UINT16 i;
00314
00315 for (i = 0; i < NumberOfDetectedClient; i++) {
00316 if (CompareAddMac(ClientInfo[i].BSSID, BSSID)) {
00317 ClientInfo[i].Channel = Channel;
00318 }
00319 }
00320 }
00321
00322 void
00323 LogPutChannel(UINT8 AddMac[WLAN_ADDR_LEN],
00324 UINT8 BSSID[WLAN_ADDR_LEN], UINT8 Channel)
00325 {
00326 if (AddMacIsBroadcast(BSSID))
00327 LogPutChannel_byAddMac(AddMac, Channel);
00328 else
00329 LogPutChannel_byBSSID(BSSID, Channel);
00330 }
00331
00332
00333 void LogPutSSID_byAddMac(UINT8 AddMac[WLAN_ADDR_LEN], char *SSID)
00334 {
00335 register UINT16 i;
00336
00337
00338
00339
00340 for (i = 0; i < NumberOfDetectedClient; i++) {
00341 if (CompareAddMac(ClientInfo[i].AddMac, AddMac)) {
00342
00343
00344 safe_strncpy(ClientInfo[i].SSID, SSID, WLAN_SSID_MAXLEN + 1);
00345
00346 break;
00347 }
00348 }
00349 }
00350
00351
00352 void LogPutSSID_byBSSID(UINT8 BSSID[WLAN_ADDR_LEN], char *SSID)
00353 {
00354 register UINT16 i;
00355
00356
00357
00358
00359 for (i = 0; i < NumberOfDetectedClient; i++) {
00360 if (CompareAddMac(ClientInfo[i].BSSID, BSSID)) {
00361 if ((strlen(ClientInfo[i].SSID) == 0)
00362 || ((strncmp(SSID, "<Hidden SSID>", WLAN_SSID_MAXLEN))
00363 &&
00364 (strncmp
00365 (SSID, "<Hidden SSID of known length>",
00366 WLAN_SSID_MAXLEN)))) {
00367 safe_strncpy(ClientInfo[i].SSID, SSID, WLAN_SSID_MAXLEN + 1);
00368 }
00369 }
00370 }
00371 }
00372
00373 void
00374 LogPutSSID(UINT8 AddMac[WLAN_ADDR_LEN],
00375 UINT8 BSSID[WLAN_ADDR_LEN], char *SSID)
00376 {
00377
00378
00379 if ((strlen(SSID) != 0) && (strncmp(SSID, " ", 32))) {
00380 if (AddMacIsBroadcast(BSSID))
00381 LogPutSSID_byAddMac(AddMac, SSID);
00382 else
00383 LogPutSSID_byBSSID(BSSID, SSID);
00384 }
00385 }
00386
00387 void LogPutIsAP(UINT8 AddMac[WLAN_ADDR_LEN], UINT8 hasWep, UINT8 hasWPA,
00388 UINT16 bcn_int)
00389 {
00390 register UINT16 i, j;
00391 UINT8 BSSID[WLAN_ADDR_LEN];
00392
00393 for (i = 0; i < NumberOfDetectedClient; i++) {
00394 if (CompareAddMac(ClientInfo[i].AddMac, AddMac)) {
00395 ClientInfo[i].hasWep = hasWep;
00396 ClientInfo[i].hasWPA = hasWPA;
00397
00398 for (j = (HISTORY_SIZE - 1); j != 0; j--)
00399 ClientInfo[i].bcn_int[j] = ClientInfo[i].bcn_int[j - 1];
00400 if (bcn_int != 0)
00401 ClientInfo[i].bcn_int[0] = bcn_int;
00402 memcpy(&BSSID, ClientInfo[i].BSSID, WLAN_ADDR_LEN);
00403
00404 ClientInfo[i].IsAP = 1;
00405
00406
00407 if (config.JammingNow == TRUE) {
00408 sendDeauth(BroadcastMAC, BSSID, 0);
00409 }
00410 break;
00411 }
00412 }
00413 LogPutWep(BSSID, hasWep, hasWPA);
00414 }
00415
00416 void LogPutIsP2P(UINT8 AddMac[WLAN_ADDR_LEN], UINT8 hasWep, UINT16 bcn_int)
00417 {
00418 register UINT16 i, j;
00419
00420 for (i = 0; i < NumberOfDetectedClient; i++) {
00421 if (CompareAddMac(ClientInfo[i].AddMac, AddMac)) {
00422 ClientInfo[i].hasWep = hasWep;
00423
00424 for (j = (HISTORY_SIZE - 1); j != 0; j--)
00425 ClientInfo[i].bcn_int[j] = ClientInfo[i].bcn_int[j - 1];
00426 if (bcn_int != 0)
00427 ClientInfo[i].bcn_int[0] = bcn_int;
00428 ClientInfo[i].IsP2P = 1;
00429 ClientInfo[i].IsAP = 0;
00430 debug(1, "IsP2P > %s\n", ClientInfo[i].AddMac);
00431 break;
00432 }
00433 }
00434 }
00435
00436 void
00437 LogPutOtherInformation(UINT8 AddMac[WLAN_ADDR_LEN], char *OtherInformation)
00438 {
00439 register UINT16 i;
00440
00441 for (i = 0; i < NumberOfDetectedClient; i++) {
00442 if (CompareAddMac(ClientInfo[i].AddMac, AddMac)) {
00443 safe_strncpy(ClientInfo[i].OtherInformation,
00444 OtherInformation, MAXSIZE_OTHERINFORMATION);
00445 break;
00446 }
00447 }
00448 }
00449
00451 void LogPutTimestamp(UINT8 AddMac[WLAN_ADDR_LEN], UINT64 TimeStamp)
00452 {
00453 register UINT16 i;
00454 UINT8 j;
00455
00456 for (i = 0; i < NumberOfDetectedClient; i++) {
00457 if (CompareAddMac(ClientInfo[i].AddMac, AddMac)) {
00458 for (j = (HISTORY_SIZE - 1); j != 0; j--) {
00459 ClientInfo[i].TimeStamp[j] = ClientInfo[i].TimeStamp[j - 1];
00460 }
00461 ClientInfo[i].TimeStamp[0] = TimeStamp;
00462 debug(3, "TS : %016llX %016llX %016llX %016llX\n",
00463 ClientInfo[i].TimeStamp[0],
00464 ClientInfo[i].TimeStamp[1],
00465 ClientInfo[i].TimeStamp[2], ClientInfo[i].TimeStamp[3]);
00467 break;
00468 }
00469 }
00470 }
00471
00473 void
00474 LogPutSeqNum(UINT8 AddMac[WLAN_ADDR_LEN],
00475 UINT8 AddMacDst[WLAN_ADDR_LEN], UINT16 SeqNum)
00476 {
00477 register UINT16 i, j;
00478
00481 if (AddMacIsBroadcast(AddMacDst)) {
00482 for (i = 0; i < NumberOfDetectedClient; i++) {
00483 if (CompareAddMac(ClientInfo[i].AddMac, AddMac)) {
00484 for (j = (HISTORY_SIZE - 1); j != 0; j--) {
00485 ClientInfo[i].SeqNum[j] = ClientInfo[i].SeqNum[j - 1];
00486 }
00487 ClientInfo[i].SeqNum[0] = WLAN_GET_SEQ_SEQNUM(SeqNum);
00488 break;
00489 }
00490 }
00491 }
00492 }
00493
00495 void LogPutLastIV(UINT8 AddMac[WLAN_ADDR_LEN], UINT8 IV[4])
00496 {
00497 register UINT16 i;
00498
00499 for (i = 0; i < NumberOfDetectedClient; i++) {
00500 if (CompareAddMac(ClientInfo[i].AddMac, AddMac)) {
00501 ClientInfo[i].LastIV[0] = IV[0];
00502 ClientInfo[i].LastIV[1] = IV[1];
00503 ClientInfo[i].LastIV[2] = IV[2];
00504 ClientInfo[i].LastIV[3] = IV[3];
00505 break;
00506 }
00507 }
00508 }
00509
00510 void Send_To_All_BSSID_A_Deauth(void)
00511 {
00512 UINT8 bssid[WLAN_ADDR_LEN];
00513 UINT8 dest[WLAN_ADDR_LEN];
00514 register UINT16 i;
00515
00516 for (i = 0; i < NumberOfDetectedClient; i++) {
00517 if (!AddMacIsNULL(ClientInfo[i].AddMac)
00518 && !AddMacIsNULL(ClientInfo[i].BSSID)) {
00519 memcpy(bssid, &ClientInfo[i].BSSID, WLAN_ADDR_LEN);
00520 memcpy(dest, &ClientInfo[i].AddMac, WLAN_ADDR_LEN);
00521 sendDeauth(dest, bssid, ClientInfo[i].Channel);
00522 sendDeauth(BroadcastMAC, bssid, ClientInfo[i].Channel);
00523 }
00524 }
00525 }
00526
00527
00528
00532 void LogWriteReport(void)
00533 {
00534 int i;
00535 UINT8 j;
00536
00537 printf("\n\n");
00538 printf("Now a summary of the detection :\n");
00539 printf("--------------------------------\n");
00540
00541 if (NumberOfDetectedClient == 0) {
00542 printf("No 802.11b information has been catched\n\n");
00543 }
00544
00545 for (i = 0; i < NumberOfDetectedClient; i++) {
00546 printf("Station (%02X:%02X:%02X:%02X:%02X:%02X) - ",
00547 ClientInfo[i].AddMac[0], ClientInfo[i].AddMac[1],
00548 ClientInfo[i].AddMac[2], ClientInfo[i].AddMac[3],
00549 ClientInfo[i].AddMac[4], ClientInfo[i].AddMac[5]);
00550 printf("BSSID=%02X:%02X:%02X:%02X:%02X:%02X - ",
00551 ClientInfo[i].BSSID[0], ClientInfo[i].BSSID[1],
00552 ClientInfo[i].BSSID[2], ClientInfo[i].BSSID[3],
00553 ClientInfo[i].BSSID[4], ClientInfo[i].BSSID[5]);
00554
00555 if ((strlen(ClientInfo[i].SSID) == 0)
00556 || ((strlen(ClientInfo[i].SSID) == 1)
00557 && (*ClientInfo[i].SSID == 0x20)))
00558 printf("SSID is not broadcasted\n");
00559 else {
00560
00561 printf("SSID='");
00562 for (j = 0; j < strlen(ClientInfo[i].SSID); j++) {
00563 if (isprint(ClientInfo[i].SSID[j]))
00564 printf("%c", ClientInfo[i].SSID[j]);
00565 else
00566 printf("/0x%02X", ClientInfo[i].SSID[j]);
00567 }
00568 printf("'\n");
00569 }
00570
00571 printf(" Manufacturer/Model : %s / %s\n",
00572 AddMacToManufName(ClientInfo[i].AddMac),
00573 AddMacToManufModel(ClientInfo[i].AddMac));
00574
00575 if (ClientInfo[i].SNMax != ClientInfo[i].SNMin)
00576 printf(" Signal is between %u and %u",
00577 ClientInfo[i].SNMin, ClientInfo[i].SNMax);
00578 else
00579 printf(" Signal is stable at %u", ClientInfo[i].SNMax);
00580
00581 if (ClientInfo[i].RateMax != ClientInfo[i].RateMin)
00582 printf(" and Data rate is between %s and %s\n",
00583 RateToString(ClientInfo[i].RateMin),
00584 RateToString(ClientInfo[i].RateMax));
00585 else
00586 printf(" and Data rate is %s\n",
00587 RateToString(ClientInfo[i].RateMax));
00588
00589 if (ClientInfo[i].MaxSpeed != 0)
00590 printf(" Max speed available is %s\n",
00591 RateToString(ClientInfo[i].MaxSpeed));
00592
00593 if (ClientInfo[i].hasWep)
00594 if (ClientInfo[i].hasWPA)
00595 printf(" Channel %d with WPA\n", ClientInfo[i].Channel);
00596 else
00597 printf(" Channel %d with Wep\n", ClientInfo[i].Channel);
00598 else
00599 printf(" Channel %d with no Wep\n", ClientInfo[i].Channel);
00600
00601 if (ClientInfo[i].bcn_int[0] != 0)
00602 printf(" 1 beacon every %d ms is sent\n", ClientInfo[i].bcn_int[0]);
00603
00604 if (ClientInfo[i].IsDS) {
00605 if (ClientInfo[i].IsAP) {
00606 printf
00607 (" This is an AP that do some NAT or is a router (because it's also a DS)\n");
00608 } else {
00609 printf
00610 (" This station is in the Wired network (DS) of the BSSID\n");
00611 }
00612 } else {
00613 if (ClientInfo[i].IsAP)
00614 printf(" This is an AP\n");
00615 else if (ClientInfo[i].IsP2P)
00616 printf(" This an Ad-HOC client\n");
00617 else
00618 printf(" This is a client\n");
00619 }
00620
00621 if (ClientInfo[i].OtherInformation == NULL) {
00622 printf(" Other information discovered:\n");
00623 printf(" > \"%s\"\n", ClientInfo[i].OtherInformation);
00624 }
00625
00626 printf("-------------\n");
00627 }
00628 }
00629
00633 void LogWriteDOT(FILE * filename)
00634 {
00635 int i;
00636
00637 if (NumberOfDetectedClient == 0) {
00638 printf("No 802.11b information has catched\n");
00639 printf("So no .dot file is created\n\n");
00640 } else {
00641 printf("802.11b information has catched so I make my .dot file ");
00642 }
00643
00644 fprintf(filename,
00645 "digraph xyz {\n ratio=compress;\n size=\"8,8\";\n"
00646 " rankdir=LR;\n node [shape=box,fontsize=8];\n");
00647
00648 for (i = 0; i < NumberOfDetectedClient; i++) {
00649 printf(".");
00650 fprintf(filename, "\"%02X:%02X:%02X:%02X:%02X:%02X\" -> ",
00651 ClientInfo[i].AddMac[0], ClientInfo[i].AddMac[1],
00652 ClientInfo[i].AddMac[2], ClientInfo[i].AddMac[3],
00653 ClientInfo[i].AddMac[4], ClientInfo[i].AddMac[5]);
00654 fprintf(filename, "\"%02X:%02X:%02X:%02X:%02X:%02X\";\n",
00655 ClientInfo[i].BSSID[0], ClientInfo[i].BSSID[1],
00656 ClientInfo[i].BSSID[2], ClientInfo[i].BSSID[3],
00657 ClientInfo[i].BSSID[4], ClientInfo[i].BSSID[5]);
00658 if (ClientInfo[i].IsDS)
00659 fprintf(filename,
00660 "\"%02X:%02X:%02X:%02X:%02X:%02X\" [shape=diamond];\n",
00661 ClientInfo[i].AddMac[0],
00662 ClientInfo[i].AddMac[1],
00663 ClientInfo[i].AddMac[2],
00664 ClientInfo[i].AddMac[3],
00665 ClientInfo[i].AddMac[4], ClientInfo[i].AddMac[5]);
00666 else {
00667 if (ClientInfo[i].IsAP) {
00668 fprintf(filename,
00669 "\"%02X:%02X:%02X:%02X:%02X:%02X\" [shape=circle,label=\"",
00670 ClientInfo[i].AddMac[0],
00671 ClientInfo[i].AddMac[1],
00672 ClientInfo[i].AddMac[2],
00673 ClientInfo[i].AddMac[3],
00674 ClientInfo[i].AddMac[4], ClientInfo[i].AddMac[5]);
00675 fprintf(filename,
00676 "%02X:%02X:%02X:%02X:%02X:%02X\\nSSID='%s'\"];\n",
00677 ClientInfo[i].AddMac[0],
00678 ClientInfo[i].AddMac[1],
00679 ClientInfo[i].AddMac[2],
00680 ClientInfo[i].AddMac[3],
00681 ClientInfo[i].AddMac[4],
00682 ClientInfo[i].AddMac[5], ClientInfo[i].SSID);
00683 }
00684 }
00685 }
00686 fprintf(filename, "}\n");
00687 printf("Done!\n\n");
00688 }
00689
00690 void LogWriteHisto(void)
00691 {
00692 #define HISTO_SIGNAL_SIZE 32
00693 #define HISTO_SIGNAL_CHAN 14
00694
00695 UINT8 i, Max = 0, Min=0xFF;
00696 float divid = 0;
00697 int j;
00698 char histo[HISTO_SIGNAL_SIZE][HISTO_SIGNAL_CHAN];
00699
00700 if (NumberOfDetectedClient != 0) {
00701
00702 printf("\n Spectral repartition :\n-----------------------\n\n");
00703
00704
00705 debug(3, " ");
00706 for (i = 0; i < HISTO_SIGNAL_CHAN; i++) {
00707 debug(3, "%02X,", Stats.MaxSignal[i]);
00708 if (Stats.MaxSignal[i] > Max)
00709 Max = Stats.MaxSignal[i];
00710 if (Stats.MaxSignal[i] < Min)
00711 Min = Stats.MaxSignal[i];
00712 }
00713
00714
00715 divid = (float) (Max + 1 - Min) / (float) HISTO_SIGNAL_SIZE;
00716 debug(3, "divid=%f ", divid);
00717 debug(3, "Min=%02X Max=%02X\n", Min, Max);
00718
00719
00720 for (i = 0; i < HISTO_SIGNAL_CHAN; i++) {
00721 for (j = 0; j < HISTO_SIGNAL_SIZE; j++)
00722 histo[j][i] = '-';
00723 }
00724
00725
00726 for (i = 0; i < HISTO_SIGNAL_CHAN; i++) {
00727 for (j = 0; j < ((Stats.MaxSignal[i] - Min) / divid); j++) {
00728 histo[j][i] = '*';
00729 }
00730 }
00731
00732 printf(" 01 02 03 04 05 06 07 08 09 10 11 12 13 14\n");
00733 for (j = HISTO_SIGNAL_SIZE; j != 0; j--) {
00734 printf("%3d ", (UINT8) ((j * divid) + Min));
00735 for (i = 0; i < HISTO_SIGNAL_CHAN; i++) {
00736 if (i == (HISTO_SIGNAL_CHAN - 1))
00737 printf(" ");
00738 printf("%c%c ", histo[j - 1][i], histo[j - 1][i]);
00739 }
00740 printf("\n");
00741 }
00742 printf(" 01 02 03 04 05 06 07 08 09 10 11 12 13 14\n\n");
00743 }
00744 }
00745
00746 void ClearPanel(void)
00747 {
00748 #ifdef WITH_THREAD
00749 pthread_mutex_lock(&screen_mutex);
00750 #endif
00751 wclear(Panel_WND);
00752 box(Panel_WND, '|', '-');
00753 wrefresh(Panel_WND);
00754 #ifdef WITH_THREAD
00755 pthread_mutex_unlock(&screen_mutex);
00756 #endif
00757 }
00758
00759
00760
00761
00762 void WritePanel(UINT8 GoodPacket)
00763
00764 {
00765 UINT8 i;
00766 char Line[256];
00767 char Histo[HISTOSIZE + 2];
00768 char MAC[20];
00769 char TYPE[4];
00770 UINT8 SNMax = 0;
00771 static UINT8 MaxFromAll = 1;
00772 UINT16 HistoSize = 0, HostDisplayed;
00773 UINT16 MinAff, MaxAff, Posit = 1, SizeOfWin;
00774 UINT16 NumberOfDetectedClientToDisplay = 0;
00775
00776
00777 SizeOfWin = (ROW_WND_PANEL - 2);
00778 if (IS_DISPLAY_STATION(config.DoNotDisplay)) {
00779 NumberOfDetectedClientToDisplay = Stats.AP;
00780 } else {
00781 NumberOfDetectedClientToDisplay = NumberOfDetectedClient;
00782 }
00783
00784 if (config.FirstNIC == 0) {
00785 if (NumberOfDetectedClientToDisplay > SizeOfWin)
00786 MinAff = NumberOfDetectedClientToDisplay - SizeOfWin;
00787 else
00788 MinAff = 0;
00789 MaxAff = NumberOfDetectedClientToDisplay;
00790 } else {
00791 if (config.FirstNIC < (NumberOfDetectedClientToDisplay - SizeOfWin)) {
00792 MinAff = config.FirstNIC;
00793 if (config.FirstNIC + SizeOfWin > NumberOfDetectedClientToDisplay)
00794 MaxAff = NumberOfDetectedClientToDisplay - 1;
00795 else
00796 MaxAff = config.FirstNIC + SizeOfWin;
00797 } else {
00798 config.FirstNIC = 0;
00799 MinAff = NumberOfDetectedClientToDisplay - SizeOfWin - 1;
00800 }
00801 }
00802
00803
00804 #ifdef WITH_THREAD
00805 pthread_mutex_lock(&screen_mutex);
00806 #endif
00807
00808
00809 HostDisplayed = 0;
00810 i = MinAff;
00811 while ((HostDisplayed < SizeOfWin) || (i < NumberOfDetectedClient)) {
00812
00813 if (IS_DISPLAY_STATION(config.DoNotDisplay) && (!ClientInfo[i].IsAP)) {
00814 i++;
00815 if (i >= NumberOfDetectedClient)
00816 break;
00817 } else {
00818 if (i >= NumberOfDetectedClient)
00819 break;
00820 snprintf(MAC, 20, "%02X:%02X:%02X:%02X:%02X:%02X",
00821 ClientInfo[i].AddMac[0], ClientInfo[i].AddMac[1],
00822 ClientInfo[i].AddMac[2], ClientInfo[i].AddMac[3],
00823 ClientInfo[i].AddMac[4], ClientInfo[i].AddMac[5]);
00824 safe_strncpy(Histo,
00825 "|________________________________________________",
00826 HISTOSIZE + 2);
00827
00828 if ((ClientInfo[i].SNMax > MaxFromAll)
00829 || (Res.Signal > MaxFromAll)) {
00830 if (Res.Signal > MaxFromAll)
00831 MaxFromAll = Res.Signal;
00832 else
00833 MaxFromAll = ClientInfo[i].SNMax;
00834 }
00835
00836
00837 HistoSize =
00838 (UINT16) ((ClientInfo[i].SNMed * HISTOSIZE) / MaxFromAll);
00839 if (!strncmp(MAC, Res.SrcMac, 20)) {
00840 strncpy(Histo,
00841 "|=======================================================",
00842 HistoSize + 1);
00843 mvwprintw(Panel_WND, Posit, 1, ">");
00844 } else {
00845 strncpy(Histo,
00846 "|.......................................................",
00847 HistoSize + 1);
00848 mvwprintw(Panel_WND, Posit, 1, " ");
00849 }
00850
00851
00852
00853 SNMax = (ClientInfo[i].SNMax * HISTOSIZE) / MaxFromAll;
00854 if (SNMax <= HISTOSIZE) {
00855 Histo[SNMax - 1] = '|';
00856
00857 }
00858 Histo[HISTOSIZE + 1] = 0;
00859 snprintf(Line, COL_WND_PANEL - POS_HISTO - 1,
00860 "%s (%d,%d,%d) %s ", Histo,
00861 (((GoodPacket == TRUE)
00862 && !strncmp(MAC, Res.SrcMac,
00863 20)) ? Res.Signal : 0),
00864 (int) ClientInfo[i].SNMed,
00865 (int) ClientInfo[i].SNMax, ClientInfo[i].Manuf);
00866
00867 if (ClientInfo[i].IsP2P)
00868 snprintf(TYPE, 4, "ADH");
00869 else if (ClientInfo[i].IsAP)
00870 snprintf(TYPE, 4, "AP ");
00871 else
00872 if (ClientInfo[i].IsDS)
00873 snprintf(TYPE, 4, "sta");
00874 else
00875 snprintf(TYPE, 4, "STA");
00876
00877
00878 mvwprintw(Panel_WND, Posit, 2, "%s", TYPE);
00879 mvwprintw(Panel_WND, Posit, POS_MAC, "%s", MAC);
00880 mvwprintw(Panel_WND, Posit, POS_SSID,
00881 "\"%s\" ", ClientInfo[i].SSID);
00882 mvwprintw(Panel_WND, Posit, POS_CHANNEL, "%X",
00883 ClientInfo[i].Channel);
00884
00885
00886 mvwprintw(Panel_WND, Posit, POS_CRYPT, "%c",
00887 DetermineCryptType(ClientInfo[i].hasWep,
00888 ClientInfo[i].hasWPA,
00889 ClientInfo[i].hasTKIP,
00890 ClientInfo[i].hasCCMP,
00891 ClientInfo[i].hasWPAPSK,
00892 ClientInfo[i].hasWPA2PSK));
00893 mvwprintw(Panel_WND, Posit, POS_HISTO, "%s", Line);
00894 Posit++;
00895 HostDisplayed++;
00896 i++;
00897 }
00898 }
00899
00900 wrefresh(Panel_WND);
00901 #ifdef WITH_THREAD
00902 pthread_mutex_unlock(&screen_mutex);
00903 #endif
00904 debug(3, "WritePanel Line #%d\n", __LINE__);
00905 }
00906
00907
00908
00909
00910
00911
00912
00913
00914
00915
00916 char DetermineCryptType(UINT8 hasWep, UINT8 hasWPA, UINT8 hasTKIP,
00917 UINT8 hasCCMP, UINT8 hasWPAPSK, UINT8 hasWPA2PSK)
00918 {
00919 UINT8 CryptType = 0;
00920
00921 if (hasWPA) {
00922 if (hasTKIP) {
00923 if (hasWPAPSK)
00924 CryptType = CRYPT_TYPE_PSK1;
00925 else
00926 CryptType = CRYPT_TYPE_TKIP;
00927 } else {
00928 if (hasCCMP) {
00929 if (hasWPA2PSK)
00930 CryptType = CRYPT_TYPE_PSK2;
00931 else
00932 CryptType = CRYPT_TYPE_CCMP;
00933 } else
00934 CryptType = CRYPT_TYPE_WPA;
00935 }
00936 } else {
00937 if (hasWep)
00938 CryptType = CRYPT_TYPE_WEP;
00939 else
00940 CryptType = CRYPT_TYPE_CLEAR;
00941 }
00942 return CryptTypeASCII[CryptType];
00943 }
00944
00946 void DoSummary(void)
00947 {
00948 UINT8 i;
00949 UINT8 ChanTab[14] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
00950
00951 Stats.AP = 0;
00952 Stats.STA = 0;
00953 Stats.Channel = 0;
00954
00955 for (i = 0; i < NumberOfDetectedClient; i++) {
00956 ChanTab[ClientInfo[i].Channel] = 1;
00957
00958 if (ClientInfo[i].IsAP)
00959 Stats.AP++;
00960 else
00961 Stats.STA++;
00962 }
00963
00964 for (i = 0; i < 14; i++) {
00965 if (ChanTab[i] != 0)
00966 Stats.Channel++;
00967 }
00968 }
00969
00970
00971
00972
00973
00978 void CalculCoef(UINT32 X[HISTORY_SIZE],
00979 UINT32 Y[HISTORY_SIZE], float *a, float *b)
00980 {
00981 float aa[HISTORY_SIZE], bb[HISTORY_SIZE];
00982 UINT8 NbData, i;
00983
00984
00985 #if (HISTORY_SIZE < 2)
00986 #error "STOP ?! HISTORY_SIZE MUST be greater than 1. Change it on include.h"
00987 #endif
00988
00989
00990 NbData = 0;
00991 for (i = 0; i < HISTORY_SIZE; i++) {
00992 if ((X[i] != 0) && (Y[i] != 0))
00993 NbData++;
00994 }
00995
00996
00997 for (i = 0; i < (NbData - 1); i++) {
00998 aa[i] = (Y[i] - Y[i + 1]) / (X[i] - X[i + 1]);
00999 bb[i] = Y[i] / (aa[i] * X[i]);
01000 }
01001
01002 *a = *b = 0;
01003 for (i = 0; i < NbData; i++) {
01004 *a = *a + aa[i];
01005 *b = *b + bb[i];
01006 }
01007 *a = *a / NbData;
01008 *b = *b / NbData;
01009 }
01010
01011
01013 UINT8 IDS_BcnInt(void)
01014 {
01015 register UINT16 i;
01016 UINT8 ret = 0, j;
01017 char MAC[20];
01018 char Message[1024];
01019
01020 for (i = 0; i < NumberOfDetectedClient; i++) {
01021 for (j = 0; j < (HISTORY_SIZE - 1); j++) {
01022 if (((ClientInfo[i].bcn_int[j] != 0)
01023 && (ClientInfo[i].bcn_int[j + 1] != 0))
01024 && (ClientInfo[i].bcn_int[j] != ClientInfo[i].bcn_int[j + 1])) {
01025 snprintf(MAC, 20,
01026 "%02X:%02X:%02X:%02X:%02X:%02X",
01027 ClientInfo[i].AddMac[0],
01028 ClientInfo[i].AddMac[1],
01029 ClientInfo[i].AddMac[2],
01030 ClientInfo[i].AddMac[3],
01031 ClientInfo[i].AddMac[4], ClientInfo[i].AddMac[5]);
01032 snprintf(Message, 1024,
01033 "IDS WARNING - beacon interval is changing for %s from %dms to %dms\n",
01034 MAC, ClientInfo[i].bcn_int[j + 1],
01035 ClientInfo[i].bcn_int[j]);
01036 Send_IDS_Warning(Message);
01037 ret = 0x01;
01038 break;
01039 }
01040 }
01041 }
01042 return ret;
01043 }
01044
01045 UINT8 IDS_TimeStamp(void)
01046 {
01047 register UINT16 i;
01048 UINT8 ret = 0, j;
01049 char MAC[20];
01050 char Message[1024];
01051
01052
01053 for (i = 0; i < NumberOfDetectedClient; i++) {
01054 for (j = 0; j < (HISTORY_SIZE - 1); j++) {
01055 if (((ClientInfo[i].TimeStamp[j] != 0)
01056 && (ClientInfo[i].TimeStamp[j + 1] != 0))
01057 && (ClientInfo[i].TimeStamp[j] < ClientInfo[i].TimeStamp[j + 1])) {
01058 snprintf(MAC, 20, "%02X:%02X:%02X:%02X:%02X:%02X",
01059 ClientInfo[i].AddMac[0], ClientInfo[i].AddMac[1],
01060 ClientInfo[i].AddMac[2], ClientInfo[i].AddMac[3],
01061 ClientInfo[i].AddMac[4], ClientInfo[i].AddMac[5]);
01062 snprintf(Message, 1024,
01063 "IDS WARNING - Time Stamp is not correct for %s\n", MAC);
01064 Send_IDS_Warning(Message);
01065 snprintf(Message, 1024,
01066 " Difference between two catched packets is : %lluµs %llums\n",
01067 ClientInfo[i].TimeStamp[j + 1] -
01068 ClientInfo[i].TimeStamp[j],
01069 (ClientInfo[i].TimeStamp[j + 1] -
01070 ClientInfo[i].TimeStamp[j]) * 100);
01071 Send_IDS_Warning(Message);
01072
01073
01074
01075
01076 ret = 0x02;
01077 break;
01078 }
01079 }
01080 }
01081 return ret;
01082 }
01083
01088 UINT8 IDS_Var_SeqNum(void)
01089 {
01090 register UINT16 i;
01091 UINT8 ret = 0, j;
01092 char MAC[20];
01093 char Message[1024];
01094
01095
01096 for (i = 0; i < NumberOfDetectedClient; i++) {
01097 for (j = 0; j < (HISTORY_SIZE - 1); j++) {
01098 if (((ClientInfo[i].SeqNum[j] != 0)
01099 && (ClientInfo[i].SeqNum[j + 1] != 0))
01100 && (ClientInfo[i].SeqNum[j] < ClientInfo[i].SeqNum[j + 1])) {
01101 snprintf(MAC, 20,
01102 "%02X:%02X:%02X:%02X:%02X:%02X",
01103 ClientInfo[i].AddMac[0],
01104 ClientInfo[i].AddMac[1],
01105 ClientInfo[i].AddMac[2],
01106 ClientInfo[i].AddMac[3],
01107 ClientInfo[i].AddMac[4], ClientInfo[i].AddMac[5]);
01108 snprintf(Message, 1024,
01109 "IDS WARNING - Sequence Number is not correct for %s\n",
01110 MAC);
01111 Send_IDS_Warning(Message);
01112 debug(1, "SeqNum = (0x%04X,0x%04X)\n", ClientInfo[i].SeqNum[j],
01113 ClientInfo[i].SeqNum[j + 1]);
01114 ret = 0x04;
01115 break;
01116 }
01117 }
01118 }
01119 return ret;
01120 }
01121
01122 UINT8 IDS_Detect_FakeAP(void)
01123 {
01124
01125
01126 return 0;
01127 }
01128
01133 UINT8 IDS(void)
01134 {
01139 UINT8 ret = 0;
01140
01141 ret += IDS_BcnInt();
01142 ret += IDS_TimeStamp();
01143 ret += IDS_Var_SeqNum();
01144 ret += IDS_Detect_FakeAP();
01145
01146 return (ret);
01147 }
01148
01161 void AnalyseTAG221(UINT8 AddMac[WLAN_ADDR_LEN], UINT8 * varBits,
01162 int tagLen)
01163 {
01164 register UINT16 i;
01165 UINT8 hasWep = 0;
01166 UINT8 hasWPA = 0;
01167 UINT8 hasTKIP = 0;
01168 UINT8 hasCCMP = 0;
01169 UINT8 hasWPAPSK = 0;
01170 UINT8 hasWPA2PSK = 0;
01171 int offset = 0;
01172 int nb_UnicastCipherSuite = 0;
01173 int nb_AuthKeyMgmntSuite = 0;
01174 UINT8 Byte1, Byte2;
01175
01176
01177 if (tagLen - 6 >= offset && !memcmp(varBits, WPA_OUI "\x01", 4)) {
01178 debug(3, "Analyse of tag 221 : %02X%02X%02X%02X\n", varBits[0],
01179 varBits[1], varBits[2], varBits[3]);
01180
01181 hasWPA = 1;
01182 offset += 6;
01183 if (tagLen - 4 >= offset) {
01184
01185 if (!memcmp(&varBits[offset], WPA_OUI, 3)) {
01186 debug(2, "Multicast cipher suite : %02X%02X%02X\n",
01187 varBits[0 + offset], varBits[1 + offset],
01188 varBits[2 + offset]);
01189 offset += 3;
01190 switch (varBits[0 + offset]) {
01191 case 0:
01192 hasWPA = 0;
01193 break;
01194 case 1:
01195 hasWPA = 0;
01196 hasWep = 1;
01197 break;
01198 case 2:
01199 hasTKIP = 1;
01200 break;
01201 case 3:
01202 case 4:
01203 hasCCMP = 1;
01204 break;
01205 case 5:
01206 hasWPA = 0;
01207 hasWep = 1;
01208 break;
01209 default:
01210 warning("WPA IE is with an unknowed cypher suite");
01211 }
01212 offset += 1;
01213 if (offset + 2 <= tagLen) {
01214
01215
01216
01217 hasWPA = 1;
01218 Byte1 = (UINT8) varBits[offset + 0];
01219 Byte2 = (UINT8) varBits[offset + 1];
01220 nb_UnicastCipherSuite = Byte1 + (Byte2 << 8);
01221 debug(3, "nb_UnicastCipherSuite = %04X\n",
01222 nb_UnicastCipherSuite);
01223 offset += 2;
01224 debug(2, "Unicast cipher suite : %02X%02X%02X%02X\n",
01225 varBits[0 + offset], varBits[1 + offset],
01226 varBits[2 + offset], varBits[3 + offset]);
01227 offset += (4 * nb_UnicastCipherSuite);
01228
01229
01230
01231 if (offset + 2 <= tagLen) {
01232 Byte1 = (UINT8) varBits[offset + 0];
01233 Byte2 = (UINT8) varBits[offset + 1];
01234 nb_AuthKeyMgmntSuite = Byte1 + (Byte2 << 8);
01235 debug(3, "nb_AuthKeyMgmntSuite = %04X\n",
01236 nb_AuthKeyMgmntSuite);
01237 offset += 2;
01238 while (offset + 4 <= tagLen) {
01239 offset += 3;
01240 switch (varBits[offset]) {
01241 case 0:
01242 break;
01243 case 1:
01244 break;
01245 case 2:
01246 if (hasCCMP)
01247 hasWPA2PSK = 1;
01248 else
01249 hasWPAPSK = 1;
01250 break;
01251 default:
01252 warning
01253 ("WPA IE is with an unknowed authenticated key management suites : %02X\n",
01254 varBits[offset]);
01255 }
01256 }
01257 }
01258 }
01259 }
01260 }
01261 } else if (tagLen - 7 >= offset
01262 && !memcmp(varBits, WME_OUI "\x02\x00", 5)) {
01263
01264 } else if (tagLen - 24 >= offset
01265 && !memcmp(varBits, WME_OUI "\x02\x01", 5)) {
01266
01267 } else if (tagLen - 56 >= offset
01268 && !memcmp(varBits, WME_OUI "\x02\x02", 5)) {
01269
01270 } else if (tagLen - 4 >= offset && !memcmp(varBits, RSN_OUI "\x04", 4)) {
01271
01272
01273
01274 } else {
01275 1;
01276 }
01277
01278
01279
01280 for (i = 0; i < NumberOfDetectedClient; i++) {
01281 if (CompareAddMac(ClientInfo[i].BSSID, AddMac)) {
01282 ClientInfo[i].hasWep = hasWep;
01283 ClientInfo[i].hasWPA = hasWPA;
01284 ClientInfo[i].hasTKIP = hasTKIP;
01285 ClientInfo[i].hasCCMP = hasCCMP;
01286 ClientInfo[i].hasWPAPSK = hasWPAPSK;
01287 ClientInfo[i].hasWPA2PSK = hasWPA2PSK;
01288 }
01289 }
01290 }