Class: Rex::Parser::IP360ASPLXMLStreamParser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ IP360ASPLXMLStreamParser

Returns a new instance of IP360ASPLXMLStreamParser


17
18
19
20
# File 'lib/rex/parser/ip360_aspl_xml.rb', line 17

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

Instance Attribute Details

#on_found_asplObject

Returns the value of attribute on_found_aspl


15
16
17
# File 'lib/rex/parser/ip360_aspl_xml.rb', line 15

def on_found_aspl
  @on_found_aspl
end

Instance Method Details

#attlistObject


99
# File 'lib/rex/parser/ip360_aspl_xml.rb', line 99

def attlist; end

#cdataObject


96
# File 'lib/rex/parser/ip360_aspl_xml.rb', line 96

def cdata; end

#comment(str) ⇒ Object


97
# File 'lib/rex/parser/ip360_aspl_xml.rb', line 97

def comment(str); end

#instruction(name, instruction) ⇒ Object


98
# File 'lib/rex/parser/ip360_aspl_xml.rb', line 98

def instruction(name, instruction); end

#reset_stateObject


22
23
24
25
26
# File 'lib/rex/parser/ip360_aspl_xml.rb', line 22

def reset_state
  @aspl = {'vulns' => {'name' => { }, 'cve' => { }, 'bid' => { } },
    'oses' => {'name' => { } } }
  @state = :generic_state
end

#tag_end(name) ⇒ Object


65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/rex/parser/ip360_aspl_xml.rb', line 65

def tag_end(name)
  case name
  when "ontology"
    on_found_aspl.call(@aspl) if on_found_aspl
    reset_state
  when "advisory"
    if (@x['pub'] =~ /CVE/)
      if (@cfirst == 0)
        @c += ","
      end
      @c += @x['refid']
      @cfirst = 0
    elsif (@x['pub'] =~ /BugTraq/)
      if (@bfirst == 0)
        @b += ","
      end
      @b += @x['refid']
      @bfirst = 0
    end
  when "advisories"
    @aspl['vulns']['cve'][@vulnid] = @c
    @aspl['vulns']['bid'][@vulnid] = @b
    @c = ""
    @b = ""
  end
  @state = :generic_state
end

#tag_start(name, attributes) ⇒ 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
# File 'lib/rex/parser/ip360_aspl_xml.rb', line 28

def tag_start(name, attributes)
  case name
  when "vulns"
    @location = "vulns"
  when "vuln"
    @vulnid = attributes['id'].strip
  when "name"
    @state = :is_name
  when "advisories"
    @c = ""
    @cfirst = 1
    @b = ""
    @bfirst = 1
    @x = Hash.new
  when "publisher"
    @state = :is_pub
  when "id"
    @state = :is_refid
  when "operatingSystems"
    @location = "os"
  when "operatingSystem"
    @osid = attributes['id'].strip
  end
end

#text(str) ⇒ Object


53
54
55
56
57
58
59
60
61
62
63
# File 'lib/rex/parser/ip360_aspl_xml.rb', line 53

def text(str)
  case @state
  when :is_name
    @aspl['vulns']['name'][@vulnid] = str if @location == "vulns"
    @aspl['oses'][@osid] = str if @location == "os"
  when :is_pub
    @x['pub'] = str
  when :is_refid
    @x['refid'] = str
  end
end

#xmldecl(version, encoding, standalone) ⇒ Object

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


95
# File 'lib/rex/parser/ip360_aspl_xml.rb', line 95

def xmldecl(version, encoding, standalone); end