Class: Metasploit::Framework::CommunityStringCollection
- Inherits:
-
Object
- Object
- Metasploit::Framework::CommunityStringCollection
- 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
-
#pass_file ⇒ String
Path to a file containing passwords, one per line.
- #password ⇒ String
-
#prepended_creds ⇒ Array<Credential>
List of credentials to be tried before any others.
Instance Method Summary collapse
-
#each {|credential| ... } ⇒ void
Combines all the provided credential sources into a stream of Credential objects, yielding them one at a time.
- #empty? ⇒ Boolean
-
#initialize(opts = {}) ⇒ CommunityStringCollection
constructor
A new instance of CommunityStringCollection.
-
#prepend_cred(cred) ⇒ self
Add credentials that will be yielded by #each.
Constructor Details
#initialize(opts = {}) ⇒ CommunityStringCollection
Returns a new instance of CommunityStringCollection.
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_file ⇒ String
Path to a file containing passwords, one per line
15 16 17 |
# File 'lib/metasploit/framework/community_string_collection.rb', line 15 def pass_file @pass_file end |
#password ⇒ String
19 20 21 |
# File 'lib/metasploit/framework/community_string_collection.rb', line 19 def password @password end |
#prepended_creds ⇒ Array<Credential>
List of credentials to be tried before any others
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
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
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
71 72 73 74 |
# File 'lib/metasploit/framework/community_string_collection.rb', line 71 def prepend_cred(cred) prepended_creds.unshift cred self end |