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/nessus_xml.rb
Views: 11777
# -*- coding: binary -*-1require 'rexml/document'23module Rex4module Parser567class NessusXMLStreamParser89attr_accessor :on_found_host1011def initialize(&block)12reset_state13on_found_host = block if block14end1516def reset_state17@host = {'hname' => nil, 'addr' => nil, 'mac' => nil, 'os' => nil, 'ports' => [18'port' => {'port' => nil, 'svc_name' => nil, 'proto' => nil, 'severity' => nil,19'nasl' => nil, 'nasl_name' => nil, 'description' => nil,20'cve' => [], 'bid' => [], 'xref' => [], 'msf' => nil } ] }21@state = :generic_state22end2324def tag_start(name, attributes)25case name26when "tag"27if attributes['name'] == "mac-address"28@state = :is_mac29end30if attributes['name'] == "host-fqdn"31@state = :is_fqdn32end33if attributes['name'] == "ip-addr"34@state = :is_ip35end36if attributes['name'] == "host-ip"37@state = :is_ip38end39if attributes['name'] == "operating-system"40@state = :is_os41end42when "ReportHost"43@host['hname'] = attributes['name']44when "ReportItem"45@cve = Array.new46@bid = Array.new47@xref = Array.new48@x = Hash.new49@x['nasl'] = attributes['pluginID']50@x['nasl_name'] = attributes['pluginName']51@x['port'] = attributes['port']52@x['proto'] = attributes['protocol']53@x['svc_name'] = attributes['svc_name']54@x['severity'] = attributes['severity']55when "description"56@state = :is_desc57when "cve"58@state = :is_cve59when "bid"60@state = :is_bid61when "xref"62@state = :is_xref63when "solution"64@state = :is_solution65when "metasploit_name"66@state = :msf67end68end6970def text(str)71case @state72when :is_fqdn73@host['hname'] = str74when :is_ip75@host['addr'] = str76when :is_os77@host['os'] = str78when :is_mac79@host['mac'] = str80when :is_desc81@x['description'] = str82when :is_cve83@cve.push str84when :is_bid85@bid.push str86when :is_xref87@xref.push str88when :msf89#p str90@x['msf'] = str91end92end9394def tag_end(name)95case name96when "ReportHost"97on_found_host.call(@host) if on_found_host98reset_state99when "ReportItem"100@x['cve'] = @cve101@x['bid'] = @bid102@x['xref'] = @xref103@host['ports'].push @x104end105@state = :generic_state106end107108# We don't need these methods, but they're necessary to keep REXML happy109#110def xmldecl(version, encoding, standalone); end111def cdata; end112def comment(str); end113def instruction(name, instruction); end114def attlist; end115end116117end118end119120121122