|
10 | 10 |
|
11 | 11 | import struct
|
12 | 12 |
|
13 |
| -from scapy.fields import BitField, ByteField, XByteField,\ |
14 |
| - ShortField, IntField, XIntField, ByteEnumField, StrLenField, XStrField,\ |
15 |
| - XStrLenField, XStrFixedLenField, LenField, FieldLenField, FieldListField,\ |
16 |
| - PacketField, PacketListField, ConditionalField, PadField |
17 |
| -from scapy.packet import Packet, Padding, bind_layers |
| 13 | +from scapy.fields import ( |
| 14 | + BitEnumField, |
| 15 | + BitField, |
| 16 | + ByteEnumField, |
| 17 | + ByteField, |
| 18 | + ConditionalField, |
| 19 | + FieldLenField, |
| 20 | + FieldListField, |
| 21 | + IntField, |
| 22 | + LenField, |
| 23 | + LongField, |
| 24 | + PacketField, |
| 25 | + PacketListField, |
| 26 | + PadField, |
| 27 | + ShortField, |
| 28 | + StrLenField, |
| 29 | + XByteField, |
| 30 | + XIntField, |
| 31 | + XStrField, |
| 32 | + XStrFixedLenField, |
| 33 | + XStrLenField, |
| 34 | +) |
| 35 | +from scapy.packet import ( |
| 36 | + Packet, |
| 37 | + Padding, |
| 38 | + bind_bottom_up, |
| 39 | + bind_layers, |
| 40 | + bind_top_down, |
| 41 | +) |
18 | 42 | from scapy.layers.l2 import SourceMACField, Ether, CookedLinux, GRE, SNAP
|
19 | 43 | from scapy.config import conf
|
20 | 44 | from scapy.compat import orb, chb
|
@@ -404,6 +428,64 @@ class LEAP(EAP):
|
404 | 428 | ]
|
405 | 429 |
|
406 | 430 |
|
| 431 | +############################################################################# |
| 432 | +# IEEE 802.1X-2010 - EAPOL-Key |
| 433 | +############################################################################# |
| 434 | + |
| 435 | +# sect 11.9 of 802.1X-2010 |
| 436 | +# AND sect 12.7.2 of 802.11-2016 |
| 437 | + |
| 438 | + |
| 439 | +class EAPOL_KEY(Packet): |
| 440 | + name = "EAPOL_KEY" |
| 441 | + fields_desc = [ |
| 442 | + ByteEnumField("key_descriptor_type", 1, {1: "RC4", 2: "RSN"}), |
| 443 | + # Key Information |
| 444 | + BitEnumField("key_descriptor_type_version", 0, 3, { |
| 445 | + 1: "HMAC-MD5+ARC4", |
| 446 | + 2: "HMAC-SHA1-128+AES-128", |
| 447 | + 3: "AES-128-CMAC+AES-128", |
| 448 | + }), |
| 449 | + BitEnumField("key_type", 0, 1, {0: "Group/SMK", 1: "Pairwise"}), |
| 450 | + BitField("res", 0, 2), |
| 451 | + BitField("install", 0, 1), |
| 452 | + BitField("key_ack", 0, 1), |
| 453 | + BitField("has_key_mic", 1, 1), |
| 454 | + BitField("secure", 0, 1), |
| 455 | + BitField("error", 0, 1), |
| 456 | + BitField("request", 0, 1), |
| 457 | + BitField("encrypted_key_data", 0, 1), |
| 458 | + BitField("smk_message", 0, 1), |
| 459 | + BitField("res2", 0, 2), |
| 460 | + # |
| 461 | + LenField("len", None, "H"), |
| 462 | + LongField("key_replay_counter", 0), |
| 463 | + XStrFixedLenField("key_nonce", "", 32), |
| 464 | + XStrFixedLenField("key_iv", "", 16), |
| 465 | + XStrFixedLenField("key_rsc", "", 8), |
| 466 | + XStrFixedLenField("key_id", "", 8), |
| 467 | + ConditionalField( |
| 468 | + XStrFixedLenField("key_mic", "", 16), # XXX size can be 24 |
| 469 | + lambda pkt: pkt.has_key_mic |
| 470 | + ), |
| 471 | + LenField("key_length", None, "H"), |
| 472 | + XStrLenField("key", "", |
| 473 | + length_from=lambda pkt: pkt.key_length) |
| 474 | + ] |
| 475 | + |
| 476 | + def extract_padding(self, s): |
| 477 | + return s[:self.len], s[self.len:] |
| 478 | + |
| 479 | + def hashret(self): |
| 480 | + return struct.pack("!B", self.type) + self.payload.hashret() |
| 481 | + |
| 482 | + def answers(self, other): |
| 483 | + if isinstance(other, EAPOL_KEY) and \ |
| 484 | + other.descriptor_type == self.descriptor_type: |
| 485 | + return 1 |
| 486 | + return 0 |
| 487 | + |
| 488 | + |
407 | 489 | #############################################################################
|
408 | 490 | # IEEE 802.1X-2010 - MACsec Key Agreement (MKA) protocol
|
409 | 491 | #############################################################################
|
@@ -765,10 +847,14 @@ def extract_padding(self, s):
|
765 | 847 | return "", s
|
766 | 848 |
|
767 | 849 |
|
768 |
| -bind_layers(Ether, EAPOL, type=34958) |
769 |
| -bind_layers(Ether, EAPOL, dst='01:80:c2:00:00:03', type=34958) |
770 |
| -bind_layers(CookedLinux, EAPOL, proto=34958) |
771 |
| -bind_layers(GRE, EAPOL, proto=34958) |
| 850 | +# Bind EAPOL types |
772 | 851 | bind_layers(EAPOL, EAP, type=0)
|
773 |
| -bind_layers(SNAP, EAPOL, code=34958) |
| 852 | +bind_layers(EAPOL, EAPOL_KEY, type=3) |
774 | 853 | bind_layers(EAPOL, MKAPDU, type=5)
|
| 854 | + |
| 855 | +bind_bottom_up(Ether, EAPOL, type=0x888e) |
| 856 | +# the reserved IEEE Std 802.1X PAE address |
| 857 | +bind_top_down(Ether, EAPOL, dst='01:80:c2:00:00:03', type=0x888e) |
| 858 | +bind_layers(CookedLinux, EAPOL, proto=0x888e) |
| 859 | +bind_layers(SNAP, EAPOL, code=0x888e) |
| 860 | +bind_layers(GRE, EAPOL, proto=0x888e) |
0 commit comments