Class: Rex::Parser::RetinaXMLStreamParser

Inherits:
Object
  • Object
show all
Defined in:
lib/rex/parser/retina_xml.rb

Overview

XXX - Retina XML does not include ANY service/port information export

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(on_found_host = nil) ⇒ RetinaXMLStreamParser

Returns a new instance of RetinaXMLStreamParser.



9
10
11
12
# File 'lib/rex/parser/retina_xml.rb', line 9

def initialize(on_found_host = nil)
  reset_state
  self.on_found_host = on_found_host if on_found_host
end

Instance Attribute Details

#on_found_hostObject

Returns the value of attribute on_found_host.



7
8
9
# File 'lib/rex/parser/retina_xml.rb', line 7

def on_found_host
  @on_found_host
end

Instance Method Details

#attlistObject



84
# File 'lib/rex/parser/retina_xml.rb', line 84

def attlist; end

#cdataObject



81
# File 'lib/rex/parser/retina_xml.rb', line 81

def cdata; end

#comment(str) ⇒ Object



82
# File 'lib/rex/parser/retina_xml.rb', line 82

def comment(str); end

#instruction(name, instruction) ⇒ Object



83
# File 'lib/rex/parser/retina_xml.rb', line 83

def instruction(name, instruction); end

#reset_audit_stateObject



20
21
22
# File 'lib/rex/parser/retina_xml.rb', line 20

def reset_audit_state
  @audit = { 'refs' => [] }
end

#reset_stateObject



14
15
16
17
18
# File 'lib/rex/parser/retina_xml.rb', line 14

def reset_state
  @state = :generic_state
  @host  = { 'vulns' => [] }
  reset_audit_state
end

#tag_end(name) ⇒ Object



68
69
70
71
72
73
74
75
76
77
# File 'lib/rex/parser/retina_xml.rb', line 68

def tag_end(name)
  case name
  when "host"
    on_found_host.call(@host) if on_found_host
    reset_state
  when "audit"
    @host['vulns'].push @audit
    reset_audit_state
  end
end

#tag_start(name, attributes) ⇒ Object



24
25
26
# File 'lib/rex/parser/retina_xml.rb', line 24

def tag_start(name, attributes)
  @state = "in_#{name.downcase}".intern
end

#text(str) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/rex/parser/retina_xml.rb', line 28

def text(str)
  return if str.to_s.strip.empty?

  case @state
  when :in_ip
    @host["address"] = str
  when :in_dnsname
    @host["hostname"] = str.split(/\s+/).first
  when :in_netbiosname
    @host["netbios"] = str
  when :in_mac
    @host["mac"] = str.split(/\s+/).first
  when :in_os
    @host["os"] = str
  when :in_rthid
    @audit['refs'].push(['RETINA', str])
  when :in_cve
    str.split(",").each do |cve|
      cve = cve.to_s.strip
      next if cve.empty?
      pre,val = cve.split('-', 2)
      next if not val
      next if pre != "CVE"
      @audit['refs'].push( ['CVE', val] )
    end
  when :in_name
    @audit['name'] = str
  when :in_description
    @audit['description'] = str
  when :in_risk
    @audit['risk'] = str
  when :in_cce
    @audit['cce'] = str
  when :in_date
    @audit['data'] = str
  when :in_context
    @audit['proto'], @audit['port'] = str.split(/\s+/).first.split(':')
  end
end

#xmldecl(version, encoding, standalone) ⇒ Object

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



80
# File 'lib/rex/parser/retina_xml.rb', line 80

def xmldecl(version, encoding, standalone); end