Skip to content

Commit ed1ed5d

Browse files
committed
Merge pull request rapid7#117 from rapid7/feature/MSP-9943/db-import-creds
Deprecation warning exorcised, specs passing, export/import accuracy confirmed. MSP-9943 #land
2 parents 08cd269 + 2eea95e commit ed1ed5d

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

config/application.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,7 @@ class Application < Rails::Application
4646
end
4747
end
4848
end
49-
end
49+
end
50+
51+
# Silence warnings about this defaulting to true
52+
I18n.enforce_available_locales = true

lib/msf/core/db.rb

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2938,7 +2938,6 @@ def import_file(args={}, &block)
29382938
# is unknown.
29392939
def import(args={}, &block)
29402940
data = args[:data] || args['data']
2941-
wspace = args[:wspace] || args['wspace'] || workspace
29422941
ftype = import_filetype_detect(data)
29432942
yield(:filetype, @import_filedata[:type]) if block
29442943
self.send "import_#{ftype}".to_sym, args, &block
@@ -2959,6 +2958,7 @@ def import(args={}, &block)
29592958
# :ip_list
29602959
# :libpcap
29612960
# :mbsa_xml
2961+
# :msf_cred_dump_zip
29622962
# :msf_pwdump
29632963
# :msf_xml
29642964
# :msf_zip
@@ -2980,6 +2980,8 @@ def import(args={}, &block)
29802980
# :wapiti_xml
29812981
#
29822982
# If there is no match, an error is raised instead.
2983+
#
2984+
# @raise DBImportError if the type can't be detected
29832985
def import_filetype_detect(data)
29842986

29852987
if data and data.kind_of? Zip::File
@@ -2992,6 +2994,11 @@ def import_filetype_detect(data)
29922994
@import_filedata[:zip_basename] = @import_filedata[:zip_filename].gsub(/\.zip$/,"")
29932995
@import_filedata[:zip_entry_names] = data.entries.map {|x| x.name}
29942996

2997+
if @import_filedata[:zip_entry_names].include?(Metasploit::Credential::Importer::Zip::MANIFEST_FILE_NAME)
2998+
@import_filedata[:type] = "Metasploit Credential Dump"
2999+
return :msf_cred_dump_zip
3000+
end
3001+
29953002
xml_files = @import_filedata[:zip_entry_names].grep(/^(.*)\.xml$/)
29963003

29973004
# TODO This check for our zip export should be more extensive
@@ -3613,10 +3620,10 @@ def import_msf_zip(args={}, &block)
36133620
}
36143621

36153622
data.entries.each do |e|
3616-
target = ::File.join(@import_filedata[:zip_tmp],e.name)
3623+
target = ::File.join(@import_filedata[:zip_tmp], e.name)
36173624
data.extract(e,target)
36183625

3619-
if target =~ /^.*.xml$/
3626+
if target =~ /\.xml\z/
36203627
target_data = ::File.open(target, "rb") {|f| f.read 1024}
36213628
if import_filetype_detect(target_data) == :msf_xml
36223629
@import_filedata[:zip_extracted_xml] = target
@@ -3801,7 +3808,9 @@ def import_msf_collateral(args={}, &block)
38013808
end
38023809

38033810
# Import credentials given a path to a valid manifest file
3811+
#
38043812
# @param creds_dump_manifest_path [String]
3813+
# @param workspace [Mdm::Workspace] Default: {#workspace}
38053814
# @return [void]
38063815
def import_msf_cred_dump(creds_dump_manifest_path, workspace)
38073816
manifest_file = File.open(creds_dump_manifest_path)
@@ -3810,6 +3819,18 @@ def import_msf_cred_dump(creds_dump_manifest_path, workspace)
38103819
importer.import!
38113820
end
38123821

3822+
# Import credentials given a path to a valid manifest file
3823+
#
3824+
# @option args [String] :filename
3825+
# @option args [Mdm::Workspace] :wspace Default: {#workspace}
3826+
# @return [void]
3827+
def import_msf_cred_dump_zip(args = {})
3828+
wspace = args[:wspace] || workspace
3829+
origin = Metasploit::Credential::Origin::Import.create!(filename: File.basename(args[:filename]))
3830+
importer = Metasploit::Credential::Importer::Zip.new(workspace: wspace, input: File.open(args[:filename]), origin: origin)
3831+
importer.import!
3832+
nil
3833+
end
38133834

38143835
# @param report [REXML::Element] to be imported
38153836
# @param args [Hash]

0 commit comments

Comments
 (0)