From d0d0c478aa1488e2015fc3c905445b8bfd5b7f58 Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Wed, 15 Oct 2014 11:12:13 -0500 Subject: [PATCH] Extract Msf::DBManager::Import::MetasploitFramework::Credential MSP-11124 --- lib/msf/core/db_manager/import.rb | 35 ------------------ .../db_manager/import/metasploit_framework.rb | 2 ++ .../import/metasploit_framework/credential.rb | 36 +++++++++++++++++++ 3 files changed, 38 insertions(+), 35 deletions(-) create mode 100644 lib/msf/core/db_manager/import/metasploit_framework/credential.rb diff --git a/lib/msf/core/db_manager/import.rb b/lib/msf/core/db_manager/import.rb index c46b659eaa..34284ff133 100644 --- a/lib/msf/core/db_manager/import.rb +++ b/lib/msf/core/db_manager/import.rb @@ -347,41 +347,6 @@ module Msf::DBManager::Import raise DBImportError.new("Could not automatically determine file type") end - # Import credentials given a path to a valid manifest file - # - # @param creds_dump_manifest_path [String] - # @param workspace [Mdm::Workspace] Default: {#workspace} - # @return [void] - def import_msf_cred_dump(creds_dump_manifest_path, workspace) - manifest_file = File.open(creds_dump_manifest_path) - origin = Metasploit::Credential::Origin::Import.create!(filename: File.basename(creds_dump_manifest_path)) - importer = Metasploit::Credential::Importer::Core.new(workspace: workspace, input: manifest_file, origin: origin) - importer.import! - end - - # Import credentials given a path to a valid manifest file - # - # @option args [String] :filename - # @option args [Mdm::Workspace] :wspace Default: {#workspace} - # @return [void] - def import_msf_cred_dump_zip(args = {}) - wspace = args[:wspace] || workspace - origin = Metasploit::Credential::Origin::Import.create!(filename: File.basename(args[:filename])) - importer = Metasploit::Credential::Importer::Zip.new(workspace: wspace, input: File.open(args[:filename]), origin: origin) - importer.import! - nil - end - - # Perform in an import of an msfpwdump file - def import_msf_pwdump(args={}, &block) - filename = File.basename(args[:data].path) - wspace = args[:wspace] || workspace - origin = Metasploit::Credential::Origin::Import.create!(filename: filename) - importer = Metasploit::Credential::Importer::Pwdump.new(input: args[:data], workspace: wspace, filename: filename, origin:origin) - importer.import! - importer.input.close unless importer.input.closed? - end - # There is no place the NBE actually stores the plugin name used to # scan. You get "Security Note" or "Security Warning," and that's it. def import_nessus_nbe(args={}, &block) diff --git a/lib/msf/core/db_manager/import/metasploit_framework.rb b/lib/msf/core/db_manager/import/metasploit_framework.rb index cb5831d8c4..89913c299d 100644 --- a/lib/msf/core/db_manager/import/metasploit_framework.rb +++ b/lib/msf/core/db_manager/import/metasploit_framework.rb @@ -1,7 +1,9 @@ module Msf::DBManager::Import::MetasploitFramework + autoload :Credential, 'msf/core/db_manager/import/metasploit_framework/credential' autoload :XML, 'msf/core/db_manager/import/metasploit_framework/xml' autoload :Zip, 'msf/core/db_manager/import/metasploit_framework/zip' + include Msf::DBManager::Import::MetasploitFramework::Credential include Msf::DBManager::Import::MetasploitFramework::XML include Msf::DBManager::Import::MetasploitFramework::Zip end \ No newline at end of file diff --git a/lib/msf/core/db_manager/import/metasploit_framework/credential.rb b/lib/msf/core/db_manager/import/metasploit_framework/credential.rb new file mode 100644 index 0000000000..fdf80e76e1 --- /dev/null +++ b/lib/msf/core/db_manager/import/metasploit_framework/credential.rb @@ -0,0 +1,36 @@ +module Msf::DBManager::Import::MetasploitFramework::Credential + # Import credentials given a path to a valid manifest file + # + # @param creds_dump_manifest_path [String] + # @param workspace [Mdm::Workspace] Default: {#workspace} + # @return [void] + def import_msf_cred_dump(creds_dump_manifest_path, workspace) + manifest_file = File.open(creds_dump_manifest_path) + origin = Metasploit::Credential::Origin::Import.create!(filename: File.basename(creds_dump_manifest_path)) + importer = Metasploit::Credential::Importer::Core.new(workspace: workspace, input: manifest_file, origin: origin) + importer.import! + end + + # Import credentials given a path to a valid manifest file + # + # @option args [String] :filename + # @option args [Mdm::Workspace] :wspace Default: {#workspace} + # @return [void] + def import_msf_cred_dump_zip(args = {}) + wspace = args[:wspace] || workspace + origin = Metasploit::Credential::Origin::Import.create!(filename: File.basename(args[:filename])) + importer = Metasploit::Credential::Importer::Zip.new(workspace: wspace, input: File.open(args[:filename]), origin: origin) + importer.import! + nil + end + + # Perform in an import of an msfpwdump file + def import_msf_pwdump(args={}, &block) + filename = File.basename(args[:data].path) + wspace = args[:wspace] || workspace + origin = Metasploit::Credential::Origin::Import.create!(filename: filename) + importer = Metasploit::Credential::Importer::Pwdump.new(input: args[:data], workspace: wspace, filename: filename, origin:origin) + importer.import! + importer.input.close unless importer.input.closed? + end +end