nessus_client 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CONTRIBUTING.md +0 -0
- data/README.md +39 -0
- data/lib/modules/exports.rb +15 -0
- data/lib/modules/folders.rb +12 -0
- data/lib/modules/policies.rb +7 -0
- data/lib/modules/scans.rb +27 -0
- data/lib/nessus_client.rb +53 -0
- data/lib/nessus_client/exception.rb +7 -0
- data/lib/nessus_client/request.rb +76 -0
- data/lib/nessus_client/session.rb +56 -0
- data/lib/nessus_client/version.rb +3 -0
- metadata +154 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1dda4cc05fbcee8eac14f8469f106944fa356ec74ecb31e3623c13338ec175f9
|
4
|
+
data.tar.gz: db9270a96eb7866357754b65e1d3e17c0c67d9fdc98e5d507104a44fee49ef31
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d8c172bec3e3039644a3352dfa279e3799153351936b3d4b9ac86d90e87a31d9d151480e34ef7eb742258b77fdeb28066224216c07ae5a2cf31c9fb5771f8e8b
|
7
|
+
data.tar.gz: 74dff229a778e97680bde8f690c845e84767b3da1847459577a377d2cfea2febc35f53c8fd1aac1befce5138c450cc7092c3b71d5f35cd840edd516dd4012461
|
data/CONTRIBUTING.md
ADDED
File without changes
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
NessusApi
|
2
|
+
=========
|
3
|
+
**Ruby wrapper for Nessus API**
|
4
|
+
|
5
|
+
* [Source Code]
|
6
|
+
* [API documentation]
|
7
|
+
* [Changelog]
|
8
|
+
* [Rubygem]
|
9
|
+
|
10
|
+
|
11
|
+
Ruby wrapper for Nessus API (all verions)
|
12
|
+
|
13
|
+
## Contact
|
14
|
+
|
15
|
+
*Code and Bug Reports*
|
16
|
+
|
17
|
+
* [Issue Tracker](https://github.com/heyder/nessus_client/issues)
|
18
|
+
* See [CONTRIBUTING](https://github.com/heyder/nessus_client/blob/master/CONTRIBUTING.md) for how to contribute along
|
19
|
+
with some common problems to check out before creating an issue.
|
20
|
+
|
21
|
+
|
22
|
+
Getting started
|
23
|
+
---------------
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
## Code of Conduct
|
29
|
+
|
30
|
+
Everyone participating in this project's development, issue trackers and other channels is expected to follow our
|
31
|
+
[Code of Conduct](./CODE_OF_CONDUCT.md)
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
See the [contributing guide](https://github.com/heyder/nessus_client/blob/master/CONTRIBUTING.md).
|
36
|
+
|
37
|
+
## Copyright
|
38
|
+
|
39
|
+
Copyright (c) 2016-2019 Heyder Andrade. See MIT-LICENSE for details.
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# require_relative '../nessus_client/request'
|
2
|
+
|
3
|
+
module NessusClient::Exports
|
4
|
+
# export scans
|
5
|
+
def export_request( scan_id, format )
|
6
|
+
params = {:format => format }
|
7
|
+
self.request.post("/scans/#{scan_id}/export", params)
|
8
|
+
end
|
9
|
+
def export_status( export_id )
|
10
|
+
self.request.get("/tokens/#{export_id}/status")
|
11
|
+
end
|
12
|
+
def export_download( export_id )
|
13
|
+
self.request.get("/tokens/#{export_id}/download")
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# require_relative '../nessus_client/request'
|
2
|
+
|
3
|
+
module NessusClient::Folders
|
4
|
+
# folders
|
5
|
+
def list_folders
|
6
|
+
self.request.get("/folders")
|
7
|
+
end
|
8
|
+
def create_folder( folder_name )
|
9
|
+
params = {:name => folder_name }.to_json
|
10
|
+
self.request.post("/folders", params)
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
|
2
|
+
module NessusClient::Scans
|
3
|
+
|
4
|
+
def list_scans( folder_id=nil )
|
5
|
+
query = folder_id.nil? ? nil : { "folder_id" => folder_id }
|
6
|
+
self.request.get( "/scans", nil, query )
|
7
|
+
end
|
8
|
+
alias_method :scans, :list_scans
|
9
|
+
|
10
|
+
def scan_details( scan_id, history_id=nil )
|
11
|
+
query = history_id.nil? ? nil : { "history_id" => history_id }
|
12
|
+
self.request.get( "/scans/#{scan_id}", nil, query )
|
13
|
+
end
|
14
|
+
|
15
|
+
def launch_by_name( scan_name, targets=[] )
|
16
|
+
scan_id = get_scan_by_name( scan_name )
|
17
|
+
params = { :alt_targets => targets } unless targets.empty?
|
18
|
+
self.request.post( "/scans/#{scan_id}/launch", params )
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_scan_by_name( folder_id=nil, name )
|
22
|
+
Oj.load(list_scans( folder_id ))["scans"].each do |scan|
|
23
|
+
return scan['id'] if scan['name'] == name
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# require 'pry'
|
2
|
+
require_relative 'nessus_client/version'
|
3
|
+
require_relative 'nessus_client/exception'
|
4
|
+
|
5
|
+
Dir[File.join(__dir__, 'modules', '*.rb')].each { |file| require file }
|
6
|
+
|
7
|
+
class NessusClient
|
8
|
+
|
9
|
+
attr_reader :request, :session
|
10
|
+
|
11
|
+
include NessusClient::Scans
|
12
|
+
include NessusClient::Exports
|
13
|
+
include NessusClient::Folders
|
14
|
+
include NessusClient::Policies
|
15
|
+
|
16
|
+
autoload :Request, "nessus_client/request"
|
17
|
+
autoload :Session, "nessus_client/session"
|
18
|
+
|
19
|
+
def initialize( params={uri: nil, username: nil, password: nil, :ssl_verify_peer => false} )
|
20
|
+
@has_session = false
|
21
|
+
req_params = params.select {|key, value| [:uri, :ssl_verify_peer].include?(key) }
|
22
|
+
# session_params = params.select {|key, value| [:username, :password].include?(key) }
|
23
|
+
|
24
|
+
@request = NessusClient::Request.new( req_params )
|
25
|
+
@session = NessusClient::Session.create( params.fetch(:username), params.fetch(:password) )
|
26
|
+
|
27
|
+
if @session.token
|
28
|
+
begin
|
29
|
+
@has_session = true
|
30
|
+
# NessusClient::Request.headers.update( 'X-Cookie' => 'token=' + api_session.token )
|
31
|
+
@request.headers.update( 'X-Cookie' => 'token=' + @session.token )
|
32
|
+
@session.set_api_token
|
33
|
+
rescue NessusClient::Error => err
|
34
|
+
puts err.message
|
35
|
+
else
|
36
|
+
request.headers.update( 'X-API-Token' => @session.api_token )
|
37
|
+
ensure
|
38
|
+
return
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
def has_session?
|
46
|
+
@has_session
|
47
|
+
end
|
48
|
+
|
49
|
+
def status
|
50
|
+
self.request.get( "/server/status" )
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'excon'
|
2
|
+
require 'json'
|
3
|
+
# require 'pry'
|
4
|
+
class NessusClient
|
5
|
+
|
6
|
+
# Excon.defaults[:ssl_verify_peer] = false
|
7
|
+
# This class should be used to in all requests classes
|
8
|
+
|
9
|
+
class Request
|
10
|
+
# attr_accessor :headers
|
11
|
+
attr_reader :url, :headers
|
12
|
+
|
13
|
+
DEFAULT_HEADERS = {
|
14
|
+
"User-Agent" => "Mozilla/5.0 (Linux x86_64)",
|
15
|
+
"Content-Type" => "application/json"
|
16
|
+
}
|
17
|
+
|
18
|
+
def initialize( params )
|
19
|
+
params = {:uri => nil, :ssl_verify_peer => false, :headers => {} }.merge( params )
|
20
|
+
@@ssl_verify_peer = params.fetch(:ssl_verify_peer)
|
21
|
+
@url = @@url = NessusClient::Request.uri_parse( params.fetch(:uri) )
|
22
|
+
@headers = params.fetch( :headers ).merge( DEFAULT_HEADERS )
|
23
|
+
end
|
24
|
+
|
25
|
+
# def self.headers
|
26
|
+
# @@headers
|
27
|
+
# end
|
28
|
+
def headers=(value)
|
29
|
+
raise NotImplementedError.new("Use update from Hash insted.")
|
30
|
+
end
|
31
|
+
|
32
|
+
def get( path=nil, payload=nil, query=nil )
|
33
|
+
http_request( :get, path, payload, query )
|
34
|
+
end
|
35
|
+
|
36
|
+
def post( path=nil, payload=nil, query=nil )
|
37
|
+
http_request( :post, path, payload, query )
|
38
|
+
end
|
39
|
+
|
40
|
+
def delete( path=nil, payload=nil, query=nil )
|
41
|
+
http_request( :delete, path, payload, query )
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.uri_parse( uri )
|
45
|
+
url = URI.parse( uri )
|
46
|
+
raise URI::InvalidURIError unless url.scheme
|
47
|
+
return url.to_s
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def http_request( method=:get, path, payload, query )
|
53
|
+
# binding.pry
|
54
|
+
connection = Excon.new( @@url )
|
55
|
+
|
56
|
+
body = payload ? payload.to_json : ''
|
57
|
+
options = {
|
58
|
+
method: method,
|
59
|
+
path: path,
|
60
|
+
body: body,
|
61
|
+
query: query,
|
62
|
+
headers: @headers,
|
63
|
+
ssl_verify_peer: @@ssl_verify_peer,
|
64
|
+
#idempotent: true,
|
65
|
+
#proxy: "http://127.0.0.1:8080",
|
66
|
+
expects: [200, 201]
|
67
|
+
}
|
68
|
+
response = connection.request( options )
|
69
|
+
|
70
|
+
return response.body if response.body.length > 0
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'oj'
|
2
|
+
require_relative 'request'
|
3
|
+
require_relative 'exception'
|
4
|
+
|
5
|
+
class NessusClient
|
6
|
+
|
7
|
+
# This class should be used to get an access token
|
8
|
+
# for use with the main client class.
|
9
|
+
class Session
|
10
|
+
attr_reader :token, :api_token
|
11
|
+
|
12
|
+
@token = @api_token = nil
|
13
|
+
|
14
|
+
# @param [String] username
|
15
|
+
# @param [String] password
|
16
|
+
def self.create( username, password )
|
17
|
+
|
18
|
+
payload = {
|
19
|
+
username: username,
|
20
|
+
password: password,
|
21
|
+
}
|
22
|
+
|
23
|
+
response = NessusClient::Request.post( '/session', payload )
|
24
|
+
response = Oj.load(response) if response.length > 0
|
25
|
+
|
26
|
+
if response['token']
|
27
|
+
return self.new( response['token'] )
|
28
|
+
else
|
29
|
+
raise NessusClient::Error.new "#{__method__}::Response did not include a session token."
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
def initialize( token )
|
35
|
+
@token = token
|
36
|
+
end
|
37
|
+
|
38
|
+
def set_api_token
|
39
|
+
response = NessusClient::Request.get( "/nessus6.js" )
|
40
|
+
response.match( %r{return"(\w{8}-(?:\w{4}-){3}\w{12})"\}} )
|
41
|
+
|
42
|
+
raise NessusClient::Error.new( "Unable to get API Token. Some features won't work." ) unless $1#.nil?
|
43
|
+
|
44
|
+
@api_token = $1
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
def destroy
|
49
|
+
NessusClient::Request.delete( '/session', nil )
|
50
|
+
@token = nil
|
51
|
+
end
|
52
|
+
alias_method :logout , :destroy
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
metadata
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nessus_client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Heyder
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-11-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: excon
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.62'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.62'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: oj
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.7'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: json
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.1'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.2'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.2'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.12'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.12'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.12.2
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.12.2
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.17.0
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.17.0
|
111
|
+
description: Ruby wrapper for Nessus API (all verions)
|
112
|
+
email: eu@heyderandrade.org
|
113
|
+
executables: []
|
114
|
+
extensions: []
|
115
|
+
extra_rdoc_files:
|
116
|
+
- README.md
|
117
|
+
- CONTRIBUTING.md
|
118
|
+
files:
|
119
|
+
- CONTRIBUTING.md
|
120
|
+
- README.md
|
121
|
+
- lib/modules/exports.rb
|
122
|
+
- lib/modules/folders.rb
|
123
|
+
- lib/modules/policies.rb
|
124
|
+
- lib/modules/scans.rb
|
125
|
+
- lib/nessus_client.rb
|
126
|
+
- lib/nessus_client/exception.rb
|
127
|
+
- lib/nessus_client/request.rb
|
128
|
+
- lib/nessus_client/session.rb
|
129
|
+
- lib/nessus_client/version.rb
|
130
|
+
homepage: https://rubygemspec.org/gems/nessus_client
|
131
|
+
licenses:
|
132
|
+
- MIT
|
133
|
+
metadata:
|
134
|
+
source_code_uri: https://github.com/heyder/nessus_client
|
135
|
+
post_install_message:
|
136
|
+
rdoc_options: []
|
137
|
+
require_paths:
|
138
|
+
- lib
|
139
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: 2.5.1
|
144
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
requirements: []
|
150
|
+
rubygems_version: 3.0.3
|
151
|
+
signing_key:
|
152
|
+
specification_version: 4
|
153
|
+
summary: Ruby wrapper for Nessus API
|
154
|
+
test_files: []
|