Skip to content

Instantly share code, notes, and snippets.

@ysakasin
Created December 23, 2016 07:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ysakasin/e926358a197f0d05554a65f82507119b to your computer and use it in GitHub Desktop.
Save ysakasin/e926358a197f0d05554a65f82507119b to your computer and use it in GitHub Desktop.
# 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