Class: Rex::Parser::NessusXMLStreamParser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ NessusXMLStreamParser

Returns a new instance of NessusXMLStreamParser


13
14
15
16
# File 'lib/rex/parser/nessus_xml.rb', line 13

def initialize(&block)
  reset_state
  on_found_host = block if block
end

Instance Attribute Details

#on_found_hostObject

Returns the value of attribute on_found_host


11
12
13
# File 'lib/rex/parser/nessus_xml.rb', line 11

def on_found_host
  @on_found_host
end

Instance Method Details

#attlistObject


116
# File 'lib/rex/parser/nessus_xml.rb', line 116

def attlist; end

#cdataObject


113
# File 'lib/rex/parser/nessus_xml.rb', line 113

def cdata; end

#comment(str) ⇒ Object


114
# File 'lib/rex/parser/nessus_xml.rb', line 114

def comment(str); end

#instruction(name, instruction) ⇒ Object


115
# File 'lib/rex/parser/nessus_xml.rb', line 115

def instruction(name, instruction); end

#reset_stateObject


18
19
20
21
22
23
24
# File 'lib/rex/parser/nessus_xml.rb', line 18

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) ⇒ Object


96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/rex/parser/nessus_xml.rb', line 96

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) ⇒ Object


26
27
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
67
68
69
70
# File 'lib/rex/parser/nessus_xml.rb', line 26

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) ⇒ Object


72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/rex/parser/nessus_xml.rb', line 72

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) ⇒ Object

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


112
# File 'lib/rex/parser/nessus_xml.rb', line 112

def xmldecl(version, encoding, standalone); end