Class: Coreimpact::Vulnerability

Inherits:
Object
  • Object
show all
Defined in:
lib/coreimpact/vulnerability.rb

Instance Method Summary collapse

Constructor Details

#initialize(xml_vulnerability) ⇒ Vulnerability

Returns a new instance of Vulnerability.



3
4
5
# File 'lib/coreimpact/vulnerability.rb', line 3

def initialize(xml_vulnerability)
  @xml = xml_vulnerability
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object

Example XML: <property type=“container” key=“Vulnerabilities”>

<property type="container" key="CVE-1999-0516">
  <property type="container" key="Modules">
    <property type="container" key="<Title>">
      <property type="string" key="description">
        Some description.
      </property>
    </property>
  </property>
</property>

</property>



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/coreimpact/vulnerability.rb', line 29

def method_missing(method, *args)
  # We could remove this check and return nil for any non-recognized tag.
  # The problem would be that it would make tricky to debug problems with
  # typos. For instance: <>.potr would return nil instead of raising an
  # exception
  unless supported_tags.include?(method)
    super
    return
  end

  result =
    case method
    when :cve
      @xml.first_element_child['key']
    when :title
      @xml.at_xpath('./property/property[@key="Modules"]/property[@type="container"]')['key']
    else
      @xml.at_xpath("./property/property[@key='Modules']/property[@type='container']/property[@key='#{method}']").text
    end

  result || 'n/a'
end

Instance Method Details

#respond_to?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
# File 'lib/coreimpact/vulnerability.rb', line 11

def respond_to?(method, include_private = false)
  return true if supported_tags.include?(method.to_sym)

  super
end

#supported_tagsObject



7
8
9
# File 'lib/coreimpact/vulnerability.rb', line 7

def supported_tags
  [:agent_deployed, :cve, :description, :port, :tried_to_install_agent, :title]
end