@@ -212,13 +212,63 @@ def adds_get_object_by_sid(ldap, object_sid)
212
212
object
213
213
end
214
214
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]
215
219
def adds_get_current_user ( ldap )
216
220
our_domain , _ , our_username = ldap . ldapwhoami . to_s . delete_prefix ( 'u:' ) . partition ( '\\' )
217
221
# todo: this is probably going to have issues if our user is from a domain that the target server is not the
218
222
# authority of
219
223
adds_get_object_by_samaccountname ( ldap , our_username )
220
224
end
221
225
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.
222
272
def adds_sd_grants_permissions? ( ldap , security_descriptor , matcher , test_sid : nil , self_sid : nil )
223
273
unless test_sid
224
274
current_user = adds_get_current_user ( ldap )
0 commit comments