Class: Metasploit::Credential::Importer::Multi
- Inherits:
-
Object
- Object
- Metasploit::Credential::Importer::Multi
- 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
-
#selected_importer ⇒ IO
An instance of the importer class which will handle the processing of input into the system.
Instance Method Summary collapse
-
#csv? ⇒ Boolean
True if the file has a comma in the first place there should be one.
-
#import! ⇒ Boolean
Perform the import.
-
#initialize(args = {}) ⇒ Multi
constructor
Instance Methods.
-
#zip? ⇒ Boolean
True if the file can be opened with ‘Zip::File::open`, false otherwise.
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_importer ⇒ IO
An instance of the importer class which will handle the processing of input into the system.
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
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! ⇒ Boolean
Perform the import. Return true if import succeeded. Return false if any cred failed due to formatting.
47 48 49 |
# File 'lib/metasploit/credential/importer/multi.rb', line 47 def import! return selected_importer.import! end |
#zip? ⇒ Boolean
True if the file can be opened with ‘Zip::File::open`, false otherwise
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 |