Skip to content

Commit 75e07e3

Browse files
committed
Improve GroupManagementCipherSuite detection
1 parent dcd54d5 commit 75e07e3

2 files changed

Lines changed: 26 additions & 6 deletions

File tree

scapy/layers/dot11.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,17 +1185,20 @@ class Dot11EltRSN(Dot11Elt):
11851185
AKMSuite,
11861186
count_from=lambda p: p.nb_akm_suites
11871187
),
1188-
BitField("mfp_capable", 0, 1),
1189-
BitField("mfp_required", 0, 1),
1188+
BitField("mfp_capable", 1, 1),
1189+
BitField("mfp_required", 1, 1),
11901190
BitField("gtksa_replay_counter", 0, 2),
11911191
BitField("ptksa_replay_counter", 0, 2),
11921192
BitField("no_pairwise", 0, 1),
11931193
BitField("pre_auth", 0, 1),
11941194
BitField("reserved", 0, 8),
1195+
# Theorically we could use mfp_capable/mfp_required to know if those
1196+
# fields are present, but some implementations poorly implement it.
1197+
# In practice, do as wireshark: guess using offset.
11951198
ConditionalField(
1196-
PacketField("pmkids", None, PMKIDListPacket),
1199+
PacketField("pmkids", PMKIDListPacket(), PMKIDListPacket),
11971200
lambda pkt: (
1198-
0 if pkt.len is None else
1201+
True if pkt.len is None else
11991202
pkt.len - (
12001203
12 +
12011204
(pkt.nb_pairwise_cipher_suites or 0) * 4 +
@@ -1206,7 +1209,15 @@ class Dot11EltRSN(Dot11Elt):
12061209
ConditionalField(
12071210
PacketField("group_management_cipher_suite",
12081211
RSNCipherSuite(cipher=0x6), RSNCipherSuite),
1209-
lambda pkt: pkt.mfp_capable == 1
1212+
lambda pkt: (
1213+
True if pkt.len is None else
1214+
pkt.len - (
1215+
12 +
1216+
(pkt.nb_pairwise_cipher_suites or 0) * 4 +
1217+
(pkt.nb_akm_suites or 0) * 4 +
1218+
(pkt.pmkids and pkt.pmkids.nb_pmkids or 0) * 16
1219+
) >= 2
1220+
)
12101221
)
12111222
]
12121223

test/scapy/layers/dot11.uts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,15 @@ assert len(pmkids.pmkid_list) == 1
196196
assert pmkids.pmkid_list[0] == b'LD\xfe\xf2l\xdcV\xce\x0b7\xab\xc62\x02O\x11'
197197

198198
= Dot11EltRSN
199-
assert bytes(Dot11EltRSN()) == b'0\x14\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x01\x00\x00'
199+
assert bytes(
200+
Dot11EltRSN(group_cipher_suite=RSNCipherSuite(),
201+
pairwise_cipher_suites=[RSNCipherSuite()],
202+
akm_suites=[AKMSuite()],
203+
pmkids=PMKIDListPacket(),
204+
group_management_cipher_suite=RSNCipherSuite(cipher=6))
205+
) == b'0\x1a\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x01\xc0\x00\x00\x00\x00\x0f\xac\x06'
206+
207+
# No pmkids, no group management cipher suite
200208
rsn_ie = Dot11EltRSN(b'0\x14\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x01\x01\x00')
201209
assert rsn_ie.group_cipher_suite.cipher == 0x04
202210
assert rsn_ie.nb_pairwise_cipher_suites == 0x01
@@ -206,6 +214,7 @@ assert rsn_ie.akm_suites[0].suite == 0x01
206214
assert rsn_ie.pre_auth
207215
assert Dot11Elt in rsn_ie
208216

217+
# pmkids, group management cipher suite
209218
pkt = RadioTap(b"\x00\x000\x00/@\x00\xa0 \x08\x00\xa0 \x08\x00\xa0 \x08\x00\x00\x00\x00\x00\x00\x0bpin;%\xedN\x10\x0cl\t\xc0\x00\xce\x00\x00\x00\xb2\x00\xbd\x01\xce\x02\x80\x00\x00\x00\xff\xff\xff\xff\xff\xff\xec\x17/\x82\x1e)\xec\x17/\x82\x1e)\x10p\x81a\xa1\x08\x00\x00\x00\x00d\x001\x04\x00\rROUTE-821E295\x01\x01\x8c\x03\x01\x01\x05\x04\x00\x02\x00\x00\x07$IL \x01\x01\x14\x02\x01\x14\x03\x01\x14\x04\x01\x14\x05\x01\x14\x06\x01\x14\x07\x01\x14\x08\x01\x14\t\x01\x14\n\x01\x14\x0b\x01\x14;\x12QQRSTstuvwxyz{}~\x7f\x80*\x01\x000\x1a\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\x8c\x00\x00\x00\x00\x0f\xac\x06-\x1a\x8d\x01\x1f\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00=\x16\x01\x00\x15\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xdd\x18\x00P\xf2\x02\x01\x01\x81\x00\x03\xa4\x00\x00'\xa4\x00\x00BT^\x00a2/\x00\x7f\x01\x04\xdd\x07\x00\xa0\xc6\x02\x02\x03\x00\xdd\x17\xec\x17/RRRRRRRRRRRRRRRRRRRRR\x9e[\xf2")
210219
assert Dot11EltRSN in pkt
211220
pkt[Dot11Beacon].network_stats()

0 commit comments

Comments
 (0)