@@ -2932,21 +2932,26 @@ def import(args={}, &block)
2932
2932
def import_filetype_detect ( data )
2933
2933
2934
2934
if data and data . kind_of? Zip ::ZipFile
2935
- raise DBImportError . new ( "The zip file provided is empty." ) if data . entries . empty?
2935
+ if data . entries . empty?
2936
+ raise DBImportError . new ( "The zip file provided is empty." )
2937
+ end
2938
+
2936
2939
@import_filedata ||= { }
2937
2940
@import_filedata [ :zip_filename ] = File . split ( data . to_s ) . last
2938
2941
@import_filedata [ :zip_basename ] = @import_filedata [ :zip_filename ] . gsub ( /\. zip$/ , "" )
2939
2942
@import_filedata [ :zip_entry_names ] = data . entries . map { |x | x . name }
2940
- begin
2941
- @import_filedata [ :zip_xml ] = @import_filedata [ :zip_entry_names ] . grep ( /^(.*)_[0-9]+\. xml$/ ) . first || raise
2942
- @import_filedata [ :zip_wspace ] = @import_filedata [ :zip_xml ] . to_s . match ( /^(.*)_[0-9]+\. xml$/ ) [ 1 ]
2943
- @import_filedata [ :type ] = "Metasploit ZIP Report"
2944
- return :msf_zip
2945
- rescue ::Interrupt
2946
- raise $!
2947
- rescue ::Exception
2948
- raise DBImportError . new ( "The zip file provided is not a Metasploit ZIP report" )
2943
+
2944
+ xml_files = @import_filedata [ :zip_entry_names ] . grep ( /^(.*)\. xml$/ )
2945
+
2946
+ # TODO This check for our zip export should be more extensive
2947
+ if xml_files . empty?
2948
+ raise DBImportError . new ( "The zip file provided is not a Metasploit Zip Export" )
2949
2949
end
2950
+
2951
+ @import_filedata [ :zip_xml ] = xml_files . first
2952
+ @import_filedata [ :type ] = "Metasploit Zip Export"
2953
+
2954
+ return :msf_zip
2950
2955
end
2951
2956
2952
2957
if data and data . kind_of? PacketFu ::PcapFile
@@ -3624,16 +3629,13 @@ def import_msf_zip(args={}, &block)
3624
3629
end
3625
3630
}
3626
3631
3627
-
3628
3632
data . entries . each do |e |
3629
3633
target = ::File . join ( @import_filedata [ :zip_tmp ] , e . name )
3630
- ::File . unlink target if ::File . exists? ( target ) # Yep. Deleted.
3631
3634
data . extract ( e , target )
3632
3635
if target =~ /^.*.xml$/
3633
3636
target_data = ::File . open ( target , "rb" ) { |f | f . read 1024 }
3634
3637
if import_filetype_detect ( target_data ) == :msf_xml
3635
3638
@import_filedata [ :zip_extracted_xml ] = target
3636
- #break
3637
3639
end
3638
3640
end
3639
3641
end
0 commit comments