Skip to content

Commit 77b4ce3

Browse files
authored
Merge pull request secdev#576 from guedou/PR#504_improved
[rewritten] PR secdev#504
2 parents 246c8bd + 1ab629e commit 77b4ce3

File tree

4 files changed

+81
-2
lines changed

4 files changed

+81
-2
lines changed

scapy/contrib/mpls.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class MPLS(Packet):
1818

1919
def guess_payload_class(self, payload):
2020
if len(payload) >= 1:
21+
if not self.s:
22+
return MPLS
2123
ip_version = (ord(payload[0]) >> 4) & 0xF
2224
if ip_version == 4:
2325
return IP

scapy/contrib/mpls.uts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# MPLS unit tests
2+
#
3+
# Type the following command to launch start the tests:
4+
# $ test/run_tests -P "load_contrib('mpls')" -t scapy/contrib/mpls.uts
5+
6+
+ MPLS
7+
8+
= Build & dissect - IPv4
9+
s = str(Ether(src="00:01:02:04:05")/MPLS()/IP())
10+
assert(s == b'\xff\xff\xff\xff\xff\xff\x00\x01\x02\x04\x05\x00\x88G\x00\x001\x00E\x00\x00\x14\x00\x01\x00\x00@\x00|\xe7\x7f\x00\x00\x01\x7f\x00\x00\x01')
11+
12+
p = Ether(s)
13+
assert(MPLS in p and IP in p)
14+
15+
16+
= Build & dissect - IPv6
17+
s = str(Ether(src="00:01:02:04:05")/MPLS(s=0)/MPLS()/IPv6())
18+
assert(s == b'\xff\xff\xff\xff\xff\xff\x00\x01\x02\x04\x05\x00\x88G\x00\x000\x00\x00\x001\x00`\x00\x00\x00\x00\x00;@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01')
19+
20+
p = Ether(s)
21+
assert(IPv6 in p and isinstance(p[MPLS].payload, MPLS))

scapy/layers/dhcp6.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ def get_cls(name, fallback_cls):
7575
36: "OPTION_GEOCONF_CIVIC", #RFC-ietf-geopriv-dhcp-civil-09.txt
7676
37: "OPTION_REMOTE_ID", #RFC4649
7777
38: "OPTION_SUBSCRIBER_ID", #RFC4580
78-
39: "OPTION_CLIENT_FQDN" } #RFC4704
78+
39: "OPTION_CLIENT_FQDN", #RFC4704
79+
68: "OPTION_VSS", #RFC6607
80+
79: "OPTION_CLIENT_LINKLAYER_ADDR" } #RFC6939
7981

8082
dhcp6opts_by_code = { 1: "DHCP6OptClientId",
8183
2: "DHCP6OptServerId",
@@ -117,12 +119,14 @@ def get_cls(name, fallback_cls):
117119
#40: "DHCP6OptPANAAgent", #RFC-ietf-dhc-paa-option-05.txt
118120
#41: "DHCP6OptNewPOSIXTimeZone, #RFC4833
119121
#42: "DHCP6OptNewTZDBTimeZone, #RFC4833
120-
43: "DHCP6OptRelayAgentERO" #RFC4994
122+
43: "DHCP6OptRelayAgentERO", #RFC4994
121123
#44: "DHCP6OptLQQuery", #RFC5007
122124
#45: "DHCP6OptLQClientData", #RFC5007
123125
#46: "DHCP6OptLQClientTime", #RFC5007
124126
#47: "DHCP6OptLQRelayData", #RFC5007
125127
#48: "DHCP6OptLQClientLink", #RFC5007
128+
68: "DHCP6OptVSS", #RFC6607
129+
79: "DHCP6OptClientLinkLayerAddr", #RFC6939
126130
}
127131

128132

@@ -839,6 +843,27 @@ class DHCP6OptRelayAgentERO(_DHCP6OptGuessPayload): # RFC4994
839843
_OptReqListField("reqopts", [23, 24],
840844
length_from = lambda pkt: pkt.optlen) ]
841845

846+
# "Client link-layer address type. The link-layer type MUST be a valid hardware
847+
# type assigned by the IANA, as described in [RFC0826]
848+
class DHCP6OptClientLinkLayerAddr(_DHCP6OptGuessPayload): # RFC6939
849+
name = "DHCP6 Option - Client Link Layer address"
850+
fields_desc = [ ShortEnumField("optcode", 79, dhcp6opts),
851+
FieldLenField("optlen", None, length_of="clladdr",
852+
adjust = lambda pkt,x: x+1),
853+
ShortField("lltype", 1), # ethernet
854+
_LLAddrField("clladdr", ETHER_ANY) ]
855+
856+
# Virtual Subnet selection
857+
class DHCP6OptVSS(_DHCP6OptGuessPayload): # RFC6607
858+
name = "DHCP6 Option - Virtual Subnet Selection"
859+
fields_desc = [ ShortEnumField("optcode", 68, dhcp6opts),
860+
FieldLenField("optlen", None, length_of="data",
861+
adjust = lambda pkt,x: x+1),
862+
ByteField("type", 255), # Default Global/default table
863+
StrLenField("data", "",
864+
length_from = lambda pkt: pkt.optlen) ]
865+
866+
842867
#####################################################################
843868
### DHCPv6 messages ###
844869
#####################################################################

test/regression.uts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,6 +1175,13 @@ str(Ether(src="00:00:00:00:00:00", dst="ff:ff:ff:ff:ff:ff")/IPv6()/TCP()) == b'\
11751175
a=Ether(str(Ether()/IPv6()/TCP()))
11761176
a.type == 0x86dd
11771177

1178+
= IPv6 Class binding with GRE - build
1179+
str(IP()/GRE()/Ether()/IP()/GRE()/IPv6()) == b'E\x00\x00f\x00\x01\x00\x00@/|f\x7f\x00\x00\x01\x7f\x00\x00\x01\x00\x00eX\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x08\x00E\x00\x00@\x00\x01\x00\x00@/|\x8c\x7f\x00\x00\x01\x7f\x00\x00\x01\x00\x00\x86\xdd`\x00\x00\x00\x00\x00;@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01'
1180+
1181+
= IPv6 Class binding with GRE - dissection
1182+
p = IP(str(IP()/GRE()/Ether()/IP()/GRE()/IPv6()))
1183+
GRE in p and p[GRE:1].proto == 0x6558 and p[GRE:2].proto == 0x86DD and IPv6 in p
1184+
11781185

11791186
########### IPv6ExtHdrRouting Class ###########################
11801187

@@ -3861,6 +3868,30 @@ a=DHCP6OptRelayAgentERO(b'\x00+\x00\x08\x00\x01\x00\x02\x00\x03\x00\x04')
38613868
a.optcode == 43 and a.optlen == 8 and a.reqopts == [1,2,3,4]
38623869

38633870

3871+
############
3872+
############
3873+
+ Test DHCP6 Option Client Link Layer address
3874+
3875+
= Basic build & dissect
3876+
s = str(DHCP6OptClientLinkLayerAddr())
3877+
assert(s == b"\x00O\x00\x07\x00\x01\x00\x00\x00\x00\x00\x00")
3878+
3879+
p = DHCP6OptClientLinkLayerAddr(s)
3880+
assert(p.clladdr == "00:00:00:00:00:00")
3881+
3882+
3883+
############
3884+
############
3885+
+ Test DHCP6 Option Virtual Subnet Selection
3886+
3887+
= Basic build & dissect
3888+
s = str(DHCP6OptVSS())
3889+
assert(s == b"\x00D\x00\x01\xff")
3890+
3891+
p = DHCP6OptVSS(s)
3892+
assert(p.type == 255)
3893+
3894+
38643895
############
38653896
############
38663897
+ Test DHCP6 Messages - DHCP6_Solicit

0 commit comments

Comments
 (0)