prenus 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -10,19 +10,15 @@ This is a quickly hacked together Ruby script that can consume version 2 nessus
10
10
 
11
11
  == Installation
12
12
 
13
- * Clone our copy of the ruby-nessus gem and install it
14
- git clone git://github.com/AsteriskLabs/ruby-nessus.git
15
- cd ruby-nessus
16
- rake install
17
- * Install the Prenus gem
18
- gem install prenus
13
+ * Install the Prenus gem:
14
+ * # gem install prenus
19
15
 
20
16
  == Usage
21
17
 
22
18
  * Download the .nessus files from Nessus you want to Prettify (make sure they're version 2 files, not version 1)
23
19
  * Cd into the folder where the files are
24
- * Run Prenus
25
- prenus -t html -o tmp *.nessus
20
+ * Run Prenus:
21
+ * # prenus -t html -o tmp *.nessus
26
22
  * Happy Happy Joy Joy
27
23
 
28
24
  == Command Line Options
@@ -100,6 +96,7 @@ This will only work if you're in the Circos Tools tableviewer folder (in my inst
100
96
  This will dump the png into the img/ folder.
101
97
 
102
98
  == Changes
99
+ * Version 0.0.4 - Shifted my copy of ruby-nessus into my lib/gemcache folder
103
100
  * Version 0.0.3 - Botched the gem push - like a chump - this should be identical to 0.0.2
104
101
  * Version 0.0.2 - Updated input - handles duplicate hosts a bit nicer (but not much nicer)
105
102
  * Version 0.0.1 - initial release .. buggy to the max
data/bin/prenus CHANGED
@@ -8,7 +8,7 @@ end
8
8
  $root_dir = File.expand_path(File.join(File.dirname(__FILE__),'..'))
9
9
 
10
10
  #require some goodies
11
- require 'ruby-nessus'
11
+ #require 'ruby-nessus'
12
12
 
13
13
  require 'fileutils'
14
14
  require 'optparse'
@@ -16,6 +16,7 @@ require 'yaml'
16
16
 
17
17
  require 'lib/output'
18
18
  require 'lib/input'
19
+ require 'lib/gemcache/ruby-nessus/ruby-nessus'
19
20
 
20
21
  #Versioning and .. those things
21
22
  $verstring = "Version 0.0.3 - 20th of August, 2012 - Created by Christian \"xntrik\" Frichot.\n\n"
@@ -0,0 +1,3 @@
1
+ # Ruby-Nessus Files
2
+ require 'lib/gemcache/ruby-nessus/ruby-nessus/nessus'
3
+ require 'lib/gemcache/ruby-nessus/ruby-nessus/version'
@@ -0,0 +1,90 @@
1
+ require 'lib/gemcache/ruby-nessus/ruby-nessus/Version1/port'
2
+
3
+ module Nessus
4
+ module Version1
5
+
6
+ class Event
7
+
8
+ # Return the total event count for a given host.
9
+ # @return [Integer]
10
+ # Return the total event count for a given host.
11
+ # @example
12
+ # host.event_count #=> 3456
13
+ def initialize(event)
14
+ @event = event
15
+ end
16
+
17
+ # Return the event port.
18
+ # @return [Object]
19
+ # Return the event port object or port string.
20
+ # @example
21
+ # event.port #=> "https (443/tcp)"
22
+ # event.port.number #=> 443
23
+ # event.port.service #=> "https"
24
+ # event.port.protocol #=> "tcp"
25
+ def port
26
+ @port ||= Port.parse(@event.at('port').inner_text)
27
+ end
28
+
29
+ # Return the event severity.
30
+ # @return [String]
31
+ # Return the event severity.
32
+ # @example
33
+ # event.severity #=> 3
34
+ # event.severity.in_words #=> "High Severity"
35
+ # @see String#in_words
36
+ def severity
37
+ @severity ||= @event.at('severity').inner_text.to_i
38
+ end
39
+
40
+ # Return the event object nessus plugin id
41
+ # @return [String]
42
+ # Return the event object nessus plugin id
43
+ # @example
44
+ # event.plugin_id #=> 3245
45
+ def plugin_id
46
+ @plugin_id ||= @event.at('pluginID').inner_text.to_i
47
+ end
48
+
49
+ # Return the event name (plugin_name)
50
+ # @return [String]
51
+ # Return the event name (plugin_name)
52
+ # @example
53
+ # event.plugin_name #=> "PHP < 5.2.4 Multiple Vulnerabilities"
54
+ # event.name #=> "PHP < 5.2.4 Multiple Vulnerabilities"
55
+ def plugin_name
56
+ s = @event.at('pluginName').inner_text
57
+
58
+ @plugin_name ||= unless s.empty?
59
+ @event.at('pluginName').inner_text || "N/A"
60
+ else
61
+ false
62
+ end
63
+
64
+ return @plugin_name
65
+ end
66
+ alias name plugin_name
67
+
68
+ # Return the event plugin output data
69
+ # @return [String]
70
+ # Return the event plugin output data
71
+ # @example
72
+ # event.output #=> "..."
73
+ # event.data #=> "..."
74
+ def data
75
+ d = "#{@event.at('data')}" || ""
76
+
77
+ @data ||= unless d.empty?
78
+ @event.at('data').inner_text || "N/A"
79
+ else
80
+ false
81
+ end
82
+ return @data
83
+ end
84
+ alias output data
85
+
86
+ end
87
+
88
+ end
89
+
90
+ end
@@ -0,0 +1,273 @@
1
+ module Nessus
2
+ module Version1
3
+
4
+ class Host
5
+ include Enumerable
6
+
7
+ # Creates A New Host Object
8
+ # @param [Object] Host Object
9
+ # @example
10
+ # Host.new(object)
11
+ def initialize(host)
12
+ @host = host
13
+ end
14
+
15
+ def to_s
16
+ "#{ip}"
17
+ end
18
+
19
+ # Return the Host Object hostname.
20
+ # @return [String]
21
+ # The Host Object Hostname
22
+ # @example
23
+ # host.hostname #=> "127.0.0.1"
24
+ def hostname
25
+ @hostname ||= @host.at('HostName').inner_text
26
+ end
27
+ alias ip hostname
28
+
29
+ # Return the host scan start time.
30
+ # @return [DateTime]
31
+ # The Host Scan Start Time
32
+ # @example
33
+ # scan.scan_start_time #=> 'Fri Nov 11 23:36:54 1985'
34
+ def scan_start_time
35
+ if @host.at('startTime').inner_text.blank?
36
+ return false
37
+ else
38
+ @host_scan_time = DateTime.strptime(@host.at('startTime').inner_text, fmt='%a %b %d %H:%M:%S %Y')
39
+ end
40
+ end
41
+
42
+ # Return the host scan stop time.
43
+ # @return [DateTime]
44
+ # The Host Scan Stop Time
45
+ # @example
46
+ # scan.scan_start_time #=> 'Fri Nov 11 23:36:54 1985'
47
+ def scan_stop_time
48
+ if @host.at('stopTime').inner_text.blank?
49
+ return false
50
+ else
51
+ @host_scan_time = DateTime.strptime(@host.at('stopTime').inner_text, fmt='%a %b %d %H:%M:%S %Y')
52
+ end
53
+ end
54
+
55
+ # Return the host run time.
56
+ # @return [String]
57
+ # The Host Scan Run Time
58
+ # @example
59
+ # scan.scan_run_time #=> '2 hours 5 minutes and 16 seconds'
60
+ def scan_runtime
61
+ get_runtime
62
+ end
63
+ alias runtime scan_runtime
64
+
65
+ # Return the Host Netbios Name.
66
+ # @return [String]
67
+ # The Host Netbios Name
68
+ # @example
69
+ # host.netbios_name #=> "SOMENAME4243"
70
+ def netbios_name
71
+ @netbios_name ||= @host.at('netbios_name').inner_text
72
+ end
73
+
74
+ # Return the Host Mac Address.
75
+ # @return [String]
76
+ # Return the Host Mac Address
77
+ # @example
78
+ # host.mac_addr #=> "00:11:22:33:44:55"
79
+ def mac_addr
80
+ @mac_addr ||= @host.at('mac_addr').inner_text
81
+ end
82
+ alias mac_address mac_addr
83
+
84
+ # Return the Host DNS Name.
85
+ # @return [String]
86
+ # Return the Host DNS Name
87
+ # @example
88
+ # host.dns_name #=> "snorby.org"
89
+ def dns_name
90
+ @dns_name ||= @host.at('dns_name').inner_text
91
+ end
92
+
93
+ # Return the Host OS Name.
94
+ # @return [String]
95
+ # Return the Host OS Name
96
+ # @example
97
+ # host.dns_name #=> "Microsoft Windows 2000, Microsoft Windows Server 2003"
98
+ def os_name
99
+ @os_name ||= @host.at('os_name').inner_text
100
+ end
101
+ alias operating_system os_name
102
+
103
+ # Return the open ports for a given host object.
104
+ # @return [Integer]
105
+ # Return the open ports for a given host object.
106
+ # @example
107
+ # host.open_ports #=> 213
108
+ def open_ports
109
+ @scanned_ports ||= @host.at('num_ports').inner_text.to_i
110
+ end
111
+
112
+ # Returns All Informational Event Objects For A Given Host.
113
+ # @yield [prog] If a block is given, it will be passed the newly
114
+ # created Event object.
115
+ # @yieldparam [EVENT] prog The newly created Event object.
116
+ # @return [Integer]
117
+ # Return The Informational Event Count For A Given Host.
118
+ # @example
119
+ # host.informational_events do |info|
120
+ # puts info.port
121
+ # puts info.data if info.data
122
+ # end
123
+ def informational_events(&block)
124
+ unless @informational_events
125
+ @informational_events = []
126
+ @informational_event_count = 0
127
+
128
+ @host.xpath("ReportItem").each do |event|
129
+ next if event.at('severity').inner_text.to_i != 0
130
+ @informational_events << Event.new(event)
131
+ @informational_event_count += 1
132
+ end
133
+
134
+ end
135
+
136
+ @informational_events.each(&block)
137
+ return @informational_event_count
138
+ end
139
+
140
+ # Returns All Low Event Objects For A Given Host.
141
+ # @yield [prog] If a block is given, it will be passed the newly
142
+ # created Event object.
143
+ # @yieldparam [EVENT] prog The newly created Event object.
144
+ # @return [Integer]
145
+ # Return The Low Event Count For A Given Host.
146
+ # @example
147
+ # host.low_severity_events do |low|
148
+ # puts low.name if low.name
149
+ # end
150
+ def low_severity_events(&block)
151
+
152
+ @low_severity_count = @host.at('num_lo').inner_text.to_i
153
+
154
+ unless @low_severity_events
155
+ @low_severity_events = []
156
+
157
+ @host.xpath("ReportItem").each do |event|
158
+ next if event.at('severity').inner_text.to_i != 1
159
+ @low_severity_events << Event.new(event)
160
+ end
161
+
162
+ end
163
+
164
+ @low_severity_events.each(&block)
165
+ return @low_severity_count
166
+ end
167
+
168
+ # Returns All Medium Event Objects For A Given Host.
169
+ # @yield [prog] If a block is given, it will be passed the newly
170
+ # created Event object.
171
+ # @yieldparam [EVENT] prog The newly created Event object.
172
+ # @return [Integer]
173
+ # Return The Medium Event Count For A Given Host.
174
+ # @example
175
+ # host.medium_severity_events do |medium|
176
+ # puts medium.name if medium.name
177
+ # end
178
+ def medium_severity_events(&block)
179
+
180
+ @high_severity_count = @host.at('num_med').inner_text.to_i
181
+
182
+ unless @medium_severity_events
183
+ @medium_severity_events = []
184
+
185
+ @host.xpath("ReportItem").each do |event|
186
+ next if event.at('severity').inner_text.to_i != 2
187
+ @medium_severity_events << Event.new(event)
188
+ end
189
+
190
+ end
191
+
192
+ @medium_severity_events.each(&block)
193
+ return @high_severity_count
194
+ end
195
+
196
+ # Returns All High Event Objects For A Given Host.
197
+ # @yield [prog] If a block is given, it will be passed the newly
198
+ # created Event object.
199
+ # @yieldparam [EVENT] prog The newly created Event object.
200
+ # @return [Integer]
201
+ # Return The High Event Count For A Given Host.
202
+ # @example
203
+ # host.high_severity_events do |high|
204
+ # puts high.name if high.name
205
+ # end
206
+ def high_severity_events(&block)
207
+
208
+ @high_severity_count = @host.at('num_hi').inner_text.to_i
209
+
210
+ unless @high_severity_events
211
+ @high_severity_events = []
212
+
213
+ @host.xpath("ReportItem").each do |event|
214
+ next if event.at('severity').inner_text.to_i != 3
215
+ @high_severity_events << Event.new(event)
216
+ end
217
+
218
+ end
219
+
220
+ @high_severity_events.each(&block)
221
+ return @high_severity_count
222
+ end
223
+
224
+ # Return the total event count for a given host.
225
+ # @return [Integer]
226
+ # Return the total event count for a given host.
227
+ # @example
228
+ # host.event_count #=> 3456
229
+ def event_count
230
+ ((low_severity_events.to_i) + (medium_severity_events.to_i) + (high_severity_events.to_i)).to_i
231
+ end
232
+
233
+ # Creates a new Event object to be parser
234
+ # @yield [prog] If a block is given, it will be passed the newly
235
+ # created Event object.
236
+ # @yieldparam [EVENT] prog The newly created Event object.
237
+ # @example
238
+ # host.events do |event|
239
+ # puts event.name if event.name
240
+ # puts event.port
241
+ # end
242
+ def each_event(&block)
243
+ @host.xpath("ReportItem").each do |event|
244
+ block.call(Event.new(event)) if block
245
+ end
246
+ end
247
+
248
+ # Parses the events of the host.
249
+ # @return [Array<String>]
250
+ # The events of the host.
251
+ def events
252
+ Enumerator.new(self,:each_event).to_a
253
+ end
254
+
255
+
256
+ private
257
+
258
+ def get_runtime
259
+ if scan_start_time && scan_stop_time
260
+ h = ("#{Time.parse(scan_stop_time.to_s).strftime('%H').to_i - Time.parse(scan_start_time.to_s).strftime('%H').to_i}").gsub('-', '')
261
+ m = ("#{Time.parse(scan_stop_time.to_s).strftime('%M').to_i - Time.parse(scan_start_time.to_s).strftime('%M').to_i}").gsub('-', '')
262
+ s = ("#{Time.parse(scan_stop_time.to_s).strftime('%S').to_i - Time.parse(scan_start_time.to_s).strftime('%S').to_i}").gsub('-', '')
263
+ return "#{h} hours #{m} minutes and #{s} seconds"
264
+ else
265
+ false
266
+ end
267
+ end
268
+
269
+ end
270
+
271
+ end
272
+
273
+ end
@@ -0,0 +1,91 @@
1
+ module Nessus
2
+ module Version1
3
+
4
+ class Port
5
+
6
+ # Port Service
7
+ attr_reader :service
8
+ # Port number
9
+ attr_reader :number
10
+ # Port Protocol
11
+ attr_reader :protocol
12
+ # Raw output string from nessus
13
+ attr_reader :raw_string
14
+
15
+ # Creates A New Port Object
16
+ # @param [String] service The Port Service.
17
+ # @param [Integer] number The Port number.
18
+ # @param [String] protocol The Port protocol.
19
+ # @param [String] raw output string from nessus.
20
+ # @example
21
+ # Port.new("ssh",22,"tcp", str)
22
+ def initialize(service,number,protocol,raw_string)
23
+ @service = service
24
+ @number = number
25
+ @protocol = protocol
26
+ @raw_string = raw_string
27
+ end
28
+
29
+ # Parse A passed port string and return a Port Object.
30
+ # @return [Object]
31
+ # New Port Object
32
+ # @example
33
+ # Port.parse(port)
34
+ def Port.parse(str)
35
+ begin
36
+ @full_port = str
37
+ components = str.match(/^([^\(]+)\((\d+)\/([^\)]+)\)/)
38
+
39
+ if components
40
+ return Port.new(components[1].strip, components[2].strip, components[3].strip, str)
41
+ else
42
+ return Port.new(false, false, false, str)
43
+ end
44
+
45
+ end
46
+
47
+ end
48
+
49
+ # Return true iF port protocol Ii tcp.
50
+ # @return [Boolean]
51
+ # Return True If The Port Protocol Is TCP.
52
+ def tcp?
53
+ @protocol == 'tcp'
54
+ end
55
+
56
+ # Return true iF port protocol Ii udp.
57
+ # @return [Boolean]
58
+ # Return True If The Port Protocol Is UDP.
59
+ def udp?
60
+ @protocol == 'udp'
61
+ end
62
+
63
+ # Return the port as a string.
64
+ # @return [String]
65
+ # Return The Port As A String
66
+ # @example
67
+ # port.to_s #=> https (443/tcp)
68
+ def to_s
69
+ if @service && @number && @protocol
70
+ "#{@service} (#{@number}/#{@protocol})"
71
+ else
72
+ "#{@raw_string}"
73
+ end
74
+ end
75
+
76
+ # Return false if the port object number is nil
77
+ # @return [Boolean]
78
+ # Return false if the port object number is nil
79
+ def number
80
+ if @number
81
+ return @number
82
+ else
83
+ false
84
+ end
85
+ end
86
+
87
+ end
88
+
89
+ end
90
+
91
+ end