@@ -7,6 +7,7 @@ module Msf
7
7
module Exploit ::Remote ::LDAP
8
8
module ActiveDirectory
9
9
include Msf ::Exploit ::Remote ::LDAP
10
+ include Msf ::Exploit ::Remote ::LDAP ::EntryCache
10
11
11
12
LDAP_CAP_ACTIVE_DIRECTORY_OID = '1.2.840.113556.1.4.800' . freeze
12
13
LDAP_SERVER_SD_FLAGS_OID = '1.2.840.113556.1.4.801' . freeze
@@ -174,41 +175,38 @@ def adds_query_member_groups(ldap, member_dn, base_dn: nil, inherited: true)
174
175
end
175
176
176
177
def adds_get_object_by_dn ( ldap , object_dn )
177
- @ldap_objects ||= [ ]
178
- object = @ldap_objects . find { |o | o [ :dN ] &.first == object_dn }
178
+ object = ldap_entry_cache . get_by_dn ( object_dn )
179
179
return object if object
180
180
181
181
object = ldap . search ( base : object_dn , controls : [ adds_build_ldap_sd_control ] , scope : Net ::LDAP ::SearchScope_BaseObject ) &.first
182
182
validate_query_result! ( ldap . get_operation_result . table )
183
183
184
- @ldap_objects << object if object
184
+ ldap_entry_cache << object if object
185
185
object
186
186
end
187
187
188
188
def adds_get_object_by_samaccountname ( ldap , object_samaccountname )
189
- @ldap_objects ||= [ ]
190
- object = @ldap_objects . find { |o | o [ :sAMAccountName ] &.first == object_samaccountname }
189
+ object = ldap_entry_cache . get_by_samaccountname ( object_samaccountname )
191
190
return object if object
192
191
193
192
filter = "(sAMAccountName=#{ ldap_escape_filter ( object_samaccountname ) } )"
194
193
object = ldap . search ( base : ldap . base_dn , controls : [ adds_build_ldap_sd_control ] , filter : filter ) &.first
195
194
validate_query_result! ( ldap . get_operation_result . table , filter )
196
195
197
- @ldap_objects << object if object
196
+ ldap_entry_cache << object if object
198
197
object
199
198
end
200
199
201
200
def adds_get_object_by_sid ( ldap , object_sid )
202
- @ldap_objects ||= [ ]
203
201
object_sid = Rex ::Proto ::MsDtyp ::MsDtypSid . new ( object_sid )
204
- object = @ldap_objects . find { | o | o [ :objectSid ] &. first == object_sid . to_binary_s }
202
+ object = ldap_entry_cache . get_by_sid ( object_sid )
205
203
return object if object
206
204
207
205
filter = "(objectSID=#{ ldap_escape_filter ( object_sid . to_s ) } )"
208
206
object = ldap . search ( base : ldap . base_dn , controls : [ adds_build_ldap_sd_control ] , filter : filter ) &.first
209
207
validate_query_result! ( ldap . get_operation_result . table , filter )
210
208
211
- @ldap_objects << object if object
209
+ ldap_entry_cache << object if object
212
210
object
213
211
end
214
212
@@ -228,11 +226,10 @@ def adds_get_current_user(ldap)
228
226
# @param [Net::LDAP::Connection] ldap The LDAP connection to use for querying.
229
227
# @rtype [Hash]
230
228
def adds_get_domain_info ( ldap )
231
- @ldap_objects ||= [ ]
232
229
domain_object = ldap . search ( base : ldap . base_dn , filter : '(objectClass=domain)' , return_result : true ) &.first
233
230
return nil unless domain_object
234
231
235
- @ldap_objects << domain_object
232
+ ldap_entry_cache << domain_object
236
233
domain_sid = Rex ::Proto ::MsDtyp ::MsDtypSid . read ( domain_object [ :objectSid ] . first )
237
234
238
235
root_dse = ldap . search (
@@ -249,7 +246,7 @@ def adds_get_domain_info(ldap)
249
246
return nil unless xrefs &.length == 1
250
247
251
248
xref = xrefs . first
252
- @ldap_objects << xref
249
+ ldap_entry_cache << xref
253
250
254
251
{
255
252
netbios_name : xref [ :nETBIOSName ] . first . to_s ,
0 commit comments