Browse Source

Fix import issue caused by missing wspace key

Modify import module to follow pattern used in other Msf::DBManager
import modules. Test module updated for method name changes.
Matthew Kienow 2 months ago
parent
commit
4e11dcfee1
No account linked to committer's email address

+ 16
- 8
lib/msf/core/db_manager/import/open_vas.rb View File

@@ -1,7 +1,7 @@
1 1
 require 'rex/parser/openvas_nokogiri'
2 2
 
3 3
 module Msf::DBManager::Import::OpenVAS
4
-  def import_openvas_new_xml(args={}, &block)
4
+  def import_openvas_noko_stream(args={}, &block)
5 5
     if block
6 6
       doc = Rex::Parser::OpenVASDocument.new(args,framework.db) {|type, data| yield type,data }
7 7
     else
@@ -11,14 +11,22 @@ module Msf::DBManager::Import::OpenVAS
11 11
     parser.parse(args[:data])
12 12
   end
13 13
 
14
-  def import_openvas_new_xml_file(args={})
15
-    filename = args[:filename]
16
-
17
-    data = ""
18
-    ::File.open(filename, 'rb') do |f|
19
-      data = f.read(f.stat.size)
14
+  def import_openvas_new_xml(args={}, &block)
15
+    wspace = Msf::Util::DBManager.process_opts_workspace(args, framework).name
16
+    if Rex::Parser.nokogiri_loaded
17
+      parser = "Nokogiri v#{::Nokogiri::VERSION}"
18
+      noko_args = args.dup
19
+      noko_args[:wspace] = wspace
20
+      if block
21
+        yield(:parser, parser)
22
+        import_openvas_noko_stream(noko_args) {|type, data| yield type,data}
23
+      else
24
+        import_openvas_noko_stream(noko_args)
25
+      end
26
+      return true
27
+    else # Sorry
28
+      raise Msf::DBImportError.new("Could not import due to missing Nokogiri parser. Try 'gem install nokogiri'.")
20 29
     end
21
-    import_wapiti_xml(args.merge(:data => data))
22 30
   end
23 31
 
24 32
   #

+ 1
- 1
spec/support/shared/examples/msf/db_manager/import/open_vas.rb View File

@@ -1,5 +1,5 @@
1 1
 RSpec.shared_examples_for 'Msf::DBManager::Import::OpenVAS' do
2
+  it { is_expected.to respond_to :import_openvas_noko_stream }
2 3
   it { is_expected.to respond_to :import_openvas_new_xml }
3
-  it { is_expected.to respond_to :import_openvas_new_xml_file }
4 4
   it { is_expected.to respond_to :import_openvas_xml }
5 5
 end

Loading…
Cancel
Save