ruby-nessus 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +13 -14
- data/examples/example.rb +34 -33
- data/gemspec.yml +1 -1
- data/lib/nessus/Version2/event.rb +1 -1
- data/lib/nessus/Version2/host.rb +52 -5
- data/lib/nessus/parse.rb +3 -3
- data/lib/nessus/version.rb +1 -1
- data/spec/helpers/xml.rb +9 -5
- data/spec/ruby-nessus/parse_spec.rb +22 -0
- metadata +4 -3
data/README.md
CHANGED
@@ -10,20 +10,19 @@ More Information:
|
|
10
10
|
|
11
11
|
## Install
|
12
12
|
|
13
|
-
sudo gem install ruby-nessus
|
13
|
+
```sudo gem install ruby-nessus```
|
14
14
|
|
15
15
|
## Usage & Examples
|
16
16
|
|
17
|
-
The below example illustrates how easy it really is to iterate
|
18
|
-
|
17
|
+
The below example illustrates how easy it really is to iterate over result data.
|
18
|
+
```ruby
|
19
19
|
require 'rubygems'
|
20
|
-
require '
|
20
|
+
require 'nessus'
|
21
21
|
|
22
22
|
Nessus::Parse.new("example_v1.nessus", :version => 1) do |scan|
|
23
23
|
# OR: Nessus::Parse.new("example_v2.nessus") do |scan| <-- Ruby-Nessus will figured out the correct Nessus file version.
|
24
24
|
|
25
25
|
puts scan.title # The Nessus Report Title.
|
26
|
-
puts scan.runtime # The Scan Runtime. #=> 2 hours 23 minutes 12 seconds
|
27
26
|
puts scan.host_count # Host Count.
|
28
27
|
puts scan.unique_ports # All Unique Ports Seen.
|
29
28
|
|
@@ -42,10 +41,10 @@ The below example illustrates how easy it really is to iterate of result data.
|
|
42
41
|
end
|
43
42
|
end
|
44
43
|
end
|
45
|
-
|
44
|
+
```
|
46
45
|
|
47
46
|
You also have the ability to search for particular hostnames. In the near future I plan to add the ability to pass the hosts block a hash of options for more complex searches.
|
48
|
-
|
47
|
+
```ruby
|
49
48
|
scan.find_by_hostname("127.0.0.1") do |host|
|
50
49
|
|
51
50
|
puts host.scan_start_time
|
@@ -59,9 +58,9 @@ You also have the ability to search for particular hostnames. In the near future
|
|
59
58
|
end
|
60
59
|
|
61
60
|
end
|
62
|
-
|
61
|
+
```
|
63
62
|
There are a bunch of convenient methods (maybe more then needed) added to make reporting a bit easier to produce quickly from a raw scan file. If you do not pass :version as an option it will default to the 2.0 .nessus schema.
|
64
|
-
|
63
|
+
```ruby
|
65
64
|
Nessus::Parse.new("example_v2.nessus") do |scan|
|
66
65
|
|
67
66
|
puts scan.event_percentage_for('low', true) #=> 8%
|
@@ -95,17 +94,17 @@ There are a bunch of convenient methods (maybe more then needed) added to make r
|
|
95
94
|
end
|
96
95
|
|
97
96
|
end
|
98
|
-
|
97
|
+
```
|
99
98
|
Ruby-Nessus also ships with a POC CLI application for the lib called 'recess':
|
100
|
-
|
99
|
+
```
|
101
100
|
Recess 0.1.1
|
102
101
|
usage: recess FILE [OPTIONS]
|
103
102
|
-f, --file FILE The .nessus file to parse.
|
104
103
|
-h, --help This help summary page.
|
105
104
|
-v, --version Recess Version.
|
106
|
-
|
105
|
+
```
|
107
106
|
Below is example output generated by recess:
|
108
|
-
|
107
|
+
```
|
109
108
|
$> recess examples/example_v2.nessus
|
110
109
|
Recess - Ruby-Nessus CLI
|
111
110
|
Version: 0.1.1
|
@@ -151,7 +150,7 @@ Below is example output generated by recess:
|
|
151
150
|
- Low Count: 13
|
152
151
|
- Medium Count: 2
|
153
152
|
- High Count: 0
|
154
|
-
|
153
|
+
```
|
155
154
|
## Requirements
|
156
155
|
* Ruby 1.8 or 1.9
|
157
156
|
* Nokogiri http://github.com/tenderlove/nokogiri
|
data/examples/example.rb
CHANGED
@@ -1,44 +1,45 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
1
2
|
$LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__),'..','lib'))
|
2
3
|
|
3
|
-
#!/usr/bin/env ruby
|
4
4
|
require 'rubygems'
|
5
5
|
require 'nessus'
|
6
6
|
|
7
7
|
# Ruby-Nessus Example
|
8
|
+
#
|
9
|
+
# This proc is called by scan.each_host in each variation of Nessus::Parse
|
10
|
+
def print_info(host)
|
11
|
+
puts host.ip
|
12
|
+
puts host.hostname
|
13
|
+
puts host.os_name
|
14
|
+
puts host.runtime
|
8
15
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
puts
|
15
|
-
puts
|
16
|
-
|
17
|
-
#puts host.mac_addr
|
18
|
-
# puts host.event_percentage_for('icmp', true)
|
19
|
-
# puts host.ports.inspect
|
20
|
-
#
|
21
|
-
# puts "\n"
|
22
|
-
#
|
23
|
-
host.each_event do |event|
|
24
|
-
|
25
|
-
puts "=> #{event.name}" if event.name
|
26
|
-
# puts event.synopsis if event.synopsis
|
27
|
-
# puts "\n"
|
28
|
-
# puts event.output
|
29
|
-
# puts "\n"
|
30
|
-
# puts event.patch_publication_date.pretty if event.patch_publication_data
|
31
|
-
# puts event.see_also unless event.see_also.empty?
|
32
|
-
# puts event.synopsis if event.synopsis
|
33
|
-
# puts event.solution if event.solution
|
34
|
-
|
35
|
-
end
|
36
|
-
#
|
16
|
+
# puts host.mac_addr
|
17
|
+
# puts host.event_percentage_for('icmp', true)
|
18
|
+
# puts host.ports.inspect
|
19
|
+
|
20
|
+
host.each_event do |event|
|
21
|
+
puts "=> #{event.name}" if event.name
|
22
|
+
# puts event.synopsis if event.synopsis
|
37
23
|
# puts "\n"
|
24
|
+
# puts event.output
|
38
25
|
# puts "\n"
|
39
|
-
|
40
|
-
|
26
|
+
# puts event.patch_publication_date.pretty if event.patch_publication_data
|
27
|
+
# puts event.see_also unless event.see_also.empty?
|
28
|
+
# puts event.synopsis if event.synopsis
|
29
|
+
# puts event.solution if event.solution
|
41
30
|
end
|
42
|
-
|
43
|
-
|
31
|
+
end
|
32
|
+
|
33
|
+
# From a file:
|
34
|
+
puts '+ Using a Nessus XML file:'
|
35
|
+
Nessus::Parse.new('example_v1.nessus') do |scan|
|
36
|
+
scan.each_host(&method(:print_info))
|
37
|
+
end
|
38
|
+
|
39
|
+
puts
|
40
|
+
|
41
|
+
# From a string:
|
42
|
+
puts '+ Using an XML string:'
|
43
|
+
Nessus::Parse.new(nil, { :xml => File.read('example_v1.nessus') }) do |scan|
|
44
|
+
scan.each_host(&method(:print_info))
|
44
45
|
end
|
data/gemspec.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
name: ruby-nessus
|
2
2
|
summary: Ruby-Nessus is a ruby interface for the popular Nessus vulnerability scanner.
|
3
|
-
version: 1.
|
3
|
+
version: 1.2.0
|
4
4
|
description:
|
5
5
|
Ruby-Nessus aims to deliver an easy yet powerful interface for interacting and
|
6
6
|
manipulating Nessus scan results and configurations.
|
data/lib/nessus/Version2/host.rb
CHANGED
@@ -289,6 +289,37 @@ module Nessus
|
|
289
289
|
@high_severity_events.each(&block)
|
290
290
|
end
|
291
291
|
|
292
|
+
#
|
293
|
+
# Returns All Critical Event Objects For A Given Host.
|
294
|
+
#
|
295
|
+
# @yield [prog] If a block is given, it will be passed the newly
|
296
|
+
# created Event object.
|
297
|
+
#
|
298
|
+
# @yieldparam [EVENT] prog The newly created Event object.
|
299
|
+
#
|
300
|
+
# @return [Integer]
|
301
|
+
# Return The Critical Event Count For A Given Host.
|
302
|
+
#
|
303
|
+
# @example
|
304
|
+
# host.critical_severity_events do |critical|
|
305
|
+
# puts critical.name if critical.name
|
306
|
+
# end
|
307
|
+
#
|
308
|
+
def critical_severity_events(&block)
|
309
|
+
|
310
|
+
unless @critical_severity_events
|
311
|
+
@critical_severity_events = []
|
312
|
+
|
313
|
+
@host.xpath("ReportItem").each do |event|
|
314
|
+
next if event['severity'].to_i != 4
|
315
|
+
@critical_severity_events << Event.new(event)
|
316
|
+
end
|
317
|
+
|
318
|
+
end
|
319
|
+
|
320
|
+
@critical_severity_events.each(&block)
|
321
|
+
end
|
322
|
+
|
292
323
|
#
|
293
324
|
# Return the total event count for a given host.
|
294
325
|
#
|
@@ -299,7 +330,7 @@ module Nessus
|
|
299
330
|
# host.event_count #=> 3456
|
300
331
|
#
|
301
332
|
def event_count
|
302
|
-
((low_severity_events.count) + (medium_severity_events.count) + (high_severity_events.count)).to_i
|
333
|
+
((low_severity_events.count) + (medium_severity_events.count) + (high_severity_events.count) + (critical_severity_events.count)).to_i
|
303
334
|
end
|
304
335
|
|
305
336
|
#
|
@@ -332,10 +363,10 @@ module Nessus
|
|
332
363
|
end
|
333
364
|
|
334
365
|
#
|
335
|
-
# Return
|
366
|
+
# Return an Array of open ports.
|
336
367
|
#
|
337
368
|
# @return [Array]
|
338
|
-
# The
|
369
|
+
# The open ports
|
339
370
|
#
|
340
371
|
# @example
|
341
372
|
# scan.ports #=> ['22', '80', '443']
|
@@ -404,6 +435,19 @@ module Nessus
|
|
404
435
|
host_stats[:informational].to_i
|
405
436
|
end
|
406
437
|
|
438
|
+
#
|
439
|
+
# Return the Critical severity count.
|
440
|
+
#
|
441
|
+
# @return [Integer]
|
442
|
+
# The Critical Severity Count
|
443
|
+
#
|
444
|
+
# @example
|
445
|
+
# scan.critical_severity_count #=> 10
|
446
|
+
#
|
447
|
+
def critical_severity_count
|
448
|
+
host_stats[:critical].to_i
|
449
|
+
end
|
450
|
+
|
407
451
|
#
|
408
452
|
# Return the High severity count.
|
409
453
|
#
|
@@ -506,7 +550,7 @@ module Nessus
|
|
506
550
|
|
507
551
|
unless @host_stats
|
508
552
|
@host_stats = {}
|
509
|
-
@open_ports, @tcp, @udp, @icmp, @informational, @low, @medium, @high = 0,0,0,0,0,0,0,0
|
553
|
+
@open_ports, @tcp, @udp, @icmp, @informational, @low, @medium, @high, @critical = 0,0,0,0,0,0,0,0,0
|
510
554
|
|
511
555
|
@host.xpath("ReportItem").each do |s|
|
512
556
|
case s['severity'].to_i
|
@@ -518,6 +562,8 @@ module Nessus
|
|
518
562
|
@medium += 1
|
519
563
|
when 3
|
520
564
|
@high += 1
|
565
|
+
when 4
|
566
|
+
@critical += 1
|
521
567
|
end
|
522
568
|
|
523
569
|
unless s['severity'].to_i == 0
|
@@ -537,7 +583,8 @@ module Nessus
|
|
537
583
|
:low => @low,
|
538
584
|
:medium => @medium,
|
539
585
|
:high => @high,
|
540
|
-
:
|
586
|
+
:critical => @critical,
|
587
|
+
:all => (@low + @medium + @high + @critical)}
|
541
588
|
|
542
589
|
end
|
543
590
|
@host_stats
|
data/lib/nessus/parse.rb
CHANGED
@@ -11,10 +11,10 @@ module Nessus
|
|
11
11
|
|
12
12
|
class Parse
|
13
13
|
|
14
|
-
def initialize(file, options={}, &block)
|
15
|
-
|
14
|
+
def initialize(file = nil, options = {}, &block)
|
15
|
+
doc = file ? File.read(file) : options[:xml]
|
16
|
+
@xml = Nokogiri::XML.parse(doc)
|
16
17
|
@version = options[:version]
|
17
|
-
@xml = Nokogiri::XML.parse(@file.read)
|
18
18
|
|
19
19
|
if @version
|
20
20
|
case @version
|
data/lib/nessus/version.rb
CHANGED
data/spec/helpers/xml.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
module Helpers
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
DOT_NESSUS_V1_PATH = File.join(File.dirname(__FILE__),'example_v1.nessus')
|
3
|
+
DOT_NESSUS_V2_PATH = File.join(File.dirname(__FILE__),'example_v2.nessus')
|
4
|
+
|
5
|
+
DOT_NESSUS_V1_DOC = File.read(DOT_NESSUS_V1_PATH)
|
6
|
+
DOT_NESSUS_V2_DOC = File.read(DOT_NESSUS_V2_PATH)
|
7
|
+
|
8
|
+
DOT_NESSUS_V1 = Nokogiri::XML.parse(DOT_NESSUS_V1_DOC)
|
9
|
+
DOT_NESSUS_V2 = Nokogiri::XML.parse(DOT_NESSUS_V2_DOC)
|
10
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
require_relative '../helpers/xml'
|
3
|
+
|
4
|
+
describe 'Nessus::Parse' do
|
5
|
+
it 'should parse a valid v1 .nessus file' do
|
6
|
+
lambda { Nessus::Parse.new(Helpers::DOT_NESSUS_V1_PATH) }.should_not raise_error
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should parse a valid v2 .nessus file' do
|
10
|
+
lambda { Nessus::Parse.new(Helpers::DOT_NESSUS_V2_PATH) }.should_not raise_error
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should parse a valid v1 .nessus string' do
|
14
|
+
options = { :xml => Helpers::DOT_NESSUS_V1_DOC }
|
15
|
+
lambda { Nessus::Parse.new(nil, options) }.should_not raise_error
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should parse a valid v2 .nessus string' do
|
19
|
+
options = { :xml => Helpers::DOT_NESSUS_V2_DOC }
|
20
|
+
lambda { Nessus::Parse.new(nil, options) }.should_not raise_error
|
21
|
+
end
|
22
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-nessus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-10-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
@@ -138,6 +138,7 @@ files:
|
|
138
138
|
- spec/helpers/example_v1.nessus
|
139
139
|
- spec/helpers/example_v2.nessus
|
140
140
|
- spec/helpers/xml.rb
|
141
|
+
- spec/ruby-nessus/parse_spec.rb
|
141
142
|
- spec/ruby-nessus_spec.rb
|
142
143
|
- spec/spec_helper.rb
|
143
144
|
homepage: http://github.com/mephux/ruby-nessus
|
@@ -161,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
161
162
|
version: '0'
|
162
163
|
requirements: []
|
163
164
|
rubyforge_project:
|
164
|
-
rubygems_version: 1.8.
|
165
|
+
rubygems_version: 1.8.23
|
165
166
|
signing_key:
|
166
167
|
specification_version: 3
|
167
168
|
summary: Ruby-Nessus is a ruby interface for the popular Nessus vulnerability scanner.
|