Class: Nessus::Version2::Host

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb

Instance Method Summary collapse

Constructor Details

#initialize(host) ⇒ Host

Creates A New Host Object

Host.new(object)

Parameters:

  • Host (Object)

    Object



15
16
17
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 15

def initialize(host)
  @host = host
end

Instance Method Details

#critical_severity_countInteger

Return the Critical severity count.

Examples:

scan.critical_severity_count #=> 10

Returns:

  • (Integer)

    The Critical Severity Count



447
448
449
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 447

def critical_severity_count
  host_stats[:critical].to_i
end

#critical_severity_events {|prog| ... } ⇒ Integer

Returns All Critical Event Objects For A Given Host.

Examples:

host.critical_severity_events do |critical|
  puts critical.name if critical.name
end

Yields:

  • (prog)

    If a block is given, it will be passed the newly created Event object.

Yield Parameters:

  • prog (EVENT)

    The newly created Event object.

Returns:

  • (Integer)

    Return The Critical Event Count For A Given Host.



308
309
310
311
312
313
314
315
316
317
318
319
320
321
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 308

def critical_severity_events(&block)

  unless @critical_severity_events
    @critical_severity_events = []

    @host.xpath("ReportItem").each do |event|
      next if event['severity'].to_i != 4
      @critical_severity_events << Event.new(event)
    end

  end

  @critical_severity_events.each(&block)
end

#each_event {|prog| ... } ⇒ Object

Creates a new Event object to be parser

Examples:

host.each_event do |event|
  puts event.name if event.name
  puts event.port
end

Yields:

  • (prog)

    If a block is given, it will be passed the newly created Event object.

Yield Parameters:

  • prog (EVENT)

    The newly created Event object.



349
350
351
352
353
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 349

def each_event(&block)
  @host.xpath("ReportItem").each do |event|
    block.call(Event.new(event)) if block
  end
end

#event_countInteger

Return the total event count for a given host.

Examples:

host.event_count #=> 3456

Returns:

  • (Integer)

    Return the total event count for a given host.



332
333
334
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 332

def event_count
  ((low_severity_events.to_i) + (medium_severity_events.to_i) + (high_severity_events.to_i) + (critical_severity_events.to_i)).to_i
end

#event_percentage_for(type, round_percentage = false) ⇒ Integer

Return the Total severity count.

Examples:

scan.event_percentage_for("low", true) #=> 11%

Parameters:

  • severity (String)

    the severity in which to calculate percentage for.

  • round (true, false)

    round the result to the nearest whole number.

Returns:

  • (Integer)

    The Percentage Of Events For A Passed Severity

Raises:

  • (ExceptionClass)

    One of the following severity options must be passed. [high, medium, low, informational, all]



522
523
524
525
526
527
528
529
530
531
532
533
534
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 522

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}"
    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

#eventsArray<String>

Parses the events of the host.

Returns:

  • (Array<String>)

    The events of the host.



361
362
363
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 361

def events
  Enumerator.new(self,:each_event).to_a
end

#high_severity_countInteger

Return the High severity count.

Examples:

scan.high_severity_count #=> 10

Returns:

  • (Integer)

    The High Severity Count



460
461
462
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 460

def high_severity_count
  host_stats[:high].to_i
end

#high_severity_events {|prog| ... } ⇒ Integer

Returns All High Event Objects For A Given Host.

Examples:

host.high_severity_events do |high|
  puts high.name if high.name
end

Yields:

  • (prog)

    If a block is given, it will be passed the newly created Event object.

Yield Parameters:

  • prog (EVENT)

    The newly created Event object.

Returns:

  • (Integer)

    Return The High Event Count For A Given Host.



277
278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 277

def high_severity_events(&block)

  unless @high_severity_events
    @high_severity_events = []

    @host.xpath("ReportItem").each do |event|
      next if event['severity'].to_i != 3
      @high_severity_events << Event.new(event)
    end

  end

  @high_severity_events.each(&block)
end

#hostnameString Also known as: name, fqdn, dns_name

Return the Host Object hostname.

Examples:

host.hostname #=> "example.com"

Returns:

  • (String)

    The Host Object Hostname



32
33
34
35
36
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 32

def hostname
  if (host = @host.at('tag[name=host-fqdn]'))
    host.inner_text
  end
end

#icmp_countInteger

Return the ICMP Event Count.

Examples:

scan.icmp_count #=> 3

Returns:

  • (Integer)

    The ICMP Event Count



421
422
423
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 421

def icmp_count
  host_stats[:icmp].to_i
end

#informational_severity_countInteger

Return the informational severity count.

Examples:

scan.informational_severity_count #=> 1203

Returns:

  • (Integer)

    The Informational Severity Count



434
435
436
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 434

def informational_severity_count
  host_stats[:informational].to_i
end

#informational_severity_events {|prog| ... } ⇒ Integer

Returns All Informational Event Objects For A Given Host.

Examples:

host.informational_severity_events do |info|
  puts info.port
  puts info.data if info.data
end

Yields:

  • (prog)

    If a block is given, it will be passed the newly created Event object.

Yield Parameters:

  • prog (EVENT)

    The newly created Event object.

Returns:

  • (Integer)

    Return The Informational Event Count For A Given Host.



182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 182

def informational_severity_events(&block)
  unless @informational_events
    @informational_events = []

    @host.xpath("ReportItem").each do |event|
      next if event['severity'].to_i != 0
      @informational_events << Event.new(event)
    end

  end

  @informational_events.each(&block)
end

#ipString

Return the Host Object IP.

Examples:

host.ip #=> "127.0.0.1"

Returns:

  • (String)

    The Host Object IP



50
51
52
53
54
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 50

def ip
  if (ip = @host.at('tag[name=host-ip]'))
    ip.inner_text
  end
end

#low_severity_countInteger

Return the Low severity count.

Examples:

scan.low_severity_count #=> 114

Returns:

  • (Integer)

    The Low Severity Count



486
487
488
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 486

def low_severity_count
  host_stats[:low].to_i
end

#low_severity_events {|prog| ... } ⇒ Integer

Returns All Low Event Objects For A Given Host.

Examples:

host.low_severity_events do |low|
  puts low.name if low.name
end

Yields:

  • (prog)

    If a block is given, it will be passed the newly created Event object.

Yield Parameters:

  • prog (EVENT)

    The newly created Event object.

Returns:

  • (Integer)

    Return The Low Event Count For A Given Host.



212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 212

def low_severity_events(&block)

  unless @low_severity_events
    @low_severity_events = []

    @host.xpath("ReportItem").each do |event|
      next if event['severity'].to_i != 1
      @low_severity_events << Event.new(event)
    end

  end

  @low_severity_events.each(&block)
end

#mac_addrString Also known as: mac_address

Return the Host Mac Address.

Examples:

host.mac_addr #=> "00:11:22:33:44:55"

Returns:

  • (String)

    Return the Host Mac Address



128
129
130
131
132
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 128

def mac_addr
  if (mac_addr = @host.at('tag[name=mac-addr]'))
    mac_addr.inner_text
  end
end

#medium_severityObject



257
258
259
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 257

def medium_severity
  Enumerator.new(self,:medium_severity_events).to_a
end

#medium_severity_countInteger

Return the Medium severity count.

Examples:

scan.medium_severity_count #=> 234

Returns:

  • (Integer)

    The Medium Severity Count



473
474
475
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 473

def medium_severity_count
  host_stats[:medium].to_i
end

#medium_severity_events {|prog| ... } ⇒ Integer

Returns All Medium Event Objects For A Given Host.

Examples:

host.medium_severity_events do |medium|
  puts medium.name if medium.name
end

Yields:

  • (prog)

    If a block is given, it will be passed the newly created Event object.

Yield Parameters:

  • prog (EVENT)

    The newly created Event object.

Returns:

  • (Integer)

    Return The Medium Event Count For A Given Host.



242
243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 242

def medium_severity_events(&block)

  unless @medium_severity_events
    @medium_severity_events = []

    @host.xpath("ReportItem").each do |event|
      next if event['severity'].to_i != 2
      @medium_severity_events << Event.new(event)
    end

  end

  @medium_severity_events.each(&block)
end

#netbios_nameString

Return the Host Netbios Name.

Examples:

host.netbios_name #=> "SOMENAME4243"

Returns:

  • (String)

    The Host Netbios Name



113
114
115
116
117
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 113

def netbios_name
  if (netbios = @host.at('tag[name=netbios-name]'))
    netbios.inner_text
  end
end

#open_portsInteger

Return the open ports for a given host object.

Examples:

host.open_ports #=> 213

Returns:

  • (Integer)

    Return the open ports for a given host object.



161
162
163
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 161

def open_ports
  @scanned_ports ||= host_stats[:open_ports].to_i
end

#os_nameString Also known as: os, operating_system

Return the Host OS Name.

Examples:

host.dns_name #=> "Microsoft Windows 2000, Microsoft Windows Server 2003"

Returns:

  • (String)

    Return the Host OS Name



144
145
146
147
148
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 144

def os_name
  if (os_name = @host.at('tag[name=operating-system]'))
    os_name.inner_text
  end
end

#portsArray

Return the Open Ports count.

Examples:

scan.ports #=> ['22', '80', '443']

Returns:

  • (Array)

    The Open Ports Count



374
375
376
377
378
379
380
381
382
383
384
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 374

def ports
  unless @ports
    @ports = []
    @host.xpath("ReportItem").each do |port|
      @ports << port['port']
    end
    @ports.uniq!
    @ports.sort!
  end
  @ports
end

#runtimeString Also known as: scan_runtime

Return the host run time.

Examples:

scan.scan_run_time #=> '2 hours 5 minutes and 16 seconds'

Returns:

  • (String)

    The Host Scan Run Time



99
100
101
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 99

def runtime
  get_runtime
end

#start_timeDateTime

Return the host scan start time.

Examples:

scan.scan_start_time #=> 'Fri Nov 11 23:36:54 1985'

Returns:

  • (DateTime)

    The Host Scan Start Time



65
66
67
68
69
70
71
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 65

def start_time
  if (start_time = @host.at('tag[name=HOST_START]'))
    DateTime.strptime(start_time.inner_text, fmt='%a %b %d %H:%M:%S %Y')
  else
    false
  end
end

#stop_timeDateTime

Return the host scan stop time.

Examples:

scan.scan_start_time #=> 'Fri Nov 11 23:36:54 1985'

Returns:

  • (DateTime)

    The Host Scan Stop Time



82
83
84
85
86
87
88
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 82

def stop_time
  if (stop_time = @host.at('tag[name=HOST_END]'))
    DateTime.strptime(stop_time.inner_text, fmt='%a %b %d %H:%M:%S %Y')
  else
    false
  end
end

#tcp_countInteger

Return the TCP Event Count.

Examples:

scan.tcp_count #=> 3

Returns:

  • (Integer)

    The TCP Event Count



395
396
397
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 395

def tcp_count
  host_stats[:tcp].to_i
end

#to_sObject



19
20
21
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 19

def to_s
  "#{ip}"
end

#total_event_count(count_informational = false) ⇒ Integer

Return the Total severity count. [high, medium, low, informational]

Examples:

scan.total_event_count #=> 1561

Returns:

  • (Integer)

    The Total Severity Count



499
500
501
502
503
504
505
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 499

def total_event_count(count_informational = false)
  if count_informational
    host_stats[:all].to_i + informational_severity_count
  else
    host_stats[:all].to_i
  end
end

#udp_countInteger

Return the UDP Event Count.

Examples:

scan.udp_count #=> 3

Returns:

  • (Integer)

    The UDP Event Count



408
409
410
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 408

def udp_count
  host_stats[:udp].to_i
end