@@ -15,6 +15,8 @@ class RhostsWalker
1515 file
1616 http
1717 https
18+ ldap
19+ ldaps
1820 mysql
1921 postgres
2022 smb
@@ -251,6 +253,45 @@ def parse_http_uri(value, datastore)
251253 end
252254 alias parse_https_uri parse_http_uri
253255
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+
254295 # Parses a uri string such as mysql://user:[email protected] into a hash 255296 # which can safely be merged with a [Msf::DataStore] datastore for setting mysql options.
256297 #
@@ -353,7 +394,7 @@ def set_hostname(datastore, result, hostname)
353394 def set_username ( datastore , result , username )
354395 # Preference setting application specific values first
355396 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 ]
357398 option_names . each do |option_name |
358399 if datastore . options . include? ( option_name )
359400 result [ option_name ] = username
@@ -372,7 +413,7 @@ def set_username(datastore, result, username)
372413 def set_password ( datastore , result , password )
373414 # Preference setting application specific values first
374415 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 ]
376417 password_option_names . each do |option_name |
377418 if datastore . options . include? ( option_name )
378419 result [ option_name ] = password
0 commit comments