def handler_ctrl(self, packet): # If AP has been seen if packet.addr1 in self.mAPs: self.mAPs[packet.addr1].mSig = (packets.get_rssi( packet.notdecoded)) return
def handler_beacon(self, packet): # If AP already seen. if self.mAPs.get(packet.addr2): self.mAPs[packet.addr2].mSig = (packets.get_rssi( packet.notdecoded)) self.mAPs[packet.addr2] + 1 # If beacon is a new AP. else: # Get name of Access Point. name = packets.get_ssid(packet.info) if "< len: " in name: self.mHidden.append(packet.addr3) channel = packets.get_channel(packet) if self.mHop and int(channel) != int(self.mChannel): return # sec is a set() cipher is a string sec, cipher = packets.get_security(packet) # Test if oui in mac address oui = packets.get_vendor(packet.addr3) # Create AP object. self.mAPs[packet.addr2] = networks.AccessPoint( name, ":".join(sec), cipher, channel, packet.addr3, unicode(oui), packets.get_rssi(packet.notdecoded), packet) # If target found set filter and cancel hopper thread. if packet.addr3 in self.mTarget: globalsx.gFILTERCHANNEL.append(int(channel)) if self.mDiagnose: print("[B-1]: New Network: {0}".format(name.encode('utf-8'))) return
def handler_deauth(self, packet): # check addresses if self.mAPs.get( packet.addr1) and not devices.check_valid_mac(packet.addr2): # Deauth is targeting broadcast > Do nothing but flag this. if self.mDiagnose: print("[D-1]: Deauth to broadcast at: {0}".format( packet.addr1)) elif self.mAPs.get( packet.addr2) and not devices.check_valid_mac(packet.addr1): # Deauth is targeting broadcast > Do nothing but flag this. if self.mDiagnose: print("[D-2]: Deauth to broadcast at: {0}".format( packet.addr2)) elif self.mCls.get(packet.addr1): del self.mCls[packet.addr1] self.mUCls[packet.addr1] = clients.Client( packet.addr1, "", packets.get_rssi(packet.notdecoded), "") if self.mDiagnose: print("[D-3]: Deauth to target at: {0}".format(packet.addr1)) elif self.mCls.get(packet.addr2): del self.mCls[packet.addr2] self.mUCls[packet.addr2] = clients.Client( packet.addr2, "", packets.get_rssi(packet.notdecoded), "") if self.mDiagnose: print("[D-4]: Deauth to target at: {0}".format(packet.addr2)) else: if self.mDiagnose: print("[D-99]: Deauth detected.") return
def handler_probe_request(self, packet): if self.mUCls.get(packet.addr2): self.mUCls[packet.addr2].mSig = (packets.get_rssi( packet.notdecoded)) self.mUCls[packet.addr2] + 1 # If Client not seen. elif devices.check_valid_mac(packet.addr2): if self.mCls.get(packet.addr2): del self.mCls[packet.addr2] self.mUCls[packet.addr2] = clients.Client( packet.addr2, "", packets.get_rssi(packet.notdecoded), "") if self.mDiagnose: print("[PR-1]: Unassociated clients.Client: {0}".format( packet.addr2)) return
def handler_data(self, packet): if packet.addr1 == packet.addr2: return # <!-- What the f**k? # if ap has been seen if self.mAPs.get(packet.addr1): # if clients.Client has been seen if self.mCls.get(packet.addr2): # if clients.Client changed access points if self.mCls[packet.addr2].mBSSID != packet.addr1: # Update access point self.mCls[packet.addr2].mSSID = (packet.addr1) if self.mDiagnose: print("[Da-1]: clients.Client: {0} probing for: {1}". format(packet.addr2, packet.addr1)) # Update signal and noise self.mCls[packet.addr2] + 1 self.mCls[packet.addr2].mSig = (packets.get_rssi( packet.notdecoded)) # If clients.Client was previously unassociated elif self.mUCls.get(packet.addr2): # Create a new clients.Client object self.mCls[packet.addr2] = clients.Client( packet.addr2, packet.addr1, packets.get_rssi(packet.notdecoded), self.mAPs[packet.addr1].mSSID) if globalsx.gDEAUTH: globalsx.gDEAUTHS[self.mChannel].append( [packet.addr2, packet.addr1]) # Destroy previous clients.Client object del self.mUCls[packet.addr2] if self.mDiagnose: print("[Da-2]: clients.Client has associated: {0}".format( packet.addr2)) # if clients.Client previously unseen elif devices.check_valid_mac(packet.addr2): # Create new clients.Client object self.mCls[packet.addr2] = clients.Client( packet.addr2, packet.addr1, packets.get_rssi(packet.notdecoded), self.mAPs[packet.addr1].mSSID) if globalsx.gDEAUTH: globalsx.gDEAUTHS[self.mChannel].append( [packet.addr2, packet.addr1]) if self.mDiagnose: print("[Da-3]: New clients.Client: {0}, {1}".format( packet.addr2, packet.addr1)) # If access point seen elif self.mAPs.get(packet.addr2): # If clients.Client seen. if self.mCls.get(packet.addr1): # if clients.Client changed access points if self.mCls[packet.addr1].mBSSID != packet.addr2: self.mCls[packet.addr1].mSSID = (packet.addr2) if self.mDiagnose: print("[Da-4]: clients.Client: {0} probing for: {1}". format(packet.addr2, packet.addr1)) # Update noise and signal self.mCls[packet.addr1] + 1 self.mCls[packet.addr1].mSig = (packets.get_rssi( packet.notdecoded)) # if clients.Client was previously unassociated elif self.mUCls.get(packet.addr1): # Create new clients.Client and delete old object self.mCls[packet.addr1] = clients.Client( packet.addr1, packet.addr2, packets.get_rssi(packet.notdecoded), self.mAPs[packet.addr2].mSSID) if globalsx.gDEAUTH: globalsx.gDEAUTHS[self.mChannel].append( [packet.addr1, packet.addr2]) del self.mUCls[packet.addr1] if self.mDiagnose: print("[Da-5]: clients.Client has associated: {0}".format( packet.addr1)) # Check if mac is valid before creating new object. elif devices.check_valid_mac(packet.addr1): # Create new clients.Client object self.mCls[packet.addr1] = clients.Client( packet.addr1, packet.addr2, packets.get_rssi(packet.notdecoded), self.mAPs[packet.addr2].mSSID) if globalsx.gDEAUTH: globalsx.gDEAUTHS[self.mChannel].append( [packet.addr1, packet.addr2]) if self.mDiagnose: print("[Da-6]: New clients.Client: {0}".format( packet.addr1)) # Check if packet is part of a wpa handshake if packet.haslayer(WPA_key): # If mac has not been seen. if packet.addr3 not in self.mAPs: return # If mac has been seen else: # Get wpa layer layer = packet.getlayer(WPA_key) if (packet.FCfield & 1): # From DS = 0, To DS = 1 STA = packet.addr2 elif (packet.FCfield & 2): # From DS = 1, To DS = 0 STA = packet.addr1 # This info may be unnecessary. key_info = layer.key_info wpa_key_length = layer.wpa_key_length replay_counter = layer.replay_counter WPA_KEY_INFO_INSTALL = 64 WPA_KEY_INFO_ACK = 128 WPA_KEY_INFO_MIC = 256 # check for frame 2 if (key_info & WPA_KEY_INFO_MIC) and ( (key_info & WPA_KEY_INFO_ACK == 0) and (key_info & WPA_KEY_INFO_INSTALL == 0) and (wpa_key_length > 0)): if self.mDiagnose: print("[K-1]: {0}".format(packet.addr3)) self.mAPs[packet.addr3].frame2 = 1 self.mAPs[packet.addr3].packets.append(packet[0]) # check for frame 3 elif (key_info & WPA_KEY_INFO_MIC) and ( (key_info & WPA_KEY_INFO_ACK) and (key_info & WPA_KEY_INFO_INSTALL)): if self.mDiagnose: print("[K-2]: {0}".format(packet.addr3)) self.mAPs[packet.addr3].frame3 = 1 self.mAPs[packet.addr3].replay_counter = replay_counter self.mAPs[packet.addr3].packets.append(packet[0]) # check for frame 4 elif (key_info & WPA_KEY_INFO_MIC) and ( (key_info & WPA_KEY_INFO_ACK == 0) and (key_info & WPA_KEY_INFO_INSTALL == 0) and self.mAPs[packet.addr3].replay_counter == replay_counter): if self.mDiagnose: print("[K-3]: {0}".format(packet.addr3)) self.mAPs[packet.addr3].frame4 = 1 self.mAPs[packet.addr3].packets.append(packet[0]) if (self.mAPs[packet.addr3].frame2 and self.mAPs[packet.addr3].frame3 and self.mAPs[packet.addr3].frame4): if self.mDiagnose: print("[Key]: {0}".format(packet.addr3)) folder_path = ("pcaps/") filename = ("{0}_{1}.pcap").format( self.mAPs[packet.addr3].mSSID.encode('utf-8'), packet.addr3[-5:].replace(":", "")) wrpcap(folder_path + filename, self.mAPs[packet.addr3].packets) self.mAPs[packet.addr3].mCapped = True # except: # print("Write failed.") return