class Metasploit::Credential::Importer::Multi

{Metasploit::Credential::Importer::Multi} allows a single class to pass off a file to the correct importer as long as the file meets certain basic requirements. Each file type is identified, and if supported, another class in the {Metasploit::Credential::Importer} namespace is instantiated with the ‘#input` attribute passed in there.

Attributes

selected_importer[RW]

@!attribute selected_importer

An instance of the importer class which will handle the processing of input into the system.
@return [IO]

Public Class Methods

new(args={}) click to toggle source

Instance Methods

# File lib/metasploit/credential/importer/multi.rb, line 33
def initialize(args={})
  @selected_importer = nil
  super(args)

  if zip?
    @selected_importer = Metasploit::Credential::Importer::Zip.new(input: input, origin: origin, workspace: workspace)
  elsif csv?
    @selected_importer = Metasploit::Credential::Importer::Core.new(input: input, origin: origin, workspace: workspace)
  end
end

Public Instance Methods

csv?() click to toggle source

True if the file has a comma in the first place there should be one. Further validation for well-formedness is available in {Metasploit::Credential::Importer::Core}

@return [Boolean]

# File lib/metasploit/credential/importer/multi.rb, line 68
def csv?
  test_header_byte_length = Metasploit::Credential::Importer::Core::VALID_SHORT_CSV_HEADERS.first.size + 1
  test_bytes              =  input.read(test_header_byte_length)
  if test_bytes.present? && test_bytes.include?(',')
    input.rewind
    true
  else
    false
  end
end
import!() click to toggle source

Perform the import. Return true if import succeeded. Return false if any cred failed due to formatting.

@return [Boolean]

# File lib/metasploit/credential/importer/multi.rb, line 47
def import!
  return selected_importer.import!
end
zip?() click to toggle source

True if the file can be opened with ‘Zip::File::open`, false otherwise

@return [Boolean]

# File lib/metasploit/credential/importer/multi.rb, line 55
def zip?
  begin
    ::Zip::File.open input.path
    true
  rescue ::Zip::Error
    false
  end
end

Private Instance Methods

is_supported_format() click to toggle source

True if the format of ‘#input` is supported for import

@return [Boolean]

# File lib/metasploit/credential/importer/multi.rb, line 84
def is_supported_format
  if zip? || csv?
    true
  else
    errors.add(:input, :unsupported_file_format)
  end
end