skipped 133 lines 134 134 else: 135 135 print(".kismet.netxml missing") 136 136 except Exception as error: 137 + errors += 1 137 138 print("parse_netxml " + str(error)) 138 139 print("Error in kismet.netxml") 140 + print(".kismet.netxml OK, errors", errors) 139 141 140 142 141 143 def parse_kismet_csv(ouiMap, name, database, verbose): skipped 38 lines 180 182 else: 181 183 print(".kismet.csv missing") 182 184 except Exception as error: 185 + errors += 1 183 186 print("parse_kismet_csv " + str(error)) 184 187 print("Error in kismet.csv") 188 + print(".kismet.csv OK, errors", errors) 185 189 186 190 187 191 def parse_csv(ouiMap, name, database, verbose): skipped 59 lines 247 251 else: 248 252 print(".csv missing") 249 253 except Exception as error: 254 + errors += 1 250 255 print("parse_csv " + str(error)) 251 256 print("Error in .csv") 257 + print(".csv OK, errors", errors) 252 258 253 259 254 260 def parse_log_csv(ouiMap, name, database, verbose, fake_lat, fake_lon): skipped 49 lines 304 310 errors += 1 305 311 print("parse_log_csv " + str(error)) 306 312 print("Error in log") 313 + print(".log.csv done, errors", errors) 307 314 308 315 309 316 def parse_cap(name, database, verbose, hcxpcapngtool, tshark): skipped 18 lines 328 335 prevFlag = "" 329 336 330 337 for pkt in cap: 331 - if verbose: 332 - print(pkt.eapol.field_names) 333 - print(pkt.eapol.type ) 334 - if pkt.eapol.type == '3': # EAPOL = 3 335 - src = pkt.wlan.ta 336 - dst = pkt.wlan.da 337 - flag = pkt.eapol.wlan_rsna_keydes_key_info 338 - # print(flag) 339 - # IF is the second and the prev is the first one add handshake 340 - if flag.find('10a') != -1: 341 - # print('handhsake 2 of 4') 342 - if (prevFlag.find('08a') and 343 - dst == prevSrc and src == prevDst): # first 344 - if verbose: 345 - print("Valid handshake from client " + prevSrc + 346 - " to AP " + prevDst) 347 - errors += database_utils.insertHandshake(cursor, 348 - verbose, dst, 349 - src, file) 350 - else: 351 - prevSrc = src 352 - prevDst = dst 353 - prevFlag = flag 338 + try: 339 + if verbose: 340 + print(pkt.eapol.field_names ) 341 + print(pkt.eapol.type) 342 + if pkt.eapol.type == '3': # EAPOL = 3 343 + src = pkt.wlan.ta 344 + dst = pkt.wlan.da 345 + flag = pkt.eapol.wlan_rsna_keydes_key_info 346 + # print(flag) 347 + # IF is the second and the prev is the first one add handshake 348 + if flag.find('10a') != -1: 349 + # print('handhsake 2 of 4') 350 + if (prevFlag.find('08a') and 351 + dst == prevSrc and src == prevDst): # first 352 + if verbose: 353 + print("Valid handshake from client " + prevSrc + 354 + " to AP " + prevDst) 355 + errors += database_utils.insertHandshake(cursor, 356 + verbose, dst, 357 + src, file) 358 + else: 359 + prevSrc = src 360 + prevDst = dst 361 + prevFlag = flag 362 + except: 363 + errors += 1 354 364 database.commit() 355 365 print(".cap Handshake done, errors", errors) 356 366 except pyshark.capture.capture.TSharkCrashException as error: 357 - print("Error in parse cap, probably PCAP cut in the " 367 + errors += 1 368 + print("Error in parse_handshakes (CAP), probably PCAP cut in the " 358 369 "middle of a packet: ", error) 359 370 except Exception as error: 360 - print("Error in parse cap: ", error) 371 + errors += 1 372 + print("Error in parse_handshakes (CAP): ", error) 373 + print(".cap Handshake done, errors", errors) 361 374 362 375 363 376 # Get handshakes from .cap skipped 2 lines 366 379 cursor = database.cursor() 367 380 errors = 0 368 381 file = name+".cap" 369 - display_filter = "wps.wifi_protected_setup_state == 0x02" 370 - cap = pyshark.FileCapture(file, display_filter) 382 + cap = pyshark.FileCapture(file, display_filter="wps.wifi_protected_setup_state == 0x02 and wlan.da == ff:ff:ff:ff:ff:ff") 371 383 # cap.set_debug() 372 384 373 385 for pkt in cap: 374 386 # print(dir(pkt['wlan.mgt'].wps_version)) 375 - bssid = pkt.wlan.sa 387 + bssid = '' 376 388 wlan_ssid = '' 377 389 wps_device_name = '' 378 390 wps_model_name = '' skipped 3 lines 382 394 wps_version = '1.0' # Default 1.0 383 395 wmgt = 'wlan.mgt' 384 396 try: 397 + bssid = pkt.wlan.sa 398 + except Exception: 399 + errors += 1 400 + try: 385 401 wlan_ssid = pkt[wmgt].wlan_ssid 386 402 if ('20' in pkt[wmgt].wps_ext_version2): 387 403 wps_version = '2.0' skipped 20 lines 408 424 except Exception: 409 425 errors += 1 410 426 411 - if verbose: 412 - print('==============================') 413 - print(bssid) 414 - print(wps_version) 415 - print(pkt[wmgt].wps_ext_version2) 427 + try: 428 + if verbose: 429 + print('==============================') 430 + print(bssid) 431 + print(wps_version) 432 + print(pkt[wmgt].wps_ext_version2) 433 + except Exception: 434 + errors += 1 435 + 416 436 database_utils.insertWPS(cursor, verbose, bssid, wlan_ssid, 417 437 wps_version, wps_device_name, 418 438 wps_model_name, wps_model_number, skipped 2 lines 421 441 422 442 print(".cap WPS done, errors", errors) 423 443 except pyshark.capture.capture.TSharkCrashException as error: 424 - print("Error in parse cap, probably PCAP cut in the " 444 + errors += 1 445 + print("Error in parse_WPS (CAP), probably PCAP cut in the " 425 446 "middle of a packet: ", error) 426 - except Exception as error: 427 - print("Error in parse cap: ", error) 447 + print(".cap WPS done, errors", errors) 448 + except Exception: 449 + errors += 1 450 + print("Critical error in parse_WPS (CAP)") 451 + print(".cap WPS done, errors", errors) 428 452 429 453 430 454 # Get Identities from MGT login skipped 10 lines 441 465 # print(pkt) 442 466 if pkt.eap.code == '2': 443 467 if pkt.eap.type == '1': # EAP = 1 444 - dst = pkt.wlan.da 445 - src = pkt.wlan.sa 446 - identity = pkt.eap.identity 447 - if verbose: 448 - print('output ' + dst + src + identity) 449 - errors += database_utils.insertIdentity(cursor, verbose, 450 - dst, src, identity) 468 + try: 469 + dst = pkt.wlan.da 470 + src = pkt.wlan.sa 471 + identity = pkt.eap.identity 472 + if verbose: 473 + print('output ' + dst + src + identity) 474 + errors += database_utils.insertIdentity(cursor, verbose, 475 + dst, src, identity) 476 + except: 477 + errors += 1 451 478 database.commit() 452 479 print(".cap Identity done, errors", errors) 453 480 except Exception as error: 454 - print("Error in parse cap: ", error) 481 + errors += 1 482 + print("Error in parse_identities (CAP): ", error) 483 + print(".cap Identity done, errors", errors) 455 484 456 485 457 486 # Use hcxpcapngtool to get the 22000 hash to hashcat skipped 40 lines 498 527 print(".cap hcxpcapngtool done, errors", errors) 499 528 500 529 except Exception as error: 501 - print("Error in parse cap hcxpcapngtool: ", error) 530 + errors += 1 531 + print("Error in exec_hcxpcapngtool (CAP): ", error) 532 + print(".cap hcxpcapngtool done, errors", errors) 502 533