Class: Metasploit::Framework::CommunityStringCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/metasploit/framework/community_string_collection.rb

Overview

This class is responsible for taking datastore options from the snmp_login module and yielding appropriate Credentials to the LoginScanner::SNMP. This one has to be different from credentialCollection as it will only have a Metasploit::Framework::Credential#public It may be slightly confusing that the attributes are called password and pass_file, because this is what the legacy module used. However, community Strings are now considered more to be public credentials than private ones.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ CommunityStringCollection

Returns a new instance of CommunityStringCollection.

Parameters:

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):



31
32
33
34
35
36
# File 'lib/metasploit/framework/community_string_collection.rb', line 31

def initialize(opts = {})
  opts.each do |attribute, value|
    public_send("#{attribute}=", value)
  end
  self.prepended_creds ||= []
end

Instance Attribute Details

#pass_fileString

Path to a file containing passwords, one per line

Returns:

  • (String)


15
16
17
# File 'lib/metasploit/framework/community_string_collection.rb', line 15

def pass_file
  @pass_file
end

#passwordString

Returns:

  • (String)


19
20
21
# File 'lib/metasploit/framework/community_string_collection.rb', line 19

def password
  @password
end

#prepended_credsArray<Credential>

List of credentials to be tried before any others

Returns:

See Also:



26
27
28
# File 'lib/metasploit/framework/community_string_collection.rb', line 26

def prepended_creds
  @prepended_creds
end

Instance Method Details

#each {|credential| ... } ⇒ void

This method returns an undefined value.

Combines all the provided credential sources into a stream of Metasploit::Framework::Credential objects, yielding them one at a time

Yield Parameters:



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/metasploit/framework/community_string_collection.rb', line 43

def each
  begin
    if pass_file.present?
      pass_fd = File.open(pass_file, 'r:binary')
      pass_fd.each_line do |line|
        line.chomp!
        yield Metasploit::Framework::Credential.new(public: line, paired: false)
      end
    end

    if password.present?
      yield Metasploit::Framework::Credential.new(public: password, paired: false)
    end

  ensure
    pass_fd.close if pass_fd && !pass_fd.closed?
  end
end

#empty?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/metasploit/framework/community_string_collection.rb', line 62

def empty?
  prepended_creds.empty? && !pass_file.present? && !password.present?
end

#prepend_cred(cred) ⇒ self

Add credentials that will be yielded by #each

Parameters:

Returns:

  • (self)

See Also:



71
72
73
74
# File 'lib/metasploit/framework/community_string_collection.rb', line 71

def prepend_cred(cred)
  prepended_creds.unshift cred
  self
end