class Nessus::Scan

Attributes

details[R]

Wrapper for XMLRPC client

@attr_reader [String] uuid of scan template @attr_reader [Fixnum] scan id @attr_reader [Hash] full scan details @attr_reader [Result] full scan result

id[R]

Wrapper for XMLRPC client

@attr_reader [String] uuid of scan template @attr_reader [Fixnum] scan id @attr_reader [Hash] full scan details @attr_reader [Result] full scan result

result[R]

Wrapper for XMLRPC client

@attr_reader [String] uuid of scan template @attr_reader [Fixnum] scan id @attr_reader [Hash] full scan details @attr_reader [Result] full scan result

uuid[R]

Wrapper for XMLRPC client

@attr_reader [String] uuid of scan template @attr_reader [Fixnum] scan id @attr_reader [Hash] full scan details @attr_reader [Result] full scan result

Public Class Methods

new(name, targets) click to toggle source

Create a new scan instance

@param [String] nessus scan template name @param [Array<String>] target addresses e.g localhost:3000

@return [Scan]

# File lib/nessus/scan.rb, line 23
def initialize(name, targets)
  set_uuid(name)
  setup_scan(targets)
end

Public Instance Methods

export_csv(filepath) click to toggle source

Export scan to csv file

@param [String] output filepath

@return [Fixnum] bytes written to file

# File lib/nessus/scan.rb, line 62
def export_csv(filepath)
  csv_id   = client.scan_export(@id, 'csv')
  csv_data = client.report_download(@id, csv_id['file'])

  File.write(filepath, csv_data)
end
launch!() click to toggle source

Launches the scan

@return [Result] the result hash from the scan

# File lib/nessus/scan.rb, line 32
def launch!
  client.scan_launch(@id)

  loop do
    raw    = client.scan_details(@id)
    status = raw['info']['status']

    if status != 'running'
      @result = Result.new(raw)
      break
    end
      
    sleep Nessus::Settings.refresh_interval
  end
end
view() click to toggle source

View the result of a finished scan

@return [Hash] the raw result hash from the scan

# File lib/nessus/scan.rb, line 52
def view
  result && result.raw
end

Private Instance Methods

client() click to toggle source
# File lib/nessus/scan.rb, line 90
def client
  @client ||= Nessus::Client.new(
    Nessus::Settings.host,
    Nessus::Settings.username,
    Nessus::Settings.password,
    Nessus::Settings.ssl_verify
  )
end
set_uuid(name) click to toggle source
# File lib/nessus/scan.rb, line 71
def set_uuid(name)
  @uuid = client
            .list_template('scan')
            .fetch('templates', [])
            .find { |t| t['name'] == name }
            .fetch('uuid')
end
setup_scan(targets) click to toggle source
# File lib/nessus/scan.rb, line 79
def setup_scan(targets)
  @details = client.scan_create(
    @uuid,
    "Automated Scan #{Time.now}",
    "This scan was created by the Nessus ruby client as part of automated testing",
    targets
  )

  @id = @details['scan']['id']
end