ruby-nessus 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,8 @@
1
1
  require 'ruby-nessus/host'
2
2
  require 'ruby-nessus/event'
3
+
3
4
  require 'nokogiri'
5
+ require 'enumerator'
4
6
  require 'time'
5
7
 
6
8
  module Nessus
@@ -8,6 +10,8 @@ module Nessus
8
10
  attr_reader :file
9
11
 
10
12
  class XML
13
+
14
+ include Enumerable
11
15
 
12
16
  # Creates a new .Nessus (XML) object to be parser
13
17
  # @param [String] file The Nessus xml results file to parse.
@@ -31,24 +35,20 @@ module Nessus
31
35
  # The Nessus Report Title
32
36
  # @example
33
37
  # scan.report_name #=> "My Super Cool Nessus Report"
34
- def report_name
38
+ def title
35
39
  @report_name ||= @xml.xpath("//NessusClientData//Report//ReportName").inner_text.split(' - ').last
36
40
  end
37
- alias name report_name
38
- alias title report_name
39
41
 
40
42
  # Return the nessus report time.
41
43
  # @return [String]
42
44
  # The Nessus Report Time
43
45
  # @example
44
46
  # scan.report_time #=> "09/11/08 02:21:22 AM"
45
- def report_time
47
+ def time
46
48
  #09/11/08 02:21:22 AM
47
49
  datetime = @xml.xpath("//NessusClientData//Report//ReportName").inner_text.split(' - ').first
48
50
  @report_time ||= DateTime.strptime(datetime, fmt='%y/%m/%d %I:%M:%S %p')
49
51
  end
50
- alias time report_time
51
- alias date report_time
52
52
 
53
53
  # Return the scan start time.
54
54
  # @return [DateTime]
@@ -83,14 +83,14 @@ module Nessus
83
83
  # Return the nessus scan policy name. When creating a nessus policy this is usually the title field.
84
84
  # @return [String]
85
85
  # The Nessus Scan Policy Name
86
- def policy_name
86
+ def policy_title
87
87
  @policy_name ||= @xml.xpath("//NessusClientData//Report//policyName").inner_text
88
88
  end
89
89
 
90
90
  # Return the nessus scan policy comments. This is the description field when creating a new policy with the Nessus GUI client.
91
91
  # @return [String]
92
92
  # The Nessus Scan Policy Comments
93
- def policy_comments
93
+ def policy_notes
94
94
  @policy_comments ||= @xml.xpath("//NessusClientData//Report//policyComments").inner_text
95
95
  end
96
96
 
@@ -149,6 +149,13 @@ module Nessus
149
149
  hosts
150
150
  end
151
151
 
152
+ # Parses the hosts of the scan.
153
+ # @return [Array<String>]
154
+ # The Hosts of the scan.
155
+ def all_hosts
156
+ Enumerator.new(self,:hosts).to_a
157
+ end
158
+
152
159
  # Return the nessus scan host count.
153
160
  # @return [Integer]
154
161
  # The Nessus Scan Host Count
@@ -259,33 +266,33 @@ module Nessus
259
266
 
260
267
  private
261
268
 
262
- # Calculates an event hash of totals for severity counts.
263
- # @return [hash]
264
- # The Event Totals For Severity
265
- def count_severity
266
- unless @count
267
- @count = {}
268
- @open_ports = 0
269
- @low = 0
270
- @medium = 0
271
- @high = 0
272
-
273
- @xml.xpath("//ReportHost").each do |s|
274
- @open_ports += s.at('num_ports').inner_text.to_i
275
- @low += s.at('num_lo').inner_text.to_i
276
- @medium += s.at('num_med').inner_text.to_i
277
- @high += s.at('num_hi').inner_text.to_i
269
+ # Calculates an event hash of totals for severity counts.
270
+ # @return [hash]
271
+ # The Event Totals For Severity
272
+ def count_severity
273
+ unless @count
274
+ @count = {}
275
+ @open_ports = 0
276
+ @low = 0
277
+ @medium = 0
278
+ @high = 0
279
+
280
+ @xml.xpath("//ReportHost").each do |s|
281
+ @open_ports += s.at('num_ports').inner_text.to_i
282
+ @low += s.at('num_lo').inner_text.to_i
283
+ @medium += s.at('num_med').inner_text.to_i
284
+ @high += s.at('num_hi').inner_text.to_i
285
+ end
286
+
287
+ @count = { :open_ports => @open_ports,
288
+ :low => @low,
289
+ :medium => @medium,
290
+ :high => @high,
291
+ :all => (@low + @medium + @high) }
278
292
  end
279
293
 
280
- @count = { :open_ports => @open_ports,
281
- :low => @low,
282
- :medium => @medium,
283
- :high => @high,
284
- :all => (@low + @medium + @high) }
294
+ return @count
285
295
  end
286
296
 
287
- return @count
288
- end
289
-
290
297
  end
291
298
  end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+ require 'helpers/xml'
3
+
4
+ describe "Event" do
5
+
6
+ before(:all) do
7
+ @xml = Nessus::XML.new(Helpers::DOT_NESSUS)
8
+ @host = @xml.all_hosts.first
9
+ @bad_event = @host.all_events.first
10
+ @good_event = @host.all_events.last
11
+ end
12
+
13
+ it "should parse the event name" do
14
+ @good_event.name.should == "Backported Security Patch Detection (WWW)"
15
+ end
16
+
17
+ it "should parse the event port" do
18
+ @good_event.port.to_s.should == "http (80/tcp)"
19
+ end
20
+
21
+ it "should parse the event port number" do
22
+ @good_event.port.number.should == "80"
23
+ end
24
+
25
+ it "should parse the event port service" do
26
+ @good_event.port.service.should == "http"
27
+ end
28
+
29
+ it "should parse the event port protocol" do
30
+ @good_event.port.protocol.should == "tcp"
31
+ end
32
+
33
+ it "should return true if the event port protocol is tcp" do
34
+ @good_event.port.tcp?.should == true
35
+ end
36
+
37
+ it "should return false if the event port protocol is not udp" do
38
+ @good_event.port.udp?.should == false
39
+ end
40
+
41
+ it "should parse the event severity" do
42
+ @good_event.severity.should == 1
43
+ end
44
+
45
+ it "should return the event severity in words" do
46
+ @good_event.severity.in_words.should == "Low Severity"
47
+ end
48
+
49
+ it "should return the event plugin output" do
50
+ @good_event.data.should_not be_nil
51
+ end
52
+
53
+ # Bad Event
54
+
55
+ it "should return false if the event name is nil" do
56
+ @bad_event.name.should == false
57
+ end
58
+
59
+ end