Skip to content

Commit 7d1cd22

Browse files
committed
Quick and dirty import of cred zip
1 parent 4d3bfcf commit 7d1cd22

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

lib/msf/core/db.rb

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2948,7 +2948,6 @@ def import_file(args={}, &block)
29482948
# is unknown.
29492949
def import(args={}, &block)
29502950
data = args[:data] || args['data']
2951-
wspace = args[:wspace] || args['wspace'] || workspace
29522951
ftype = import_filetype_detect(data)
29532952
yield(:filetype, @import_filedata[:type]) if block
29542953
self.send "import_#{ftype}".to_sym, args, &block
@@ -2969,6 +2968,7 @@ def import(args={}, &block)
29692968
# :ip_list
29702969
# :libpcap
29712970
# :mbsa_xml
2971+
# :msf_cred_dump_zip
29722972
# :msf_pwdump
29732973
# :msf_xml
29742974
# :msf_zip
@@ -2990,6 +2990,8 @@ def import(args={}, &block)
29902990
# :wapiti_xml
29912991
#
29922992
# If there is no match, an error is raised instead.
2993+
#
2994+
# @raise DBImportError if the type can't be detected
29932995
def import_filetype_detect(data)
29942996

29952997
if data and data.kind_of? Zip::File
@@ -3002,6 +3004,10 @@ def import_filetype_detect(data)
30023004
@import_filedata[:zip_basename] = @import_filedata[:zip_filename].gsub(/\.zip$/,"")
30033005
@import_filedata[:zip_entry_names] = data.entries.map {|x| x.name}
30043006

3007+
if @import_filedata[:zip_entry_names].include?("manifest.csv")
3008+
return :msf_cred_dump_zip
3009+
end
3010+
30053011
xml_files = @import_filedata[:zip_entry_names].grep(/^(.*)\.xml$/)
30063012

30073013
# TODO This check for our zip export should be more extensive
@@ -3623,10 +3629,10 @@ def import_msf_zip(args={}, &block)
36233629
}
36243630

36253631
data.entries.each do |e|
3626-
target = ::File.join(@import_filedata[:zip_tmp],e.name)
3632+
target = ::File.join(@import_filedata[:zip_tmp], e.name)
36273633
data.extract(e,target)
36283634

3629-
if target =~ /^.*.xml$/
3635+
if target =~ /\.xml\z/
36303636
target_data = ::File.open(target, "rb") {|f| f.read 1024}
36313637
if import_filetype_detect(target_data) == :msf_xml
36323638
@import_filedata[:zip_extracted_xml] = target
@@ -3811,7 +3817,9 @@ def import_msf_collateral(args={}, &block)
38113817
end
38123818

38133819
# Import credentials given a path to a valid manifest file
3820+
#
38143821
# @param creds_dump_manifest_path [String]
3822+
# @param workspace [Mdm::Workspace]
38153823
# @return [void]
38163824
def import_msf_cred_dump(creds_dump_manifest_path, workspace)
38173825
manifest_file = File.open(creds_dump_manifest_path)
@@ -3820,6 +3828,17 @@ def import_msf_cred_dump(creds_dump_manifest_path, workspace)
38203828
importer.import!
38213829
end
38223830

3831+
# Import credentials given a path to a valid manifest file
3832+
#
3833+
# @opt args [String] :filename
3834+
# @return [void]
3835+
def import_msf_cred_dump_zip(args = {})
3836+
wspace = args[:wspace] || workspace
3837+
origin = Metasploit::Credential::Origin::Import.create!(filename: File.basename(args[:filename]))
3838+
importer = Metasploit::Credential::Importer::Zip.new(workspace: wspace, input: File.open(args[:filename]), origin: origin)
3839+
importer.import!
3840+
nil
3841+
end
38233842

38243843
# @param report [REXML::Element] to be imported
38253844
# @param args [Hash]

0 commit comments

Comments
 (0)