@@ -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,45 @@ 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
+ end
288
+
289
+ set_password ( datastore , result , uri . password ) if uri . password
290
+
291
+ result
292
+ end
293
+ alias parse_ldaps_uri parse_ldap_uri
294
+
254
295
# Parses a uri string such as mysql://user:[email protected] into a hash
255
296
# which can safely be merged with a [Msf::DataStore] datastore for setting mysql options.
256
297
#
@@ -353,7 +394,7 @@ def set_hostname(datastore, result, hostname)
353
394
def set_username ( datastore , result , username )
354
395
# Preference setting application specific values first
355
396
username_set = false
356
- option_names = %w[ SMBUser FtpUser Username user USER USERNAME username ]
397
+ option_names = %w[ SMBUser FtpUser LDAPUsername Username user USER USERNAME username ]
357
398
option_names . each do |option_name |
358
399
if datastore . options . include? ( option_name )
359
400
result [ option_name ] = username
@@ -372,7 +413,7 @@ def set_username(datastore, result, username)
372
413
def set_password ( datastore , result , password )
373
414
# Preference setting application specific values first
374
415
password_set = false
375
- password_option_names = %w[ SMBPass FtpPass Password pass PASSWORD password ]
416
+ password_option_names = %w[ SMBPass FtpPass LDAPPassword Password pass PASSWORD password ]
376
417
password_option_names . each do |option_name |
377
418
if datastore . options . include? ( option_name )
378
419
result [ option_name ] = password
0 commit comments