Class: RubyNessus::Version2::Host
- Inherits:
-
Object
- Object
- RubyNessus::Version2::Host
- Includes:
- Enumerable
- Defined in:
- lib/ruby-nessus/version2/host.rb
Instance Method Summary collapse
-
#critical_severity_count ⇒ Integer
Return the Critical severity count.
-
#critical_severity_events ⇒ Event
Returns All critical severity Event Objects For A Given Host.
-
#each_event {|prog| ... } ⇒ Object
Creates a new Event object to be parser.
-
#event_count ⇒ Integer
Return the total event count for a given host.
-
#event_percentage_for(type, round_percentage = false) ⇒ Integer
Return the Total severity count.
-
#events ⇒ Array<String>
Parses the events of the host.
-
#high_severity_count ⇒ Integer
Return the High severity count.
-
#high_severity_events ⇒ Event
Returns All high severity Event Objects For A Given Host.
-
#hostname ⇒ String
(also: #fqdn, #dns_name)
Return the Host Object hostname.
-
#icmp_count ⇒ Integer
Return the ICMP Event Count.
-
#informational_severity_count ⇒ Integer
Return the informational severity count.
-
#informational_severity_events ⇒ Event
Returns All Informational Event Objects For A Given Host.
-
#initialize(host) ⇒ Host
constructor
Creates A New Host Object.
-
#ip ⇒ String
Return the Host Object IP.
-
#low_severity_count ⇒ Integer
Return the Low severity count.
-
#low_severity_events ⇒ Event
Returns All low_severity Event Objects For A Given Host.
-
#mac_addr ⇒ String
(also: #mac_address)
Return the Host Mac Address.
-
#medium_severity_count ⇒ Integer
Return the Medium severity count.
-
#medium_severity_events ⇒ Event
Returns All medium severity Event Objects For A Given Host.
- #name ⇒ Object
-
#netbios_name ⇒ String?
Return the Host Netbios Name.
-
#open_ports ⇒ Integer
Return the open ports for a given host object.
-
#os_name ⇒ String
(also: #os, #operating_system)
Return the Host OS Name.
-
#ports ⇒ Array
Return an Array of open ports.
-
#runtime ⇒ String
(also: #scan_runtime, #get_runtime)
Return the host run time.
-
#start_time ⇒ Time
Return the host scan start time.
-
#stop_time ⇒ Time
Return the host scan stop time.
-
#tcp_count ⇒ Integer
Return the TCP Event Count.
- #to_s ⇒ Object
-
#total_event_count(count_informational = nil) ⇒ Integer
Return the Total severity count.
-
#udp_count ⇒ Integer
Return the UDP Event Count.
Constructor Details
#initialize(host) ⇒ Host
Creates A New Host Object
Host.new(object)
16 17 18 |
# File 'lib/ruby-nessus/version2/host.rb', line 16 def initialize(host) @host = host end |
Instance Method Details
#critical_severity_count ⇒ Integer
Return the Critical severity count.
379 380 381 |
# File 'lib/ruby-nessus/version2/host.rb', line 379 def critical_severity_count host_stats[:critical].to_i end |
#critical_severity_events ⇒ Event
Returns All critical severity Event Objects For A Given Host.
254 255 256 257 258 259 260 |
# File 'lib/ruby-nessus/version2/host.rb', line 254 def critical_severity_events return if @critical_events @critical_events = @host.xpath('ReportItem').select { |event| (event['severity'].to_i == 4) }.map do |event| Event.new(event) end @critical_events end |
#each_event {|prog| ... } ⇒ Object
Creates a new Event object to be parser
288 289 290 |
# File 'lib/ruby-nessus/version2/host.rb', line 288 def each_event(&block) events.each(&block) end |
#event_count ⇒ Integer
Return the total event count for a given host.
271 272 273 |
# File 'lib/ruby-nessus/version2/host.rb', line 271 def event_count low_severity_events.count + medium_severity_events.count + high_severity_events.count + critical_severity_events.count end |
#event_percentage_for(type, round_percentage = false) ⇒ Integer
Return the Total severity count.
454 455 456 457 458 459 460 461 462 463 464 465 466 |
# File 'lib/ruby-nessus/version2/host.rb', line 454 def event_percentage_for(type, round_percentage = false) @sc ||= host_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.to_s else return calc.to_s end else raise "Error: #{type} is not an acceptable severity. Possible options include: all, tdp, udp, icmp, high, medium and low." end end |
#events ⇒ Array<String>
Parses the events of the host.
298 299 300 301 302 |
# File 'lib/ruby-nessus/version2/host.rb', line 298 def events @host.xpath('ReportItem').map do |event| Event.new(event) end end |
#high_severity_count ⇒ Integer
Return the High severity count.
392 393 394 |
# File 'lib/ruby-nessus/version2/host.rb', line 392 def high_severity_count host_stats[:high].to_i end |
#high_severity_events ⇒ Event
Returns All high severity Event Objects For A Given Host.
233 234 235 236 237 238 239 |
# File 'lib/ruby-nessus/version2/host.rb', line 233 def high_severity_events return if @high_severity_events @high_severity_events = @host.xpath('ReportItem').select { |event| (event['severity'].to_i == 3) }.map do |event| Event.new(event) end @high_severity_events end |
#hostname ⇒ String Also known as: fqdn, dns_name
Return the Host Object hostname.
37 38 39 |
# File 'lib/ruby-nessus/version2/host.rb', line 37 def hostname @host.at('tag[name=host-fqdn]')&.inner_text end |
#icmp_count ⇒ Integer
Return the ICMP Event Count.
353 354 355 |
# File 'lib/ruby-nessus/version2/host.rb', line 353 def icmp_count host_stats[:icmp].to_i end |
#informational_severity_count ⇒ Integer
Return the informational severity count.
366 367 368 |
# File 'lib/ruby-nessus/version2/host.rb', line 366 def informational_severity_count host_stats[:informational].to_i end |
#informational_severity_events ⇒ Event
Returns All Informational Event Objects For A Given Host.
170 171 172 173 174 175 176 |
# File 'lib/ruby-nessus/version2/host.rb', line 170 def informational_severity_events return if @informational_events @informational_events = @host.xpath('ReportItem').select { |event| event['severity'].to_i.zero? }.map do |event| Event.new(event) end @informational_events end |
#ip ⇒ String
Return the Host Object IP.
52 53 54 |
# File 'lib/ruby-nessus/version2/host.rb', line 52 def ip @host.at('tag[name=host-ip]')&.inner_text end |
#low_severity_count ⇒ Integer
Return the Low severity count.
418 419 420 |
# File 'lib/ruby-nessus/version2/host.rb', line 418 def low_severity_count host_stats[:low].to_i end |
#low_severity_events ⇒ Event
Returns All low_severity Event Objects For A Given Host.
191 192 193 194 195 196 197 |
# File 'lib/ruby-nessus/version2/host.rb', line 191 def low_severity_events return if @low_severity_events @low_severity_events = @host.xpath('ReportItem').select { |event| (event['severity'].to_i == 1) }.map do |event| Event.new(event) end @low_severity_events end |
#mac_addr ⇒ String Also known as: mac_address
Return the Host Mac Address.
124 125 126 |
# File 'lib/ruby-nessus/version2/host.rb', line 124 def mac_addr @host.at('tag[name=mac-address]')&.inner_text end |
#medium_severity_count ⇒ Integer
Return the Medium severity count.
405 406 407 |
# File 'lib/ruby-nessus/version2/host.rb', line 405 def medium_severity_count host_stats[:medium].to_i end |
#medium_severity_events ⇒ Event
Returns All medium severity Event Objects For A Given Host.
212 213 214 215 216 217 218 |
# File 'lib/ruby-nessus/version2/host.rb', line 212 def medium_severity_events return if @medium_severity_events @medium_severity_events = @host.xpath('ReportItem').select { |event| (event['severity'].to_i == 2) }.map do |event| Event.new(event) end @medium_severity_events end |
#name ⇒ Object
24 25 26 |
# File 'lib/ruby-nessus/version2/host.rb', line 24 def name @host["name"] end |
#netbios_name ⇒ String?
Return the Host Netbios Name.
111 112 113 |
# File 'lib/ruby-nessus/version2/host.rb', line 111 def netbios_name @host.at('tag[name=netbios-name]')&.inner_text end |
#open_ports ⇒ Integer
Return the open ports for a given host object.
153 154 155 |
# File 'lib/ruby-nessus/version2/host.rb', line 153 def open_ports @scanned_ports ||= host_stats[:open_ports].to_i end |
#os_name ⇒ String Also known as: os, operating_system
Return the Host OS Name.
138 139 140 |
# File 'lib/ruby-nessus/version2/host.rb', line 138 def os_name @host.at('tag[name=operating-system]')&.inner_text end |
#ports ⇒ Array
Return an Array of open ports.
313 314 315 316 |
# File 'lib/ruby-nessus/version2/host.rb', line 313 def ports return if @ports @ports = @host.xpath('ReportItem').map { |port| port['port'] }.uniq.sort end |
#runtime ⇒ String Also known as: scan_runtime, get_runtime
Return the host run time.
95 96 97 98 |
# File 'lib/ruby-nessus/version2/host.rb', line 95 def runtime return unless stop_time && start_time Time.at(stop_time - start_time).utc.strftime('%H hours %M minutes and %S seconds') end |
#start_time ⇒ Time
Return the host scan start time.
65 66 67 68 69 |
# File 'lib/ruby-nessus/version2/host.rb', line 65 def start_time if (start_time = @host.at('tag[name=HOST_START]')) Time.parse(start_time.inner_text + ' UTC') end end |
#stop_time ⇒ Time
Return the host scan stop time.
80 81 82 83 84 |
# File 'lib/ruby-nessus/version2/host.rb', line 80 def stop_time if (stop_time = @host.at('tag[name=HOST_END]')) Time.parse(stop_time.inner_text + ' UTC') end end |
#tcp_count ⇒ Integer
Return the TCP Event Count.
327 328 329 |
# File 'lib/ruby-nessus/version2/host.rb', line 327 def tcp_count host_stats[:tcp].to_i end |
#to_s ⇒ Object
20 21 22 |
# File 'lib/ruby-nessus/version2/host.rb', line 20 def to_s ip.to_s end |
#total_event_count(count_informational = nil) ⇒ Integer
Return the Total severity count. [high, medium, low, informational]
431 432 433 434 435 436 437 |
# File 'lib/ruby-nessus/version2/host.rb', line 431 def total_event_count(count_informational = nil) if count_informational host_stats[:all].to_i + informational_severity_count else host_stats[:all].to_i end end |
#udp_count ⇒ Integer
Return the UDP Event Count.
340 341 342 |
# File 'lib/ruby-nessus/version2/host.rb', line 340 def udp_count host_stats[:udp].to_i end |