commited some broken code but i will refactor it

This commit is contained in:
Brendan McDevitt 2022-09-20 13:17:44 -05:00
parent 70840cb272
commit 449a730d86

View file

@ -4,17 +4,58 @@ require '../microsoft_cvrf_client.rb'
require 'optparse'
require 'json'
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
@options = {}
OptionParser.new do |opts|
opts.on("-id", "--id", "Bulletin ID") do |id|
@options[:id] = id
end
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
end.parse!
# set vars from our cmdline args
bulletin_id = @options[:id]
export_on = @options[:export]
export_all = @options[:export_all]
api_client = MicrosoftCvrfClient.new
#bulletin_response = api_client.get_id(bulletin_id)
puts JSON.pretty_generate(api_client.exploited_vulns_only(bulletin_id))
# 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