Skip to content
Browse files

added cli app - fixed hostname nil error - support for ruby 1.9

  • Loading branch information...
1 parent ce68b71 commit 3434c70b84b8fc19e00a56a44ccba92bfe90e6c2 @mephux committed
View
1 Rakefile
@@ -14,6 +14,7 @@ begin
gem.homepage = "http://github.com/mephux/ruby-nessus"
gem.authors = ["Dustin Willis Webber"]
gem.add_dependency "nokogiri", ">= 1.4.0"
+ gem.add_dependency "rainbow", ">= 1.0.4"
gem.add_development_dependency "rspec", ">= 1.2.9"
gem.add_development_dependency "yard", ">=0.2.3.5"
end
View
2 examples/example.rb
@@ -6,7 +6,7 @@
# Ruby-Nessus Example
-Nessus::Parse.new('example_v2.nessus', :version => 2) do |scan|
+Nessus::Parse.new('example_v1.nessus') do |scan|
scan.each_host do |host|
puts host.ip
View
11 lib/ruby-nessus/Version1/version1.rb
@@ -28,12 +28,15 @@ class XML
# scan.report_name
# end
#
- def initialize(file)
- @file = File.open(file)
- @xml = Nokogiri::XML.parse(@file.read)
+ def initialize(xml)
+ @xml = xml
raise "Error: Not A Version 1.0 .Nessus file." unless @xml.at('NessusClientData')
end
+ def version
+ 1
+ end
+
#
# Return the nessus report title.
#
@@ -297,7 +300,7 @@ def low_severity_count
def total_event_count
count_severity[:all].to_i
end
-
+
#
# Return the Total severity count.
#
View
12 lib/ruby-nessus/Version2/version2.rb
@@ -27,12 +27,16 @@ class XML
# scan.report_name
# end
#
- def initialize(file)
- @file = File.open(file)
- @xml = Nokogiri::XML.parse(@file.read)
+ def initialize(xml)
+ @xml = xml
raise "Error: Not A Version 2.0 .Nessus file." unless @xml.at('NessusClientData_v2')
end
-
+
+
+ def version
+ 2
+ end
+
#
# Return the nessus report title.
#
View
70 lib/ruby-nessus/cli.rb
@@ -6,7 +6,7 @@
require 'pp'
module Nessus
-
+
class CLI
def initialize
@@ -22,6 +22,62 @@ def CLI.run
def run(*args)
optparse(*args)
+ Log.it "Recess - Ruby-Nessus CLI"
+ Log.it "Version: #{Nessus::VERSION}"
+ Log.it
+
+ Nessus::Parse.new("#{@file}") do |scan|
+
+ Log.h1 "SCAN Metadata"
+ Log.it
+ Log.h2 "Scan Title", scan.title
+ Log.h2 "Policy Title", scan.policy_title
+ Log.it
+ Log.h1 "SCAN Statistics"
+ Log.it
+ Log.h2 "Host Count", scan.host_count
+ Log.h2 "Open Port Count", scan.open_ports_count
+
+ unless scan.version == 1
+ Log.h2 "TCP Count", scan.tcp_count
+ Log.h2 "UDP Count", scan.udp_count
+ Log.h2 "ICMP Count", scan.icmp_count
+ end
+
+ Log.it
+ Log.h1 "EVENT Statistics"
+ Log.it
+
+ unless scan.version == 1
+ Log.informational "Informational Severity Count", scan.informational_severity_count
+ end
+ Log.low "Low Severity Count", scan.low_severity_count
+ Log.medium "Medium Severity Count", scan.medium_severity_count
+ Log.high "High Severity Count", scan.high_severity_count
+ Log.h3 "Total Event Count", scan.total_event_count
+ Log.break
+ Log.it! "Low Event Percentage: #{scan.event_percentage_for('low', true)}"
+ Log.it! "Medium Event Percentage: #{scan.event_percentage_for('medium', true)}"
+ Log.it! "High Event Percentage: #{scan.event_percentage_for('high', true)}"
+ Log.it
+
+ Log.h1 "HOSTS"
+ Log.it
+
+ scan.each_host do |host|
+ Log.h2 "Hostname", host.hostname
+ Log.h5 "IP Address:", host.ip
+ Log.h5 "Informational Count", host.informational_severity_count
+ Log.h5 "Low Count", host.low_severity_count
+ Log.h5 "Medium Count", host.medium_severity_count
+ Log.h5 "High Count", host.high_severity_count
+ Log.it
+ end
+
+ Log.end
+
+ end
+
end
protected
@@ -36,13 +92,19 @@ def optparse(*args)
@file = file
end
+ opts.on('-f','--file FILE','The .nessus file to parse.') do |file|
+ @file = file
+ end
+
opts.on('-h','--help','This help summary page.') do |help|
Log.it opts
+ Log.it
exit -1
end
-
- opts.on('-v','--version','Version number') do |version|
+
+ opts.on('-v','--version','Recess Version.') do |version|
Log.it Nessus::VERSION
+ Log.it
exit -1
end
@@ -51,11 +113,13 @@ def optparse(*args)
@file ||= @args[0]
if @file.nil?
Log.it opts
+ Log.it
exit -1
end
rescue => e
Log.error e.message
Log.it opts
+ Log.it
exit -1
end
end
View
73 lib/ruby-nessus/log.rb
@@ -1,23 +1,82 @@
+require 'rainbow'
module Nessus
class Log
- def self.it(msg)
+ #
+ # Formatting
+ #
+ def self.it(msg=nil)
STDERR.puts "#{msg}"
end
- def self.error(msg)
- STDERR.puts "ERROR: #{msg}"
+ def self.it!(msg=nil)
+ STDERR.puts "\t#{msg}"
end
- def self.warn(msg)
- STDERR.puts "WARNING: #{msg}"
+ def self.break
+ STDERR.puts "\t"
+ STDERR.puts ""
end
- def self.info(msg)
- STDERR.puts "ERROR: #{msg}"
+ def self.end
+ STDERR.puts "\n\n"
+ end
+
+ #
+ # Headers
+ #
+ def self.h1(title, msg=nil)
+ STDERR.puts "-> #{title}: ".foreground(:green).bright + "#{msg}"
+ end
+
+ def self.h2(title, msg=nil)
+ STDERR.puts "\t#{title}: ".foreground(:blue).bright + "#{msg}"
+ end
+
+ def self.h3(title, msg=nil)
+ STDERR.puts "\t#{title}: " + "#{msg}".foreground(:blue).underline
+ end
+
+ def self.h4(msg=nil)
+ STDERR.puts "\t\t- #{msg}"
+ end
+
+ def self.h5(title, msg=nil)
+ STDERR.puts "\t\t- #{title}: #{msg}"
+ end
+
+ #
+ # Errors
+ #
+ def self.error(msg=nil)
+ STDERR.puts "ERROR: ".foreground(:red).bright + "#{msg}"
+ end
+
+ def self.warn(msg=nil)
+ STDERR.puts "WARNING: ".foreground(:yellow).bright + "#{msg}"
+ end
+
+ def self.info(msg=nil)
+ STDERR.puts "INFO: ".foreground(:green).bright + "#{msg}"
end
+ #
+ # Event Severities
+ #
+ def self.informational(title, msg=nil)
+ STDERR.puts "\t#{title}: ".foreground(:magenta).bright + "#{msg}"
+ end
+ def self.low(title, msg=nil)
+ STDERR.puts "\t#{title}: ".foreground(:green) + "#{msg}"
+ end
+ def self.medium(title, msg=nil)
+ STDERR.puts "\t#{title}: ".foreground(:yellow).bright + "#{msg}"
+ end
+ def self.high(title, msg=nil)
+ STDERR.puts "\t#{title}: ".foreground(:red).bright + "#{msg}"
+ end
+
end
end
View
31 lib/ruby-nessus/parse.rb
@@ -1,3 +1,4 @@
+require 'ruby-nessus/log'
require 'ruby-nessus/Version1/version1'
require 'ruby-nessus/Version2/version2'
@@ -10,18 +11,28 @@ module Nessus
class Parse
- def initialize(file, attributes={}, &block)
- @file = file
- @version = attributes[:version] || 2
-
- case @version
-
- when 1
- block.call(Version1::XML.new(file)) if block
- when 2
- block.call(Version2::XML.new(file)) if block
+ def initialize(file, options={}, &block)
+ @file = File.open(file)
+ @version = options[:version]
+ @xml = Nokogiri::XML.parse(@file.read)
+
+ if @version
+ case @version
+ when 1
+ block.call(Version1::XML.new(@xml)) if block
+ when 2
+ block.call(Version2::XML.new(@xml)) if block
+ else
+ raise "Error: Supported .Nessus Version are 1 and 2."
+ end
+ else
+ if @xml.at('NessusClientData')
+ block.call(Version1::XML.new(@xml)) if block
+ elsif @xml.at('NessusClientData_v2')
+ block.call(Version2::XML.new(@xml)) if block
else
raise "Error: Supported .Nessus Version are 1 and 2."
+ end
end
end

0 comments on commit 3434c70

Please sign in to comment.
Something went wrong with that request. Please try again.