Skip to content

Commit a6ec468

Browse files
committed
Use the BASE_DN and don't require QUERY_ATTRIBUTES
1 parent cfaaa16 commit a6ec468

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

modules/auxiliary/gather/ldap_query.rb

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,13 @@ def run
129129
ldap_connect do |ldap|
130130
validate_bind_success!(ldap)
131131

132-
fail_with(Failure::UnexpectedReply, "Couldn't discover base DN!") unless ldap.base_dn
133-
base_dn = ldap.base_dn
134-
print_status("#{ldap.peerinfo} Discovered base DN: #{base_dn}")
132+
if datastore['BASE_DN'].blank?
133+
fail_with(Failure::UnexpectedReply, "Couldn't discover base DN!") unless ldap.base_dn
134+
base_dn = ldap.base_dn
135+
print_status("#{ldap.peerinfo} Discovered base DN: #{base_dn}")
136+
else
137+
base_dn = datastore['BASE_DN']
138+
end
135139

136140
schema_dn = ldap.schema_dn
137141
case action.name
@@ -149,22 +153,21 @@ def run
149153
run_queries_from_file(ldap, parsed_queries, schema_dn, datastore['OUTPUT_FORMAT'])
150154
return
151155
when 'RUN_SINGLE_QUERY'
152-
unless datastore['QUERY_FILTER'] && datastore['QUERY_ATTRIBUTES']
153-
fail_with(Failure::BadConfig, 'When using the RUN_SINGLE_QUERY action, one must supply the QUERY_FILTER and QUERY_ATTRIBUTE datastore options!')
156+
unless datastore['QUERY_FILTER']
157+
fail_with(Failure::BadConfig, 'When using the RUN_SINGLE_QUERY action, one must supply the QUERY_FILTER datastore option!')
154158
end
155159

156160
print_status("Sending single query #{datastore['QUERY_FILTER']} to the LDAP server...")
157-
attributes = datastore['QUERY_ATTRIBUTES']
158-
if attributes.empty?
159-
fail_with(Failure::BadConfig, 'Attributes list is empty as we could not find at least one attribute to filter on!')
161+
if datastore['QUERY_ATTRIBUTES'].present?
162+
# Split attributes string into an array of attributes, splitting on the comma character.
163+
# Also downcase for consistency with rest of the code since LDAP searches aren't case sensitive.
164+
attributes = datastore['QUERY_ATTRIBUTES'].downcase.split(',')
165+
166+
# Strip out leading and trailing whitespace from the attributes before using them.
167+
attributes.map(&:strip!)
168+
else
169+
attributes = nil
160170
end
161-
162-
# Split attributes string into an array of attributes, splitting on the comma character.
163-
# Also downcase for consistency with rest of the code since LDAP searches aren't case sensitive.
164-
attributes = attributes.downcase.split(',')
165-
166-
# Strip out leading and trailing whitespace from the attributes before using them.
167-
attributes.map(&:strip!)
168171
filter_string = datastore['QUERY_FILTER']
169172
query_base = base_dn
170173
else

0 commit comments

Comments
 (0)