class Rex::Parser::NessusXMLStreamParser

Attributes

on_found_host[RW]

Public Class Methods

new(&block) click to toggle source
# File lib/rex/parser/nessus_xml.rb, line 12
def initialize(&block)
  reset_state
  on_found_host = block if block
end

Public Instance Methods

attlist() click to toggle source
# File lib/rex/parser/nessus_xml.rb, line 115
def attlist; end
cdata() click to toggle source
# File lib/rex/parser/nessus_xml.rb, line 112
def cdata; end
comment(str) click to toggle source
# File lib/rex/parser/nessus_xml.rb, line 113
def comment(str); end
instruction(name, instruction) click to toggle source
# File lib/rex/parser/nessus_xml.rb, line 114
def instruction(name, instruction); end
reset_state() click to toggle source
# File lib/rex/parser/nessus_xml.rb, line 17
def reset_state
  @host = {'hname' => nil, 'addr' => nil, 'mac' => nil, 'os' => nil, 'ports' => [
    'port' => {'port' => nil, 'svc_name'  => nil, 'proto' => nil, 'severity' => nil,
    'nasl' => nil, 'nasl_name' => nil, 'description' => nil,
    'cve' => [], 'bid' => [], 'xref' => [], 'msf' => nil } ] }
  @state = :generic_state
end
tag_end(name) click to toggle source
# File lib/rex/parser/nessus_xml.rb, line 95
def tag_end(name)
  case name
  when "ReportHost"
    on_found_host.call(@host) if on_found_host
    reset_state
  when "ReportItem"
    @x['cve'] = @cve
    @x['bid'] = @bid
    @x['xref'] = @xref
    @host['ports'].push @x
  end
  @state = :generic_state
end
tag_start(name, attributes) click to toggle source
# File lib/rex/parser/nessus_xml.rb, line 25
def tag_start(name, attributes)
  case name
  when "tag"
    if attributes['name'] == "mac-address"
      @state = :is_mac
    end
    if attributes['name'] == "host-fqdn"
      @state = :is_fqdn
    end
    if attributes['name'] == "ip-addr"
      @state = :is_ip
    end
    if attributes['name'] == "host-ip"
      @state = :is_ip
    end
    if attributes['name'] == "operating-system"
      @state = :is_os
    end
  when "ReportHost"
    @host['hname'] = attributes['name']
  when "ReportItem"
    @cve = Array.new
    @bid = Array.new
    @xref = Array.new
    @x = Hash.new
    @x['nasl'] = attributes['pluginID']
    @x['nasl_name'] = attributes['pluginName']
    @x['port'] = attributes['port']
    @x['proto'] = attributes['protocol']
    @x['svc_name'] = attributes['svc_name']
    @x['severity'] = attributes['severity']
  when "description"
    @state = :is_desc
  when "cve"
    @state = :is_cve
  when "bid"
    @state = :is_bid
  when "xref"
    @state = :is_xref
  when "solution"
    @state = :is_solution
  when "metasploit_name"
    @state = :msf
  end
end
text(str) click to toggle source
# File lib/rex/parser/nessus_xml.rb, line 71
def text(str)
  case @state
  when :is_fqdn
    @host['hname'] = str
  when :is_ip
    @host['addr'] = str
  when :is_os
    @host['os'] = str
  when :is_mac
    @host['mac'] = str
  when :is_desc
    @x['description'] = str
  when :is_cve
    @cve.push str
  when :is_bid
    @bid.push str
  when :is_xref
    @xref.push str
  when :msf
    #p str
    @x['msf'] = str
  end
end
xmldecl(version, encoding, standalone) click to toggle source

We don’t need these methods, but they’re necessary to keep REXML happy

# File lib/rex/parser/nessus_xml.rb, line 111
def xmldecl(version, encoding, standalone); end