Add MsDtypSecurityDescriptor#to_sddl_text #19879
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This updates the existing
MsDtypSecurityDescriptor
class to include a#to_sddl_text
method. This allows an initialized object to be displayed using the Security Descriptor Definition Language defined by Microsoft. This is the counter part to the.from_sddl_text
class method which parses SDDL text into an initialized object. During the course of the development, a few bugs were fixed in the SID to SDDL text mapping, and support for access masks as hex (e.g.0x12345678
) was supported. Thedomain_sid
keyword argument is optional. When it's specified, it'll be used to reduce known SIDs to their SDDL two letter short code. When it's not specified, the SID is left as is.Finally, three modules were updated to print the SDDL text when operating with security descriptors so the user can view it. In the RBCD module, this is particularly useful because the module modifies the security descriptor, so allowing the user to view it makes what is happening easier to understand and debug.
Verification (Metasploit)
List the steps needed to make sure this thing works
msfconsole
ldap_query
module and run a single query that includes thentsecuritydescriptor
attribute. See that it's parsed and displayed.ad_cs_cert_template
module and theREAD
action, see the security descriptor is parsed and displayed.rbcd
module and the READaction, see the security descriptor is parsed and displayed. It may be necessary to create one with the
WRITEaction first since the
msDS-AllowedToActOnBehalfOfOtherIdentity` attribute doesn't exist by default.Verification (Technical Accuracy)
The following Powershell functions can be used to convert from binary to SDDL security descriptors.
Powershell Code
This Powershell code can be use to double check that a security descriptor is correct. The following snippet can be used to validate the SDDL SID short code mappings. In this case the domain SID is
S-1-5-21-3978004297-3499718965-4169012971
. In the output on my Server 2019 test system, there are 4 codes that couldn't be converted to a SID that are included in the language definition. Those codes areKA
,CN
,AP
, andEK
. To retain compatibility, Metasploit's implementation will accept those codes as input, but will not output them. On output, the full SID will be used instead which ensure compatibility with Windows systems that don't support the codes.SDDL SID short code validation
Demo