Class: RubyNessus::Version2::XML
- Inherits:
-
Object
- Object
- RubyNessus::Version2::XML
- Includes:
- Enumerable
- Defined in:
- lib/ruby-nessus/version2/scan.rb
Instance Method Summary collapse
-
#critical_severity_count ⇒ Integer
Return the Critical severity count.
-
#each_host {|prog| ... } ⇒ Object
Creates a new Host object to be parser.
-
#event_percentage_for(type, round_percentage = nil) ⇒ 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.
-
#icmp_count ⇒ Integer
Return the ICMP Event Count.
-
#informational_severity_count ⇒ Integer
Return the informational severity count.
-
#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 Open Ports count.
-
#policy_notes ⇒ String
Return the nessus scan policy comments.
-
#policy_title ⇒ String
Return the nessus scan policy name.
-
#target_hosts ⇒ Array<String>
Return the hosts the were targeted for the initial scan.
-
#tcp_count ⇒ Integer
Return the TCP Event Count.
-
#title ⇒ String
Return the nessus report title.
-
#total_event_count(count_informational = nil) ⇒ Integer
Return the Total severity count.
-
#udp_count ⇒ Integer
Return the UDP Event 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
29 30 31 32 |
# File 'lib/ruby-nessus/version2/scan.rb', line 29 def initialize(xml) @xml = xml raise 'Error: Not A Version 2.0 .Nessus file.' unless @xml.at('NessusClientData_v2') end |
Instance Method Details
#critical_severity_count ⇒ Integer
Return the Critical severity count.
219 220 221 |
# File 'lib/ruby-nessus/version2/scan.rb', line 219 def critical_severity_count count_stats[:critical].to_i end |
#each_host {|prog| ... } ⇒ Object
Creates a new Host object to be parser
97 98 99 |
# File 'lib/ruby-nessus/version2/scan.rb', line 97 def each_host(&block) hosts.each(&block) end |
#event_percentage_for(type, round_percentage = nil) ⇒ Integer
Return the Total severity count.
296 297 298 299 300 301 302 303 304 305 306 307 308 |
# File 'lib/ruby-nessus/version2/scan.rb', line 296 def event_percentage_for(type, round_percentage = nil) @sc ||= count_stats if %w[critical high medium low tcp udp icmp 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, tdp, udp, icmp, critical, high, medium and low." end end |
#find_by_hostname(hostname) {|prog| ... } ⇒ Object
Creates a new Host object to be parser from a passed search param.
325 326 327 328 329 330 331 |
# File 'lib/ruby-nessus/version2/scan.rb', line 325 def find_by_hostname(hostname, &block) raise "Error: hostname can't be blank." if hostname.nil? || hostname.empty? @xml.xpath('//ReportHost').each do |host| next unless host['name'].match(hostname) yield(Host.new(host)) if block end end |
#high_severity_count ⇒ Integer
Return the High severity count.
232 233 234 |
# File 'lib/ruby-nessus/version2/scan.rb', line 232 def high_severity_count count_stats[:high].to_i end |
#host_count ⇒ Integer
Return the nessus scan host count.
122 123 124 |
# File 'lib/ruby-nessus/version2/scan.rb', line 122 def host_count each_host.size end |
#hosts ⇒ Array<String>
Parses the hosts of the scan.
107 108 109 110 111 |
# File 'lib/ruby-nessus/version2/scan.rb', line 107 def hosts @xml.xpath('//ReportHost').map do |host| Host.new(host) end end |
#icmp_count ⇒ Integer
Return the ICMP Event Count.
193 194 195 |
# File 'lib/ruby-nessus/version2/scan.rb', line 193 def icmp_count count_stats[:icmp].to_i end |
#informational_severity_count ⇒ Integer
Return the informational severity count.
206 207 208 |
# File 'lib/ruby-nessus/version2/scan.rb', line 206 def informational_severity_count count_stats[:informational].to_i end |
#low_severity_count ⇒ Integer
Return the Low severity count.
258 259 260 |
# File 'lib/ruby-nessus/version2/scan.rb', line 258 def low_severity_count count_stats[:low].to_i end |
#medium_severity_count ⇒ Integer
Return the Medium severity count.
245 246 247 |
# File 'lib/ruby-nessus/version2/scan.rb', line 245 def medium_severity_count count_stats[:medium].to_i end |
#open_ports_count ⇒ Integer
Return the Open Ports count.
154 155 156 |
# File 'lib/ruby-nessus/version2/scan.rb', line 154 def open_ports_count count_stats[:open_ports].to_i 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.
67 68 69 |
# File 'lib/ruby-nessus/version2/scan.rb', line 67 def policy_notes @policy_notes ||= @xml.at('//Policy/policyComments').inner_text end |
#policy_title ⇒ String
Return the nessus scan policy name. When creating a nessus policy this is usually the title field.
57 58 59 |
# File 'lib/ruby-nessus/version2/scan.rb', line 57 def policy_title @policy_name ||= @xml.at('//Policy/policyName').inner_text 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.
78 79 80 81 82 83 |
# File 'lib/ruby-nessus/version2/scan.rb', line 78 def target_hosts @xml.xpath('//Preferences/ServerPreferences/preference').each do |element| return element.children[3].inner_text.split(',') if element.children[1].inner_text == 'TARGET' end nil end |
#tcp_count ⇒ Integer
Return the TCP Event Count.
167 168 169 |
# File 'lib/ruby-nessus/version2/scan.rb', line 167 def tcp_count count_stats[:tcp].to_i end |
#title ⇒ String
Return the nessus report title.
47 48 49 |
# File 'lib/ruby-nessus/version2/scan.rb', line 47 def title @report_name ||= @xml.at('Report/@name').inner_text end |
#total_event_count(count_informational = nil) ⇒ Integer
Return the Total severity count. [critical, high, medium, low, informational]
273 274 275 276 277 278 279 |
# File 'lib/ruby-nessus/version2/scan.rb', line 273 def total_event_count(count_informational = nil) if count_informational count_stats[:all].to_i + informational_severity_count else count_stats[:all].to_i end end |
#udp_count ⇒ Integer
Return the UDP Event Count.
180 181 182 |
# File 'lib/ruby-nessus/version2/scan.rb', line 180 def udp_count count_stats[:udp].to_i end |
#unique_ports ⇒ Array
Retunrs an array of all unique ports.
134 135 136 137 138 139 140 141 142 143 |
# File 'lib/ruby-nessus/version2/scan.rb', line 134 def unique_ports unless @unique_ports @unique_ports = [] @xml.xpath('//ReportItem').each do |port| @unique_ports << port['port'] end @unique_ports.uniq! @unique_ports.sort! end end |
#version ⇒ Object
34 35 36 |
# File 'lib/ruby-nessus/version2/scan.rb', line 34 def version 2 end |