Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/rex/parser/outpost24_document.rb
Views: 11780
# -*- coding: binary -*-1require "rex/parser/nokogiri_doc_mixin"23module Rex4module Parser56load_nokogiri && class Outpost24Document < Nokogiri::XML::SAX::Document78include NokogiriDocMixin910def start_element(name, attrs)11@state[:current_tag][name] = true12case name13when "description", "information"14return unless in_tag("detaillist")15return unless in_tag("detail")16record_text17when "detail"18return unless in_tag("detaillist")19record_vuln20when "detaillist"21record_vulns22when "host"23return unless in_tag("hostlist")24record_host25when "hostlist"26record_hosts27when "id"28return unless in_tag("detaillist")29return unless in_tag("detail")30return unless in_tag("cve")31record_text32when "name"33return unless in_tag("hostlist") || in_tag("detaillist")34return unless in_tag("host") || in_tag("detail")35record_text36when "platform"37return unless in_tag("hostlist")38return unless in_tag("host")39record_text40when "portinfo"41return unless in_tag("portlist")42return unless in_tag("portlist-host")43record_service44when "portlist"45record_services46when "portnumber", "protocol", "service"47return unless in_tag("portlist")48return unless in_tag("portlist-host")49return unless in_tag("portinfo")50record_text51when "report", "ip"52record_text53end54end5556def end_element(name)57case name58when "description", "information"59return unless in_tag("detaillist")60return unless in_tag("detail")61collect_vuln_data(name)62when "detail"63return unless in_tag("detaillist")64collect_vuln65when "detaillist"66report_vulns67when "host"68return unless in_tag("hostlist")69collect_host70when "hostlist"71report_hosts72when "id"73return unless in_tag("detaillist")74return unless in_tag("detail")75return unless in_tag("cve")76collect_vuln_data(name)77when "ip"78collect_ip79when "name"80if in_tag("hostlist") && in_tag("host")81collect_host_data(name)82elsif in_tag("detaillist") && in_tag("detail")83collect_vuln_data(name)84end85when "platform"86return unless in_tag("hostlist")87return unless in_tag("host")88collect_host_data(name)89when "portinfo"90return unless in_tag("portlist")91return unless in_tag("portlist-host")92collect_service93when "portlist"94report_services95when "portnumber", "protocol", "service"96return unless in_tag("portlist")97return unless in_tag("portlist-host")98return unless in_tag("portinfo")99collect_service_data(name)100when "report"101collect_product102end103@state[:current_tag].delete(name)104end105106def record_hosts107@report_data[:hosts] = []108end109110def record_services111@report_data[:services] = []112end113114def record_vulns115@report_data[:vulns] = []116end117118def record_host119@host = {}120end121122def record_service123@service = {}124end125126def record_vuln127@vuln = {}128@refs = []129end130131def record_text132@state[:has_text] = true133end134135def collect_host136@host[:host] = @state[:host]137@host[:name] = @state[:hname]138@host[:os_name] = @state[:os_name]139@host[:info] = @state[:pinfo]140@report_data[:hosts] << @host141end142143def collect_service144@service[:host] = @state[:host]145@service[:port] = @state[:port]146@service[:proto] = @state[:proto]147@service[:name] = @state[:sname]148@service[:info] = @state[:pinfo]149@report_data[:services] << @service150end151152def collect_vuln153@vuln[:host] = @state[:host]154@vuln[:name] = @state[:vname]155@vuln[:info] = @state[:vinfo]156@vuln[:refs] = @refs157@report_data[:vulns] << @vuln158end159160def collect_product161@state[:has_text] = false162@state[:pinfo] = @text.strip if @text163@text = nil164end165166def collect_ip167@state[:has_text] = false168@state[:host] = @text.strip if @text169@text = nil170end171172def collect_host_data(name)173@state[:has_text] = false174if name == "name"175@state[:hname] = @text.strip if @text176elsif name == "platform"177if @text178@state[:os_name] = @text.strip179else180@state[:os_name] = Msf::OperatingSystems::UNKNOWN181end182end183@text = nil184end185186def collect_service_data(name)187@state[:has_text] = false188if name == "portnumber"189@state[:port] = @text.strip if @text190elsif name == "protocol"191@state[:proto] = @text.strip.downcase if @text192elsif name == "service"193@state[:sname] = @text.strip if @text194end195@text = nil196end197198def collect_vuln_data(name)199@state[:has_text] = false200if name == "name"201@state[:vname] = @text.strip if @text202elsif name == "description"203@state[:vinfo] = @text.strip if @text204elsif name == "information"205@state[:vinfo] << " #{@text.strip if @text}"206elsif name == "id"207@state[:ref] = @text.strip if @text208@refs << normalize_ref("CVE", @state[:ref])209end210@text = nil211end212213def report_hosts214block = @block215@report_data[:hosts].each do |h|216db.emit(:address, h[:host], &block) if block217db_report(:host, h)218end219end220221def report_services222block = @block223@report_data[:services].each do |s|224db.emit(:service, "#{s[:host]}:#{s[:port]}/#{s[:proto]}", &block) if block225db_report(:service, s)226end227end228229def report_vulns230block = @block231@report_data[:vulns].each do |v|232db.emit(:vuln, ["#{v[:name]} (#{v[:host]})", 1], &block) if block233db_report(:vuln, v)234end235end236237end238end239end240241242