nessus_client 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/modules/exports.rb +12 -12
- data/lib/modules/folders.rb +10 -6
- data/lib/modules/policies.rb +5 -2
- data/lib/modules/scans.rb +19 -19
- data/lib/modules/server.rb +9 -8
- data/lib/modules/session.rb +32 -31
- data/lib/modules/tokens.rb +26 -25
- data/lib/nessus_client.rb +16 -18
- data/lib/nessus_client/exception.rb +4 -2
- data/lib/nessus_client/request.rb +43 -52
- data/lib/nessus_client/resource.rb +4 -1
- data/lib/nessus_client/version.rb +3 -1
- metadata +66 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f66280ff351ca3d9c29874252f4a88d9a3758f2ba16d6db75812edce9e40d1b9
|
4
|
+
data.tar.gz: 41d3b43e5a05682680ba05f6b7d33fec52ed81ddbd8a996eb27f7af499310b3a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a3ca44fbc46b2ff5a230e81457618976a9648a5c5154c39bfd82e29453f6530658b1aa884712f4d343b574e48389d3547a4ad60313652b488382faa0c528e28
|
7
|
+
data.tar.gz: 3251fca055bccd4aae51eba580ada175ad670f1ae5d9b2b982a4a1f218816b865cbe5246e32368d39e8545f93eeeea7f374f244f94ac33aa9ba720ca11f68680
|
data/lib/modules/exports.rb
CHANGED
@@ -1,24 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
|
-
|
3
|
-
|
3
|
+
# Namespace for Exports resource.
|
4
|
+
module Resource::Exports
|
4
5
|
# Export the given scan. Once requested, the file can be downloaded using the Resource::Tokens.token_download method upon receiving a "ready" status from the Resource::Tokens#token_status method. You can also use the older Resource::Exports#export_status and Resource::Exports#export_download methods.
|
5
6
|
# @param [String] scan_id The export uuid string.
|
6
7
|
# @param [String] format The file format to use (Nessus, HTML, PDF, CSV, or DB).
|
7
|
-
# @return [JSON]
|
8
|
-
def export_request(
|
9
|
-
payload = {:
|
10
|
-
|
8
|
+
# @return [JSON]
|
9
|
+
def export_request(scan_id, format = 'nessus')
|
10
|
+
payload = { format: format }
|
11
|
+
request.post({ path: "/scans/#{scan_id}/export", payload: payload, headers: headers })
|
11
12
|
end
|
12
13
|
|
13
14
|
# Check the file status of an exported scan. When an export has been requested, it is necessary to poll this resource until a "ready" status is returned, at which point the file is complete and can be downloaded using the export download resource.
|
14
15
|
# @param [String] scan_id The identifier for the scan. This identifier can be the either the 'schedule_uuid' or the numeric 'id' attribute for the scan. We recommend that you use 'schedule_uuid'.
|
15
16
|
# @param [String] file_id The ID of the file to poll (Included in response from #export_request).
|
16
|
-
# @return [JSON]
|
17
|
+
# @return [JSON]
|
17
18
|
# @example Checking the status of a export.
|
18
19
|
# export_status = nc.export_status( "15", "cd956" )
|
19
20
|
# return true if export_status["status"] == "ready"
|
20
|
-
def export_status(
|
21
|
-
|
21
|
+
def export_status(scan_id, file_id)
|
22
|
+
request.get({ path: "/scans/#{scan_id}/export/#{file_id}/status", headers: headers })
|
22
23
|
end
|
23
24
|
|
24
25
|
# Download exported scan.
|
@@ -30,8 +31,7 @@ module Resource::Exports # Namespace for Exports resource.
|
|
30
31
|
# open("scan_report", "wb") do |file|
|
31
32
|
# file.write( export )
|
32
33
|
# end
|
33
|
-
def export_download(
|
34
|
-
|
34
|
+
def export_download(scan_id, file_id)
|
35
|
+
request.get({ path: "/scans/#{scan_id}/export/#{file_id}/download", headers: headers })
|
35
36
|
end
|
36
|
-
|
37
37
|
end
|
data/lib/modules/folders.rb
CHANGED
@@ -1,14 +1,18 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Namespace for Folders resource.
|
4
|
+
module Resource::Folders
|
2
5
|
# Get the list of folders from the resource.
|
3
6
|
# @return [JSON]
|
4
7
|
def list_folders
|
5
|
-
|
8
|
+
request.get({ path: '/folders', headers: headers })
|
6
9
|
end
|
10
|
+
|
7
11
|
# Create a folder into the resource.
|
8
12
|
# @param [String] folder_name The name of the folder the will be created.
|
9
13
|
# @return [JSON]
|
10
|
-
def create_folder(
|
11
|
-
payload = {:
|
12
|
-
|
14
|
+
def create_folder(folder_name)
|
15
|
+
payload = { name: folder_name }
|
16
|
+
request.post({ path: '/folders', payload: payload, headers: headers })
|
13
17
|
end
|
14
|
-
end
|
18
|
+
end
|
data/lib/modules/policies.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Namespace for Policies resource.
|
4
|
+
module Resource::Policies
|
2
5
|
# List the scan polices.
|
3
6
|
# @return [JSON]
|
4
7
|
def policies
|
5
|
-
|
8
|
+
request.get({ path: '/policies', headers: headers })
|
6
9
|
end
|
7
10
|
end
|
data/lib/modules/scans.rb
CHANGED
@@ -1,50 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
|
-
|
3
|
-
|
3
|
+
# Namespace for Scans resource.
|
4
|
+
module Resource::Scans
|
4
5
|
# List scans from the resource.
|
5
6
|
# @param [String] folder_id (nil) The name of a alredy created scan.
|
6
7
|
# @return [JSON]
|
7
|
-
def list_scans(
|
8
|
-
query = folder_id.nil? ? nil : {
|
9
|
-
|
8
|
+
def list_scans(folder_id = nil)
|
9
|
+
query = folder_id.nil? ? nil : { 'folder_id' => folder_id }
|
10
|
+
request.get({ path: '/scans', query: query, headers: headers })
|
10
11
|
end
|
11
|
-
|
12
|
+
alias scans list_scans
|
12
13
|
|
13
14
|
# See details of a scan.
|
14
15
|
# @param [String] scan_id The `uuid` of a scan.
|
15
16
|
# @param [String] history_id (nil) The `history_id` of a scan.
|
16
17
|
# @return [JSON]
|
17
|
-
def scan_details(
|
18
|
-
query = history_id.nil? ? nil : {
|
19
|
-
|
18
|
+
def scan_details(scan_id, history_id = nil)
|
19
|
+
query = history_id.nil? ? nil : { 'history_id' => history_id }
|
20
|
+
request.get({ path: "/scans/#{scan_id}", query: query, headers: headers })
|
20
21
|
end
|
21
22
|
|
22
23
|
# Lauch a scan by its id
|
23
24
|
# @param [Integer] scan_id The ID of a alredy created scan.
|
24
25
|
# @param [Array<String>] targets comma separeted new target to be scanned.
|
25
26
|
# @return [JSON]
|
26
|
-
def launch(
|
27
|
-
payload = { :
|
28
|
-
|
27
|
+
def launch(scan_id, targets = [])
|
28
|
+
payload = { alt_targets: targets } unless targets.empty?
|
29
|
+
request.post({ path: "/scans/#{scan_id}/launch", payload: payload, headers: headers })
|
29
30
|
end
|
30
31
|
|
31
32
|
# Lauch a scan by its name
|
32
33
|
# @param [String] scan_name The name of a alredy created scan.
|
33
34
|
# @param [Array<String>] targets comma separeted new target to be scanned.
|
34
35
|
# @return [JSON]
|
35
|
-
def launch_by_name(
|
36
|
-
scan_id = get_scan_by_name(
|
37
|
-
launch(
|
36
|
+
def launch_by_name(scan_name, targets = [])
|
37
|
+
scan_id = get_scan_by_name(scan_name)
|
38
|
+
launch(scan_id, targets)
|
38
39
|
end
|
39
40
|
|
40
41
|
# Get a scan by its name
|
41
42
|
# @param [String] folder_id The id of the folder to look into.
|
42
43
|
# @param [String] scan_name The name of the scan to look for.
|
43
44
|
# @return [String, nil] The uuid of the scan.
|
44
|
-
def get_scan_by_name( folder_id=nil
|
45
|
-
list_scans(
|
45
|
+
def get_scan_by_name(scan_name, folder_id = nil)
|
46
|
+
list_scans(folder_id)['scans'].each do |scan|
|
46
47
|
return scan['id'] if scan['name'] == scan_name
|
47
48
|
end
|
48
49
|
end
|
49
|
-
|
50
|
-
end
|
50
|
+
end
|
data/lib/modules/server.rb
CHANGED
@@ -1,15 +1,16 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Namespace for Server resource.
|
4
|
+
module Resource::Server
|
3
5
|
# Returns the server status.
|
4
|
-
# @return [JSON] Returns the server status
|
6
|
+
# @return [JSON] Returns the server status
|
5
7
|
def server_status
|
6
|
-
|
8
|
+
request.get({ path: '/server/status', headers: headers })
|
7
9
|
end
|
8
|
-
|
10
|
+
|
9
11
|
# Returns the server version and other properties.
|
10
12
|
# @return [JSON] Returns the server properties
|
11
13
|
def server_properties
|
12
|
-
|
14
|
+
request.get({ path: '/server/properties', headers: headers })
|
13
15
|
end
|
14
|
-
|
15
|
-
end
|
16
|
+
end
|
data/lib/modules/session.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
|
-
|
3
|
-
|
3
|
+
# Namespace for Session resource.
|
4
|
+
module Resource::Session
|
4
5
|
# @return [Boolean] whether has a session.
|
5
6
|
attr_reader :session
|
6
7
|
|
@@ -12,50 +13,50 @@ module Resource::Session # Namespace for Session resource.
|
|
12
13
|
# @return [nil]
|
13
14
|
# @raise [NessusClient::Error] Unable to authenticate.
|
14
15
|
# @todo Validate response token format
|
15
|
-
def set_session(
|
16
|
-
|
16
|
+
def set_session(username, password)
|
17
17
|
payload = {
|
18
18
|
username: username,
|
19
19
|
password: password
|
20
20
|
}
|
21
21
|
|
22
|
-
resp =
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
self.headers.update( 'X-Cookie' => 'token=' + resp["token"] )
|
29
|
-
@session = true
|
30
|
-
self.headers.update( 'X-API-Token' => set_api_token() )
|
31
|
-
rescue NessusClient::Error => err
|
32
|
-
puts err.message
|
33
|
-
ensure
|
34
|
-
return
|
22
|
+
resp = request.post({ path: '/session', payload: payload, headers: headers })
|
23
|
+
# binding.pry
|
24
|
+
if !resp.key?('token')
|
25
|
+
raise NessusClient::Error, 'Unable to authenticate.'
|
26
|
+
elsif !resp['token'].match(/(?<token>[a-z0-9]{48})/)
|
27
|
+
raise NessusClient::Error, 'The token doesnt match with the pattern.'
|
35
28
|
end
|
36
|
-
|
29
|
+
|
30
|
+
headers.update('X-Cookie' => 'token=' + resp['token'])
|
31
|
+
@session = true
|
32
|
+
api_token = set_api_token
|
33
|
+
headers.update('X-API-Token' => api_token) if api_token
|
34
|
+
rescue NessusClient::Error => e
|
35
|
+
raise e
|
37
36
|
end
|
38
|
-
|
37
|
+
alias session_create set_session
|
39
38
|
|
40
|
-
|
41
|
-
|
42
|
-
|
39
|
+
# Destroy the current session.
|
40
|
+
def destroy
|
41
|
+
request.delete({ path: '/session', headers: headers })
|
43
42
|
@session = false
|
44
43
|
end
|
45
|
-
|
44
|
+
alias logout destroy
|
46
45
|
|
47
46
|
private
|
47
|
+
|
48
48
|
# Set the API Token from legacy Nessus version
|
49
49
|
# @raise [NessusClient::Error] Unable to get API Token.
|
50
50
|
# @todo To get it direct from the session authentication on v6.x
|
51
51
|
def set_api_token
|
52
|
-
response =
|
53
|
-
response.match(
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
52
|
+
response = request.get({ path: '/nessus6.js', headers: headers })
|
53
|
+
response.match(/return"(\w{8}-(?:\w{4}-){3}\w{12})"\}/)
|
54
|
+
unless Regexp.last_match(1)
|
55
|
+
raise NessusClient::Error, "Unable to get API Token. Some features won't work."
|
56
|
+
end
|
57
|
+
rescue NessusClient::Error => e
|
58
|
+
puts e.message
|
59
|
+
else
|
60
|
+
Regexp.last_match(1)
|
59
61
|
end
|
60
|
-
|
61
62
|
end
|
data/lib/modules/tokens.rb
CHANGED
@@ -1,25 +1,26 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
#
|
6
|
-
# @
|
7
|
-
#
|
8
|
-
#
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
#
|
16
|
-
# @
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Namespace for tokens resource.
|
4
|
+
module Resource::Tokens
|
5
|
+
# Check the status of a export request
|
6
|
+
# @param [String] export_uuid The export uuid string.
|
7
|
+
# @return [JSON]
|
8
|
+
# @example Checking the status of a export.
|
9
|
+
# export_status = nc.export_status( "73376c41-1508-46b7-8587-483d159cd956" )
|
10
|
+
# return true if export_status["status"] == "ready"
|
11
|
+
def token_status(export_uuid)
|
12
|
+
request.get({ path: "/tokens/#{export_uuid}/status", headers: headers })
|
13
|
+
end
|
14
|
+
|
15
|
+
# Check the download of a export request
|
16
|
+
# @param [String] export_uuid The export uuid string.
|
17
|
+
# @return [JSON] (@see #format)
|
18
|
+
# @example Download a ready export.
|
19
|
+
# export = nc.export_download( '73376c41-1508-46b7-8587-483d159cd956')
|
20
|
+
# open("scan_report", "wb") do |file|
|
21
|
+
# file.write( export )
|
22
|
+
# end
|
23
|
+
def token_download(export_uuid)
|
24
|
+
request.get({ path: "/tokens/#{export_uuid}/download", headers: headers })
|
25
|
+
end
|
26
|
+
end
|
data/lib/nessus_client.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'nessus_client/version'
|
2
4
|
require_relative 'nessus_client/exception'
|
3
5
|
require_relative 'nessus_client/resource'
|
4
6
|
|
5
|
-
Dir[File.join(__dir__, 'modules', '*.rb')].each { |file| require file }
|
7
|
+
Dir[File.join(__dir__, 'modules', '*.rb')].sort.each { |file| require file }
|
6
8
|
|
7
9
|
# Nessus resource abstraction.
|
8
10
|
class NessusClient
|
9
|
-
|
10
11
|
# @return [NessusClient::Request] Instance HTTP request object.
|
11
12
|
# @see NessusClient::Request
|
12
13
|
attr_reader :request
|
@@ -14,7 +15,7 @@ class NessusClient
|
|
14
15
|
attr_reader :session
|
15
16
|
# @return [Hash] Instance current HTTP headers.
|
16
17
|
attr_reader :headers
|
17
|
-
|
18
|
+
|
18
19
|
include Resource::Exports
|
19
20
|
include Resource::Folders
|
20
21
|
include Resource::Policies
|
@@ -23,34 +24,31 @@ class NessusClient
|
|
23
24
|
include Resource::Session
|
24
25
|
include Resource::Tokens
|
25
26
|
|
26
|
-
autoload :Request,
|
27
|
+
autoload :Request, 'nessus_client/request'
|
27
28
|
|
28
29
|
# @param [Hash] params the options to create a NessusClient with.
|
29
30
|
# @option params [String] :uri ('https://localhost:8834/') Nessus resource to connect with
|
30
31
|
# @option params [String] :username (nil) Username to use in the connection
|
31
32
|
# @option params [String] :password (nil) Password to use in the connection
|
32
33
|
# @option params [String] :ssl_verify_peer (true) Whether should check valid SSL certificate
|
33
|
-
def initialize(
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
password: nil,
|
34
|
+
def initialize(params = {})
|
35
|
+
default_params = {
|
36
|
+
uri: 'https://localhost:8834/',
|
37
|
+
username: nil,
|
38
|
+
password: nil,
|
39
39
|
ssl_verify_peer: true
|
40
40
|
}
|
41
|
-
params = default_params.merge(
|
42
|
-
req_params = params.select { |key,
|
41
|
+
params = default_params.merge(params)
|
42
|
+
req_params = params.select { |key, _value| %i[uri ssl_verify_peer].include?(key) }
|
43
43
|
|
44
|
-
@request = NessusClient::Request.new(
|
44
|
+
@request = NessusClient::Request.new(req_params)
|
45
45
|
@headers = NessusClient::Request::DEFAULT_HEADERS.dup
|
46
|
-
|
47
|
-
|
46
|
+
set_session(params.fetch(:username), params.fetch(:password))
|
48
47
|
end
|
49
48
|
|
50
49
|
# Gets NessusClient::Session authentication status.
|
51
50
|
# @return [Boolean] whether NessusClient has successfully authenticated.
|
52
51
|
def has_session?
|
53
|
-
|
52
|
+
session
|
54
53
|
end
|
55
|
-
|
56
|
-
end
|
54
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class NessusClient
|
2
4
|
# Abstract Error class for NessusClient.
|
3
5
|
class Error < ::StandardError
|
@@ -5,8 +7,8 @@ class NessusClient
|
|
5
7
|
# @param [String] msg The exception message.
|
6
8
|
# @example
|
7
9
|
# NessusClient::Error.new('This is a custom error.')
|
8
|
-
def initialize(
|
10
|
+
def initialize(msg)
|
9
11
|
super
|
10
12
|
end
|
11
13
|
end
|
12
|
-
end
|
14
|
+
end
|
@@ -1,26 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'excon'
|
2
4
|
require 'oj'
|
3
5
|
|
4
6
|
class NessusClient
|
5
|
-
|
6
|
-
#
|
7
|
+
# Abstract http request class for NessusClient.
|
8
|
+
# Provides some helper methods for perform HTTP requests.
|
7
9
|
class Request
|
8
10
|
# @return [String] The base url of the API.
|
9
11
|
attr_reader :url
|
10
12
|
|
11
13
|
# Default HTTP header to be used on the requests.
|
12
14
|
DEFAULT_HEADERS = {
|
13
|
-
|
14
|
-
|
15
|
+
'User-Agent' => 'NessusClient::Request - rubygems.org nessus_client',
|
16
|
+
'Content-Type' => 'application/json'
|
15
17
|
}.freeze
|
16
18
|
|
17
19
|
# @param [Hash] params the options to create a NessusClient::Request with.
|
18
20
|
# @option params [String] :uri ('https://localhost:8834/') Nessus server to connect with
|
19
21
|
# @option params [String] :ssl_verify_peer (true) Whether should check valid SSL certificate
|
20
|
-
def initialize(
|
21
|
-
params = {:
|
22
|
-
|
23
|
-
@url =
|
22
|
+
def initialize(params = {})
|
23
|
+
params = { uri: nil }.merge(params)
|
24
|
+
@ssl_verify_peer = params[:ssl_verify_peer] ? true : false
|
25
|
+
@url = NessusClient::Request.uri_parse(params.fetch(:uri))
|
24
26
|
end
|
25
27
|
|
26
28
|
# Perform a HTTP GET request.
|
@@ -28,9 +30,9 @@ class NessusClient
|
|
28
30
|
# @option opts [String] path The URI path to perform the request.
|
29
31
|
# @option opts [String] payload The HTTP body to send.
|
30
32
|
# @option opts [String] query The URI query to send.
|
31
|
-
# @return [
|
32
|
-
def get(
|
33
|
-
http_request( :get
|
33
|
+
# @return [Hash, String] The body of the resposnse if there is any.
|
34
|
+
def get(opts = {})
|
35
|
+
http_request(opts, :get)
|
34
36
|
end
|
35
37
|
|
36
38
|
# Perform a HTTP POST request.
|
@@ -38,9 +40,9 @@ class NessusClient
|
|
38
40
|
# @option opts [String] path The URI path to perform the request.
|
39
41
|
# @option opts [String] payload The HTTP body to send.
|
40
42
|
# @option opts [String] query The URI query to send.
|
41
|
-
# @return [
|
42
|
-
def post(
|
43
|
-
http_request( :post
|
43
|
+
# @return [Hash, String] The body of the resposnse if there is any.
|
44
|
+
def post(opts = {})
|
45
|
+
http_request(opts, :post)
|
44
46
|
end
|
45
47
|
|
46
48
|
# Perform a HTTP DELETE request.
|
@@ -48,21 +50,23 @@ class NessusClient
|
|
48
50
|
# @option opts [String] path The URI path to perform the request.
|
49
51
|
# @option opts [String] payload The HTTP body to send.
|
50
52
|
# @option opts [String] query The URI query to send.
|
51
|
-
# @return [
|
52
|
-
def delete(
|
53
|
-
http_request( :delete
|
53
|
+
# @return [Hash, String] The body of the resposnse if there is any.
|
54
|
+
def delete(opts = {})
|
55
|
+
http_request(opts, :delete)
|
54
56
|
end
|
55
57
|
|
56
58
|
# Parse a receiveid string against the URI stantard.
|
57
59
|
# @param [String] uri A string to be validate URI.
|
58
60
|
# @return [String] A string uri.
|
59
|
-
def self.uri_parse(
|
60
|
-
url = URI.parse(
|
61
|
+
def self.uri_parse(uri)
|
62
|
+
url = URI.parse(uri)
|
61
63
|
raise URI::InvalidURIError unless url.scheme
|
62
|
-
|
64
|
+
|
65
|
+
url.to_s
|
63
66
|
end
|
64
67
|
|
65
68
|
private
|
69
|
+
|
66
70
|
# @private HTTP request abstraction to be used.
|
67
71
|
# @param [Symbol] method The HTTP method to be used on the request.
|
68
72
|
# @param [Hash] args Parameters to use in the request.
|
@@ -70,38 +74,25 @@ class NessusClient
|
|
70
74
|
# @option args [String] payload (nil) The HTTP body to send.
|
71
75
|
# @option args [String] query (nil) The URI query to send.
|
72
76
|
# @option args [String] headers (nil) The headers to send.
|
73
|
-
# @return [
|
74
|
-
def http_request( method
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
headers: opts.fetch(:headers),
|
93
|
-
expects: [200, 201]
|
94
|
-
}
|
95
|
-
|
96
|
-
response = connection.request( options )
|
97
|
-
ret = Oj.load(response.body) #if response.body.length > 0
|
98
|
-
rescue Oj::ParseError => e
|
99
|
-
return response.body
|
100
|
-
else
|
101
|
-
return ret
|
102
|
-
end
|
77
|
+
# @return [Hash, String] The body of the resposnse if there is any.
|
78
|
+
def http_request(args, method = :get)
|
79
|
+
opts = { path: nil, payload: nil, query: nil, headers: nil }.merge(args)
|
80
|
+
connection = Excon.new(@url, { ssl_verify_peer: @ssl_verify_peer })
|
81
|
+
body = opts[:payload] ? Oj.dump(opts[:payload], mode: :compat) : ''
|
82
|
+
options = {
|
83
|
+
method: method,
|
84
|
+
path: opts.fetch(:path),
|
85
|
+
body: body,
|
86
|
+
query: opts.fetch(:query),
|
87
|
+
headers: opts.fetch(:headers),
|
88
|
+
expects: [200, 201]
|
89
|
+
}
|
90
|
+
response = connection.request(options)
|
91
|
+
ret = Oj.load(response.body) # if response.body.length > 0
|
92
|
+
rescue Oj::ParseError
|
93
|
+
response.body
|
94
|
+
else
|
95
|
+
ret
|
103
96
|
end
|
104
|
-
|
105
97
|
end
|
106
|
-
|
107
98
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nessus_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Heyder
|
@@ -14,16 +14,16 @@ dependencies:
|
|
14
14
|
name: excon
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.73.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 0.73.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: oj
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,6 +38,48 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '3.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.12'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.12'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.12.2
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.12.2
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: regexp-examples
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.5.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.5.0
|
41
83
|
- !ruby/object:Gem::Dependency
|
42
84
|
name: rspec
|
43
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,50 +95,56 @@ dependencies:
|
|
53
95
|
- !ruby/object:Gem::Version
|
54
96
|
version: '3.2'
|
55
97
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
98
|
+
name: simplecov
|
57
99
|
requirement: !ruby/object:Gem::Requirement
|
58
100
|
requirements:
|
59
101
|
- - "~>"
|
60
102
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
103
|
+
version: 0.17.0
|
62
104
|
type: :development
|
63
105
|
prerelease: false
|
64
106
|
version_requirements: !ruby/object:Gem::Requirement
|
65
107
|
requirements:
|
66
108
|
- - "~>"
|
67
109
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
110
|
+
version: 0.17.0
|
69
111
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
112
|
+
name: codecov
|
71
113
|
requirement: !ruby/object:Gem::Requirement
|
72
114
|
requirements:
|
73
115
|
- - "~>"
|
74
116
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.
|
117
|
+
version: 0.1.14
|
76
118
|
type: :development
|
77
119
|
prerelease: false
|
78
120
|
version_requirements: !ruby/object:Gem::Requirement
|
79
121
|
requirements:
|
80
122
|
- - "~>"
|
81
123
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0.
|
124
|
+
version: 0.1.14
|
83
125
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
126
|
+
name: yard
|
85
127
|
requirement: !ruby/object:Gem::Requirement
|
86
128
|
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0.9'
|
87
132
|
- - ">="
|
88
133
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
134
|
+
version: 0.9.20
|
90
135
|
type: :development
|
91
136
|
prerelease: false
|
92
137
|
version_requirements: !ruby/object:Gem::Requirement
|
93
138
|
requirements:
|
139
|
+
- - "~>"
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0.9'
|
94
142
|
- - ">="
|
95
143
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
97
|
-
description: Usable, fast, simple Ruby gem for Tenable Nessus Pro from v7.0.1
|
98
|
-
NessusClient was designed to be simple, fast and performant through
|
99
|
-
with Nessus
|
144
|
+
version: 0.9.20
|
145
|
+
description: "\n Usable, fast, simple Ruby gem for Tenable Nessus Pro from v7.0.1
|
146
|
+
to v8.3.1.\n NessusClient was designed to be simple, fast and performant through
|
147
|
+
communication with Nessus\n over REST interface.\n "
|
100
148
|
email: eu@heyderandrade.org
|
101
149
|
executables: []
|
102
150
|
extensions: []
|
@@ -141,7 +189,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
189
|
- !ruby/object:Gem::Version
|
142
190
|
version: '0'
|
143
191
|
requirements: []
|
144
|
-
rubygems_version: 3.0.
|
192
|
+
rubygems_version: 3.0.6
|
145
193
|
signing_key:
|
146
194
|
specification_version: 4
|
147
195
|
summary: Usable, fast, simple Ruby gem for Tenable Nessus Pro from v7.0.1 to v8.3.1.
|