Skip to content

Commit d8eff2a

Browse files
committed
Add a method to get domain info
1 parent e9564e4 commit d8eff2a

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,63 @@ def adds_get_object_by_sid(ldap, object_sid)
212212
object
213213
end
214214

215+
# Get the LDAP object that describes the current user.
216+
#
217+
# @param [Net::LDAP::Connection] ldap The LDAP connection to use for querying.
218+
# @rtype [Net::LDAP::Entry]
215219
def adds_get_current_user(ldap)
216220
our_domain, _, our_username = ldap.ldapwhoami.to_s.delete_prefix('u:').partition('\\')
217221
# todo: this is probably going to have issues if our user is from a domain that the target server is not the
218222
# authority of
219223
adds_get_object_by_samaccountname(ldap, our_username)
220224
end
221225

226+
# Get the AD DS domain info for the current server.
227+
#
228+
# @param [Net::LDAP::Connection] ldap The LDAP connection to use for querying.
229+
# @rtype [Hash]
230+
def adds_get_domain_info(ldap)
231+
@ldap_objects ||= []
232+
domain_object = ldap.search(base: ldap.base_dn, filter: '(objectClass=domain)', return_result: true)&.first
233+
return nil unless domain_object
234+
235+
@ldap_objects << domain_object
236+
domain_sid = Rex::Proto::MsDtyp::MsDtypSid.read(domain_object[:objectSid].first)
237+
238+
root_dse = ldap.search(
239+
base: '',
240+
scope: Net::LDAP::SearchScope_BaseObject,
241+
attributes: %i[configurationNamingContext]
242+
)&.first
243+
return nil unless root_dse
244+
245+
xrefs = ldap.search(
246+
base: root_dse[:configurationNamingContext].first,
247+
filter: "(&(objectCategory=crossref)(nETBIOSName=*)(nCName=#{ldap.base_dn}))"
248+
)
249+
return nil unless xrefs&.length == 1
250+
251+
xref = xrefs.first
252+
@ldap_objects << xref
253+
254+
{
255+
netbios_name: xref[:nETBIOSName].first.to_s,
256+
dns_name: xref[:dNSRoot].first.to_s,
257+
sid: domain_sid
258+
}
259+
end
260+
261+
# Determine if a security descriptor will grant the permissions identified by *matcher* to the
262+
# *test_sid*.
263+
#
264+
# @param [Net::LDAP::Connection] ldap The LDAP connection to use for querying.
265+
# @param [Rex::Proto::MsDtyp::MsDtypSecurityDescriptor] security_descriptor The security descriptor object to
266+
# evaluate.
267+
# @param [#call] matcher An object that will match ACEs that allow or deny the desired permissions.
268+
# @param [Rex::Proto::MsDtyp::MsDtypSid] test_sid The SID to check for access.
269+
# @param [Rex::Proto::MsDtyp::MsDtypSid] self_sid The SID of the object who owns the security_descriptor. This is
270+
# typically the objectSid LDAP attribute and is used when the security descriptor references the special 'SELF'
271+
# entity.
222272
def adds_sd_grants_permissions?(ldap, security_descriptor, matcher, test_sid: nil, self_sid: nil)
223273
unless test_sid
224274
current_user = adds_get_current_user(ldap)

modules/auxiliary/gather/ldap_esc_vulnerable_cert_finder.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ def print_vulnerable_cert_info
659659
end
660660

661661
if hash[:write_sids]
662-
print_status(' Certificate Template Write-Enabled SIDs:')
662+
print_status(' Certificate Template Write-Enabled SIDs:')
663663
hash[:write_sids].each do |sid|
664664
print_status(" * #{highlight_sid(sid)}")
665665
end

0 commit comments

Comments
 (0)