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

Commit 2ea246b

Browse files
author
Jonathan Claudius
authored
Merge pull request #480 from mozilla/add_yaml_output_support
Add YAML output support to ssh_scan binary
2 parents 2ac9d06 + dcafe28 commit 2ea246b

File tree

1 file changed

+13
-28
lines changed

1 file changed

+13
-28
lines changed

bin/ssh_scan

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ require 'netaddr'
88
require 'optparse'
99
require 'ssh_scan'
1010
require 'logger'
11+
require 'yaml'
1112

1213
#Default options
1314
options = {
@@ -18,7 +19,8 @@ options = {
1819
"threads" => 5,
1920
"verbosity" => nil,
2021
"logger" => Logger.new(STDERR),
21-
"fingerprint_database" => ENV['HOME']+'/.ssh_scan_fingerprints.yml'
22+
"fingerprint_database" => ENV['HOME']+'/.ssh_scan_fingerprints.yml',
23+
"output_type" => "json"
2224
}
2325

2426
# Reorder arguments before parsing
@@ -107,6 +109,11 @@ scan") do |file|
107109
$stdout.reopen(file, "w")
108110
end
109111

112+
opts.on("--output-type [json, yaml]",
113+
"Format to write stdout to json or yaml") do |output_type|
114+
options["output_type"] = output_type
115+
end
116+
110117
opts.on("-p", "--port [PORT]", Array,
111118
"Port (Default: 22)") do |ports|
112119
temp = []
@@ -225,39 +232,17 @@ unless File.exist?(options["policy"])
225232
exit 1
226233
end
227234

228-
# Check to see if we're running the latest released version
229-
#if !options["suppress_update_status"]
230-
# update = SSHScan::Update.new
231-
# if update.newer_gem_available?
232-
# options["logger"].warn(
233-
# "You're NOT using the latest version of ssh_scan, try 'gem update \
234-
#ssh_scan' to get the latest"
235-
# )
236-
# else
237-
# if update.errors.any?
238-
# update.errors.each do |error|
239-
# options["logger"].error(error)
240-
# end
241-
# else
242-
# options["logger"].info(
243-
# "You're using the latest version of ssh_scan #{SSHScan::VERSION}"
244-
# )
245-
# end
246-
# end
247-
#end
248-
249-
# Limit scope of fingerprints DB to (per scan)
250-
# if options["fingerprint_database"] && File.exists?(options["fingerprint_database"])
251-
# File.unlink(options["fingerprint_database"])
252-
# end
253-
254235
options["policy_file"] = SSHScan::Policy.from_file(options["policy"])
255236

256237
# Perform scan and get results
257238
scan_engine = SSHScan::ScanEngine.new()
258239
results = scan_engine.scan(options)
259240

260-
puts JSON.pretty_generate(results)
241+
if options["output_type"] == "yaml"
242+
puts YAML.dump(results)
243+
elsif options["output_type"] == "json"
244+
puts JSON.pretty_generate(results)
245+
end
261246

262247
if options["unit_test"] == true
263248
results.each do |result|

0 commit comments

Comments
 (0)