From 389bcbd343e836a5282327b1bf52491b7c97378c Mon Sep 17 00:00:00 2001 From: David Maloney Date: Tue, 24 Feb 2015 12:18:32 -0600 Subject: [PATCH] refactor note import into sep method we will now be importing notes from multiple place within the XML document. the importing of notes has been refactored into a seperate method to be easily reused in this fashion MSP-12183 --- .../import/metasploit_framework/xml.rb | 40 ++++++++++++------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/lib/msf/core/db_manager/import/metasploit_framework/xml.rb b/lib/msf/core/db_manager/import/metasploit_framework/xml.rb index b94e564dc4..4789406471 100644 --- a/lib/msf/core/db_manager/import/metasploit_framework/xml.rb +++ b/lib/msf/core/db_manager/import/metasploit_framework/xml.rb @@ -64,6 +64,30 @@ module Msf::DBManager::Import::MetasploitFramework::XML import_msf_xml(args.merge(:data => data)) end + # Imports `Mdm::Note` objects from the XML element. + # + # @param note [REXML::Element] The Note element + # @param allow_yaml [Boolean] whether to allow yaml + # @param note_data [Hash] hash containing note attributes to be passed along + # @return [void] + def import_msf_note_element(note, allow_yaml, note_data={}) + note_data[:type] = nils_for_nulls(note.elements["ntype"].text.to_s.strip) + note_data[:data] = nils_for_nulls(unserialize_object(note.elements["data"], allow_yaml)) + + if note.elements["critical"].text + note_data[:critical] = true unless note.elements["critical"].text.to_s.strip == "NULL" + end + if note.elements["seen"].text + note_data[:seen] = true unless note.elements["critical"].text.to_s.strip == "NULL" + end + %W{created-at updated-at}.each { |datum| + if note.elements[datum].text + note_data[datum.gsub("-","_")] = nils_for_nulls(note.elements[datum].text.to_s.strip) + end + } + report_note(note_data) + end + # Imports web_form element using {Msf::DBManager#report_web_form}. # # @param element [REXML::Element] web_form element. @@ -280,21 +304,7 @@ module Msf::DBManager::Import::MetasploitFramework::XML note_data = {} note_data[:workspace] = wspace note_data[:host] = hobj - note_data[:type] = nils_for_nulls(note.elements["ntype"].text.to_s.strip) - note_data[:data] = nils_for_nulls(unserialize_object(note.elements["data"], allow_yaml)) - - if note.elements["critical"].text - note_data[:critical] = true unless note.elements["critical"].text.to_s.strip == "NULL" - end - if note.elements["seen"].text - note_data[:seen] = true unless note.elements["critical"].text.to_s.strip == "NULL" - end - %W{created-at updated-at}.each { |datum| - if note.elements[datum].text - note_data[datum.gsub("-","_")] = nils_for_nulls(note.elements[datum].text.to_s.strip) - end - } - report_note(note_data) + import_msf_note_element(note,allow_yaml,note_data) end host.elements.each('tags/tag') do |tag|