class Nessus6::Client

The Client class is used to interact with the Nessus API

Attributes

client[RW]
editor[R]
file[R]
folder[R]
group[R]
permission[R]
plugin[R]
plugin_rule[R]
policy[R]
scan[R]
scanner[R]
server[R]
session[R]
user[R]

Public Class Methods

new(credentials, nessus) click to toggle source
# File lib/Nessus6.rb, line 30
def initialize(credentials, nessus)
  nessus[:port] = '8834' unless nessus.key?(:port)

  # Create our client
  @client = Hurley::Client.new "https://#{nessus[:ip]}:#{nessus[:port]}"
  @client.ssl_options.skip_verification = true

  authenticate credentials

  build_clients @client

  @client
end

Public Instance Methods

authenticate(credentials) click to toggle source
# File lib/Nessus6.rb, line 44
def authenticate(credentials)
  # Open up a session and get our token so we can make queries
  @session = Nessus6::Session.new @client
  if credentials[:username] && credentials[:password]
    @token = @session.create(credentials[:username], credentials[:password])
    @client.header['X-Cookie'] = "token = #{@token}"
  elsif credentials[:access_key] && credentials[:secret_key]
    @client.header['X-ApiKeys'] = "accessKey=#{credentials[:access_key]}; secretKey=#{credentials[:secret_key]}"
  else
    fail Nessus6::Error::AuthenticationError, 'Authentication credentials' \
      ' not provided. Must provided either username and password or ' \
      'access key and secret key.'
  end
end
logout() click to toggle source
# File lib/Nessus6.rb, line 59
def logout
  @session.destroy
end

Private Instance Methods

build_clients(client) click to toggle source
# File lib/Nessus6.rb, line 65
def build_clients(client)
  @editor = Nessus6::Editor.new client
  @file = Nessus6::File.new client
  @folder = Nessus6::Folder.new client
  @group = Nessus6::Group.new client
  @permission = Nessus6::Permission.new client
  @plugin = Nessus6::Plugin.new client
  @policy = Nessus6::Policy.new client
  @plugin_rule = Nessus6::PluginRule.new client
  @scan = Nessus6::Scan.new client
  @scanner = Nessus6::Scanner.new client
  @server = Nessus6::Server.new client
  @session = Nessus6::Session.new client
  @user = Nessus6::User.new client
end