Skip to content

Commit 4507a9f

Browse files
committed
Allow toggling the SACL in queries
1 parent 7325d2a commit 4507a9f

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def perform_ldap_query(ldap, filter, attributes, base, schema_dn, scope: nil)
8181
results
8282
end
8383

84-
def perform_ldap_query_streaming(ldap, filter, attributes, base, schema_dn, scope: nil)
84+
def perform_ldap_query_streaming(ldap, filter, attributes, base, schema_dn, scope: nil, controls: nil)
8585
if attributes.nil? || schema_dn.nil?
8686
attribute_properties = {}
8787
else
@@ -96,7 +96,7 @@ def perform_ldap_query_streaming(ldap, filter, attributes, base, schema_dn, scop
9696

9797
scope ||= Net::LDAP::SearchScope_WholeSubtree
9898
result_count = 0
99-
ldap.search(base: base, filter: filter, attributes: attributes, scope: scope, return_result: false) do |result|
99+
ldap.search(base: base, filter: filter, attributes: attributes, scope: scope, controls: controls, return_result: false) do |result|
100100
result_count += 1
101101
yield result, attribute_properties if block_given?
102102
end

modules/auxiliary/gather/ldap_query.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
class MetasploitModule < Msf::Auxiliary
77

88
include Msf::Exploit::Remote::LDAP
9+
include Msf::Exploit::Remote::LDAP::ActiveDirectory
910
include Msf::Exploit::Remote::LDAP::Queries
1011
include Msf::OptionalSession::LDAP
1112
require 'json'
@@ -66,6 +67,10 @@ def initialize(info = {})
6667
OptString.new('QUERY_FILTER', [false, 'Filter to send to the target LDAP server to perform the query'], conditions: %w[ACTION == RUN_SINGLE_QUERY]),
6768
OptString.new('QUERY_ATTRIBUTES', [false, 'Comma separated list of attributes to retrieve from the server'], conditions: %w[ACTION == RUN_SINGLE_QUERY])
6869
])
70+
71+
register_advanced_options([
72+
OptBool.new('LDAP::QuerySacl', [true, 'Query the SACL field from security descriptors (requires privileges)', true])
73+
])
6974
end
7075

7176
def initialize_actions
@@ -185,7 +190,13 @@ def run
185190
fail_with(Failure::BadConfig, "Could not compile the filter #{filter_string}. Error was #{e}")
186191
end
187192

188-
result_count = perform_ldap_query_streaming(ldap, filter, attributes, query_base, schema_dn) do |result, attribute_properties|
193+
controls = []
194+
unless datastore['LDAP::QuerySacl']
195+
# omit the control entirely if querying the SACL because that's the default behavior
196+
controls = [adds_build_ldap_sd_control(sacl: false)]
197+
end
198+
199+
result_count = perform_ldap_query_streaming(ldap, filter, attributes, query_base, schema_dn, controls: controls) do |result, attribute_properties|
189200
show_output(normalize_entry(result, attribute_properties), datastore['OUTPUT_FORMAT'])
190201
end
191202

0 commit comments

Comments
 (0)