Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# The MIT License (MIT)
# Copyright (c) 2016 SAKATA Sinji
# Require install nokogiri.
# `gem install nokogiri`
require 'nokogiri'
TARGETS = ["nvdcve-2.0-2014.xml", "nvdcve-2.0-2015.xml", "nvdcve-2.0-2016.xml"]
amount = {}
TARGETS.each do |target|
doc = File.open(target) { |f| Nokogiri::XML(f) }
entries = doc.xpath('//xmlns:entry')
entries.each do |entry|
unless entry.xpath('vuln:cvss/cvss:base_metrics/cvss:score').text.to_f >= 7.0
next
end
products = entry.xpath("vuln:vulnerable-software-list/vuln:product")
products = products.map do |node|
elems = node.text.split(':')
"#{elems[2]}:#{elems[3]}"
end.uniq
products.each do |product|
amount[product] = (amount[product] || 0) + 1
end
end
end
amount = amount.sort {|(k1, v1), (k2, v2)| v2 <=> v1}
amount.each do |key, count|
puts "#{key}: #{count}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment