Nessus6 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 80b280c90c8525f396797ee7a8ede1eaafee968e
4
- data.tar.gz: bb9bba8b28e74ffde223f0e88f2a15c7b285bd7a
3
+ metadata.gz: 45de2929582d290d256e02d1e7ca7b8cd91cd559
4
+ data.tar.gz: ef441435d1ef84096b44319284fae90e6ee6dbec
5
5
  SHA512:
6
- metadata.gz: adca72a28588ee39fc1ccaee35eb9d78783637eaf136f702b984b62f88c7b3b61ff61e686a1153a2aeb907750723896bfa9bf494ca12e11bf7a7c8ee7f7c001a
7
- data.tar.gz: 8ec5723e60ea92f8220dd9357b0359edd4d5074dccca9c394bce984c7870e8221a839cd3ae4848410e9a413d3928149dd7f164190ce5530ffc72c89858576880
6
+ metadata.gz: 07ad4b0de59890b92c5048c60743aed6c48c932d6a12f7b69cb5d10df72ce1296ccd49a1479d059e1b1df2972f5ded92b86ac1cfd1145d85e85d69a3391466ea
7
+ data.tar.gz: 23a8777b7b42bafdc63c5bf2e67fbc208b99182801945cdf158ce6ce40fc8203a92a55f954c673f17672c483013addb7377f29390e9ad41fc6014031b9972322
data/.travis.yml CHANGED
@@ -1,3 +1,21 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - 2.0.0
4
+ - 2.1.0
3
5
  - 2.1.5
6
+ - 2.2.0
7
+ - 2.2.1
8
+ - 2.2.2
9
+ - rbx-2
10
+ - ruby-head
11
+ - jruby-head
12
+
13
+ before_install:
14
+ - gem update --system
15
+ - gem --version
16
+
17
+ gemfile:
18
+ - Gemfile
19
+
20
+ notifications:
21
+ email: false
data/Nessus6.gemspec CHANGED
@@ -25,5 +25,6 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency "rake", "~> 10.0"
26
26
  spec.add_development_dependency "minitest", "~> 5.8"
27
27
  spec.add_development_dependency "yard", "~> 0.8"
28
+ spec.add_development_dependency 'codeclimate-test-reporter', '~> 0.4'
28
29
  spec.add_runtime_dependency "hurley", "~> 0.1"
29
30
  end
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Code Climate](https://codeclimate.com/github/kkirsche/Nessus6/badges/gpa.svg)](https://codeclimate.com/github/kkirsche/Nessus6) [![Test Coverage](https://codeclimate.com/github/kkirsche/Nessus6/badges/coverage.svg)](https://codeclimate.com/github/kkirsche/Nessus6/coverage)
2
+
1
3
  # Nessus6
2
4
 
3
5
  Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/Nessus6`. To experiment with that code, run `bin/console` for an interactive prompt.
data/Rakefile CHANGED
@@ -1 +1,11 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test/'
6
+ t.libs << 'bin/'
7
+ t.libs << 'lib/'
8
+ t.pattern = 'test/spec/**/*_spec.rb'
9
+ end
10
+
11
+ task :default => :test
data/bin/console CHANGED
@@ -1,14 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "Nessus6"
3
+ require 'bundler/setup'
4
+ require 'Nessus6'
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
8
8
 
9
9
  # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
10
+ # require 'pry'
11
11
  # Pry.start
12
12
 
13
- require "irb"
13
+ require 'irb'
14
14
  IRB.start
data/lib/Nessus6.rb CHANGED
@@ -1,19 +1,23 @@
1
1
  require 'hurley'
2
+ # Must go first
3
+ require 'Nessus6/verification'
4
+ # Inherits from verification
2
5
  require 'Nessus6/version'
3
- require 'Nessus6/editor/methods'
4
- require 'Nessus6/session/methods'
5
- require 'Nessus6/users/methods'
6
- require 'Nessus6/file/methods'
7
- require 'Nessus6/folders/methods'
8
- require 'Nessus6/groups/methods'
9
- require 'Nessus6/permissions/methods'
10
- require 'Nessus6/scans/methods'
6
+ require 'Nessus6/editor'
7
+ require 'Nessus6/session'
8
+ require 'Nessus6/user'
9
+ require 'Nessus6/file'
10
+ require 'Nessus6/folder'
11
+ require 'Nessus6/group'
12
+ require 'Nessus6/permission'
13
+ require 'Nessus6/scan'
14
+ require 'Nessus6/errors/authentication_error'
11
15
 
12
16
  module Nessus6
13
17
  # The Client class is used to interact with the Nessus API
14
18
  class Client
15
- attr_reader :client, :editor, :session, :users, :file, :folders, :groups,
16
- :permissions, :scans
19
+ attr_reader :client, :editor, :session, :user, :file, :folder, :group,
20
+ :permission, :scan
17
21
 
18
22
  def initialize(credentials, nessus)
19
23
  nessus[:port] = '8834' unless nessus.key?(:port)
@@ -37,9 +41,9 @@ module Nessus6
37
41
  @client.header['X-Cookie'] = "token = #{@token}"
38
42
  elsif credentials[:access_key] && credentials[:secret_key]
39
43
  else
40
- fail AuthenticationError, 'Authentication credentials not provided. ' \
41
- 'Must provided either username and password or access key and' \
42
- ' secret key.'
44
+ fail Nessus6::Error::AuthenticationError, 'Authentication credentials' \
45
+ ' not provided. Must provided either username and password or ' \
46
+ 'access key and secret key.'
43
47
  end
44
48
  end
45
49
 
@@ -52,12 +56,12 @@ module Nessus6
52
56
  def build_clients(client)
53
57
  @session = Nessus6::Session.new client
54
58
  @editor = Nessus6::Editor.new client
55
- @users = Nessus6::Users.new client
59
+ @user = Nessus6::User.new client
56
60
  @file = Nessus6::File.new client
57
- @folders = Nessus6::Folders.new client
58
- @groups = Nessus6::Groups.new client
59
- @permissions = Nessus6::Permissions.new client
60
- @scans = Nessus6::Scans.new client
61
+ @folder = Nessus6::Folder.new client
62
+ @group = Nessus6::Group.new client
63
+ @permission = Nessus6::Permission.new client
64
+ @scan = Nessus6::Scan.new client
61
65
  end
62
66
  end
63
67
  end
@@ -0,0 +1,88 @@
1
+ require 'json'
2
+ require 'Nessus6/errors/bad_request' # 400
3
+ require 'Nessus6/errors/forbidden' # 403
4
+ require 'Nessus6/errors/not_found' # 404
5
+ require 'Nessus6/errors/conflict' # 409
6
+ require 'Nessus6/errors/internal_server_error' # 500
7
+ require 'Nessus6/errors/unknown' # Unknown Error Code
8
+
9
+ module Nessus6
10
+ # The Editor class is for interacting with Nessus6 templates. Templates are
11
+ # used to create scans or policies with predefined parameters.
12
+ # https://localhost:8834/api#/resources/editor
13
+ class Editor
14
+ include Nessus6::Verification
15
+
16
+ public
17
+
18
+ def initialize(client)
19
+ @client = client
20
+ end
21
+
22
+ # Export the given audit file.
23
+ #
24
+ # @param type [String] The type of template to retrieve (scan or policy).
25
+ # @param object_id [String, Fixnum] The unique id of the object.
26
+ # @param file_id [String, Fixnum] The id of the file to export.
27
+ # @return [Hash]
28
+ def audits(type, object_id, file_id)
29
+ response = @client.get("editor/#{type}/#{object_id}/audits/#{file_id}")
30
+ verify response,
31
+ forbidden: 'You do not have permission to export the audit file',
32
+ not_found: 'Audit file does not exist',
33
+ internal_server_error: 'Internal server error occurred.'
34
+ end
35
+
36
+ # Returns the details for the given template.
37
+ #
38
+ # @param type [String] The type of template to retrieve (scan or policy).
39
+ # @param template_uuid [String] The uuid for the template.
40
+ # @return [Hash] Details for the given template
41
+ def details(type, template_uuid)
42
+ response = @client.get("editor/#{type}/templates/#{template_uuid}")
43
+ verify response,
44
+ forbidden: 'You do not have permission to open the template',
45
+ not_found: 'Template does not exist',
46
+ internal_server_error: 'Internal server error occurred.'
47
+ end
48
+
49
+ # Returns the requested object.
50
+ #
51
+ # @param type [String] The type of template to retrieve (scan or policy).
52
+ # @param id [String, Fixnum] The unique id of the object.
53
+ # @return [Hash] The requested object
54
+ def edit(type, id)
55
+ response = @client.get("editor/#{type}/#{id}")
56
+ verify response,
57
+ forbidden: 'You do not have permission to open the object',
58
+ not_found: 'Object does not exist',
59
+ internal_server_error: 'Internal server error occurred.'
60
+ end
61
+
62
+ # Returns the template list.
63
+ #
64
+ # @param type [String] The type of template to retrieve (scan or policy).
65
+ # @return [Hash] { "templates": [ template Resource ] }
66
+ def list(type)
67
+ response = @client.get("editor/#{type}/templates")
68
+ verify response,
69
+ forbidden: 'You do not have permission to view the list',
70
+ internal_server_error: 'Internal server error occurred.'
71
+ end
72
+
73
+ # Returns the plugin description. This request requires standard user
74
+ # permissions
75
+ #
76
+ # @param policy_id [String, Fixnum] The id of the policy to lookup.
77
+ # @param family_id [String, Fixnum] The id of the family to lookup within
78
+ # the policy.
79
+ # @param plugin_id [String, Fixnum] The id of the plugin to lookup within
80
+ # the family.
81
+ # @return [Hash] The plugin output
82
+ def plugin_description(policy_id, family_id, plugin_id)
83
+ response = @client.get("editor/policy/#{policy_id}/families/#{family_id}/plugins/#{plugin_id}")
84
+ verify response,
85
+ internal_server_error: 'Internal server error occurred.'
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,8 @@
1
+ module Nessus6
2
+ module Error
3
+ # Authentication error is thrown when the user cannot authenticate with
4
+ # Nessus
5
+ class AuthenticationError < StandardError
6
+ end
7
+ end
8
+ end
@@ -1,7 +1,11 @@
1
- # BadRequestError represents HTTP 400 Responses
2
- # The server cannot or will not process the request
3
- # due to something that is perceived to be a client
4
- # error (e.g. malformed request syntax, invalid request
5
- # message framing, or deceptive request routing)
6
- class BadRequestError < StandardError
1
+ module Nessus6
2
+ module Error
3
+ # BadRequestError represents HTTP 400 Responses
4
+ # The server cannot or will not process the request
5
+ # due to something that is perceived to be a client
6
+ # error (e.g. malformed request syntax, invalid request
7
+ # message framing, or deceptive request routing)
8
+ class BadRequestError < StandardError
9
+ end
10
+ end
7
11
  end
@@ -1,6 +1,10 @@
1
- # ConflictError represents HTTP 409 Responses
2
- # Indicates that the request could not be processed
3
- # because of a conflict in the request such as an
4
- # edit conflict in the case of multiple updates.
5
- class ConflictError < StandardError
1
+ module Nessus6
2
+ module Error
3
+ # ConflictError represents HTTP 409 Responses
4
+ # Indicates that the request could not be processed
5
+ # because of a conflict in the request such as an
6
+ # edit conflict in the case of multiple updates.
7
+ class ConflictError < StandardError
8
+ end
9
+ end
6
10
  end
@@ -1,6 +1,10 @@
1
- # ForbiddenError represents HTTP 403 Responses
2
- # The request was a valid request, but the server
3
- # is refusing to respond to it. Unlike 401 Unauthorized
4
- # responses, authenticating will make no difference
5
- class ForbiddenError < StandardError
1
+ module Nessus6
2
+ module Error
3
+ # ForbiddenError represents HTTP 403 Responses
4
+ # The request was a valid request, but the server
5
+ # is refusing to respond to it. Unlike 401 Unauthorized
6
+ # responses, authenticating will make no difference
7
+ class ForbiddenError < StandardError
8
+ end
9
+ end
6
10
  end
@@ -1,5 +1,9 @@
1
- # InternalServerError represents HTTP 500 Responses
2
- # A generic error message, given when an unexpected condition
3
- # was encountered and no more specific message is suitable
4
- class InternalServerError < StandardError
1
+ module Nessus6
2
+ module Error
3
+ # InternalServerError represents HTTP 500 Responses
4
+ # A generic error message, given when an unexpected condition
5
+ # was encountered and no more specific message is suitable
6
+ class InternalServerError < StandardError
7
+ end
8
+ end
5
9
  end
@@ -1,6 +1,10 @@
1
- # NotFoundError represents HTTP 404 Responses
2
- # The requested resource could not be found but may be
3
- # available again in the future. Subsequent requests by
4
- # the client are permissible.
5
- class NotFoundError < StandardError
1
+ module Nessus6
2
+ module Error
3
+ # NotFoundError represents HTTP 404 Responses
4
+ # The requested resource could not be found but may be
5
+ # available again in the future. Subsequent requests by
6
+ # the client are permissible.
7
+ class NotFoundError < StandardError
8
+ end
9
+ end
6
10
  end
@@ -1,8 +1,12 @@
1
- # UnauthorizedError represents HTTP 401 Responses
2
- # Similar to 403 Forbidden, but specifically for use
3
- # when authentication is required and has failed or has
4
- # not yet been provided. The response must include a
5
- # WWW-Authenticate header field containing a challenge
6
- # applicable to the requested resource
7
- class UnauthorizedError < StandardError
1
+ module Nessus6
2
+ module Error
3
+ # UnauthorizedError represents HTTP 401 Responses
4
+ # Similar to 403 Forbidden, but specifically for use
5
+ # when authentication is required and has failed or has
6
+ # not yet been provided. The response must include a
7
+ # WWW-Authenticate header field containing a challenge
8
+ # applicable to the requested resource
9
+ class UnauthorizedError < StandardError
10
+ end
11
+ end
8
12
  end
@@ -1,4 +1,8 @@
1
- # UnknownError represents something that Nessus doesn't
2
- # provide an HTTP code for
3
- class UnknownError < StandardError
1
+ module Nessus6
2
+ module Error
3
+ # UnknownError represents something that Nessus doesn't
4
+ # provide an HTTP code for
5
+ class UnknownError < StandardError
6
+ end
7
+ end
4
8
  end
@@ -0,0 +1,31 @@
1
+ require 'json'
2
+ require 'hurley'
3
+ require 'Nessus6/errors/internal_server_error'
4
+ require 'Nessus6/errors/unknown'
5
+
6
+ module Nessus6
7
+ # The File class is for uploading files to Nessus.
8
+ # https://localhost:8834/api#/resources/file
9
+ class File
10
+ include Nessus6::Verification
11
+
12
+ public
13
+
14
+ def initialize(client)
15
+ @client = client
16
+ end
17
+
18
+ # Uploads a file. This request requires read only user permissions.
19
+ #
20
+ # @param file_path [String] Path to the file to upload
21
+ # @param file_type [String] MIME type. E.g. 'text/plain'
22
+ # @return [Hash] Returns a :fileuploaded string.
23
+ def upload(file_path, file_type, encrypted = 0)
24
+ response = @client.post('file/upload',
25
+ file: Hurley::UploadIO.new(file_path, file_type),
26
+ no_enc: encrypted)
27
+ verify response,
28
+ internal_server_error: 'File failed to upload'
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,72 @@
1
+ require 'json'
2
+ require 'Nessus6/errors/internal_server_error'
3
+ require 'Nessus6/errors/forbidden'
4
+ require 'Nessus6/errors/bad_request'
5
+ require 'Nessus6/errors/not_found'
6
+ require 'Nessus6/errors/unknown'
7
+
8
+ module Nessus6
9
+ # The Folders class is for interacting with Nessus6 folders. Folders are used
10
+ # to sort and organize a user's scan results.
11
+ # https://localhost:8834/api#/resources/folders
12
+ class Folder
13
+ include Nessus6::Verification
14
+
15
+ public
16
+
17
+ def initialize(client)
18
+ @client = client
19
+ end
20
+
21
+ # Creates a new folder for the current user. This request requires
22
+ # read-only user permissions.
23
+ #
24
+ # @param name [String] The name of the folder.
25
+ # @return [Hash]
26
+ def create(name)
27
+ response = @client.post('folders', name: name)
28
+ verify response,
29
+ bad_request: 'Folder name is invalid',
30
+ forbidden: 'You do not have permission to create a folder.',
31
+ internal_server_error: 'Server failed to create the folder.'
32
+ end
33
+
34
+ # Deletes a folder. This request requires read-only user permissions.
35
+ #
36
+ # @param folder_id [String, Fixnum] The id of the folder to delete.
37
+ # @return [Hash]
38
+ def delete(folder_id)
39
+ response = @client.delete("folders/#{folder_id}")
40
+ verify response,
41
+ forbidden: 'Cannot delete a system folder.',
42
+ not_found: 'Folder does not exist.',
43
+ internal_server_error: 'Server failed to delete the folder.'
44
+ end
45
+
46
+ # Rename a folder for the current user. This request requires read-only
47
+ # user permissions.
48
+ #
49
+ # @param folder_id [String, Fixnum] The id of the folder to edit.
50
+ # @param name [String] The name of the folder.
51
+ # @return [Hash]
52
+ def edit(folder_id, name)
53
+ response = @client.put("folders/#{folder_id}", name: name)
54
+ verify response,
55
+ forbidden: 'Cannot rename a system folder.',
56
+ not_found: 'Folder does not exist.',
57
+ internal_server_error: 'Server failed to rename the folder.'
58
+ end
59
+
60
+ alias_method :rename, :edit
61
+
62
+ # Returns the current user's scan folders.
63
+ #
64
+ # @return [Hash] { "folders": [folder Resource] }
65
+ def list
66
+ response = @client.get('folders')
67
+ verify response,
68
+ forbidden: 'You do not have permission to view the folder list.',
69
+ internal_server_error: 'An internal server error occurred.'
70
+ end
71
+ end
72
+ end