Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

Commit

Permalink
Merge pull request #480 from mozilla/add_yaml_output_support
Browse files Browse the repository at this point in the history
Add YAML output support to ssh_scan binary
  • Loading branch information
Jonathan Claudius authored Jan 17, 2019
2 parents 2ac9d06 + dcafe28 commit 2ea246b
Showing 1 changed file with 13 additions and 28 deletions.
41 changes: 13 additions & 28 deletions bin/ssh_scan
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require 'netaddr'
require 'optparse'
require 'ssh_scan'
require 'logger'
require 'yaml'

#Default options
options = {
Expand All @@ -18,7 +19,8 @@ options = {
"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
Expand Down Expand Up @@ -107,6 +109,11 @@ scan") 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 = []
Expand Down Expand Up @@ -225,39 +232,17 @@ unless File.exist?(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|
Expand Down

0 comments on commit 2ea246b

Please sign in to comment.