Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in extended right dacl check #177

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions certipy/lib/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ class CERTIFICATE_RIGHTS(IntFlag):
GENERIC_ALL = 983551
WRITE_OWNER = 524288
WRITE_DACL = 262144
EXTENDED_RIGHT = 256
WRITE_PROPERTY = 32

def to_list(self):
Expand Down
50 changes: 39 additions & 11 deletions certipy/lib/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
ACTIVE_DIRECTORY_RIGHTS,
CERTIFICATE_RIGHTS,
CERTIFICATION_AUTHORITY_RIGHTS,
EXTENDED_RIGHTS_NAME_MAP,
)


Expand Down Expand Up @@ -38,26 +39,53 @@ def __init__(
"inherited": ace["AceFlags"] & INHERITED_ACE == INHERITED_ACE,
}

mask = self.RIGHTS_TYPE(ace["Ace"]["Mask"]["Mask"])
if ace["AceType"] == ldaptypes.ACCESS_ALLOWED_ACE.ACE_TYPE:
self.aces[sid]["rights"] |= self.RIGHTS_TYPE(ace["Ace"]["Mask"]["Mask"])
self.aces[sid]["rights"] |= mask

if ace["AceType"] == ldaptypes.ACCESS_ALLOWED_OBJECT_ACE.ACE_TYPE:
if ace["Ace"]["Flags"] == 2:
uuid = bin_to_string(ace["Ace"]["InheritedObjectType"]).lower()
elif ace["Ace"]["Flags"] == 1:
uuid = bin_to_string(ace["Ace"]["ObjectType"]).lower()
else:
continue
if self.RIGHTS_TYPE.EXTENDED_RIGHT & mask:
self.aces[sid]["extended_rights"].append(EXTENDED_RIGHTS_NAME_MAP["All-Extended-Rights"])

if ace["AceType"] == ldaptypes.ACCESS_ALLOWED_OBJECT_ACE.ACE_TYPE and \
self.RIGHTS_TYPE.EXTENDED_RIGHT & mask and \
ace['Ace'].hasFlag(ldaptypes.ACCESS_ALLOWED_OBJECT_ACE.ACE_OBJECT_TYPE_PRESENT):

uuid = bin_to_string(ace["Ace"]["ObjectType"]).lower()
self.aces[sid]["extended_rights"].append(uuid)


class CASecurity(ActiveDirectorySecurity):
class CertifcateSecurity(ActiveDirectorySecurity):
RIGHTS_TYPE = CERTIFICATE_RIGHTS


class CASecurity:
RIGHTS_TYPE = CERTIFICATION_AUTHORITY_RIGHTS

def __init__(
self,
security_descriptor: bytes,
):
sd = ldaptypes.SR_SECURITY_DESCRIPTOR()
sd.fromString(security_descriptor)
self.sd = sd

class CertifcateSecurity(ActiveDirectorySecurity):
RIGHTS_TYPE = CERTIFICATE_RIGHTS
self.owner = format_sid(sd["OwnerSid"].getData())
self.aces = {}

aces = sd["Dacl"]["Data"]
for ace in aces:
sid = format_sid(ace["Ace"]["Sid"].getData())

if sid not in self.aces:
self.aces[sid] = {
"rights": self.RIGHTS_TYPE(0),
"extended_rights": [],
"inherited": ace["AceFlags"] & INHERITED_ACE == INHERITED_ACE,
}

mask = self.RIGHTS_TYPE(ace["Ace"]["Mask"]["Mask"])
if ace["AceType"] == ldaptypes.ACCESS_ALLOWED_ACE.ACE_TYPE:
self.aces[sid]["rights"] |= mask


def is_admin_sid(sid: str):
Expand Down