Module: Resource::Scans

Included in:
NessusClient
Defined in:
lib/modules/scans.rb

Overview

Namespace for Scans resource.

Instance Method Summary collapse

Instance Method Details

#get_scan_by_name(scan_name, folder_id = nil) ⇒ String?

Get a scan by its name

Parameters:

  • folder_id (String) (defaults to: nil)

    The id of the folder to look into.

  • scan_name (String)

    The name of the scan to look for.

Returns:

  • (String, nil)

    The uuid of the scan.



45
46
47
48
49
# File 'lib/modules/scans.rb', line 45

def get_scan_by_name(scan_name, folder_id = nil)
  list_scans(folder_id)['scans'].each do |scan|
    return scan['id'] if scan['name'] == scan_name
  end
end

#launch(scan_id, targets = []) ⇒ JSON

Lauch a scan by its id

Parameters:

  • scan_id (Integer)

    The ID of a alredy created scan.

  • targets (Array<String>) (defaults to: [])

    comma separeted new target to be scanned.

Returns:

  • (JSON)


27
28
29
30
# File 'lib/modules/scans.rb', line 27

def launch(scan_id, targets = [])
  payload = { alt_targets: targets } unless targets.empty?
  request.post({ path: "/scans/#{scan_id}/launch", payload: payload, headers: headers })
end

#launch_by_name(scan_name, targets = []) ⇒ JSON

Lauch a scan by its name

Parameters:

  • scan_name (String)

    The name of a alredy created scan.

  • targets (Array<String>) (defaults to: [])

    comma separeted new target to be scanned.

Returns:

  • (JSON)


36
37
38
39
# File 'lib/modules/scans.rb', line 36

def launch_by_name(scan_name, targets = [])
  scan_id = get_scan_by_name(scan_name)
  launch(scan_id, targets)
end

#list_scans(folder_id = nil) ⇒ JSON Also known as: scans

List scans from the resource.

Parameters:

  • folder_id (String) (defaults to: nil)

    (nil) The name of a alredy created scan.

Returns:

  • (JSON)


8
9
10
11
# File 'lib/modules/scans.rb', line 8

def list_scans(folder_id = nil)
  query = folder_id.nil? ? nil : { 'folder_id' => folder_id }
  request.get({ path: '/scans', query: query, headers: headers })
end

#scan_details(scan_id, history_id = nil) ⇒ JSON

See details of a scan.

Parameters:

  • scan_id (String)

    The ‘uuid` of a scan.

  • history_id (String) (defaults to: nil)

    (nil) The ‘history_id` of a scan.

Returns:

  • (JSON)


18
19
20
21
# File 'lib/modules/scans.rb', line 18

def scan_details(scan_id, history_id = nil)
  query = history_id.nil? ? nil : { 'history_id' => history_id }
  request.get({ path: "/scans/#{scan_id}", query: query, headers: headers })
end