Class: Kekkan::Parsers::Cve2Document
- Inherits:
-
Nokogiri::XML::SAX::Document
- Object
- Nokogiri::XML::SAX::Document
- Kekkan::Parsers::Cve2Document
- Defined in:
- lib/kekkan/parsers/cve_2_sax_listener.rb
Instance Method Summary collapse
-
#characters(text) ⇒ Object
Called when the inner text of a element is reached.
-
#end_element(element) ⇒ Object
Called when the end of the XML element is reached.
-
#initialize ⇒ Cve2Document
constructor
Sets up a array of all valid XML fields.
-
#start_element(element, attributes = []) ⇒ Object
Callback for when the start of a XML element is reached.
Constructor Details
#initialize ⇒ Cve2Document
Sets up a array of all valid XML fields
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/kekkan/parsers/cve_2_sax_listener.rb', line 28 def initialize @vals = Hash.new @valid_elements = Array[ "nvd", "vuln:cve-id", "vuln:published-datetime", "vuln:last-modified-datetime", "cvss:score", "cvss:access-vector", "cvss:access-complexity", "cvss:authentication", "cvss:confidentiality-impact", "cvss:integrity-impact", "cvss:availability-impact", "cvss:source", "cvss:generated-on-datetime", "cvss:base_metrics", "vuln:cvss", "vuln:summary", "vuln:reference", " vuln:source", "vuln:references", "vuln:source", "entry", "vuln:vulnerable-software-list", "vuln:product", "vuln:cwe", "vuln:security-protection", "vuln:assessment_check", "vuln:definition", "vuln:scanner" ] @ignored_elements = Array[ "cpe-lang:logical-test", "vuln:vulnerable-configuration", "cpe-lang:fact-ref" ] @valid_elements = @valid_elements + @ignored_elements end |
Instance Method Details
#characters(text) ⇒ Object
Called when the inner text of a element is reached
112 113 114 115 116 117 118 |
# File 'lib/kekkan/parsers/cve_2_sax_listener.rb', line 112 def characters(text) if @vals[@tag] == nil then @vals[@tag] = text.strip else @vals[@tag] << text.strip end end |
#end_element(element) ⇒ Object
Called when the end of the XML element is reached
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/kekkan/parsers/cve_2_sax_listener.rb', line 123 def end_element(element) #puts "End element: #{element}" @tag = nil case element when "vuln:cve-id" @entry.attributes = { :cve => @vals["vuln:cve-id"] } @entry.save when "vuln:published-datetime" @entry.attributes = { :published_datetime => @vals["vuln:published-datetime"] } @entry.save when "vuln:last-modified-datetime" @entry.attributes = { :last_modified_datetime => @vals["vuln:last-modified-datetime"] } @entry.save when "vuln:summary" @entry.attributes = { :summary => @vals["vuln:summary"] } @entry.save when "vuln:security-protection" @entry.attributes = { :security_protection => @vals["vuln:security-protection"]} @entry.save when "vuln:product" @product = @entry.vulnerable_software_lists.create @product.attributes = { :product => @vals["vuln:product"] } @product.save when "vuln:cvss" @cvss.attributes = { :score => @vals["cvss:score"], :access_vector => @vals["cvss:access-vector"], :access_complexity => @vals["cvss:access-complexity"], :authenication => @vals["cvss:authentication"], :confidentiality_impact => @vals["cvss:confidentiality-impact"], :integrity_impact => @vals["cvss:integrity-impact"], :availability_impact => @vals["cvss:availability-impact"], :source => @vals["cvss:source"], :generated_on_datetime => @vals["cvss:generated-on-datetime"] } @cvss.save when "vuln:references" @reference.attributes = { :source => @vals["vuln:source"], :reference => @vals["vuln:reference"] } @reference.save end end |
#start_element(element, attributes = []) ⇒ Object
Callback for when the start of a XML element is reached
54 55 56 57 58 59 60 61 62 63 64 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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/kekkan/parsers/cve_2_sax_listener.rb', line 54 def start_element(element, attributes = []) @tag = element @vals[@tag] = "" if !@valid_elements.include?(element) puts "New XML element detected: #{element}. Please report this to #{Kekkan::EMAIL}" end case element when "entry" @entry = Kekkan::Models::Entry.create @entry.save when "vuln:cvss" @cvss = @entry.cvsses.create @cvss.save when "vuln:cwe" @entry.attributes = { :cwe => Hash[attributes]["id"] } @entry.save when "vuln:references" @reference = @entry.references.create @reference.attributes = { :ref_type => Hash[attributes]["reference_type"] } @reference.save when "vuln:reference" @reference.attributes = { :href => Hash[attributes]["href"], :language => Hash[attributes]["xml:lang"] } @reference.save when "vuln:assessment_check " @ass = @entry.assessment_check.create @ass.attributes = { :name => Hash[attributes]["name"], :href => Hash[attributes]["href"], :system => Hash[attributes]["system"] } @entry.save when "vuln:definition" @scanner = @entry.scanners.create @scanner.attributes = { :name => Hash[attributes]["name"], :href => Hash[attributes]["href"], :system => Hash[attributes]["system"] } @scanner.save end end |