Class: RubyNessus::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-nessus/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



12
13
14
15
16
# File 'lib/ruby-nessus/cli.rb', line 12

def initialize
  @file = nil
  @nessus_version = nil
  @args = []
end

Class Method Details

.runObject



18
19
20
# File 'lib/ruby-nessus/cli.rb', line 18

def self.run
  new.run(*ARGV)
end

Instance Method Details

#optparse(*args) ⇒ Object (protected)



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/ruby-nessus/cli.rb', line 84

def optparse(*args)
  opts = OptionParser.new
  opts.program_name = 'recess'
  opts.banner = "Recess #{RubyNessus::VERSION}"
  opts.separator 'usage: recess FILE [OPTIONS]'

  opts.on('-f', '--file FILE', 'The .nessus file to parse.') do |file|
    @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', 'Recess Version.') do |_version|
    Log.it RubyNessus::VERSION
    Log.it
    exit(-1)
  end

  begin
    @args = opts.parse!(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

#run(*args) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/ruby-nessus/cli.rb', line 22

def run(*args)
  optparse(*args)

  Log.it 'Recess - Ruby-Nessus CLI'
  Log.it "Version: #{RubyNessus::VERSION}"
  Log.it

  RubyNessus::Parse.new(@file.to_s) 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

    Log.informational 'Informational Severity Count', scan.informational_severity_count unless scan.version == 1

    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

      unless scan.version == 1
        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
      end
      Log.it
    end

    Log.end
  end
end