openvas 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +51 -0
- data/.rspec +2 -0
- data/.rubocop.yml +13 -0
- data/.rubocop_todo.yml +28 -0
- data/.travis.yml +13 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +73 -0
- data/LICENSE +21 -0
- data/README.md +123 -0
- data/Rakefile +18 -0
- data/lib/openvas/auth.rb +25 -0
- data/lib/openvas/client.rb +77 -0
- data/lib/openvas/config.rb +10 -0
- data/lib/openvas/reports.rb +37 -0
- data/lib/openvas/results.rb +53 -0
- data/lib/openvas/scans.rb +52 -0
- data/lib/openvas/version.rb +5 -0
- data/lib/openvas.rb +26 -0
- data/openvas.gemspec +30 -0
- data/spec/fixtures/openvas/client/version.xml +4 -0
- data/spec/openvas/client_spec.rb +15 -0
- data/spec/openvas_spec.rb +6 -0
- data/spec/spec_helper.rb +18 -0
- metadata +140 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 82164fc6425d0877dbf5cbff5de61ea444155e8f
|
|
4
|
+
data.tar.gz: 611bcc9ca8bc58cf38a81a56bef6350cb69223ea
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 236ea50cf8113e17ed9870f2dfe1a856dac4eb244b1d22014954036f1d85c9e0ce02065fa7726d6821e8edd8eaee6d21744694eb4087687ee4daac9dd11af81c
|
|
7
|
+
data.tar.gz: 13b7e6de70a8004aa94112c47a2a591b49d9ef300cf848fa0b4a835d76104e1e1c9847460174133435bb9312f8bed9652a2965e86b64cdf889debc067c3a2f99
|
data/.gitignore
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
*.gem
|
|
2
|
+
*.rbc
|
|
3
|
+
/.config
|
|
4
|
+
/coverage/
|
|
5
|
+
/InstalledFiles
|
|
6
|
+
/pkg/
|
|
7
|
+
/spec/reports/
|
|
8
|
+
/spec/examples.txt
|
|
9
|
+
/test/tmp/
|
|
10
|
+
/test/version_tmp/
|
|
11
|
+
/tmp/
|
|
12
|
+
|
|
13
|
+
# Used by dotenv library to load environment variables.
|
|
14
|
+
# .env
|
|
15
|
+
|
|
16
|
+
## Specific to RubyMotion:
|
|
17
|
+
.dat*
|
|
18
|
+
.repl_history
|
|
19
|
+
build/
|
|
20
|
+
*.bridgesupport
|
|
21
|
+
build-iPhoneOS/
|
|
22
|
+
build-iPhoneSimulator/
|
|
23
|
+
|
|
24
|
+
## Specific to RubyMotion (use of CocoaPods):
|
|
25
|
+
#
|
|
26
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
|
27
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
|
28
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
|
29
|
+
#
|
|
30
|
+
# vendor/Pods/
|
|
31
|
+
|
|
32
|
+
## Documentation cache and generated files:
|
|
33
|
+
/.yardoc/
|
|
34
|
+
/_yardoc/
|
|
35
|
+
/doc/
|
|
36
|
+
/rdoc/
|
|
37
|
+
|
|
38
|
+
## Environment normalization:
|
|
39
|
+
/.bundle/
|
|
40
|
+
/vendor/bundle
|
|
41
|
+
/lib/bundler/man/
|
|
42
|
+
|
|
43
|
+
# for a library or gem, you might want to ignore these files since the code is
|
|
44
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
45
|
+
# Gemfile.lock
|
|
46
|
+
# .ruby-version
|
|
47
|
+
# .ruby-gemset
|
|
48
|
+
|
|
49
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
|
50
|
+
.rvmrc
|
|
51
|
+
.idea
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.rubocop_todo.yml
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# This configuration was generated by
|
|
2
|
+
# `rubocop --auto-gen-config`
|
|
3
|
+
# on 2017-12-12 13:58:50 +0100 using RuboCop version 0.51.0.
|
|
4
|
+
# The point is for the user to remove these configuration records
|
|
5
|
+
# one by one as the offenses are removed from the code base.
|
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
|
8
|
+
|
|
9
|
+
# Offense count: 10
|
|
10
|
+
Style/Documentation:
|
|
11
|
+
Exclude:
|
|
12
|
+
- 'spec/**/*'
|
|
13
|
+
- 'test/**/*'
|
|
14
|
+
- 'lib/openvas.rb'
|
|
15
|
+
- 'lib/openvas/auth.rb'
|
|
16
|
+
- 'lib/openvas/client.rb'
|
|
17
|
+
- 'lib/openvas/config.rb'
|
|
18
|
+
- 'lib/openvas/reports.rb'
|
|
19
|
+
- 'lib/openvas/results.rb'
|
|
20
|
+
- 'lib/openvas/scans.rb'
|
|
21
|
+
|
|
22
|
+
# Offense count: 2
|
|
23
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
|
24
|
+
# SupportedStyles: module_function, extend_self
|
|
25
|
+
Style/ModuleFunction:
|
|
26
|
+
Exclude:
|
|
27
|
+
- 'lib/openvas.rb'
|
|
28
|
+
- 'lib/openvas/config.rb'
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
openvas (0.1.0)
|
|
5
|
+
nokogiri (~> 1.8)
|
|
6
|
+
|
|
7
|
+
GEM
|
|
8
|
+
remote: https://rubygems.org/
|
|
9
|
+
specs:
|
|
10
|
+
ast (2.3.0)
|
|
11
|
+
coveralls (0.8.21)
|
|
12
|
+
json (>= 1.8, < 3)
|
|
13
|
+
simplecov (~> 0.14.1)
|
|
14
|
+
term-ansicolor (~> 1.3)
|
|
15
|
+
thor (~> 0.19.4)
|
|
16
|
+
tins (~> 1.6)
|
|
17
|
+
diff-lcs (1.3)
|
|
18
|
+
docile (1.1.5)
|
|
19
|
+
json (2.1.0)
|
|
20
|
+
mini_portile2 (2.3.0)
|
|
21
|
+
nokogiri (1.8.1)
|
|
22
|
+
mini_portile2 (~> 2.3.0)
|
|
23
|
+
parallel (1.12.0)
|
|
24
|
+
parser (2.4.0.2)
|
|
25
|
+
ast (~> 2.3)
|
|
26
|
+
powerpack (0.1.1)
|
|
27
|
+
rainbow (3.0.0)
|
|
28
|
+
rake (12.3.0)
|
|
29
|
+
rspec (3.7.0)
|
|
30
|
+
rspec-core (~> 3.7.0)
|
|
31
|
+
rspec-expectations (~> 3.7.0)
|
|
32
|
+
rspec-mocks (~> 3.7.0)
|
|
33
|
+
rspec-core (3.7.0)
|
|
34
|
+
rspec-support (~> 3.7.0)
|
|
35
|
+
rspec-expectations (3.7.0)
|
|
36
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
37
|
+
rspec-support (~> 3.7.0)
|
|
38
|
+
rspec-mocks (3.7.0)
|
|
39
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
40
|
+
rspec-support (~> 3.7.0)
|
|
41
|
+
rspec-support (3.7.0)
|
|
42
|
+
rubocop (0.52.0)
|
|
43
|
+
parallel (~> 1.10)
|
|
44
|
+
parser (>= 2.4.0.2, < 3.0)
|
|
45
|
+
powerpack (~> 0.1)
|
|
46
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
47
|
+
ruby-progressbar (~> 1.7)
|
|
48
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
|
49
|
+
ruby-progressbar (1.9.0)
|
|
50
|
+
simplecov (0.14.1)
|
|
51
|
+
docile (~> 1.1.0)
|
|
52
|
+
json (>= 1.8, < 3)
|
|
53
|
+
simplecov-html (~> 0.10.0)
|
|
54
|
+
simplecov-html (0.10.2)
|
|
55
|
+
term-ansicolor (1.6.0)
|
|
56
|
+
tins (~> 1.0)
|
|
57
|
+
thor (0.19.4)
|
|
58
|
+
tins (1.16.3)
|
|
59
|
+
unicode-display_width (1.3.0)
|
|
60
|
+
|
|
61
|
+
PLATFORMS
|
|
62
|
+
ruby
|
|
63
|
+
|
|
64
|
+
DEPENDENCIES
|
|
65
|
+
bundler (~> 1.16)
|
|
66
|
+
coveralls
|
|
67
|
+
openvas!
|
|
68
|
+
rake (~> 12.3)
|
|
69
|
+
rspec (~> 3.7)
|
|
70
|
+
rubocop (~> 0.52)
|
|
71
|
+
|
|
72
|
+
BUNDLED WITH
|
|
73
|
+
1.16.0
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 Cyberwatch
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# Ruby OpenVas
|
|
2
|
+
|
|
3
|
+
[](https://travis-ci.org/Cyberwatch/ruby-openvas)
|
|
4
|
+
[](https://coveralls.io/github/Cyberwatch/ruby-openvas?branch=master)
|
|
5
|
+
|
|
6
|
+
A ruby client for OpenVas API OMP 7.0.
|
|
7
|
+
|
|
8
|
+
## Description
|
|
9
|
+
|
|
10
|
+
Ruby-Openvas is a ruby interface for OpenVas vulnerability scanner.
|
|
11
|
+
Please remember to submit bugs and request features if needed.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
gem install openvas
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
- Configure the gem
|
|
22
|
+
|
|
23
|
+
```ruby
|
|
24
|
+
require 'openvas'
|
|
25
|
+
|
|
26
|
+
Openvas.configure do |config|
|
|
27
|
+
config.url = "https://localhost:9390"
|
|
28
|
+
config.username = "admin"
|
|
29
|
+
config.password = "admin"
|
|
30
|
+
end
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
- Connect the client to OpenVas
|
|
34
|
+
|
|
35
|
+
```ruby
|
|
36
|
+
Openvas::Client.connect
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
- Authenticate to Openvas
|
|
40
|
+
|
|
41
|
+
```ruby
|
|
42
|
+
Openvas::Auth.login
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
- Retrive all scans and list the results
|
|
46
|
+
|
|
47
|
+
```ruby
|
|
48
|
+
Openvas::Scans.all.each do |scan|
|
|
49
|
+
puts 'Scan Name : ' + scan.name
|
|
50
|
+
puts '-'*40
|
|
51
|
+
scan.last_results.each do |result|
|
|
52
|
+
puts "\t- " +result.name
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
puts "-"*40
|
|
56
|
+
end
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
Scan Name : my vulnerable server
|
|
61
|
+
----------------------------------------
|
|
62
|
+
- Apache Web Server Version Detection
|
|
63
|
+
- Apache Web Server Version Detection
|
|
64
|
+
- CGI Scanning Consolidation
|
|
65
|
+
- CGI Scanning Consolidation
|
|
66
|
+
- Check open ports
|
|
67
|
+
- CPE Inventory
|
|
68
|
+
- Database Open Access Vulnerability
|
|
69
|
+
- Determine which version of BIND name daemon is running
|
|
70
|
+
- DIRB (NASL wrapper)
|
|
71
|
+
- DIRB (NASL wrapper)
|
|
72
|
+
- DNS Server Detection (TCP)
|
|
73
|
+
- HTTP Security Headers Detection
|
|
74
|
+
- HTTP Server type and version
|
|
75
|
+
- HTTP Server type and version
|
|
76
|
+
- ICMP Timestamp Detection
|
|
77
|
+
- MySQL/MariaDB Detection
|
|
78
|
+
- Nikto (NASL wrapper)
|
|
79
|
+
- Nikto (NASL wrapper)
|
|
80
|
+
- No 404 check
|
|
81
|
+
- OS Detection Consolidation and Reporting
|
|
82
|
+
- PHP Version Detection (Remote)
|
|
83
|
+
- robot(s).txt exists on the Web Server
|
|
84
|
+
- Service Detection with nmap
|
|
85
|
+
- Services
|
|
86
|
+
- Services
|
|
87
|
+
- Services
|
|
88
|
+
- Services
|
|
89
|
+
- Services
|
|
90
|
+
- Services
|
|
91
|
+
- SSH Protocol Algorithms Supported
|
|
92
|
+
- SSH Protocol Versions Supported
|
|
93
|
+
- SSH Server type and version
|
|
94
|
+
- SSH Weak Encryption Algorithms Supported
|
|
95
|
+
- SSH Weak MAC Algorithms Supported
|
|
96
|
+
- SSL/TLS: Collect and Report Certificate Details
|
|
97
|
+
- SSL/TLS: Report Medium Cipher Suites
|
|
98
|
+
- SSL/TLS: Report Non Weak Cipher Suites
|
|
99
|
+
- SSL/TLS: Report Perfect Forward Secrecy (PFS) Cipher Suites
|
|
100
|
+
- SSL/TLS: Report Supported Cipher Suites
|
|
101
|
+
- SSL/TLS: Report Vulnerable Cipher Suites for HTTPS
|
|
102
|
+
- TCP timestamps
|
|
103
|
+
- Traceroute
|
|
104
|
+
----------------------------------------
|
|
105
|
+
Scan Name : test
|
|
106
|
+
----------------------------------------
|
|
107
|
+
- Ping Host
|
|
108
|
+
----------------------------------------
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Requirements
|
|
112
|
+
|
|
113
|
+
- Ruby >= 2.3
|
|
114
|
+
- Nokogiri http://github.com/tenderlove/nokogiri
|
|
115
|
+
|
|
116
|
+
## Note on Patches & Pull Requests
|
|
117
|
+
|
|
118
|
+
Pull Request are very welcome. Please fork the project, make your feature addition or bug fix
|
|
119
|
+
and send a pull request.
|
|
120
|
+
|
|
121
|
+
## Copyright
|
|
122
|
+
|
|
123
|
+
Copyright (c) 2017 Cyberwatch. See LICENSE for details.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'bundler/gem_tasks'
|
|
4
|
+
require 'rspec/core/rake_task'
|
|
5
|
+
|
|
6
|
+
task default: :test
|
|
7
|
+
|
|
8
|
+
RSpec::Core::RakeTask.new do |spec|
|
|
9
|
+
spec.verbose = false
|
|
10
|
+
spec.pattern = './spec/{*/**/}*_spec.rb'
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
task :test do
|
|
14
|
+
ENV['RACK_ENV'] = 'test'
|
|
15
|
+
|
|
16
|
+
require './spec/spec_helper'
|
|
17
|
+
Rake::Task['spec'].invoke
|
|
18
|
+
end
|
data/lib/openvas/auth.rb
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'nokogiri'
|
|
4
|
+
|
|
5
|
+
module Openvas
|
|
6
|
+
class Auth < Client
|
|
7
|
+
class InvalidLogin < StandardError; end
|
|
8
|
+
|
|
9
|
+
# Do Login
|
|
10
|
+
def self.login
|
|
11
|
+
content = Nokogiri::XML::Builder.new do |xml|
|
|
12
|
+
xml.authenticate do
|
|
13
|
+
xml.credentials do
|
|
14
|
+
xml.username Openvas::Config.username
|
|
15
|
+
xml.password Openvas::Config.password
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
query(content)
|
|
21
|
+
|
|
22
|
+
true
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'uri'
|
|
4
|
+
require 'socket'
|
|
5
|
+
require 'openssl'
|
|
6
|
+
|
|
7
|
+
module Openvas
|
|
8
|
+
class Client
|
|
9
|
+
class InvalidUrlConfigError < StandardError; end
|
|
10
|
+
class QueryError < StandardError; end
|
|
11
|
+
|
|
12
|
+
# buffer size for socket
|
|
13
|
+
BLOCK_SIZE = 1024 * 16
|
|
14
|
+
|
|
15
|
+
# Connect the websocket
|
|
16
|
+
def self.connect
|
|
17
|
+
# Retrieve URI
|
|
18
|
+
raise InvalidUrlConfigError, 'Please Configure the client before' unless Openvas::Config.url
|
|
19
|
+
|
|
20
|
+
uri = URI.parse(Openvas::Config.url)
|
|
21
|
+
|
|
22
|
+
plain_socket = TCPSocket.open(uri.host, uri.port)
|
|
23
|
+
self.socket = OpenSSL::SSL::SSLSocket.new(plain_socket, OpenSSL::SSL::SSLContext.new)
|
|
24
|
+
|
|
25
|
+
# Enable to close socket and SSL layer together
|
|
26
|
+
socket.sync_close = true
|
|
27
|
+
socket.connect
|
|
28
|
+
|
|
29
|
+
true
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def self.disconnect
|
|
33
|
+
return unless socket
|
|
34
|
+
socket.close
|
|
35
|
+
self.socket = nil
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def self.version
|
|
39
|
+
query = Nokogiri::XML::Builder.new { get_version }
|
|
40
|
+
query(query).at_xpath('/get_version_response/version').text
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def self.query(data)
|
|
44
|
+
res = Nokogiri::XML(send_receive(data.to_xml))
|
|
45
|
+
|
|
46
|
+
raise QueryError 'Unknown query error' unless res.at_xpath('//@status')&.value == '200'
|
|
47
|
+
|
|
48
|
+
res
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Private class methods
|
|
52
|
+
class << self
|
|
53
|
+
private
|
|
54
|
+
|
|
55
|
+
# send_receive data
|
|
56
|
+
def send_receive(send)
|
|
57
|
+
socket.syswrite(send)
|
|
58
|
+
|
|
59
|
+
buffer = ''
|
|
60
|
+
loop do
|
|
61
|
+
last_part = socket.sysread(BLOCK_SIZE)
|
|
62
|
+
buffer += last_part
|
|
63
|
+
break if last_part.size < BLOCK_SIZE
|
|
64
|
+
end
|
|
65
|
+
buffer
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def socket
|
|
69
|
+
Openvas::Config.socket
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def socket=(socket)
|
|
73
|
+
Openvas::Config.socket = socket
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'time'
|
|
4
|
+
|
|
5
|
+
module Openvas
|
|
6
|
+
class Reports < Client
|
|
7
|
+
def self.all
|
|
8
|
+
query = Nokogiri::XML::Builder.new { get_reports }
|
|
9
|
+
query(query).xpath('//get_reports_response/report').map do |report|
|
|
10
|
+
Openvas::Report.new(report)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.find_by_id(id)
|
|
15
|
+
query = Nokogiri::XML::Builder.new { get_reports(report_id: id) }
|
|
16
|
+
Openvas::Report.new(query(query).at_xpath('//get_reports_response/report'))
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
class Report
|
|
21
|
+
attr_accessor :id, :name, :comment, :created_at, :updated_at
|
|
22
|
+
|
|
23
|
+
def initialize(report)
|
|
24
|
+
@id = report.at_xpath('@id').value
|
|
25
|
+
@name = report.at_xpath('name').text
|
|
26
|
+
@comment = report.at_xpath('comment').text
|
|
27
|
+
@user = report.at_xpath('owner/name').text
|
|
28
|
+
|
|
29
|
+
@created_at = Time.parse(report.at_xpath('creation_time').text)
|
|
30
|
+
@updated_at = Time.parse(report.at_xpath('modification_time').text)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def results
|
|
34
|
+
Openvas::Results.find_by_report_id(@id)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'time'
|
|
4
|
+
|
|
5
|
+
module Openvas
|
|
6
|
+
class Results < Client
|
|
7
|
+
MAX_RESULTS = 1000
|
|
8
|
+
|
|
9
|
+
def self.all
|
|
10
|
+
# TODO: implement pagination
|
|
11
|
+
query = Nokogiri::XML::Builder.new { get_results(filter: "first=1 rows=#{MAX_RESULTS}") }
|
|
12
|
+
query(query).xpath('//get_results_response/result').map do |result|
|
|
13
|
+
Openvas::Result.new(result)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.find_by_id(id)
|
|
18
|
+
query = Nokogiri::XML::Builder.new { get_results(result_id: id) }
|
|
19
|
+
Openvas::Result.new(query(query).at_xpath('//get_results_response/result'))
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.find_by_report_id(id)
|
|
23
|
+
# TODO: implement pagination
|
|
24
|
+
query = Nokogiri::XML::Builder.new { get_results(filter: "report_id=#{id} first=1 rows=#{MAX_RESULTS}") }
|
|
25
|
+
|
|
26
|
+
query(query).xpath('//get_results_response/result').map do |result|
|
|
27
|
+
Openvas::Result.new(result)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
class Result
|
|
33
|
+
attr_accessor :id, :name, :comment, :description, :host, :user, :port, :severity, :created_at, :updated_at
|
|
34
|
+
|
|
35
|
+
def initialize(result)
|
|
36
|
+
@id = result.at_xpath('@id').value
|
|
37
|
+
@name = result.at_xpath('name').text
|
|
38
|
+
@comment = result.at_xpath('comment').text
|
|
39
|
+
@user = result.at_xpath('owner/name').text
|
|
40
|
+
@host = result.at_xpath('host').text
|
|
41
|
+
@port = result.at_xpath('port').text
|
|
42
|
+
@severity = result.at_xpath('severity').text
|
|
43
|
+
@description = result.at_xpath('description').text
|
|
44
|
+
|
|
45
|
+
@created_at = Time.parse(result.at_xpath('creation_time').text)
|
|
46
|
+
@updated_at = Time.parse(result.at_xpath('modification_time').text)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def results
|
|
50
|
+
Openvas::Results.find_by_report_id(@id)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'time'
|
|
4
|
+
|
|
5
|
+
module Openvas
|
|
6
|
+
class Scans < Client
|
|
7
|
+
def self.all
|
|
8
|
+
query = Nokogiri::XML::Builder.new { get_tasks }
|
|
9
|
+
query(query).xpath('//get_tasks_response/task').map do |scan|
|
|
10
|
+
Openvas::Scan.new(scan)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.find_by_id(id)
|
|
15
|
+
query = Nokogiri::XML::Builder.new { get_tasks(task_id: id) }
|
|
16
|
+
Openvas::Scan.new(query(query).at_xpath('//get_tasks_response/task'))
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
class Scan
|
|
21
|
+
attr_accessor :id, :name, :comment, :status, :target, :created_at, :updated_at
|
|
22
|
+
|
|
23
|
+
def initialize(scan)
|
|
24
|
+
@id = scan.at_xpath('@id').value
|
|
25
|
+
@name = scan.at_xpath('name').text
|
|
26
|
+
@comment = scan.at_xpath('comment').text
|
|
27
|
+
@user = scan.at_xpath('owner/name').text
|
|
28
|
+
|
|
29
|
+
@status = scan.at_xpath('status').text
|
|
30
|
+
@target = scan.at_xpath('target')&.first_element_child&.text
|
|
31
|
+
|
|
32
|
+
@created_at = Time.parse(scan.at_xpath('creation_time').text)
|
|
33
|
+
@updated_at = Time.parse(scan.at_xpath('modification_time').text)
|
|
34
|
+
|
|
35
|
+
@last_report_id = scan.at_xpath('last_report/report/@id')&.value
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def last_report
|
|
39
|
+
Openvas::Reports.find_by_id(@last_report_id)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def last_results
|
|
43
|
+
Openvas::Results.find_by_report_id(@last_report_id)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def finished?
|
|
47
|
+
return true if @status.eql? 'Done'
|
|
48
|
+
|
|
49
|
+
false
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
data/lib/openvas.rb
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'openvas/version'
|
|
4
|
+
|
|
5
|
+
require 'openvas/config'
|
|
6
|
+
require 'openvas/client'
|
|
7
|
+
require 'openvas/auth'
|
|
8
|
+
|
|
9
|
+
require 'openvas/scans'
|
|
10
|
+
require 'openvas/reports'
|
|
11
|
+
require 'openvas/results'
|
|
12
|
+
|
|
13
|
+
module Openvas
|
|
14
|
+
module_function
|
|
15
|
+
|
|
16
|
+
def configure
|
|
17
|
+
block_given? ? yield(Config) : Config
|
|
18
|
+
%w[url username password].each do |key|
|
|
19
|
+
next unless Openvas::Config.instance_variable_get("@#{key}").nil?
|
|
20
|
+
raise Openvas::Config::RequiredOptionMissing,
|
|
21
|
+
"Configuration parameter missing: '#{key}'. " \
|
|
22
|
+
'Please add it to the Openvas.configure block'
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
alias config configure
|
|
26
|
+
end
|
data/openvas.gemspec
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
|
+
require 'openvas/version'
|
|
6
|
+
|
|
7
|
+
Gem::Specification.new do |s|
|
|
8
|
+
s.name = 'openvas'
|
|
9
|
+
s.version = Openvas::VERSION
|
|
10
|
+
s.date = '2017-12-25'
|
|
11
|
+
s.summary = 'Openvas API Client (OMP 7.0)'
|
|
12
|
+
s.description = 'Easily interface with the Openvas for consuming results'
|
|
13
|
+
s.authors = ['Florian Wininger']
|
|
14
|
+
s.email = 'fw.centrale@gmail.com'
|
|
15
|
+
s.homepage = 'https://github.com/Cyberwatch/ruby-openvas'
|
|
16
|
+
|
|
17
|
+
s.license = 'MIT'
|
|
18
|
+
|
|
19
|
+
s.require_paths = ['lib']
|
|
20
|
+
s.files = `git ls-files -z`.split("\x0")
|
|
21
|
+
# s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
22
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
|
23
|
+
|
|
24
|
+
s.add_dependency 'nokogiri', '~> 1.8'
|
|
25
|
+
|
|
26
|
+
s.add_development_dependency 'bundler', '~> 1.16'
|
|
27
|
+
s.add_development_dependency 'rake', '~> 12.3'
|
|
28
|
+
s.add_development_dependency 'rspec', '~> 3.7'
|
|
29
|
+
s.add_development_dependency 'rubocop', '~> 0.52'
|
|
30
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Openvas::Client do
|
|
6
|
+
describe '#version' do
|
|
7
|
+
before(:each) do
|
|
8
|
+
allow(Openvas::Client).to receive(:query).and_return(fixture_xml('openvas/client/version.xml'))
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it 'get the version' do
|
|
12
|
+
expect(Openvas::Client.version).to eq '7.0'
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'coveralls'
|
|
4
|
+
Coveralls.wear!
|
|
5
|
+
|
|
6
|
+
require 'openvas'
|
|
7
|
+
|
|
8
|
+
def fixture(path)
|
|
9
|
+
File.open(File.dirname(__FILE__) + '/fixtures/' + path).read
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def fixture_xml(path)
|
|
13
|
+
Nokogiri::XML(fixture(path))
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def fixture_query(path)
|
|
17
|
+
Nokogiri::XML(fixture(path))
|
|
18
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: openvas
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Florian Wininger
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2017-12-25 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: nokogiri
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.8'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.8'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: bundler
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '1.16'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '1.16'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rake
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '12.3'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '12.3'
|
|
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.7'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '3.7'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rubocop
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0.52'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0.52'
|
|
83
|
+
description: Easily interface with the Openvas for consuming results
|
|
84
|
+
email: fw.centrale@gmail.com
|
|
85
|
+
executables: []
|
|
86
|
+
extensions: []
|
|
87
|
+
extra_rdoc_files: []
|
|
88
|
+
files:
|
|
89
|
+
- ".gitignore"
|
|
90
|
+
- ".rspec"
|
|
91
|
+
- ".rubocop.yml"
|
|
92
|
+
- ".rubocop_todo.yml"
|
|
93
|
+
- ".travis.yml"
|
|
94
|
+
- Gemfile
|
|
95
|
+
- Gemfile.lock
|
|
96
|
+
- LICENSE
|
|
97
|
+
- README.md
|
|
98
|
+
- Rakefile
|
|
99
|
+
- lib/openvas.rb
|
|
100
|
+
- lib/openvas/auth.rb
|
|
101
|
+
- lib/openvas/client.rb
|
|
102
|
+
- lib/openvas/config.rb
|
|
103
|
+
- lib/openvas/reports.rb
|
|
104
|
+
- lib/openvas/results.rb
|
|
105
|
+
- lib/openvas/scans.rb
|
|
106
|
+
- lib/openvas/version.rb
|
|
107
|
+
- openvas.gemspec
|
|
108
|
+
- spec/fixtures/openvas/client/version.xml
|
|
109
|
+
- spec/openvas/client_spec.rb
|
|
110
|
+
- spec/openvas_spec.rb
|
|
111
|
+
- spec/spec_helper.rb
|
|
112
|
+
homepage: https://github.com/Cyberwatch/ruby-openvas
|
|
113
|
+
licenses:
|
|
114
|
+
- MIT
|
|
115
|
+
metadata: {}
|
|
116
|
+
post_install_message:
|
|
117
|
+
rdoc_options: []
|
|
118
|
+
require_paths:
|
|
119
|
+
- lib
|
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
121
|
+
requirements:
|
|
122
|
+
- - ">="
|
|
123
|
+
- !ruby/object:Gem::Version
|
|
124
|
+
version: '0'
|
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
|
+
requirements:
|
|
127
|
+
- - ">="
|
|
128
|
+
- !ruby/object:Gem::Version
|
|
129
|
+
version: '0'
|
|
130
|
+
requirements: []
|
|
131
|
+
rubyforge_project:
|
|
132
|
+
rubygems_version: 2.6.14
|
|
133
|
+
signing_key:
|
|
134
|
+
specification_version: 4
|
|
135
|
+
summary: Openvas API Client (OMP 7.0)
|
|
136
|
+
test_files:
|
|
137
|
+
- spec/fixtures/openvas/client/version.xml
|
|
138
|
+
- spec/openvas/client_spec.rb
|
|
139
|
+
- spec/openvas_spec.rb
|
|
140
|
+
- spec/spec_helper.rb
|