openvas 0.2.1 → 0.3.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 +4 -4
- data/.rubocop.yml +5 -1
- data/.rubocop_todo.yml +0 -2
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/lib/openvas/reports.rb +1 -1
- data/lib/openvas/result.rb +55 -0
- data/lib/openvas/{scans.rb → scan.rb} +18 -18
- data/lib/openvas/version.rb +1 -1
- data/lib/openvas.rb +2 -2
- data/spec/openvas/scan_spec.rb +71 -0
- metadata +5 -5
- data/lib/openvas/results.rb +0 -53
- data/spec/openvas/scans_spec.rb +0 -61
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6094b62731b5348bd12957817944e7cefa4f1374
|
4
|
+
data.tar.gz: e3f959afb305df9725ea3dada3dd123e4831dcf3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94c12bb0387ca5ed328b63ec98a006264ccdee4c999b7d53314d4f07071f11d02d2f4795ab755183454ef7635f877011f3d6a472e0667c0a4eeb5ae413addfcf
|
7
|
+
data.tar.gz: 1268415590f0b935765e500605458b3bd878f18c851e6db4ca37d47119309585a0377dea851c9f7191f8bc9dc42c8971d8dd15aa07c95982c49e6f3ecde1fa62
|
data/.rubocop.yml
CHANGED
data/.rubocop_todo.yml
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
data/lib/openvas/reports.rb
CHANGED
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'time'
|
4
|
+
|
5
|
+
module Openvas
|
6
|
+
# Class used to interact with OpenVAS' scans results
|
7
|
+
class Result
|
8
|
+
attr_accessor :id, :name, :comment, :description, :host, :user, :port, :severity, :created_at, :updated_at
|
9
|
+
|
10
|
+
def initialize(result)
|
11
|
+
@id = result.at_xpath('@id').value
|
12
|
+
@name = result.at_xpath('name').text
|
13
|
+
@comment = result.at_xpath('comment').text
|
14
|
+
@user = result.at_xpath('owner/name').text
|
15
|
+
@host = result.at_xpath('host').text
|
16
|
+
@port = result.at_xpath('port').text
|
17
|
+
@severity = result.at_xpath('severity').text
|
18
|
+
@description = result.at_xpath('description').text
|
19
|
+
|
20
|
+
@created_at = Time.parse(result.at_xpath('creation_time').text)
|
21
|
+
@updated_at = Time.parse(result.at_xpath('modification_time').text)
|
22
|
+
end
|
23
|
+
|
24
|
+
def results
|
25
|
+
Openvas::Result.find_by_report_id(@id)
|
26
|
+
end
|
27
|
+
|
28
|
+
class << self
|
29
|
+
MAX_RESULTS = 1000
|
30
|
+
|
31
|
+
def all
|
32
|
+
# TODO: implement pagination
|
33
|
+
query = Nokogiri::XML::Builder.new { get_results(filter: "first=1 rows=#{MAX_RESULTS}") }
|
34
|
+
|
35
|
+
query(query).xpath('//get_results_response/result').map do |result|
|
36
|
+
new(result)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def find_by_id(id)
|
41
|
+
query = Nokogiri::XML::Builder.new { get_results(result_id: id) }
|
42
|
+
new(query(query).at_xpath('//get_results_response/result'))
|
43
|
+
end
|
44
|
+
|
45
|
+
def find_by_report_id(id)
|
46
|
+
# TODO: implement pagination
|
47
|
+
query = Nokogiri::XML::Builder.new { get_results(filter: "report_id=#{id} first=1 rows=#{MAX_RESULTS}") }
|
48
|
+
|
49
|
+
query(query).xpath('//get_results_response/result').map do |result|
|
50
|
+
new(result)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -3,21 +3,8 @@
|
|
3
3
|
require 'time'
|
4
4
|
|
5
5
|
module Openvas
|
6
|
-
|
7
|
-
|
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
|
6
|
+
# Class used to interact with OpenVAS' scans
|
7
|
+
class Scan < Client
|
21
8
|
attr_accessor :id, :name, :comment, :status, :target, :user, :created_at, :updated_at
|
22
9
|
|
23
10
|
def initialize(scan)
|
@@ -40,13 +27,26 @@ module Openvas
|
|
40
27
|
end
|
41
28
|
|
42
29
|
def last_results
|
43
|
-
Openvas::
|
30
|
+
Openvas::Result.find_by_report_id(@last_report_id)
|
44
31
|
end
|
45
32
|
|
46
33
|
def finished?
|
47
|
-
|
34
|
+
@status == 'Done'
|
35
|
+
end
|
36
|
+
|
37
|
+
class << self
|
38
|
+
def all
|
39
|
+
data = Nokogiri::XML::Builder.new { get_tasks }
|
48
40
|
|
49
|
-
|
41
|
+
query(data).xpath('//get_tasks_response/task').map do |scan|
|
42
|
+
new(scan)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def find_by_id(id)
|
47
|
+
data = Nokogiri::XML::Builder.new { get_tasks(task_id: id) }
|
48
|
+
new(query(data).at_xpath('//get_tasks_response/task'))
|
49
|
+
end
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|
data/lib/openvas/version.rb
CHANGED
data/lib/openvas.rb
CHANGED
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Openvas::Scan do
|
6
|
+
let(:scan) { Openvas::Scan.find_by_id('96625625-8e22-4b1c-9c65-4ddf80f78d20') }
|
7
|
+
|
8
|
+
describe '.all' do
|
9
|
+
before { allow(Openvas::Scan).to receive(:query).and_return(fixture_xml('openvas/scans/all.xml')) }
|
10
|
+
|
11
|
+
it 'list scans' do
|
12
|
+
expect(Openvas::Scan.all.count).to eq 2
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '.find_by_id' do
|
17
|
+
before { allow(Openvas::Scan).to receive(:query).and_return(fixture_xml('openvas/scans/find_by_id.xml')) }
|
18
|
+
|
19
|
+
it 'returns an Openvas::Scan object' do
|
20
|
+
expect(scan).to be_a(Openvas::Scan)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'retrieves the scan\'s id' do
|
24
|
+
expect(scan.id).to eq '96625625-8e22-4b1c-9c65-4ddf80f78d20'
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'retrieves the scan\'s name' do
|
28
|
+
expect(scan.name).to eq 'shellshock_01'
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'retrieves the scan\'s comment' do
|
32
|
+
expect(scan.comment).to be_empty
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'retrieves the scan\'s user' do
|
36
|
+
expect(scan.user).to eq 'admin'
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'retrieves the scan\'s status' do
|
40
|
+
expect(scan.status).to eq 'Done'
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'retrieves the scan\'s creation date' do
|
44
|
+
expect(scan.created_at.to_s).to eq '2017-12-11 16:40:16 UTC'
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'retrieves the scan\'s modification date' do
|
48
|
+
expect(scan.updated_at.to_s).to eq '2017-12-12 08:13:44 UTC'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#finished?' do
|
53
|
+
before { allow(Openvas::Scan).to receive(:query).and_return(fixture_xml('openvas/scans/find_by_id.xml')) }
|
54
|
+
|
55
|
+
context 'when the status is Done' do
|
56
|
+
before { scan.status = 'Done' }
|
57
|
+
|
58
|
+
it 'returns true' do
|
59
|
+
expect(scan.finished?).to be_truthy
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'when the status is not Done' do
|
64
|
+
before { scan.status = 'Running' }
|
65
|
+
|
66
|
+
it 'returns false' do
|
67
|
+
expect(scan.finished?).to be_falsey
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openvas
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Wininger
|
@@ -101,8 +101,8 @@ files:
|
|
101
101
|
- lib/openvas/client.rb
|
102
102
|
- lib/openvas/config.rb
|
103
103
|
- lib/openvas/reports.rb
|
104
|
-
- lib/openvas/
|
105
|
-
- lib/openvas/
|
104
|
+
- lib/openvas/result.rb
|
105
|
+
- lib/openvas/scan.rb
|
106
106
|
- lib/openvas/version.rb
|
107
107
|
- openvas.gemspec
|
108
108
|
- spec/fixtures/openvas/client/version.xml
|
@@ -110,7 +110,7 @@ files:
|
|
110
110
|
- spec/fixtures/openvas/scans/find_by_id.xml
|
111
111
|
- spec/openvas/auth_spec.rb
|
112
112
|
- spec/openvas/client_spec.rb
|
113
|
-
- spec/openvas/
|
113
|
+
- spec/openvas/scan_spec.rb
|
114
114
|
- spec/openvas_spec.rb
|
115
115
|
- spec/spec_helper.rb
|
116
116
|
homepage: https://github.com/Cyberwatch/ruby-openvas
|
@@ -143,6 +143,6 @@ test_files:
|
|
143
143
|
- spec/fixtures/openvas/scans/find_by_id.xml
|
144
144
|
- spec/openvas/auth_spec.rb
|
145
145
|
- spec/openvas/client_spec.rb
|
146
|
-
- spec/openvas/
|
146
|
+
- spec/openvas/scan_spec.rb
|
147
147
|
- spec/openvas_spec.rb
|
148
148
|
- spec/spec_helper.rb
|
data/lib/openvas/results.rb
DELETED
@@ -1,53 +0,0 @@
|
|
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
|
data/spec/openvas/scans_spec.rb
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Openvas::Scans do
|
6
|
-
describe '#all' do
|
7
|
-
before(:each) do
|
8
|
-
allow(Openvas::Scans).to receive(:query).and_return(fixture_xml('openvas/scans/all.xml'))
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'list scans' do
|
12
|
-
expect(Openvas::Scans.all.count).to eq 2
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
describe '#find_by_id' do
|
17
|
-
before(:each) do
|
18
|
-
allow(Openvas::Scans).to receive(:query).and_return(fixture_xml('openvas/scans/find_by_id.xml'))
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'get the version' do
|
22
|
-
expect(Openvas::Scans.find_by_id('96625625-8e22-4b1c-9c65-4ddf80f78d20')).to be_a(Openvas::Scan)
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'scan' do
|
26
|
-
let(:scan) { Openvas::Scans.find_by_id('96625625-8e22-4b1c-9c65-4ddf80f78d20') }
|
27
|
-
|
28
|
-
it '#id' do
|
29
|
-
expect(scan.id).to eq '96625625-8e22-4b1c-9c65-4ddf80f78d20'
|
30
|
-
end
|
31
|
-
|
32
|
-
it '#name' do
|
33
|
-
expect(scan.name).to eq 'shellshock_01'
|
34
|
-
end
|
35
|
-
|
36
|
-
it '#comment' do
|
37
|
-
expect(scan.comment).to eq ''
|
38
|
-
end
|
39
|
-
|
40
|
-
it '#user' do
|
41
|
-
expect(scan.user).to eq 'admin'
|
42
|
-
end
|
43
|
-
|
44
|
-
it '#status' do
|
45
|
-
expect(scan.status).to eq 'Done'
|
46
|
-
end
|
47
|
-
|
48
|
-
it '#finished' do
|
49
|
-
expect(scan.finished?).to be_truthy
|
50
|
-
end
|
51
|
-
|
52
|
-
it '#created_at' do
|
53
|
-
expect(scan.created_at.to_s).to eq '2017-12-11 16:40:16 UTC'
|
54
|
-
end
|
55
|
-
|
56
|
-
it '#updated_at' do
|
57
|
-
expect(scan.updated_at.to_s).to eq '2017-12-12 08:13:44 UTC'
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|