Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/metasploit/framework/community_string_collection.rb
Views: 11780
require 'metasploit/framework/credential'12module Metasploit3module Framework45# This class is responsible for taking datastore options from the snmp_login module6# and yielding appropriate {Metasploit::Framework::Credential}s to the {Metasploit::Framework::LoginScanner::SNMP}.7# This one has to be different from credentialCollection as it will only have a {Metasploit::Framework::Credential#public}8# It may be slightly confusing that the attributes are called password and pass_file, because this is what the legacy9# module used. However, community Strings are now considered more to be public credentials than private ones.10class CommunityStringCollection11# @!attribute pass_file12# Path to a file containing passwords, one per line13# @return [String]14attr_accessor :pass_file1516# @!attribute password17# @return [String]18attr_accessor :password1920# @!attribute prepended_creds21# List of credentials to be tried before any others22#23# @see #prepend_cred24# @return [Array<Credential>]25attr_accessor :prepended_creds2627# @option opts [String] :pass_file See {#pass_file}28# @option opts [String] :password See {#password}29# @option opts [Array<Credential>] :prepended_creds ([]) See {#prepended_creds}30def initialize(opts = {})31opts.each do |attribute, value|32public_send("#{attribute}=", value)33end34self.prepended_creds ||= []35end3637# Combines all the provided credential sources into a stream of {Credential}38# objects, yielding them one at a time39#40# @yieldparam credential [Metasploit::Framework::Credential]41# @return [void]42def each43begin44if pass_file.present?45pass_fd = File.open(pass_file, 'r:binary')46pass_fd.each_line do |line|47line.chomp!48yield Metasploit::Framework::Credential.new(public: line, paired: false)49end50end5152if password.present?53yield Metasploit::Framework::Credential.new(public: password, paired: false)54end5556ensure57pass_fd.close if pass_fd && !pass_fd.closed?58end59end6061def empty?62prepended_creds.empty? && !pass_file.present? && !password.present?63end6465# Add {Credential credentials} that will be yielded by {#each}66#67# @see prepended_creds68# @param cred [Credential]69# @return [self]70def prepend_cred(cred)71prepended_creds.unshift cred72self73end7475end76end77end787980