@@ -15,6 +15,8 @@ class RhostsWalker
15
15
file
16
16
http
17
17
https
18
+ ldap
19
+ ldaps
18
20
mysql
19
21
postgres
20
22
smb
@@ -251,6 +253,52 @@ def parse_http_uri(value, datastore)
251
253
end
252
254
alias parse_https_uri parse_http_uri
253
255
256
+ # Parses a uri string such as ldap://user:[email protected] into a hash which can safely be
257
+ # merged with a [Msf::DataStore] datastore for setting ldap options.
258
+ #
259
+ # @see https://datatracker.ietf.org/doc/html/rfc4516
260
+ #
261
+ # @param value [String] the ldap string
262
+ # @return [Hash] A hash where keys match the required datastore options associated with
263
+ # the uri value
264
+ def parse_ldap_uri ( value , datastore )
265
+ uri = ::Addressable ::URI . parse ( value )
266
+ result = { }
267
+
268
+ result [ 'RHOSTS' ] = uri . hostname
269
+ is_ssl = %w[ ssl ldaps ] . include? ( uri . scheme )
270
+ result [ 'RPORT' ] = uri . port || ( is_ssl ? 636 : 389 )
271
+ result [ 'SSL' ] = is_ssl
272
+
273
+ if uri . path . present?
274
+ base_dn = uri . path . delete_prefix ( '/' ) . split ( '?' , 2 ) . first
275
+ result [ 'BASE_DN' ] = base_dn if base_dn . present?
276
+ end
277
+
278
+ set_hostname ( datastore , result , uri . hostname )
279
+
280
+ if uri . user && uri . user . include? ( ';' )
281
+ domain , user = uri . user . split ( ';' )
282
+ result [ 'LDAPDomain' ] = domain
283
+ set_username ( datastore , result , user )
284
+ elsif uri . user
285
+ result [ 'LDAPDomain' ] = ''
286
+ set_username ( datastore , result , uri . user )
287
+ else
288
+ result [ 'LDAPDomain' ] = ''
289
+ result [ 'LDAPUsername' ] = ''
290
+ end
291
+
292
+ if uri . password
293
+ set_password ( datastore , result , uri . password )
294
+ else
295
+ result [ 'LDAPPasssword' ] = ''
296
+ end
297
+
298
+ result
299
+ end
300
+ alias parse_ldaps_uri parse_ldap_uri
301
+
254
302
# Parses a uri string such as mysql://user:[email protected] into a hash
255
303
# which can safely be merged with a [Msf::DataStore] datastore for setting mysql options.
256
304
#
@@ -353,7 +401,7 @@ def set_hostname(datastore, result, hostname)
353
401
def set_username ( datastore , result , username )
354
402
# Preference setting application specific values first
355
403
username_set = false
356
- option_names = %w[ SMBUser FtpUser Username user USER USERNAME username ]
404
+ option_names = %w[ SMBUser FtpUser LDAPUsername Username user USER USERNAME username ]
357
405
option_names . each do |option_name |
358
406
if datastore . options . include? ( option_name )
359
407
result [ option_name ] = username
@@ -372,7 +420,7 @@ def set_username(datastore, result, username)
372
420
def set_password ( datastore , result , password )
373
421
# Preference setting application specific values first
374
422
password_set = false
375
- password_option_names = %w[ SMBPass FtpPass Password pass PASSWORD password ]
423
+ password_option_names = %w[ SMBPass FtpPass LDAPPassword Password pass PASSWORD password ]
376
424
password_option_names . each do |option_name |
377
425
if datastore . options . include? ( option_name )
378
426
result [ option_name ] = password
0 commit comments