Handle multiple versions of Metasploit Express XML files.
git-svn-id: file:///home/svn/framework3/trunk@9431 4d416f70-5f16-0410-b530-b9f4589650daunstable
parent
f0c82d8646
commit
432284ce5a
|
@ -1180,7 +1180,7 @@ class DBManager
|
||||||
|
|
||||||
|
|
||||||
# Returns one of: :nexpose_simplexml :nexpose_rawxml :nmap_xml :openvas_xml
|
# Returns one of: :nexpose_simplexml :nexpose_rawxml :nmap_xml :openvas_xml
|
||||||
# :nessus_xml :nessus_xml_v2 :qualys_xml :msfe_v1_xml :nessus_nbe :amap_mlog :ip_list
|
# :nessus_xml :nessus_xml_v2 :qualys_xml :msfe_xml :nessus_nbe :amap_mlog :ip_list
|
||||||
# If there is no match, an error is raised instead.
|
# If there is no match, an error is raised instead.
|
||||||
def import_filetype_detect(data)
|
def import_filetype_detect(data)
|
||||||
di = data.index("\n")
|
di = data.index("\n")
|
||||||
|
@ -1213,9 +1213,9 @@ class DBManager
|
||||||
when "SCAN"
|
when "SCAN"
|
||||||
@import_filedata[:type] = "Qualys XML"
|
@import_filedata[:type] = "Qualys XML"
|
||||||
return :qualys_xml
|
return :qualys_xml
|
||||||
when "MetasploitExpressV1"
|
when /MetasploitExpressV[12]/
|
||||||
@import_filedata[:type] = "Metasploit Express XML"
|
@import_filedata[:type] = "Metasploit Express XML"
|
||||||
return :msfe_v1_xml
|
return :msfe_xml
|
||||||
else
|
else
|
||||||
# Give up if we haven't hit the root tag in the first few lines
|
# Give up if we haven't hit the root tag in the first few lines
|
||||||
break if line_count > 10
|
break if line_count > 10
|
||||||
|
@ -1255,25 +1255,36 @@ class DBManager
|
||||||
|
|
||||||
# Import a Metasploit Express XML file.
|
# Import a Metasploit Express XML file.
|
||||||
# TODO: loot, tasks, and reports
|
# TODO: loot, tasks, and reports
|
||||||
def import_msfe_v1_file(args={})
|
def import_msfe_file(args={})
|
||||||
filename = args[:filename]
|
filename = args[:filename]
|
||||||
wspace = args[:wspace] || workspace
|
wspace = args[:wspace] || workspace
|
||||||
|
|
||||||
f = File.open(filename, 'rb')
|
f = File.open(filename, 'rb')
|
||||||
data = f.read(f.stat.size)
|
data = f.read(f.stat.size)
|
||||||
import_msfe_v1_xml(args.merge(:data => data))
|
import_msfe_xml(args.merge(:data => data))
|
||||||
end
|
end
|
||||||
|
|
||||||
# For each host, step through services, notes, and vulns, and import
|
# For each host, step through services, notes, and vulns, and import
|
||||||
# them.
|
# them.
|
||||||
# TODO: loot, tasks, and reports
|
# TODO: loot, tasks, and reports
|
||||||
def import_msfe_v1_xml(args={})
|
def import_msfe_xml(args={})
|
||||||
data = args[:data]
|
data = args[:data]
|
||||||
wspace = args[:wspace] || workspace
|
wspace = args[:wspace] || workspace
|
||||||
bl = validate_ips(args[:blacklist]) ? args[:blacklist].split : []
|
bl = validate_ips(args[:blacklist]) ? args[:blacklist].split : []
|
||||||
|
|
||||||
doc = rexmlify(data)
|
doc = rexmlify(data)
|
||||||
doc.elements.each('/MetasploitExpressV1/hosts/host') do |host|
|
if doc.elements["MetasploitExpressV1"]
|
||||||
|
m_ver = 1
|
||||||
|
elsif doc.elements["MetasploitExpressV2"]
|
||||||
|
m_ver = 2
|
||||||
|
else
|
||||||
|
m_ver = nil
|
||||||
|
end
|
||||||
|
unless m_ver
|
||||||
|
raise DBImportError.new("Unknown verion for MetasploitExpress XML document")
|
||||||
|
end
|
||||||
|
|
||||||
|
doc.elements.each("/MetasploitExpressV#{m_ver}/hosts/host") do |host|
|
||||||
host_data = {}
|
host_data = {}
|
||||||
host_data[:workspace] = wspace
|
host_data[:workspace] = wspace
|
||||||
host_data[:host] = host.elements["address"].text.to_s.strip
|
host_data[:host] = host.elements["address"].text.to_s.strip
|
||||||
|
|
|
@ -1030,7 +1030,7 @@ class Db
|
||||||
print_status("Could not read the Metasploit Express file")
|
print_status("Could not read the Metasploit Express file")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
framework.db.import_msfe_v1_file(:filename => args[0])
|
framework.db.import_msfe_file(:filename => args[0])
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
Loading…
Reference in New Issue