Skip to content

Instantly share code, notes, and snippets.

@diogomonica
Last active August 29, 2015 14:04
Show Gist options
  • Save diogomonica/4c6d63666261c47ac810 to your computer and use it in GitHub Desktop.
Save diogomonica/4c6d63666261c47ac810 to your computer and use it in GitHub Desktop.
Get description of the all the CVE's for vulnerabilities that affect RHEL, given an importance level and a year
require 'nokogiri'
require 'open-uri'
def get_cve_description_text(cve_id)
cve_search = Nokogiri.HTML(open("http://www.cve.mitre.org/cgi-bin/cvename.cgi?name=#{cve_id}"))
description = cve_search.xpath('//*[@id="GeneratedTable"]')
description_text = description.text
begin
description_text = description[0].children[1].children[3].text
rescue => e
puts "Exception: #{e}"
end
description_text.chomp()
end
def get_cve_dates(importance, year)
vulnerabilities = []
reg_exp = /^(?<cve>CVE-(?<year>\d{4})-\d{4}) impact=(?<impact>[a-z]*)/
open("https://www.redhat.com/security/data/metrics/cve_dates.txt").readlines().each do |line|
if line
parts = line.match(reg_exp)
vulnerabilities << parts["cve"] if (parts && parts["year"] == year && parts["impact"] == importance)
end
end
return vulnerabilities
end
def print_usage()
puts "# Usage: #{$0} impact year"
puts "# Example: #{$0} critical 2014"
end
IMPACTS = %w{critical important moderate low}
unless ARGV[0] && ARGV[1] && IMPACTS.include?(ARGV[0])
print_usage()
exit(0)
end
get_cve_dates(ARGV[0], ARGV[1]).each do |cve|
puts "#{cve}"
puts get_cve_description_text(cve)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment