bin/ssh_scan in ssh_scan-0.0.38.pre vs bin/ssh_scan in ssh_scan-0.0.38

- old
+ new

@@ -6,21 +6,23 @@ require 'json' require 'netaddr' require 'optparse' require 'ssh_scan' require 'logger' +require 'yaml' #Default options options = { "sockets" => [], "policy" => File.join(File.dirname(__FILE__),"../config/policies/mozilla_modern.yml"), "unit_test" => false, "timeout" => 5, "threads" => 5, "verbosity" => nil, "logger" => Logger.new(STDERR), - "fingerprint_database" => ENV['HOME']+'/.ssh_scan_fingerprints.yml' + "fingerprint_database" => ENV['HOME']+'/.ssh_scan_fingerprints.yml', + "output_type" => "json" } # Reorder arguments before parsing def reorder_args!(order, opt_parser) old_args = opt_parser.default_argv @@ -105,10 +107,15 @@ opts.on("-o", "--output [FilePath]", "File to write JSON output to") do |file| $stdout.reopen(file, "w") end + opts.on("--output-type [json, yaml]", + "Format to write stdout to json or yaml") do |output_type| + options["output_type"] = output_type + end + opts.on("-p", "--port [PORT]", Array, "Port (Default: 22)") do |ports| temp = [] options["sockets"].each do |socket| ports.each do |port| @@ -223,42 +230,20 @@ puts opt_parser.help puts "\nReason: policy file supplied is not a file #{options["policy"]}" exit 1 end -# Check to see if we're running the latest released version -#if !options["suppress_update_status"] -# update = SSHScan::Update.new -# if update.newer_gem_available? -# options["logger"].warn( -# "You're NOT using the latest version of ssh_scan, try 'gem update \ -#ssh_scan' to get the latest" -# ) -# else -# if update.errors.any? -# update.errors.each do |error| -# options["logger"].error(error) -# end -# else -# options["logger"].info( -# "You're using the latest version of ssh_scan #{SSHScan::VERSION}" -# ) -# end -# end -#end - -# Limit scope of fingerprints DB to (per scan) -# if options["fingerprint_database"] && File.exists?(options["fingerprint_database"]) -# File.unlink(options["fingerprint_database"]) -# end - options["policy_file"] = SSHScan::Policy.from_file(options["policy"]) # Perform scan and get results scan_engine = SSHScan::ScanEngine.new() results = scan_engine.scan(options) -puts JSON.pretty_generate(results) +if options["output_type"] == "yaml" + puts YAML.dump(results) +elsif options["output_type"] == "json" + puts JSON.pretty_generate(results) +end if options["unit_test"] == true results.each do |result| if result["compliance"] && result["compliance"]["compliant"] == false exit 1 #non-zero means a false