openvas-cli 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.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +18 -0
- data/Gemfile.lock +50 -0
- data/LICENSE.txt +250 -0
- data/README.rdoc +26 -0
- data/Rakefile +65 -0
- data/VERSION +1 -0
- data/features/openvas-cli.feature +9 -0
- data/features/step_definitions/openvas-cli_steps.rb +0 -0
- data/features/support/env.rb +13 -0
- data/lib/openvas-cli/oid_validator.rb +10 -0
- data/lib/openvas-cli/openvas-cli.rb +273 -0
- data/lib/openvas-cli/uuid_validator.rb +9 -0
- data/lib/openvas-cli/vas_base.rb +40 -0
- data/lib/openvas-cli/vas_exceptions.rb +8 -0
- data/lib/openvas-cli/vas_nvt.rb +70 -0
- data/lib/openvas-cli/vas_nvt_family.rb +37 -0
- data/lib/openvas-cli/vas_override.rb +7 -0
- data/lib/openvas-cli/vas_preference.rb +59 -0
- data/lib/openvas-cli/vas_report.rb +118 -0
- data/lib/openvas-cli/vas_result.rb +102 -0
- data/lib/openvas-cli/vas_schedule.rb +63 -0
- data/lib/openvas-cli/vas_target.rb +28 -0
- data/lib/openvas-cli/vas_task.rb +36 -0
- data/openvas-cli.gemspec +138 -0
- data/spec/openvas-cli/openvas-cli_spec.rb +45 -0
- data/spec/openvas-cli/vas_nvt_family_spec.rb +9 -0
- data/spec/openvas-cli/vas_nvt_spec.rb +32 -0
- data/spec/openvas-cli/vas_preference_spec.rb +26 -0
- data/spec/openvas-cli/vas_report_spec.rb +75 -0
- data/spec/openvas-cli/vas_result_spec.rb +109 -0
- data/spec/openvas-cli/vas_schedule_spec.rb +61 -0
- data/spec/openvas-cli/vas_target_spec.rb +39 -0
- data/spec/openvas-cli/vas_task_spec.rb +19 -0
- data/spec/spec_helper.rb +30 -0
- metadata +387 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
|
+
require 'nokogiri'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
describe "OpenvasCli" do
|
|
6
|
+
before(:all) do
|
|
7
|
+
@cli = OpenvasCli.new
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
after(:all) do
|
|
11
|
+
@cli.close
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it 'should create a valid instance with the provided credentials' do
|
|
15
|
+
#handled in the before(:all) block
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it 'should pull rule definitions', :slow => true do
|
|
19
|
+
defs = @cli.get_rule_defs
|
|
20
|
+
defs.count.should > 0
|
|
21
|
+
|
|
22
|
+
defs.each { |d|
|
|
23
|
+
d.oid.should_not be nil
|
|
24
|
+
d.name.should_not be nil
|
|
25
|
+
d.name.length.should > 0
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it 'should throw a command exception' do
|
|
31
|
+
bad_msg = Nokogiri::XML::Builder.new { |xml|
|
|
32
|
+
xml.foo
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
lambda {@cli.send_receive(bad_msg.doc)}.should raise_error(VasExceptions::CommandException)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it 'should throw a CommunicationException' do
|
|
39
|
+
bad_msg = Nokogiri::XML::Builder.new { |xml|
|
|
40
|
+
xml.get_schedules(:details => '1', :sort_field => 'next_time')
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
lambda {@cli.send_receive(bad_msg.doc)}.should raise_error(VasExceptions::CommunicationException)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
|
+
|
|
3
|
+
describe VasNVT do
|
|
4
|
+
it 'should pull NVT`s', :slow => true do
|
|
5
|
+
rules = VasNVT.get_all
|
|
6
|
+
rules.should_not be nil
|
|
7
|
+
rules.count.should > 0
|
|
8
|
+
rules.each{ |r| r.should be_valid }
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it 'should pull an NVT by OID' do
|
|
12
|
+
rule = VasNVT.get_all(:oid => '1.3.6.1.4.1.25623.1.0.902230')
|
|
13
|
+
rule.should_not be nil
|
|
14
|
+
rule.count.should == 1
|
|
15
|
+
|
|
16
|
+
rule[0].should be_valid
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'should pull an NVT by Family' do
|
|
20
|
+
fams = VasNVTFamily.get_all
|
|
21
|
+
|
|
22
|
+
my_fam = fams[rand(fams.count)]
|
|
23
|
+
|
|
24
|
+
rules = VasNVT.get_all(:family => my_fam.name)
|
|
25
|
+
rules.should_not be nil
|
|
26
|
+
rules.count.should == my_fam.nvt_count
|
|
27
|
+
rules.each { |r|
|
|
28
|
+
r.should be_valid
|
|
29
|
+
r.family.should == my_fam.name
|
|
30
|
+
}
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
|
+
|
|
3
|
+
describe VasPreference do
|
|
4
|
+
it 'should pull all preferences' do
|
|
5
|
+
preferences = VasPreference.get_all
|
|
6
|
+
preferences.should_not be nil
|
|
7
|
+
|
|
8
|
+
preferences.each { |p|
|
|
9
|
+
p.should be_valid
|
|
10
|
+
}
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it 'should pull a single preference by name' do
|
|
14
|
+
all = VasPreference.get_all
|
|
15
|
+
|
|
16
|
+
o_pref = all[rand(all.count)]
|
|
17
|
+
o_pref.should_not be nil
|
|
18
|
+
|
|
19
|
+
n_pref = VasPreference.get_all(:name=>o_pref.name)[0]
|
|
20
|
+
n_pref.should_not be nil
|
|
21
|
+
|
|
22
|
+
o_pref.name.should == n_pref.name
|
|
23
|
+
o_pref.value.should == n_pref.value
|
|
24
|
+
o_pref.config_id.should == n_pref.config_id
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
|
+
require 'nokogiri'
|
|
3
|
+
|
|
4
|
+
describe "VasReport" do
|
|
5
|
+
it "should pull all available reports" do
|
|
6
|
+
repts = VasReport.get_all
|
|
7
|
+
|
|
8
|
+
repts.should_not be nil
|
|
9
|
+
|
|
10
|
+
repts.each { |r| r.should be_valid }
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it 'should pull a raw XML dump for a single report' do
|
|
14
|
+
rept = VasReport.get_all[0]
|
|
15
|
+
|
|
16
|
+
xml = rept.to_xml
|
|
17
|
+
|
|
18
|
+
xdoc = Nokogiri::XML(xml) #it should be a valid xml document
|
|
19
|
+
|
|
20
|
+
xdoc.at_xpath("//report/@id").value.should == rept.report_id
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'should pull a specific report by id' do
|
|
24
|
+
all = VasReport.get_all
|
|
25
|
+
|
|
26
|
+
o_rept = all[rand(all.count)]
|
|
27
|
+
o_rept.should_not be nil
|
|
28
|
+
n_rept = VasReport.get_all(:report_id => o_rept.report_id)[0]
|
|
29
|
+
n_rept.should_not be nil
|
|
30
|
+
|
|
31
|
+
o_rept.report_id.should == n_rept.report_id
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it 'should report the associated results' do
|
|
35
|
+
all = VasReport.get_all
|
|
36
|
+
|
|
37
|
+
all.each { |r|
|
|
38
|
+
r.result_count[:filtered].should == r.results.count
|
|
39
|
+
}
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it 'should filter the results' do
|
|
43
|
+
all = VasReport.get_all(:filter => [:high])
|
|
44
|
+
|
|
45
|
+
all.each { |report|
|
|
46
|
+
report.results.each{ |result|
|
|
47
|
+
result.threat.should =~ /high/i
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
all = VasReport.get_all(:filter => [:log])
|
|
52
|
+
|
|
53
|
+
all.each { |report|
|
|
54
|
+
report.results.each{ |result|
|
|
55
|
+
result.threat.should =~ /log/i
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
all = VasReport.get_all(:filter => [:medium, :debug, :low])
|
|
60
|
+
|
|
61
|
+
all.each { |report|
|
|
62
|
+
report.results.each{ |result|
|
|
63
|
+
result.threat.should =~ /(medium)|(debug)|(low)/i
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it 'should return an empty set when passed a bad report_id' do
|
|
69
|
+
lambda {
|
|
70
|
+
r = VasReport.get_all(:report_id => '0000000000')
|
|
71
|
+
r.should_not be nil
|
|
72
|
+
r.should be_empty
|
|
73
|
+
}.should_not raise_error
|
|
74
|
+
end
|
|
75
|
+
end
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
|
+
|
|
3
|
+
describe 'VasResult' do
|
|
4
|
+
it 'should pull all results' do
|
|
5
|
+
all_results = VasResult.get_all
|
|
6
|
+
|
|
7
|
+
all_results.should_not be nil
|
|
8
|
+
|
|
9
|
+
all_results.count.should > 0
|
|
10
|
+
|
|
11
|
+
all_results.each { |r| r.should be_valid }
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it 'should be able to paginate results', :slow=>true do
|
|
15
|
+
result_count = VasResult.get_all.count
|
|
16
|
+
|
|
17
|
+
start = 0
|
|
18
|
+
num = 20
|
|
19
|
+
|
|
20
|
+
while start < result_count do
|
|
21
|
+
results = VasResult.get_all(:start => start, :count => num)
|
|
22
|
+
|
|
23
|
+
results.count.should <= 20
|
|
24
|
+
|
|
25
|
+
start += results.count
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it 'should sort by threat by default' do
|
|
30
|
+
results = VasResult.get_all
|
|
31
|
+
|
|
32
|
+
last_val = 9
|
|
33
|
+
results.each { |r|
|
|
34
|
+
r.threat_level.should <= last_val
|
|
35
|
+
last_val = r.threat_level
|
|
36
|
+
}
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it 'should sort the results by ID' do
|
|
40
|
+
results = VasResult.get_all(:sort_by => :result_id)
|
|
41
|
+
|
|
42
|
+
last_id = ""
|
|
43
|
+
results.each { |r|
|
|
44
|
+
r.result_id.should >= last_id
|
|
45
|
+
last_id = r.result_id
|
|
46
|
+
}
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it 'should sort the results by host' do
|
|
50
|
+
results = VasResult.get_all(:sort_by => :host)
|
|
51
|
+
|
|
52
|
+
last_host = ""
|
|
53
|
+
results.each { |r|
|
|
54
|
+
r.host.should >= last_host
|
|
55
|
+
last_host = r.host
|
|
56
|
+
}
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it 'should sort the results by rule_id' do
|
|
60
|
+
results = VasResult.get_all(:sort_by => :rule_id)
|
|
61
|
+
|
|
62
|
+
last_val = ""
|
|
63
|
+
results.each { |r|
|
|
64
|
+
r.rule_id.should >= last_val
|
|
65
|
+
last_val = r.rule_id
|
|
66
|
+
}
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it 'should sort the results by subnet' do
|
|
70
|
+
results = VasResult.get_all(:sort_by => :subnet)
|
|
71
|
+
|
|
72
|
+
last_val = ""
|
|
73
|
+
results.each { |r|
|
|
74
|
+
r.subnet.should >= last_val
|
|
75
|
+
last_val = r.subnet
|
|
76
|
+
}
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it 'should sort the results by threat' do
|
|
80
|
+
results = VasResult.get_all(:sort_by => :threat)
|
|
81
|
+
|
|
82
|
+
last_val = 9
|
|
83
|
+
results.each { |r|
|
|
84
|
+
r.threat_level.should <= last_val
|
|
85
|
+
last_val = r.threat_level
|
|
86
|
+
}
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
it 'shoudl pull results for a specified task' do
|
|
90
|
+
tasks = VasTask.get_all
|
|
91
|
+
|
|
92
|
+
tasks.count.should > 0
|
|
93
|
+
task_id = tasks[0].task_id
|
|
94
|
+
results = VasResult.get_all(:task_id => task_id)
|
|
95
|
+
results.each { |r| r.task_id.should == task_id }
|
|
96
|
+
|
|
97
|
+
all_tasks = VasResult.get_all
|
|
98
|
+
|
|
99
|
+
all_tasks.count.should >= results.count
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
it 'should filter based off of threat level' do
|
|
103
|
+
results = VasResult.get_all(:filter=>[:high, :medium])
|
|
104
|
+
threats = ["High", "Medium"]
|
|
105
|
+
results.each { |r|
|
|
106
|
+
threats.should include r.threat
|
|
107
|
+
}
|
|
108
|
+
end
|
|
109
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
|
+
|
|
3
|
+
describe 'VasSchedule' do
|
|
4
|
+
it 'should pull all available schedules' do
|
|
5
|
+
schedules = VasSchedule.get_all
|
|
6
|
+
schedules.should_not be nil
|
|
7
|
+
schedules.count.should > 0
|
|
8
|
+
schedules.each{ |s| s.should be_valid }
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it 'should pull a schedule by ID' do
|
|
12
|
+
all = VasSchedule.get_all
|
|
13
|
+
all.should_not be nil
|
|
14
|
+
all.count.should > 0
|
|
15
|
+
|
|
16
|
+
schedule_id = all[rand(all.count)].schedule_id
|
|
17
|
+
schedules = VasSchedule.get_all(:schedule_id => schedule_id)
|
|
18
|
+
schedules.count.should == 1
|
|
19
|
+
schedules[0].schedule_id.should == schedule_id
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it 'default sort should be by name' do
|
|
23
|
+
all = VasSchedule.get_all
|
|
24
|
+
|
|
25
|
+
old_val = ""
|
|
26
|
+
all.each { |s|
|
|
27
|
+
s.name.should >= old_val
|
|
28
|
+
old_val = s.name
|
|
29
|
+
}
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'should sort by schedule_id' do
|
|
33
|
+
all = VasSchedule.get_all(:sort_by=>:schedule_id)
|
|
34
|
+
|
|
35
|
+
old_val = ""
|
|
36
|
+
all.each { |s|
|
|
37
|
+
s.schedule_id.should >= old_val
|
|
38
|
+
old_val = s.schedule_id
|
|
39
|
+
}
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it 'should sort_by first_time' do
|
|
43
|
+
all = VasSchedule.get_all(:sort_by=>:first_time)
|
|
44
|
+
|
|
45
|
+
old_val = Time.at(0)
|
|
46
|
+
all.each { |s|
|
|
47
|
+
s.first_time.should >= old_val
|
|
48
|
+
old_val = s.first_time
|
|
49
|
+
}
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it 'should sort_by next_time' do
|
|
53
|
+
all = VasSchedule.get_all(:sort_by=>:next_time)
|
|
54
|
+
|
|
55
|
+
old_val = Time.at(0)
|
|
56
|
+
all.each { |s|
|
|
57
|
+
s.next_time.should >= old_val
|
|
58
|
+
old_val = s.next_time
|
|
59
|
+
}
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
|
+
|
|
3
|
+
describe VasTarget do
|
|
4
|
+
it 'should get all available targets' do
|
|
5
|
+
targs = VasTarget.get_all
|
|
6
|
+
targs.count.should > 0
|
|
7
|
+
|
|
8
|
+
targs.each { |t|
|
|
9
|
+
t.should be_valid
|
|
10
|
+
}
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it 'should require a non-empty vas_id' do
|
|
14
|
+
t = VasTarget.new
|
|
15
|
+
t.vas_id = ""
|
|
16
|
+
|
|
17
|
+
t.should_not be_valid
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it 'should require a valid UUID format' do
|
|
21
|
+
t = VasTarget.new
|
|
22
|
+
t.vas_id = "This is not a valid UUID"
|
|
23
|
+
|
|
24
|
+
t.should_not be_valid
|
|
25
|
+
t.should have(1).errors
|
|
26
|
+
|
|
27
|
+
valid_chars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a',
|
|
28
|
+
'b', 'c', 'd', 'e', 'f', 'A', 'B', 'C', 'D', 'E', 'F', '-']
|
|
29
|
+
|
|
30
|
+
1.upto(10) {
|
|
31
|
+
uuid = ''
|
|
32
|
+
1.upto(rand(40) + 1) {
|
|
33
|
+
uuid += valid_chars[rand(valid_chars.length)]
|
|
34
|
+
}
|
|
35
|
+
t.vas_id = uuid
|
|
36
|
+
t.should be_valid
|
|
37
|
+
}
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
|
+
|
|
3
|
+
describe 'VasTask' do
|
|
4
|
+
it 'should pull all tasks' do
|
|
5
|
+
tasks = VasTask.get_all
|
|
6
|
+
|
|
7
|
+
tasks.should_not be nil
|
|
8
|
+
|
|
9
|
+
tasks.each { |t| t.should be_valid }
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it 'should pull a single task given the task_id' do
|
|
13
|
+
task = VasTask.get_all[0]
|
|
14
|
+
|
|
15
|
+
new_task = VasTask.get_all(:task_id => task.task_id)[0]
|
|
16
|
+
|
|
17
|
+
task.task_id.should == new_task.task_id
|
|
18
|
+
end
|
|
19
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'openvas-cli')))
|
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
3
|
+
|
|
4
|
+
require 'rspec'
|
|
5
|
+
require 'openvas-cli'
|
|
6
|
+
require 'log4r'
|
|
7
|
+
|
|
8
|
+
Dir["#{File.dirname(__FILE__)}/../lib/openvas-cli/vas_*.rb"].each {|f| require f}
|
|
9
|
+
# Requires supporting files with custom matchers and macros, etc,
|
|
10
|
+
# in ./support/ and its subdirectories.
|
|
11
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
|
12
|
+
|
|
13
|
+
RSpec.configure do |config|
|
|
14
|
+
config.filter_run_excluding :slow => true
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
# Set the client and logger up to meet your needs. Be careful if you set the
|
|
19
|
+
# log level to Log4r::DEBUG. This will cause A LOT of information to be dumped
|
|
20
|
+
# to file.
|
|
21
|
+
logger = Log4r::Logger.new 'test_log'
|
|
22
|
+
log_file = File.expand_path(File.join(File.dirname(__FILE__), '..', 'log', 'test.log'))
|
|
23
|
+
log_out = Log4r::RollingFileOutputter.new('test_log' ,
|
|
24
|
+
{:filename => log_file.to_s,
|
|
25
|
+
:maxsize => 10485760})
|
|
26
|
+
log_out.level = Log4r::WARN
|
|
27
|
+
logger.outputters = log_out
|
|
28
|
+
OpenvasCli.logger = logger
|
|
29
|
+
OpenvasCli.user = "admin"
|
|
30
|
+
OpenvasCli.password = "Password"
|