From 449a730d865ea8184359b89c9e92cd0a7e6b94e7 Mon Sep 17 00:00:00 2001 From: bpmcdevitt Date: Tue, 20 Sep 2022 13:17:44 -0500 Subject: [PATCH] commited some broken code but i will refactor it --- .../bin/get_exploited_vulns_msft_bulletin.rb | 47 +++++++++++++++++-- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/tools/microsoft/bin/get_exploited_vulns_msft_bulletin.rb b/tools/microsoft/bin/get_exploited_vulns_msft_bulletin.rb index 3c66dd0..1ec7ba0 100755 --- a/tools/microsoft/bin/get_exploited_vulns_msft_bulletin.rb +++ b/tools/microsoft/bin/get_exploited_vulns_msft_bulletin.rb @@ -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