Skip to content

Commit 16219ba

Browse files
committed
Update some modules to print the SDDL
1 parent bbf261d commit 16219ba

File tree

3 files changed

+58
-15
lines changed

3 files changed

+58
-15
lines changed

lib/msf/core/exploit/remote/ldap/queries.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,14 @@ def normalize_entry(entry, attribute_properties)
284284
end
285285
normalized_attribute[0] = time_string
286286
when 66 # String (Nt Security Descriptor)
287+
if attribute_property[:attributesyntax] == '2.5.5.15'
288+
begin
289+
sd = Rex::Proto::MsDtyp::MsDtypSecurityDescriptor.read(entry[attribute_name][0])
290+
normalized_attribute[0] = sd.to_sddl_text(domain_sid: nil)
291+
rescue StandardError => e
292+
elog('failed to parse a binary security descriptor to SDDL', error: e)
293+
end
294+
end
287295
when 127 # Object
288296
else
289297
print_error("Unknown oMSyntax entry: #{attribute_property[:omsyntax]}")

modules/auxiliary/admin/ldap/ad_cs_cert_template.rb

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,11 +339,21 @@ def action_read
339339
obj, stored = get_certificate_template
340340

341341
print_status('Certificate Template:')
342-
print_status(" distinguishedName: #{obj['distinguishedname'].first}")
343-
print_status(" displayName: #{obj['displayname'].first}") if obj['displayname'].present?
342+
print_status(" distinguishedName: #{obj['distinguishedname'].first}")
343+
print_status(" displayName: #{obj['displayname'].first}") if obj['displayname'].present?
344344
if obj['objectguid'].first.present?
345345
object_guid = Rex::Proto::MsDtyp::MsDtypGuid.read(obj['objectguid'].first)
346-
print_status(" objectGUID: #{object_guid}")
346+
print_status(" objectGUID: #{object_guid}")
347+
end
348+
if obj['ntsecuritydescriptor'].first.present?
349+
begin
350+
sd = Rex::Proto::MsDtyp::MsDtypSecurityDescriptor.read(obj['ntsecuritydescriptor'].first)
351+
sddl_text = sd.to_sddl_text(domain_sid: get_domain_sid)
352+
rescue StandardError => e
353+
elog('failed to parse a binary security descriptor to SDDL', error: e)
354+
else
355+
print_status(" nTSecurityDescriptor: #{sddl_text}")
356+
end
347357
end
348358

349359
pki_flag = obj['flags']&.first

modules/auxiliary/admin/ldap/rbcd.rb

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,16 @@ def run
167167
def action_read(obj)
168168
security_descriptor = obj[ATTRIBUTE]
169169
if security_descriptor.nil?
170-
print_status('The msDS-AllowedToActOnBehalfOfOtherIdentity field is empty.')
170+
print_status("The #{ATTRIBUTE} field is empty.")
171171
return
172172
end
173173

174+
if (sddl = sd_to_sddl(security_descriptor))
175+
vprint_status("#{ATTRIBUTE}: #{sddl}")
176+
end
177+
174178
if security_descriptor.dacl.nil?
175-
print_status('The msDS-AllowedToActOnBehalfOfOtherIdentity DACL field is empty.')
179+
print_status("The #{ATTRIBUTE} DACL field is empty.")
176180
return
177181
end
178182

@@ -211,22 +215,22 @@ def action_remove(obj)
211215
security_descriptor.dacl.acl_size.clear
212216

213217
unless @ldap.replace_attribute(obj['dn'], ATTRIBUTE, security_descriptor.to_binary_s)
214-
fail_with_ldap_error('Failed to update the msDS-AllowedToActOnBehalfOfOtherIdentity attribute.')
218+
fail_with_ldap_error("Failed to update the #{ATTRIBUTE} attribute.")
215219
end
216-
print_good('Successfully updated the msDS-AllowedToActOnBehalfOfOtherIdentity attribute.')
220+
print_good("Successfully updated the #{ATTRIBUTE} attribute.")
217221
end
218222

219223
def action_flush(obj)
220224
unless obj[ATTRIBUTE]
221-
print_status('The msDS-AllowedToActOnBehalfOfOtherIdentity field is empty. No changes are necessary.')
225+
print_status("The #{ATTRIBUTE} field is empty. No changes are necessary.")
222226
return
223227
end
224228

225229
unless @ldap.delete_attribute(obj['dn'], ATTRIBUTE)
226-
fail_with_ldap_error('Failed to deleted the msDS-AllowedToActOnBehalfOfOtherIdentity attribute.')
230+
fail_with_ldap_error("Failed to deleted the #{ATTRIBUTE} attribute.")
227231
end
228232

229-
print_good('Successfully deleted the msDS-AllowedToActOnBehalfOfOtherIdentity attribute.')
233+
print_good("Successfully deleted the #{ATTRIBUTE} attribute.")
230234
end
231235

232236
def action_write(obj)
@@ -239,26 +243,37 @@ def action_write(obj)
239243
end
240244

241245
def _action_write_create(obj, delegate_from)
246+
vprint_status("Creating new #{ATTRIBUTE}...")
242247
security_descriptor = Rex::Proto::MsDtyp::MsDtypSecurityDescriptor.new
243248
security_descriptor.owner_sid = Rex::Proto::MsDtyp::MsDtypSid.new('S-1-5-32-544')
244249
security_descriptor.dacl = Rex::Proto::MsDtyp::MsDtypAcl.new
245250
security_descriptor.dacl.acl_revision = Rex::Proto::MsDtyp::MsDtypAcl::ACL_REVISION_DS
246251
security_descriptor.dacl.aces << build_ace(delegate_from['ObjectSid'])
247252

253+
if (sddl = sd_to_sddl(security_descriptor))
254+
vprint_status("New #{ATTRIBUTE}: #{sddl}")
255+
end
256+
248257
unless @ldap.add_attribute(obj['dn'], ATTRIBUTE, security_descriptor.to_binary_s)
249-
fail_with_ldap_error('Failed to create the msDS-AllowedToActOnBehalfOfOtherIdentity attribute.')
258+
fail_with_ldap_error("Failed to create the #{ATTRIBUTE} attribute.")
250259
end
251260

252-
print_good('Successfully created the msDS-AllowedToActOnBehalfOfOtherIdentity attribute.')
261+
print_good("Successfully created the #{ATTRIBUTE} attribute.")
253262
print_status('Added account:')
254263
print_status(" #{delegate_from['ObjectSid']} (#{delegate_from['sAMAccountName']})")
255264
end
256265

257266
def _action_write_update(obj, delegate_from)
267+
vprint_status("Updating existing #{ATTRIBUTE}...")
258268
security_descriptor = obj[ATTRIBUTE]
269+
270+
if (sddl = sd_to_sddl(security_descriptor))
271+
vprint_status("Old #{ATTRIBUTE}: #{sddl}")
272+
end
273+
259274
if security_descriptor.dacl
260275
if security_descriptor.dacl.aces.any? { |ace| ace.body[:sid].to_s == delegate_from['ObjectSid'].to_s }
261-
print_status("Delegation from #{delegate_from['sAMAccountName']} to #{obj['sAMAccountName']} is already enabled.")
276+
print_status("Delegation from #{delegate_from['sAMAccountName']} to #{obj['sAMAccountName']} is already configured.")
262277
end
263278
# clear these fields so they'll be calculated automatically after the update
264279
security_descriptor.dacl.acl_count.clear
@@ -271,10 +286,20 @@ def _action_write_update(obj, delegate_from)
271286

272287
security_descriptor.dacl.aces << build_ace(delegate_from['ObjectSid'])
273288

289+
if (sddl = sd_to_sddl(security_descriptor))
290+
vprint_status("New #{ATTRIBUTE}: #{sddl}")
291+
end
292+
274293
unless @ldap.replace_attribute(obj['dn'], ATTRIBUTE, security_descriptor.to_binary_s)
275-
fail_with_ldap_error('Failed to update the msDS-AllowedToActOnBehalfOfOtherIdentity attribute.')
294+
fail_with_ldap_error("Failed to update the #{ATTRIBUTE} attribute.")
276295
end
277296

278-
print_good('Successfully updated the msDS-AllowedToActOnBehalfOfOtherIdentity attribute.')
297+
print_good("Successfully updated the #{ATTRIBUTE} attribute.")
298+
end
299+
300+
def sd_to_sddl(sd)
301+
sd.to_sddl_text
302+
rescue StandardError => e
303+
elog('failed to parse a binary security descriptor to SDDL', error: e)
279304
end
280305
end

0 commit comments

Comments
 (0)