2014-08-17 22:31:53 +00:00
|
|
|
# -*- coding: binary -*-
|
2013-10-11 21:51:41 +00:00
|
|
|
require "rex/parser/nokogiri_doc_mixin"
|
|
|
|
|
|
|
|
module Rex
|
|
|
|
module Parser
|
|
|
|
|
|
|
|
load_nokogiri && class Outpost24Document < Nokogiri::XML::SAX::Document
|
|
|
|
|
|
|
|
include NokogiriDocMixin
|
|
|
|
|
|
|
|
def start_element(name, attrs)
|
|
|
|
@state[:current_tag][name] = true
|
|
|
|
case name
|
2013-10-18 18:21:28 +00:00
|
|
|
when "description", "information"
|
|
|
|
return unless in_tag("detaillist")
|
|
|
|
return unless in_tag("detail")
|
|
|
|
record_text
|
|
|
|
when "detail"
|
|
|
|
return unless in_tag("detaillist")
|
|
|
|
record_vuln
|
2013-10-11 21:51:41 +00:00
|
|
|
when "detaillist"
|
2013-10-18 17:20:43 +00:00
|
|
|
record_vulns
|
2013-10-11 21:51:41 +00:00
|
|
|
when "host"
|
|
|
|
return unless in_tag("hostlist")
|
2013-10-18 17:20:43 +00:00
|
|
|
record_host
|
2013-10-18 18:21:28 +00:00
|
|
|
when "hostlist"
|
|
|
|
record_hosts
|
|
|
|
when "id"
|
2013-10-11 21:51:41 +00:00
|
|
|
return unless in_tag("detaillist")
|
2013-10-18 18:21:28 +00:00
|
|
|
return unless in_tag("detail")
|
|
|
|
return unless in_tag("cve")
|
2013-10-18 17:20:43 +00:00
|
|
|
record_text
|
2013-10-17 20:31:48 +00:00
|
|
|
when "name"
|
|
|
|
return unless in_tag("hostlist") || in_tag("detaillist")
|
|
|
|
return unless in_tag("host") || in_tag("detail")
|
2013-10-18 17:20:43 +00:00
|
|
|
record_text
|
2013-10-11 21:51:41 +00:00
|
|
|
when "platform"
|
|
|
|
return unless in_tag("hostlist")
|
|
|
|
return unless in_tag("host")
|
2013-10-18 17:20:43 +00:00
|
|
|
record_text
|
2013-10-18 18:21:28 +00:00
|
|
|
when "portinfo"
|
|
|
|
return unless in_tag("portlist")
|
|
|
|
return unless in_tag("portlist-host")
|
|
|
|
record_service
|
|
|
|
when "portlist"
|
|
|
|
record_services
|
2013-10-11 21:51:41 +00:00
|
|
|
when "portnumber", "protocol", "service"
|
|
|
|
return unless in_tag("portlist")
|
|
|
|
return unless in_tag("portlist-host")
|
|
|
|
return unless in_tag("portinfo")
|
2013-10-18 17:20:43 +00:00
|
|
|
record_text
|
2013-10-18 18:21:28 +00:00
|
|
|
when "report", "ip"
|
2013-10-18 17:20:43 +00:00
|
|
|
record_text
|
2013-10-11 21:51:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def end_element(name)
|
|
|
|
case name
|
2013-10-18 18:21:28 +00:00
|
|
|
when "description", "information"
|
|
|
|
return unless in_tag("detaillist")
|
|
|
|
return unless in_tag("detail")
|
|
|
|
collect_vuln_data(name)
|
|
|
|
when "detail"
|
|
|
|
return unless in_tag("detaillist")
|
|
|
|
collect_vuln
|
2013-10-11 21:51:41 +00:00
|
|
|
when "detaillist"
|
|
|
|
report_vulns
|
|
|
|
when "host"
|
|
|
|
return unless in_tag("hostlist")
|
|
|
|
collect_host
|
2013-10-18 18:21:28 +00:00
|
|
|
when "hostlist"
|
|
|
|
report_hosts
|
|
|
|
when "id"
|
2013-10-11 21:51:41 +00:00
|
|
|
return unless in_tag("detaillist")
|
2013-10-18 18:21:28 +00:00
|
|
|
return unless in_tag("detail")
|
|
|
|
return unless in_tag("cve")
|
|
|
|
collect_vuln_data(name)
|
2013-10-11 21:51:41 +00:00
|
|
|
when "ip"
|
|
|
|
collect_ip
|
2013-10-17 20:31:48 +00:00
|
|
|
when "name"
|
|
|
|
if in_tag("hostlist") && in_tag("host")
|
|
|
|
collect_host_data(name)
|
|
|
|
elsif in_tag("detaillist") && in_tag("detail")
|
|
|
|
collect_vuln_data(name)
|
|
|
|
end
|
2013-10-11 21:51:41 +00:00
|
|
|
when "platform"
|
|
|
|
return unless in_tag("hostlist")
|
|
|
|
return unless in_tag("host")
|
|
|
|
collect_host_data(name)
|
2013-10-18 18:21:28 +00:00
|
|
|
when "portinfo"
|
|
|
|
return unless in_tag("portlist")
|
|
|
|
return unless in_tag("portlist-host")
|
|
|
|
collect_service
|
|
|
|
when "portlist"
|
|
|
|
report_services
|
2013-10-11 21:51:41 +00:00
|
|
|
when "portnumber", "protocol", "service"
|
|
|
|
return unless in_tag("portlist")
|
|
|
|
return unless in_tag("portlist-host")
|
|
|
|
return unless in_tag("portinfo")
|
|
|
|
collect_service_data(name)
|
2013-10-18 18:21:28 +00:00
|
|
|
when "report"
|
|
|
|
collect_product
|
2013-10-11 21:51:41 +00:00
|
|
|
end
|
|
|
|
@state[:current_tag].delete(name)
|
|
|
|
end
|
|
|
|
|
2013-10-18 17:20:43 +00:00
|
|
|
def record_hosts
|
|
|
|
@report_data[:hosts] = []
|
|
|
|
end
|
|
|
|
|
|
|
|
def record_services
|
|
|
|
@report_data[:services] = []
|
|
|
|
end
|
|
|
|
|
|
|
|
def record_vulns
|
|
|
|
@report_data[:vulns] = []
|
|
|
|
end
|
|
|
|
|
|
|
|
def record_host
|
|
|
|
@host = {}
|
|
|
|
end
|
|
|
|
|
|
|
|
def record_service
|
|
|
|
@service = {}
|
|
|
|
end
|
|
|
|
|
|
|
|
def record_vuln
|
|
|
|
@vuln = {}
|
|
|
|
@refs = []
|
|
|
|
end
|
|
|
|
|
|
|
|
def record_text
|
|
|
|
@state[:has_text] = true
|
|
|
|
end
|
|
|
|
|
2013-10-11 21:51:41 +00:00
|
|
|
def collect_host
|
|
|
|
@host[:host] = @state[:host]
|
2013-10-17 20:31:48 +00:00
|
|
|
@host[:name] = @state[:hname]
|
2013-10-11 21:51:41 +00:00
|
|
|
@host[:os_name] = @state[:os_name]
|
2013-10-17 21:18:27 +00:00
|
|
|
@host[:info] = @state[:pinfo]
|
2013-10-11 21:51:41 +00:00
|
|
|
@report_data[:hosts] << @host
|
|
|
|
end
|
|
|
|
|
|
|
|
def collect_service
|
|
|
|
@service[:host] = @state[:host]
|
|
|
|
@service[:port] = @state[:port]
|
|
|
|
@service[:proto] = @state[:proto]
|
|
|
|
@service[:name] = @state[:sname]
|
2013-10-17 21:18:27 +00:00
|
|
|
@service[:info] = @state[:pinfo]
|
2013-10-11 21:51:41 +00:00
|
|
|
@report_data[:services] << @service
|
|
|
|
end
|
|
|
|
|
|
|
|
def collect_vuln
|
|
|
|
@vuln[:host] = @state[:host]
|
2013-10-17 19:27:17 +00:00
|
|
|
@vuln[:name] = @state[:vname]
|
2013-10-17 21:18:27 +00:00
|
|
|
@vuln[:info] = @state[:vinfo]
|
2013-10-17 19:27:17 +00:00
|
|
|
@vuln[:refs] = @refs
|
2013-10-11 21:51:41 +00:00
|
|
|
@report_data[:vulns] << @vuln
|
|
|
|
end
|
|
|
|
|
2013-10-18 17:07:34 +00:00
|
|
|
def collect_product
|
|
|
|
@state[:has_text] = false
|
|
|
|
@state[:pinfo] = @text.strip if @text
|
|
|
|
@text = nil
|
|
|
|
end
|
|
|
|
|
2013-10-11 21:51:41 +00:00
|
|
|
def collect_ip
|
|
|
|
@state[:has_text] = false
|
|
|
|
@state[:host] = @text.strip if @text
|
|
|
|
@text = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def collect_host_data(name)
|
|
|
|
@state[:has_text] = false
|
2013-10-17 20:31:48 +00:00
|
|
|
if name == "name"
|
|
|
|
@state[:hname] = @text.strip if @text
|
|
|
|
elsif name == "platform"
|
2013-10-11 21:51:41 +00:00
|
|
|
if @text
|
|
|
|
@state[:os_name] = @text.strip
|
|
|
|
else
|
|
|
|
@state[:os_name] = Msf::OperatingSystems::UNKNOWN
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@text = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def collect_service_data(name)
|
|
|
|
@state[:has_text] = false
|
|
|
|
if name == "portnumber"
|
|
|
|
@state[:port] = @text.strip if @text
|
|
|
|
elsif name == "protocol"
|
|
|
|
@state[:proto] = @text.strip.downcase if @text
|
|
|
|
elsif name == "service"
|
|
|
|
@state[:sname] = @text.strip if @text
|
|
|
|
end
|
|
|
|
@text = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def collect_vuln_data(name)
|
|
|
|
@state[:has_text] = false
|
|
|
|
if name == "name"
|
2013-10-17 19:27:17 +00:00
|
|
|
@state[:vname] = @text.strip if @text
|
2013-10-11 21:51:41 +00:00
|
|
|
elsif name == "description"
|
2013-10-17 21:18:27 +00:00
|
|
|
@state[:vinfo] = @text.strip if @text
|
2013-10-18 16:31:54 +00:00
|
|
|
elsif name == "information"
|
|
|
|
@state[:vinfo] << " #{@text.strip if @text}"
|
2013-10-17 19:27:17 +00:00
|
|
|
elsif name == "id"
|
|
|
|
@state[:ref] = @text.strip if @text
|
|
|
|
@refs << normalize_ref("CVE", @state[:ref])
|
2013-10-11 21:51:41 +00:00
|
|
|
end
|
|
|
|
@text = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def report_hosts
|
2013-10-17 19:27:17 +00:00
|
|
|
block = @block
|
|
|
|
@report_data[:hosts].each do |h|
|
|
|
|
db.emit(:address, h[:host], &block) if block
|
|
|
|
db_report(:host, h)
|
2013-10-11 21:51:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def report_services
|
2013-10-17 19:27:17 +00:00
|
|
|
block = @block
|
|
|
|
@report_data[:services].each do |s|
|
|
|
|
db.emit(:service, "#{s[:host]}:#{s[:port]}/#{s[:proto]}", &block) if block
|
|
|
|
db_report(:service, s)
|
2013-10-11 21:51:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def report_vulns
|
2013-10-17 19:27:17 +00:00
|
|
|
block = @block
|
|
|
|
@report_data[:vulns].each do |v|
|
|
|
|
db.emit(:vuln, ["#{v[:name]} (#{v[:host]})", 1], &block) if block
|
|
|
|
db_report(:vuln, v)
|
2013-10-11 21:51:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|