1 # This file is part of Scapy 2 # Scapy is free software: you can redistribute it and/or modify 3 # it under the terms of the GNU General Public License as published by 4 # the Free Software Foundation, either version 2 of the License, or 5 # any later version. 6 # 7 # Scapy is distributed in the hope that it will be useful, 8 # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 # GNU General Public License for more details. 11 # 12 # You should have received a copy of the GNU General Public License 13 # along with Scapy. If not, see <http://www.gnu.org/licenses/>. 14 15 # scapy.contrib.description = WPA EAPOL dissector 16 # scapy.contrib.status = loads 17 18 from scapy.packet import * 19 from scapy.fields import * 20 from scapy.layers.l2 import * 21 from scapy.layers.eap import EAPOL 22 23 class WPA_key(Packet): 24 name = "WPA_key" 25 fields_desc = [ ByteField("descriptor_type", 1), 26 ShortField("key_info",0), 27 LenField("len", None, "H"), 28 StrFixedLenField("replay_counter", "", 8), 29 StrFixedLenField("nonce", "", 32), 30 StrFixedLenField("key_iv", "", 16), 31 StrFixedLenField("wpa_key_rsc", "", 8), 32 StrFixedLenField("wpa_key_id", "", 8), 33 StrFixedLenField("wpa_key_mic", "", 16), 34 LenField("wpa_key_length", None, "H"), 35 StrLenField("wpa_key", "", length_from=lambda pkt:pkt.wpa_key_length) ] 36 def extract_padding(self, s): 37 l = self.len 38 return s[:l],s[l:] 39 def hashret(self): 40 return chr(self.type)+self.payload.hashret() 41 def answers(self, other): 42 if isinstance(other,WPA_key): 43 return 1 44 return 0 45 46 47 bind_layers( EAPOL, WPA_key, type=3) 48