Projects STRLCPY wifi_db Commits 2fba872b
🤬
  • Fix error, pyshark errors, read files from Folder Fix error count,most pyshark errors, read files from Folder different Fix WPS read all, instead just WPS

  • Loading...
  • RaulCalvoLaorden committed 1 year ago
    2fba872b
    1 parent e5f6a6a2
  • ■ ■ ■ ■ ■
    requirements.txt
    1 1  ftfy==5.6
     2 +nest_asyncio==1.5.6
    2 3  pyshark==0.4.3
    3 4  requests==2.26.0
    4 5   
  • ■ ■ ■ ■ ■ ■
    wifi_db.py
    skipped 9 lines
    10 10  from os import path
    11 11  import platform
    12 12  import subprocess
     13 +import nest_asyncio
     14 + 
     15 +# import nest_asyncio ; nest_asyncio.apply() ->
     16 +# Fix RuntimeError: This event loop is already running”
     17 + 
    13 18   
    14 19   
    15 20  def main():
     21 + nest_asyncio.apply()
    16 22   '''Function main. Parse argument and exec the functions '''
    17 23   # args
    18 24   parser = argparse.ArgumentParser()
    skipped 75 lines
    94 100   print("Parsing file:", capture)
    95 101   # Remove format if any
    96 102   
     103 + # If it is a folder...
    97 104   if path.isdir(capture):
    98 105   files = []
    99 106   dirpath = os.getcwd()
    skipped 5 lines
    105 112   print(dir_capture)
    106 113   print("current directory is : " + dirpath)
    107 114   
    108  - for r, d, f in os.walk(dir_capture):
    109  - for file in f:
    110  - if 'kismet.netxml' in file:
    111  - files.append(os.path.join(r, file))
     115 + for file in os.listdir(dir_capture):
     116 + if (('.cap' in file) or ('.csv' in file)
     117 + or ('.kismet.csv' in file)
     118 + or ('kismet.netxml' in file)
     119 + or ('.log.csv' in file)):
     120 + files.append(file)
     121 + 
     122 + files.sort()
     123 + print(files)
    112 124   
    113 125   counter = 0
     126 + # for each file with correct format of folder ...
    114 127   for f in files:
    115 128   counter += 1
    116 129   print("File: " + str(counter) + " of " + str(len(files)))
    117  - base = os.path.basename(f)
    118  - name = os.path.splitext(os.path.splitext(base)[0])[0]
    119  - capture_aux = dir_capture+"/"+name
     130 + capture_aux = dir_capture+"/"+f
    120 131   print("\n" + capture_aux)
    121  - wifi_db_aircrack.parse_netxml(ouiMap, capture_aux,
    122  - database, verbose)
    123  - wifi_db_aircrack.parse_kismet_csv(ouiMap, capture_aux,
    124  - database, verbose)
    125  - wifi_db_aircrack.parse_csv(ouiMap, capture_aux,
    126  - database, verbose)
    127  - wifi_db_aircrack.parse_log_csv(ouiMap, capture_aux,
    128  - database, verbose, fake_lat,
    129  - fake_lon)
    130  - wifi_db_aircrack.parse_cap(capture_aux, database, verbose,
    131  - hcxpcapngtool, tshark)
     132 + process_capture(ouiMap, capture_aux, database,
     133 + verbose, fake_lat, fake_lon,
     134 + hcxpcapngtool, tshark)
    132 135   
    133  - else: # file
    134  - if ".cap" in capture:
    135  - capture = capture.replace(".cap", "") # remove format
    136  - wifi_db_aircrack.parse_cap(capture, database, verbose,
    137  - hcxpcapngtool, tshark)
    138  - elif ".kismet.netxml" in capture:
    139  - capture = capture.replace(".kismet.netxml", "")
    140  - wifi_db_aircrack.parse_netxml(ouiMap, capture,
    141  - database, verbose)
    142  - elif ".kismet.csv" in capture:
    143  - capture = capture.replace(".kismet.csv", "")
    144  - wifi_db_aircrack.parse_kismet_csv(ouiMap, capture,
    145  - database, verbose)
    146  - elif ".log.csv" in capture:
    147  - capture = capture.replace(".log.csv", "") # remove format
    148  - wifi_db_aircrack.parse_log_csv(ouiMap, capture,
    149  - database, verbose, fake_lat,
    150  - fake_lon)
    151  - elif ".csv" in capture:
    152  - capture = capture.replace(".csv", "") # remove format
    153  - wifi_db_aircrack.parse_csv(ouiMap, capture,
    154  - database, verbose)
    155  - else:
    156  - print("Not format found!")
    157  - wifi_db_aircrack.parse_netxml(ouiMap, capture,
    158  - database, verbose)
    159  - wifi_db_aircrack.parse_kismet_csv(ouiMap, capture,
    160  - database, verbose)
    161  - wifi_db_aircrack.parse_csv(ouiMap, capture,
    162  - database, verbose)
    163  - wifi_db_aircrack.parse_log_csv(ouiMap, capture,
    164  - database, verbose, fake_lat,
    165  - fake_lon)
    166  - wifi_db_aircrack.parse_cap(capture, database, verbose,
    167  - hcxpcapngtool, tshark)
     136 + else: # it is a file
     137 + process_capture(ouiMap, capture_aux, database,
     138 + verbose, fake_lat, fake_lon,
     139 + hcxpcapngtool, tshark)
    168 140   
    169 141   elif source == "kismet":
    170 142   print("Parsing Kismet capture")
    skipped 11 lines
    182 154   if obfuscated:
    183 155   print("-o is enable, so obfuscate. This may take a while")
    184 156   database_utils.obfuscatedDB(database)
     157 + 
     158 + 
     159 +def process_capture(ouiMap, capture, database,
     160 + verbose, fake_lat, fake_lon,
     161 + hcxpcapngtool, tshark):
     162 + if ".cap" in capture:
     163 + capture = capture.replace(".cap", "") # remove format
     164 + wifi_db_aircrack.parse_cap(capture, database, verbose,
     165 + hcxpcapngtool, tshark)
     166 + elif ".kismet.netxml" in capture:
     167 + capture = capture.replace(".kismet.netxml", "")
     168 + wifi_db_aircrack.parse_netxml(ouiMap, capture,
     169 + database, verbose)
     170 + elif ".kismet.csv" in capture:
     171 + capture = capture.replace(".kismet.csv", "")
     172 + wifi_db_aircrack.parse_kismet_csv(ouiMap, capture,
     173 + database, verbose)
     174 + elif ".log.csv" in capture:
     175 + capture = capture.replace(".log.csv", "") # remove format
     176 + wifi_db_aircrack.parse_log_csv(ouiMap, capture,
     177 + database, verbose, fake_lat,
     178 + fake_lon)
     179 + elif ".csv" in capture:
     180 + capture = capture.replace(".csv", "") # remove format
     181 + wifi_db_aircrack.parse_csv(ouiMap, capture,
     182 + database, verbose)
     183 + else:
     184 + print("Not format found!")
     185 + wifi_db_aircrack.parse_netxml(ouiMap, capture,
     186 + database, verbose)
     187 + wifi_db_aircrack.parse_kismet_csv(ouiMap, capture,
     188 + database, verbose)
     189 + wifi_db_aircrack.parse_csv(ouiMap, capture,
     190 + database, verbose)
     191 + wifi_db_aircrack.parse_log_csv(ouiMap, capture,
     192 + database, verbose, fake_lat,
     193 + fake_lon)
     194 + wifi_db_aircrack.parse_cap(capture, database, verbose,
     195 + hcxpcapngtool, tshark)
    185 196   
    186 197   
    187 198  if __name__ == "__main__":
    skipped 2 lines
  • ■ ■ ■ ■ ■ ■
    wifi_db_aircrack.py
    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   
Please wait...
Page is in error, reload to recover