Skip to content

Commit 58526ec

Browse files
authored
Fix SECURITY_DESCRIPTOR computation (#4809)
1 parent be3e1ae commit 58526ec

File tree

3 files changed

+58
-6
lines changed

3 files changed

+58
-6
lines changed

scapy/layers/smb2.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,21 +1550,21 @@ class SECURITY_DESCRIPTOR(_NTLMPayloadPacket):
15501550
"SELF_RELATIVE",
15511551
],
15521552
),
1553-
LEIntField("OwnerSidOffset", 0),
1554-
LEIntField("GroupSidOffset", 0),
1555-
LEIntField("SACLOffset", 0),
1556-
LEIntField("DACLOffset", 0),
1553+
LEIntField("OwnerSidOffset", None),
1554+
LEIntField("GroupSidOffset", None),
1555+
LEIntField("SACLOffset", None),
1556+
LEIntField("DACLOffset", None),
15571557
_NTLMPayloadField(
15581558
"Data",
15591559
OFFSET,
15601560
[
15611561
ConditionalField(
15621562
PacketField("OwnerSid", WINNT_SID(), WINNT_SID),
1563-
lambda pkt: pkt.OwnerSidOffset,
1563+
lambda pkt: pkt.OwnerSidOffset != 0,
15641564
),
15651565
ConditionalField(
15661566
PacketField("GroupSid", WINNT_SID(), WINNT_SID),
1567-
lambda pkt: pkt.GroupSidOffset,
1567+
lambda pkt: pkt.GroupSidOffset != 0,
15681568
),
15691569
ConditionalField(
15701570
PacketField("SACL", WINNT_ACL(), WINNT_ACL),
@@ -1579,6 +1579,26 @@ class SECURITY_DESCRIPTOR(_NTLMPayloadPacket):
15791579
),
15801580
]
15811581

1582+
def post_build(self, pkt, pay):
1583+
# type: (bytes, bytes) -> bytes
1584+
return (
1585+
_NTLM_post_build(
1586+
self,
1587+
pkt,
1588+
self.OFFSET,
1589+
{
1590+
"OwnerSid": 4,
1591+
"GroupSid": 8,
1592+
"SACL": 12,
1593+
"DACL": 16,
1594+
},
1595+
config=[
1596+
("Offset", _NTLM_ENUM.OFFSET),
1597+
]
1598+
)
1599+
+ pay
1600+
)
1601+
15821602

15831603
# [MS-FSCC] 2.4.2 FileAllInformation
15841604

scapy/modules/ldaphero.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,6 +1191,12 @@ def edit(*_):
11911191
control |= v
11921192
nTSecurityDescriptor.Control = control
11931193

1194+
# Offsets need to be recalculated
1195+
nTSecurityDescriptor.OwnerSidOffset = None
1196+
nTSecurityDescriptor.GroupSidOffset = None
1197+
nTSecurityDescriptor.DACLOffset = None
1198+
nTSecurityDescriptor.SACLOffset = None
1199+
11941200
# Pfew, we did it. That was some big UI.
11951201

11961202
# Now update the SD.

test/scapy/layers/smb2.uts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,3 +549,29 @@ assert isinstance(set_info.Data, FileRenameInformation)
549549
assert set_info.Data.FileName == "test"
550550
assert not set_info.Data.ReplaceIfExists
551551

552+
= SMB2 - Build and dissect SECURITY_DESCRIPTOR
553+
554+
sd = SECURITY_DESCRIPTOR(
555+
Control="DACL_PRESENT+DACL_PROTECTED+SELF_RELATIVE",
556+
OwnerSid=WINNT_SID.fromstr("S-1-1-0"),
557+
GroupSid=WINNT_SID.fromstr("S-1-1-0"),
558+
DACL=WINNT_ACL(
559+
Aces=[
560+
WINNT_ACE_HEADER() / WINNT_ACCESS_ALLOWED_ACE(
561+
Mask=1,
562+
Sid=WINNT_SID.fromstr("S-1-1-0"),
563+
)
564+
]
565+
)
566+
)
567+
568+
sd = SECURITY_DESCRIPTOR(bytes(sd))
569+
570+
assert sd.OwnerSidOffset == 20
571+
assert sd.GroupSidOffset == 32
572+
assert sd.SACLOffset == 0
573+
assert sd.DACLOffset == 44
574+
575+
assert sd.OwnerSid.summary() == "S-1-1-0"
576+
assert sd.GroupSid.summary() == "S-1-1-0"
577+
assert sd.DACL.toSDDL() == ['(A;;;;;S-1-1-0)']

0 commit comments

Comments
 (0)