Class: RubyNessus::Version1::XML
- Inherits:
-
Object
- Object
- RubyNessus::Version1::XML
- Includes:
- Enumerable
- Defined in:
- lib/ruby-nessus/version1/scan.rb
Instance Method Summary collapse
-
#each_host {|prog| ... } ⇒ Object
Creates a new Host object to be parser.
-
#event_percentage_for(type, round_percentage = false) ⇒ Integer
Return the Total severity count.
-
#find_by_hostname(hostname) {|prog| ... } ⇒ Object
Creates a new Host object to be parser from a passed search param.
-
#high_severity_count ⇒ Integer
Return the High severity count.
-
#host_count ⇒ Integer
Return the nessus scan host count.
-
#hosts ⇒ Array<String>
Parses the hosts of the scan.
-
#initialize(xml) {|prog| ... } ⇒ XML
constructor
Creates a new .Nessus (XML) object to be parser.
-
#low_severity_count ⇒ Integer
Return the Low severity count.
-
#medium_severity_count ⇒ Integer
Return the Medium severity count.
-
#open_ports_count ⇒ Integer
Return the informational severity count.
-
#plugin_ids ⇒ Array
Returns and array of the plugin ids userd for the passed .nessus scan.
-
#plugins ⇒ Array
Returns and array of the plugin names userd for the passed .nessus scan.
-
#policy_notes ⇒ String
Return the nessus scan policy comments.
-
#policy_title ⇒ String
Return the nessus scan policy name.
-
#runtime ⇒ String
Return the scan run time.
-
#start_time ⇒ DateTime
Return the scan start time.
-
#stop_time ⇒ DateTime
Return the scan stop time.
-
#target_hosts ⇒ Array<String>
Return the hosts the were targeted for the initial scan.
-
#time ⇒ String
Return the nessus report time.
-
#title ⇒ String
Return the nessus report title.
-
#total_event_count ⇒ Integer
Return the Total severity count.
-
#unique_ports ⇒ Array
Retunrs an array of all unique ports.
- #version ⇒ Object
Constructor Details
#initialize(xml) {|prog| ... } ⇒ XML
Creates a new .Nessus (XML) object to be parser
30 31 32 33 |
# File 'lib/ruby-nessus/version1/scan.rb', line 30 def initialize(xml) @xml = xml raise 'Error: Not A Version 1.0 .Nessus file.' unless @xml.at('NessusClientData') end |
Instance Method Details
#each_host {|prog| ... } ⇒ Object
Creates a new Host object to be parser
202 203 204 205 206 207 208 209 |
# File 'lib/ruby-nessus/version1/scan.rb', line 202 def each_host(&block) hosts = [] @xml.xpath('//ReportHost').each do |host| hosts << host.at('HostName').inner_text if host.at('HostName').inner_text yield(Host.new(host)) if block end hosts end |
#event_percentage_for(type, round_percentage = false) ⇒ Integer
Return the Total severity count.
333 334 335 336 337 338 339 340 341 342 343 344 345 |
# File 'lib/ruby-nessus/version1/scan.rb', line 333 def event_percentage_for(type, round_percentage = false) @sc ||= count_severity if %w[high medium low all].include?(type) calc = ((@sc[:"#{type}"].to_f / @sc[:all].to_f) * 100) if round_percentage return calc.round.to_s else return calc.to_s end else raise "Error: #{type} is not an acceptable severity. Possible options include: all, high, medium, low and informational." end end |
#find_by_hostname(hostname) {|prog| ... } ⇒ Object
Creates a new Host object to be parser from a passed search param.
362 363 364 365 366 367 368 |
# File 'lib/ruby-nessus/version1/scan.rb', line 362 def find_by_hostname(hostname, &block) raise "Error: hostname can't be blank." if hostname.nil? || hostname.empty? @xml.xpath('//ReportHost[HostName]').each do |host| next unless host.inner_text.match(hostname) yield(Host.new(host)) if block end end |
#high_severity_count ⇒ Integer
Return the High severity count.
275 276 277 |
# File 'lib/ruby-nessus/version1/scan.rb', line 275 def high_severity_count count_severity[:high].to_i end |
#host_count ⇒ Integer
Return the nessus scan host count.
230 231 232 |
# File 'lib/ruby-nessus/version1/scan.rb', line 230 def host_count hosts.size end |
#hosts ⇒ Array<String>
Parses the hosts of the scan.
217 218 219 |
# File 'lib/ruby-nessus/version1/scan.rb', line 217 def hosts to_enum(:each_host).to_a end |
#low_severity_count ⇒ Integer
Return the Low severity count.
301 302 303 |
# File 'lib/ruby-nessus/version1/scan.rb', line 301 def low_severity_count count_severity[:low].to_i end |
#medium_severity_count ⇒ Integer
Return the Medium severity count.
288 289 290 |
# File 'lib/ruby-nessus/version1/scan.rb', line 288 def medium_severity_count count_severity[:medium].to_i end |
#open_ports_count ⇒ Integer
Return the informational severity count.
262 263 264 |
# File 'lib/ruby-nessus/version1/scan.rb', line 262 def open_ports_count count_severity[:open_ports].to_i end |
#plugin_ids ⇒ Array
Returns and array of the plugin ids userd for the passed .nessus scan.
152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/ruby-nessus/version1/scan.rb', line 152 def plugin_ids unless @plugin_ids @plugin_ids = [] @xml.xpath('//PluginSelection').last.text.split(';').each do |id| @plugin_ids << id end end @plugin_ids end |
#plugins ⇒ Array
Returns and array of the plugin names userd for the passed .nessus scan.
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/ruby-nessus/version1/scan.rb', line 173 def plugins unless @plugins # get elements with attribute: @plugins = [] @xml.xpath('//pluginName').each do |x| @plugins << x.inner_text unless x.inner_text.empty? end @plugins.uniq! @plugins.sort! end @plugins end |
#policy_notes ⇒ String
Return the nessus scan policy comments. This is the description field when creating a new policy with the Nessus GUI client.
124 125 126 |
# File 'lib/ruby-nessus/version1/scan.rb', line 124 def policy_notes @policy_comments ||= @xml.xpath('//NessusClientData//Report//policyComments').inner_text end |
#policy_title ⇒ String
Return the nessus scan policy name. When creating a nessus policy this is usually the title field.
114 115 116 |
# File 'lib/ruby-nessus/version1/scan.rb', line 114 def policy_title @policy_name ||= @xml.xpath('//NessusClientData//Report//policyName').inner_text end |
#runtime ⇒ String
Return the scan run time.
101 102 103 104 105 106 |
# File 'lib/ruby-nessus/version1/scan.rb', line 101 def runtime h = (Time.parse(stop_time.to_s).strftime('%H').to_i - Time.parse(start_time.to_s).strftime('%H').to_i).to_s.delete('-') m = (Time.parse(stop_time.to_s).strftime('%M').to_i - Time.parse(start_time.to_s).strftime('%M').to_i).to_s.delete('-') s = (Time.parse(stop_time.to_s).strftime('%S').to_i - Time.parse(start_time.to_s).strftime('%S').to_i).to_s.delete('-') "#{h} hours #{m} minutes and #{s} seconds" end |
#start_time ⇒ DateTime
Return the scan start time.
75 76 77 |
# File 'lib/ruby-nessus/version1/scan.rb', line 75 def start_time @start_time = DateTime.strptime(@xml.xpath('//NessusClientData//Report//StartTime').inner_text, '%a %b %d %H:%M:%S %Y') end |
#stop_time ⇒ DateTime
Return the scan stop time.
88 89 90 |
# File 'lib/ruby-nessus/version1/scan.rb', line 88 def stop_time @stop_time = DateTime.strptime(@xml.xpath('//NessusClientData//Report//StopTime').inner_text, '%a %b %d %H:%M:%S %Y') end |
#target_hosts ⇒ Array<String>
Return the hosts the were targeted for the initial scan. These are the hosts that were inputed when creating the scan.
135 136 137 138 139 140 141 |
# File 'lib/ruby-nessus/version1/scan.rb', line 135 def target_hosts hosts = [] @xml.xpath('//Targets/Target/value').each do |element| hosts << element.inner_text end hosts.sort.uniq! end |
#time ⇒ String
Return the nessus report time.
61 62 63 64 |
# File 'lib/ruby-nessus/version1/scan.rb', line 61 def time datetime = @xml.xpath('//NessusClientData//Report//ReportName').inner_text.split(' - ').first @report_time ||= DateTime.strptime(datetime, '%y/%m/%d %I:%M:%S %p') end |
#title ⇒ String
Return the nessus report title.
48 49 50 |
# File 'lib/ruby-nessus/version1/scan.rb', line 48 def title @report_name ||= @xml.xpath('//NessusClientData//Report//ReportName').inner_text.split(' - ').last end |
#total_event_count ⇒ Integer
Return the Total severity count. [high, medium, low, informational]
314 315 316 |
# File 'lib/ruby-nessus/version1/scan.rb', line 314 def total_event_count count_severity[:all].to_i end |
#unique_ports ⇒ Array
Retunrs an array of all unique ports.
242 243 244 245 246 247 248 249 250 251 |
# File 'lib/ruby-nessus/version1/scan.rb', line 242 def unique_ports return if @unique_ports @unique_ports = [] @xml.xpath('//ReportItem//port').each do |port| @unique_ports << port.inner_text end @unique_ports.uniq! @unique_ports.sort! end |
#version ⇒ Object
35 36 37 |
# File 'lib/ruby-nessus/version1/scan.rb', line 35 def version 1 end |