Class: Metasploit::Credential::Importer::Multi

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/metasploit/credential/importer/multi.rb

Overview

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.

Constant Summary

Constants included from Base

Base::LONG_FORM_ALLOWED_PRIVATE_TYPE_NAMES, Base::SHORT_FORM_ALLOWED_PRIVATE_TYPE_NAMES

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Multi

Instance Methods



33
34
35
36
37
38
39
40
41
42
# 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

Instance Attribute Details

#selected_importerIO

An instance of the importer class which will handle the processing of input into the system.

Returns:

  • (IO)


21
22
23
# File 'lib/metasploit/credential/importer/multi.rb', line 21

def selected_importer
  @selected_importer
end

Instance Method Details

#csv?Boolean

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

Returns:

  • (Boolean)


68
69
70
71
72
73
74
75
76
77
# 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!void

This method returns an undefined value.

Perform the import



47
48
49
# File 'lib/metasploit/credential/importer/multi.rb', line 47

def import!
  selected_importer.import!
end

#zip?Boolean

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

Returns:

  • (Boolean)


55
56
57
58
59
60
61
62
# File 'lib/metasploit/credential/importer/multi.rb', line 55

def zip?
  begin
    ::Zip::File.open input.path
    true
  rescue ::Zip::Error
    false
  end
end