Skip to content

Commit d05de38

Browse files
authored
Several contrib layers cleanups (secdev#3939)
1 parent 181aa4d commit d05de38

File tree

8 files changed

+124
-180
lines changed

8 files changed

+124
-180
lines changed

.config/ci/test.sh

+3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ fi
5252
if python --version 2>&1 | grep -q PyPy
5353
then
5454
UT_FLAGS+=" -K not_pypy"
55+
# Code coverage with PyPy makes it very, very slow. Tests work
56+
# but take around 30minutes, so we disable it.
57+
export DISABLE_COVERAGE=" "
5558
fi
5659

5760
# libpcap

pyproject.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ version = { attr="scapy.VERSION" }
8383
concurrency = [ "thread", "multiprocessing" ]
8484
source = [ "scapy" ]
8585
omit = [
86-
# Scapy specific paths
87-
"scapy/tools/UTscapy.py",
86+
# Scapy tools
87+
"scapy/tools/",
8888
# Scapy external modules
8989
"scapy/libs/six.py",
9090
"scapy/libs/winpcapy.py",

scapy/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def _version():
158158

159159
VERSION = __version__ = _version()
160160

161-
_tmp = re.search(r"[0-9.]+", VERSION)
161+
_tmp = re.search(r"([0-9]|\.[0-9])+", VERSION)
162162
VERSION_MAIN = _tmp.group() if _tmp is not None else VERSION
163163

164164
if __name__ == "__main__":

scapy/contrib/ubberlogger.py

-119
This file was deleted.

scapy/contrib/wpa_eapol.py

-41
This file was deleted.

scapy/layers/eap.py

+96-10
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,35 @@
1010

1111
import struct
1212

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+
)
1842
from scapy.layers.l2 import SourceMACField, Ether, CookedLinux, GRE, SNAP
1943
from scapy.config import conf
2044
from scapy.compat import orb, chb
@@ -404,6 +428,64 @@ class LEAP(EAP):
404428
]
405429

406430

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+
407489
#############################################################################
408490
# IEEE 802.1X-2010 - MACsec Key Agreement (MKA) protocol
409491
#############################################################################
@@ -765,10 +847,14 @@ def extract_padding(self, s):
765847
return "", s
766848

767849

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
772851
bind_layers(EAPOL, EAP, type=0)
773-
bind_layers(SNAP, EAPOL, code=34958)
852+
bind_layers(EAPOL, EAPOL_KEY, type=3)
774853
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)

test/scapy/layers/eap.uts

+15
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,21 @@ assert eapol.type == 0
5252
assert eapol.len == 60
5353
assert eapol.haslayer(EAP_FAST)
5454

55+
############
56+
############
57+
+ EAPOL-Key class tests
58+
59+
= EAPOK-Key - over 802.11 - Dissection
60+
s = b'\x08\x02:\x01\x00\xc0\xcab\xa4\xf6\x00"k\xfbI+\x00"k\xfbI+\xa0[\xaa\xaa\x03\x00\x00\x00\x88\x8e\x02\x03\x00u\x02\x00\x8a\x00\x10\x00\x00\x00\x00\x00\x00\x00\x04\x95X{I5\':3\x8f\x90\xb1I\xae\x1f\xd7-"\x82\x1e\\$\xefC=\x83\x97?M\xd6\xdf>\x9b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x16\xdd\x14\x00\x0f\xac\x04\x03\xca?d\xca\xed\xdd\xef\xf69;\xefX\xd4\x97w'
61+
wifi = Dot11(s)
62+
assert wifi[EAPOL].key_descriptor_type == 2
63+
assert wifi[EAPOL].key_type == 0
64+
assert wifi[EAPOL].has_key_mic == 1
65+
assert wifi[EAPOL].encrypted_key_data == 1
66+
assert wifi[EAPOL].key_replay_counter == 4
67+
assert wifi[EAPOL].key_mic == b"\x00" * 16
68+
assert wifi[EAPOL].key_length == 22
69+
assert len(wifi[EAPOL].key) == 22
5570

5671
############
5772
############

tox.ini

+7-7
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ platform =
3939
bsd_non_root,bsd_root: darwin|freebsd|openbsd|netbsd
4040
windows: win32
4141
commands =
42-
linux_non_root: {envpython} {env:SCAPY_PY_OPTS:-m coverage run} -m scapy.tools.UTscapy -c ./test/configs/linux.utsc -N {posargs}
43-
linux_root: sudo -E {envpython} {env:SCAPY_PY_OPTS:-m coverage run} -m scapy.tools.UTscapy -c ./test/configs/linux.utsc {posargs}
44-
bsd_non_root: {envpython} {env:SCAPY_PY_OPTS:-m coverage run} -m scapy.tools.UTscapy -c test/configs/bsd.utsc -K manufdb -K tshark -N {posargs}
45-
bsd_root: sudo -E {envpython} {env:SCAPY_PY_OPTS:-m coverage run} -m scapy.tools.UTscapy -c test/configs/bsd.utsc -K manufdb -K tshark {posargs}
46-
windows: {envpython} {env:SCAPY_PY_OPTS:-m coverage run} -m scapy.tools.UTscapy -c test/configs/windows.utsc {posargs}
47-
coverage combine
48-
coverage xml -i
42+
linux_non_root: {envpython} {env:DISABLE_COVERAGE:-m coverage run} -m scapy.tools.UTscapy -c ./test/configs/linux.utsc -N {posargs}
43+
linux_root: sudo -E {envpython} {env:DISABLE_COVERAGE:-m coverage run} -m scapy.tools.UTscapy -c ./test/configs/linux.utsc {posargs}
44+
bsd_non_root: {envpython} {env:DISABLE_COVERAGE:-m coverage run} -m scapy.tools.UTscapy -c test/configs/bsd.utsc -K manufdb -K tshark -N {posargs}
45+
bsd_root: sudo -E {envpython} {env:DISABLE_COVERAGE:-m coverage run} -m scapy.tools.UTscapy -c test/configs/bsd.utsc -K manufdb -K tshark {posargs}
46+
windows: {envpython} {env:DISABLE_COVERAGE:-m coverage run} -m scapy.tools.UTscapy -c test/configs/windows.utsc {posargs}
47+
{env:DISABLE_COVERAGE:coverage combine}
48+
{env:DISABLE_COVERAGE:coverage xml -i}
4949

5050
# Variants of the main tests
5151

0 commit comments

Comments
 (0)