2022-09-20 09:55:47 -05:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
|
|
|
require '../microsoft_cvrf_client.rb'
|
|
|
|
require 'optparse'
|
|
|
|
require 'json'
|
|
|
|
|
2022-09-20 13:17:44 -05:00
|
|
|
def export_to_json(bulletin_vulns, filepath)
|
|
|
|
File.write(filepath, bulletin_vulns)
|
|
|
|
end
|
|
|
|
|
|
|
|
def do_export(bulletin_vulns, bulletin_id)
|
|
|
|
filename = "./data/exploited_cves_for_msft_#{bulletin_id}.json"
|
|
|
|
export_to_json(bulletin_vulns, filename)
|
|
|
|
puts "----" * 12
|
|
|
|
puts "Succesfully Exported to #{filename}:"
|
|
|
|
puts "----" * 12
|
|
|
|
puts pretty_vulns
|
|
|
|
puts "----" * 12
|
|
|
|
end
|
|
|
|
|
2022-09-20 09:55:47 -05:00
|
|
|
@options = {}
|
|
|
|
|
|
|
|
OptionParser.new do |opts|
|
|
|
|
opts.on("-id", "--id", "Bulletin ID") do |id|
|
|
|
|
@options[:id] = id
|
|
|
|
end
|
2022-09-20 13:17:44 -05:00
|
|
|
opts.on("-e", "--export", FalseClass, "Export bulletin info to json doc") do |export|
|
|
|
|
@options[:export] = export
|
|
|
|
end
|
|
|
|
opts.on("-a", "--export-all", FalseClass, "Export bulletin info for all bulletin_ids into json docs.") do |export_all|
|
|
|
|
@options[:export_all] = export_all
|
|
|
|
end
|
2022-09-20 09:55:47 -05:00
|
|
|
end.parse!
|
|
|
|
|
2022-09-20 13:17:44 -05:00
|
|
|
# set vars from our cmdline args
|
2022-09-20 09:55:47 -05:00
|
|
|
bulletin_id = @options[:id]
|
2022-09-20 13:17:44 -05:00
|
|
|
export_on = @options[:export]
|
|
|
|
export_all = @options[:export_all]
|
2022-09-20 09:55:47 -05:00
|
|
|
|
2022-09-20 13:17:44 -05:00
|
|
|
api_client = MicrosoftCvrfClient.new
|
2022-09-20 09:55:47 -05:00
|
|
|
|
2022-09-20 13:17:44 -05:00
|
|
|
# this is broke as fuk: fix it with a case statement probably
|
|
|
|
if bulletin_id && export_on.nil? && export_all.nil?
|
|
|
|
exploited_vulns_for_bulletin = api_client.exploited_vulns_only(bulletin_id)
|
|
|
|
pretty_vulns = JSON.pretty_generate(exploited_vulns_for_bulletin)
|
|
|
|
puts "----" * 12
|
|
|
|
puts pretty_vulns
|
|
|
|
puts "----" * 12
|
|
|
|
elsif bulletin_id && export_on
|
|
|
|
do_export(pretty_vulns, bulletin_id)
|
|
|
|
elsif bulletin_id.nil? && export_all
|
|
|
|
puts "Exporting All Bulletin Data:"
|
|
|
|
api_client.ids.each do |bulletin_id|
|
|
|
|
puts "----" * 12
|
|
|
|
puts "Now exporting #{bulletin_id}"
|
|
|
|
puts "----" * 12
|
|
|
|
vulns = api_client.exploited_vulns_only(bulletin_id)
|
|
|
|
pretty_vulns = JSON.pretty_generate(vulns)
|
|
|
|
do_export(pretty_vulns, bulletin_id)
|
|
|
|
end
|
|
|
|
end
|