Class: Nessus::Version1::XML
- Inherits:
-
Object
- Object
- Nessus::Version1::XML
- Includes:
- Enumerable
- Defined in:
- lib/gemcache/ruby-nessus/ruby-nessus/Version1/version1.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.
-
#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
31 32 33 34 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version1/version1.rb', line 31 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
188 189 190 191 192 193 194 195 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version1/version1.rb', line 188 def each_host(&block) hosts = [] @xml.xpath("//ReportHost").each do |host| hosts << host.at('HostName').inner_text if host.at('HostName').inner_text block.call(Host.new(host)) if block end hosts end |
#event_percentage_for(type, round_percentage = false) ⇒ Integer
Return the Total severity count.
319 320 321 322 323 324 325 326 327 328 329 330 331 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version1/version1.rb', line 319 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}" else return "#{calc}" 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.
348 349 350 351 352 353 354 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version1/version1.rb', line 348 def find_by_hostname(hostname, &block) raise "Error: hostname can't be blank." if hostname.blank? @xml.xpath('//ReportHost[HostName]').each do |host| next unless host.inner_text.match(hostname) block.call(Host.new(host)) if block end end |
#high_severity_count ⇒ Integer
Return the High severity count.
261 262 263 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version1/version1.rb', line 261 def high_severity_count count_severity[:high].to_i end |
#host_count ⇒ Integer
Return the nessus scan host count.
216 217 218 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version1/version1.rb', line 216 def host_count hosts.size end |
#hosts ⇒ Array<String>
Parses the hosts of the scan.
203 204 205 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version1/version1.rb', line 203 def hosts Enumerator.new(self,:each_host).to_a end |
#low_severity_count ⇒ Integer
Return the Low severity count.
287 288 289 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version1/version1.rb', line 287 def low_severity_count count_severity[:low].to_i end |
#medium_severity_count ⇒ Integer
Return the Medium severity count.
274 275 276 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version1/version1.rb', line 274 def medium_severity_count count_severity[:medium].to_i end |
#open_ports_count ⇒ Integer
Return the informational severity count.
248 249 250 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version1/version1.rb', line 248 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.
138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version1/version1.rb', line 138 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.
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version1/version1.rb', line 159 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 return @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.
125 126 127 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version1/version1.rb', line 125 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.
115 116 117 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version1/version1.rb', line 115 def policy_title @policy_name ||= @xml.xpath("//NessusClientData//Report//policyName").inner_text end |
#runtime ⇒ String
Return the scan run time.
102 103 104 105 106 107 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version1/version1.rb', line 102 def runtime h = ("#{Time.parse(stop_time.to_s).strftime('%H').to_i - Time.parse(start_time.to_s).strftime('%H').to_i}").gsub('-', '') m = ("#{Time.parse(stop_time.to_s).strftime('%M').to_i - Time.parse(start_time.to_s).strftime('%M').to_i}").gsub('-', '') s = ("#{Time.parse(stop_time.to_s).strftime('%S').to_i - Time.parse(start_time.to_s).strftime('%S').to_i}").gsub('-', '') return "#{h} hours #{m} minutes and #{s} seconds" end |
#start_time ⇒ DateTime
Return the scan start time.
76 77 78 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version1/version1.rb', line 76 def start_time @start_time = DateTime.strptime(@xml.xpath("//NessusClientData//Report//StartTime").inner_text, fmt='%a %b %d %H:%M:%S %Y') end |
#stop_time ⇒ DateTime
Return the scan stop time.
89 90 91 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version1/version1.rb', line 89 def stop_time @stop_time = DateTime.strptime(@xml.xpath("//NessusClientData//Report//StopTime").inner_text, fmt='%a %b %d %H:%M:%S %Y') end |
#time ⇒ String
Return the nessus report time.
62 63 64 65 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version1/version1.rb', line 62 def time datetime = @xml.xpath("//NessusClientData//Report//ReportName").inner_text.split(' - ').first @report_time ||= DateTime.strptime(datetime, fmt='%y/%m/%d %I:%M:%S %p') end |
#title ⇒ String
Return the nessus report title.
49 50 51 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version1/version1.rb', line 49 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]
300 301 302 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version1/version1.rb', line 300 def total_event_count count_severity[:all].to_i end |
#unique_ports ⇒ Array
Retunrs an array of all unique ports.
228 229 230 231 232 233 234 235 236 237 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version1/version1.rb', line 228 def unique_ports unless @unique_ports @unique_ports = [] @xml.xpath("//ReportItem//port").each do |port| @unique_ports << port.inner_text end @unique_ports.uniq! @unique_ports.sort! end end |
#version ⇒ Object
36 37 38 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version1/version1.rb', line 36 def version 1 end |