Class: Nessus::Version2::XML
- Inherits:
-
Object
- Object
- Nessus::Version2::XML
- Includes:
- Enumerable
- Defined in:
- lib/gemcache/ruby-nessus/ruby-nessus/Version2/version2.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.
-
#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.
-
#tcp_count ⇒ Integer
Return the TCP Event Count.
-
#title ⇒ String
Return the nessus report title.
-
#total_event_count(count_informational = false) ⇒ 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
30 31 32 33 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/version2.rb', line 30 def initialize(xml) @xml = xml raise "Error: Not A Version 2.0 .Nessus file." unless @xml.at('NessusClientData_v2') end |
Instance Method Details
#each_host {|prog| ... } ⇒ Object
Creates a new Host object to be parser
85 86 87 88 89 90 91 92 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/version2.rb', line 85 def each_host(&block) hosts = [] @xml.xpath("//ReportHost").each do |host| hosts << host['name'] if host['name'] block.call(Host.new(host)) if block end hosts end |
#event_percentage_for(type, round_percentage = false) ⇒ Integer
Return the Total severity count.
274 275 276 277 278 279 280 281 282 283 284 285 286 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/version2.rb', line 274 def event_percentage_for(type, round_percentage=false) @sc ||= count_stats if %W(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}" else return "#{calc}" end else raise "Error: #{type} is not an acceptable severity. Possible options include: all, tdp, udp, icmp, 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.
303 304 305 306 307 308 309 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/version2.rb', line 303 def find_by_hostname(hostname, &block) raise "Error: hostname can't be blank." if hostname.blank? @xml.xpath('//ReportHost').each do |host| next unless host['name'].match(hostname) block.call(Host.new(host)) if block end end |
#high_severity_count ⇒ Integer
Return the High severity count.
210 211 212 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/version2.rb', line 210 def high_severity_count count_stats[:high].to_i end |
#host_count ⇒ Integer
Return the nessus scan host count.
113 114 115 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/version2.rb', line 113 def host_count each_host.size end |
#hosts ⇒ Array<String>
Parses the hosts of the scan.
100 101 102 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/version2.rb', line 100 def hosts Enumerator.new(self,:each_host).to_a end |
#icmp_count ⇒ Integer
Return the ICMP Event Count.
184 185 186 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/version2.rb', line 184 def icmp_count count_stats[:icmp].to_i end |
#informational_severity_count ⇒ Integer
Return the informational severity count.
197 198 199 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/version2.rb', line 197 def informational_severity_count count_stats[:informational].to_i end |
#low_severity_count ⇒ Integer
Return the Low severity count.
236 237 238 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/version2.rb', line 236 def low_severity_count count_stats[:low].to_i end |
#medium_severity_count ⇒ Integer
Return the Medium severity count.
223 224 225 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/version2.rb', line 223 def medium_severity_count count_stats[:medium].to_i end |
#open_ports_count ⇒ Integer
Return the Open Ports count.
145 146 147 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/version2.rb', line 145 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.
69 70 71 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/version2.rb', line 69 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.
59 60 61 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/version2.rb', line 59 def policy_title @policy_name ||= @xml.at("//Policy/policyName").inner_text end |
#tcp_count ⇒ Integer
Return the TCP Event Count.
158 159 160 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/version2.rb', line 158 def tcp_count count_stats[:tcp].to_i end |
#title ⇒ String
Return the nessus report title.
49 50 51 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/version2.rb', line 49 def title @report_name ||= @xml.at('Report/@name').inner_text end |
#total_event_count(count_informational = false) ⇒ Integer
Return the Total severity count. [high, medium, low, informational]
251 252 253 254 255 256 257 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/version2.rb', line 251 def total_event_count(count_informational = false) 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.
171 172 173 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/version2.rb', line 171 def udp_count count_stats[:udp].to_i end |
#unique_ports ⇒ Array
Retunrs an array of all unique ports.
125 126 127 128 129 130 131 132 133 134 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/version2.rb', line 125 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
36 37 38 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/version2.rb', line 36 def version 2 end |