nasl-pedant 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +38 -0
- data/bin/pedant +1 -1
- data/lib/pedant.rb +3 -1
- data/lib/pedant/check.rb +20 -12
- data/lib/pedant/checks/conditional_or_loop_is_empty.rb +1 -1
- data/lib/pedant/checks/contains_ip_address_literals.rb +1 -1
- data/lib/pedant/checks/contains_no_carriage_returns.rb +1 -1
- data/lib/pedant/checks/contains_no_tabs.rb +1 -1
- data/lib/pedant/checks/contains_registration_section.rb +10 -4
- data/lib/pedant/checks/contains_unreachable_code.rb +2 -2
- data/lib/pedant/checks/ends_with_newline.rb +1 -1
- data/lib/pedant/checks/{files_parse_without_error.rb → files_parse_without_errors.rb} +1 -1
- data/lib/pedant/checks/local_variable_unused.rb +51 -0
- data/lib/pedant/checks/parse_test_code.rb +1 -1
- data/lib/pedant/checks/plugin_type_not_specified.rb +4 -3
- data/lib/pedant/checks/script_category.rb +111 -0
- data/lib/pedant/checks/script_family_not_specified.rb +53 -16
- data/lib/pedant/checks/script_id.rb +115 -0
- data/lib/pedant/checks/script_name.rb +133 -0
- data/lib/pedant/checks/script_summary.rb +142 -0
- data/lib/pedant/cli.rb +41 -31
- data/lib/pedant/command.rb +16 -29
- data/lib/pedant/commands/check.rb +105 -6
- data/lib/pedant/commands/test.rb +24 -2
- data/lib/pedant/knowledge_base.rb +1 -1
- data/lib/pedant/test.rb +5 -5
- data/lib/pedant/version.rb +1 -1
- data/pedant.gemspec +33 -6
- data/test/test_helper.rb +26 -0
- data/test/unit/checks/test_conditional_or_loop_is_empty.rb +1 -1
- data/test/unit/checks/test_contains_ip_address_literals.rb +1 -1
- data/test/unit/checks/test_contains_no_carriage_returns.rb +1 -1
- data/test/unit/checks/test_contains_no_tabs.rb +1 -1
- data/test/unit/checks/test_contains_registration_section.rb +17 -1
- data/test/unit/checks/test_contains_unreachable_code.rb +11 -1
- data/test/unit/checks/test_ends_with_newline.rb +1 -1
- data/test/unit/checks/test_plugin_type_not_specified.rb +9 -1
- data/test/unit/checks/test_script_family_not_specified.rb +54 -13
- metadata +30 -20
data/Rakefile
CHANGED
@@ -1,3 +1,29 @@
|
|
1
|
+
################################################################################
|
2
|
+
# Copyright (c) 2011-2014, Tenable Network Security
|
3
|
+
# All rights reserved.
|
4
|
+
#
|
5
|
+
# Redistribution and use in source and binary forms, with or without
|
6
|
+
# modification, are permitted provided that the following conditions are met:
|
7
|
+
#
|
8
|
+
# 1. Redistributions of source code must retain the above copyright notice, this
|
9
|
+
# list of conditions and the following disclaimer.
|
10
|
+
#
|
11
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
12
|
+
# this list of conditions and the following disclaimer in the documentation
|
13
|
+
# and/or other materials provided with the distribution.
|
14
|
+
#
|
15
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
16
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
17
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
18
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
19
|
+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
20
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
21
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
22
|
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
23
|
+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
24
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
25
|
+
################################################################################
|
26
|
+
|
1
27
|
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
|
2
28
|
|
3
29
|
require 'bundler/gem_tasks'
|
@@ -17,4 +43,16 @@ task :build => :compile do
|
|
17
43
|
system "gem build pedant.gemspec"
|
18
44
|
end
|
19
45
|
|
46
|
+
task :tag_and_bag do
|
47
|
+
system "git tag -a v#{Pedant::VERSION} -m 'version #{Pedant::VERSION}'"
|
48
|
+
system "git push --tags"
|
49
|
+
system "git checkout master"
|
50
|
+
#system "git merge #{Pedant::VERSION}"
|
51
|
+
system "git push"
|
52
|
+
end
|
53
|
+
|
54
|
+
task :release => [:tag_and_bag, :build] do
|
55
|
+
system "gem push #{Pedant::APP_NAME}-#{Pedant::VERSION}.gem"
|
56
|
+
end
|
57
|
+
|
20
58
|
task :default => :compile
|
data/bin/pedant
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
################################################################################
|
4
|
-
# Copyright (c) 2011,
|
4
|
+
# Copyright (c) 2011-2014, Tenable Network Security
|
5
5
|
# All rights reserved.
|
6
6
|
#
|
7
7
|
# Redistribution and use in source and binary forms, with or without
|
data/lib/pedant.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
################################################################################
|
2
|
-
# Copyright (c) 2011,
|
2
|
+
# Copyright (c) 2011-2014, Tenable Network Security
|
3
3
|
# All rights reserved.
|
4
4
|
#
|
5
5
|
# Redistribution and use in source and binary forms, with or without
|
@@ -27,6 +27,7 @@
|
|
27
27
|
require 'nasl'
|
28
28
|
require 'pathname'
|
29
29
|
require 'rainbow'
|
30
|
+
require 'rainbow/ext/string'
|
30
31
|
|
31
32
|
module Pedant
|
32
33
|
def self.root
|
@@ -46,6 +47,7 @@ module Pedant
|
|
46
47
|
autoload :Command, 'pedant/command'
|
47
48
|
autoload :KnowledgeBase, 'pedant/knowledge_base'
|
48
49
|
autoload :Test, 'pedant/test'
|
50
|
+
autoload :VERSION, 'pedant/version'
|
49
51
|
end
|
50
52
|
|
51
53
|
$LOAD_PATH.unshift(Pedant.lib.to_s)
|
data/lib/pedant/check.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
################################################################################
|
2
|
-
# Copyright (c) 2011,
|
2
|
+
# Copyright (c) 2011-2014, Tenable Network Security
|
3
3
|
# All rights reserved.
|
4
4
|
#
|
5
5
|
# Redistribution and use in source and binary forms, with or without
|
@@ -29,12 +29,12 @@ module Pedant
|
|
29
29
|
attr_reader :result
|
30
30
|
|
31
31
|
@@statuses = {
|
32
|
-
:died => 'DIED'.color(:red),
|
33
|
-
:fail => 'FAIL'.color(:red),
|
34
|
-
:pass => 'PASS'.color(:green),
|
35
|
-
:skip => 'SKIP'.color(:green),
|
36
|
-
:warn => 'WARN'.color(:yellow),
|
37
|
-
:void => 'VOID'.color(:magenta)
|
32
|
+
:died => Rainbow('DIED').color(:red),
|
33
|
+
:fail => Rainbow('FAIL').color(:red),
|
34
|
+
:pass => Rainbow('PASS').color(:green),
|
35
|
+
:skip => Rainbow('SKIP').color(:green),
|
36
|
+
:warn => Rainbow('WARN').color(:yellow),
|
37
|
+
:void => Rainbow('VOID').color(:magenta)
|
38
38
|
}
|
39
39
|
|
40
40
|
@@levels = [:error, :warn, :info]
|
@@ -57,6 +57,10 @@ module Pedant
|
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
+
def self.list
|
61
|
+
all.map{ |cls| cls.friendly_name }.sort
|
62
|
+
end
|
63
|
+
|
60
64
|
def self.all
|
61
65
|
(@_all ||= [])
|
62
66
|
end
|
@@ -88,7 +92,11 @@ module Pedant
|
|
88
92
|
end
|
89
93
|
|
90
94
|
def report(level, text=nil)
|
91
|
-
|
95
|
+
unless text.nil?
|
96
|
+
if @@levels.index(level).nil?
|
97
|
+
raise "Reporting level #{level} is not known."
|
98
|
+
end
|
99
|
+
|
92
100
|
@report << [level, text]
|
93
101
|
return
|
94
102
|
end
|
@@ -101,14 +109,14 @@ module Pedant
|
|
101
109
|
msg << "\n" unless msg.empty?
|
102
110
|
|
103
111
|
# Format the check's result.
|
104
|
-
msg = "[#{@@statuses[@result]}] #{self.
|
112
|
+
msg = "[#{@@statuses[@result]}] #{self.class.friendly_name}\n#{msg}"
|
105
113
|
|
106
114
|
return msg
|
107
115
|
end
|
108
116
|
|
109
|
-
def
|
110
|
-
# Mangle the
|
111
|
-
self.
|
117
|
+
def self.friendly_name
|
118
|
+
# Mangle the class name to be more user-friendly.
|
119
|
+
self.name.gsub(/.*::/, '').gsub(/^Check/, '').gsub(/[A-Z][^A-Z]*/, ' \&').strip
|
112
120
|
end
|
113
121
|
|
114
122
|
def fail
|
@@ -1,5 +1,5 @@
|
|
1
1
|
################################################################################
|
2
|
-
# Copyright (c) 2011,
|
2
|
+
# Copyright (c) 2011-2014, Tenable Network Security
|
3
3
|
# All rights reserved.
|
4
4
|
#
|
5
5
|
# Redistribution and use in source and binary forms, with or without
|
@@ -1,5 +1,5 @@
|
|
1
1
|
################################################################################
|
2
|
-
# Copyright (c) 2011,
|
2
|
+
# Copyright (c) 2011-2014, Tenable Network Security
|
3
3
|
# All rights reserved.
|
4
4
|
#
|
5
5
|
# Redistribution and use in source and binary forms, with or without
|
@@ -1,5 +1,5 @@
|
|
1
1
|
################################################################################
|
2
|
-
# Copyright (c) 2011,
|
2
|
+
# Copyright (c) 2011-2014, Tenable Network Security
|
3
3
|
# All rights reserved.
|
4
4
|
#
|
5
5
|
# Redistribution and use in source and binary forms, with or without
|
@@ -1,5 +1,5 @@
|
|
1
1
|
################################################################################
|
2
|
-
# Copyright (c) 2011,
|
2
|
+
# Copyright (c) 2011-2014, Tenable Network Security
|
3
3
|
# All rights reserved.
|
4
4
|
#
|
5
5
|
# Redistribution and use in source and binary forms, with or without
|
@@ -1,5 +1,5 @@
|
|
1
1
|
################################################################################
|
2
|
-
# Copyright (c) 2011,
|
2
|
+
# Copyright (c) 2011-2014, Tenable Network Security
|
3
3
|
# All rights reserved.
|
4
4
|
#
|
5
5
|
# Redistribution and use in source and binary forms, with or without
|
@@ -41,7 +41,7 @@ module Pedant
|
|
41
41
|
|
42
42
|
# Find the registration If statement.
|
43
43
|
regs = tree.all(:If).select do |node|
|
44
|
-
(node.cond.is_a?(Nasl::Lvalue) && node.cond.ident.name == 'description')
|
44
|
+
(node.cond.is_a?(Nasl::Lvalue) && node.cond.ident.name == 'description' && node.cond.indexes == [])
|
45
45
|
end
|
46
46
|
|
47
47
|
# Ensure there's a registration section.
|
@@ -82,8 +82,14 @@ module Pedant
|
|
82
82
|
return fail
|
83
83
|
end
|
84
84
|
|
85
|
-
unless statement.name.
|
86
|
-
report(:error, "The registration section ends with a call to
|
85
|
+
unless statement.name.indexes == []
|
86
|
+
report(:error, "The registration section ends with a call to something other than exit.")
|
87
|
+
report(:error, statement.context(reg))
|
88
|
+
return fail
|
89
|
+
end
|
90
|
+
|
91
|
+
unless statement.name.ident.name == 'exit'
|
92
|
+
report(:error, "The registration section ends with a call to #{statement.name.ident.name}, not exit as expected.")
|
87
93
|
report(:error, statement.context(reg))
|
88
94
|
return fail
|
89
95
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
################################################################################
|
2
|
-
# Copyright (c) 2011,
|
2
|
+
# Copyright (c) 2011-2014, Tenable Network Security
|
3
3
|
# All rights reserved.
|
4
4
|
#
|
5
5
|
# Redistribution and use in source and binary forms, with or without
|
@@ -36,7 +36,7 @@ module Pedant
|
|
36
36
|
# Check if the Node is capable of jumping out of the Block, without
|
37
37
|
# resuming where it left off (i.e., Call). The exception is exit(),
|
38
38
|
# which is a builtin Function that terminates execution.
|
39
|
-
if node.is_a?(Nasl::Break) || node.is_a?(Nasl::Continue) || node.is_a?(Nasl::Return) || (node.is_a?(Nasl::Call) && node.name.name == 'exit')
|
39
|
+
if node.is_a?(Nasl::Break) || node.is_a?(Nasl::Continue) || node.is_a?(Nasl::Return) || (node.is_a?(Nasl::Call) && node.name.ident.name == 'exit' && node.name.indexes == [])
|
40
40
|
# If this is not the final node in the list, then there is
|
41
41
|
# absolutely no way for the later nodes to be accessed.
|
42
42
|
if node != list.last
|
@@ -1,5 +1,5 @@
|
|
1
1
|
################################################################################
|
2
|
-
# Copyright (c) 2011,
|
2
|
+
# Copyright (c) 2011-2014, Tenable Network Security
|
3
3
|
# All rights reserved.
|
4
4
|
#
|
5
5
|
# Redistribution and use in source and binary forms, with or without
|
@@ -1,5 +1,5 @@
|
|
1
1
|
################################################################################
|
2
|
-
# Copyright (c) 2011,
|
2
|
+
# Copyright (c) 2011-2014, Tenable Network Security
|
3
3
|
# All rights reserved.
|
4
4
|
#
|
5
5
|
# Redistribution and use in source and binary forms, with or without
|
@@ -0,0 +1,51 @@
|
|
1
|
+
################################################################################
|
2
|
+
# Copyright (c) 2011-2014, Tenable Network Security
|
3
|
+
# All rights reserved.
|
4
|
+
#
|
5
|
+
# Redistribution and use in source and binary forms, with or without
|
6
|
+
# modification, are permitted provided that the following conditions are met:
|
7
|
+
#
|
8
|
+
# 1. Redistributions of source code must retain the above copyright notice, this
|
9
|
+
# list of conditions and the following disclaimer.
|
10
|
+
#
|
11
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
12
|
+
# this list of conditions and the following disclaimer in the documentation
|
13
|
+
# and/or other materials provided with the distribution.
|
14
|
+
#
|
15
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
16
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
17
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
18
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
19
|
+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
20
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
21
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
22
|
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
23
|
+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
24
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
25
|
+
################################################################################
|
26
|
+
|
27
|
+
module Pedant
|
28
|
+
class CheckLocalVariableUnused < Check
|
29
|
+
def self.requires
|
30
|
+
super + [:trees]
|
31
|
+
end
|
32
|
+
|
33
|
+
def check(file, tree)
|
34
|
+
def check_function(id, blk)
|
35
|
+
report(:warn, "Function #{id.name} was not analyzed since this check is unfinished.")
|
36
|
+
end
|
37
|
+
|
38
|
+
# Local variable statements can technically occur anywhere, they only
|
39
|
+
# create new variables when found in functions.
|
40
|
+
tree.all(:Function).each { |fn| check_function(fn.name, fn.body) }
|
41
|
+
end
|
42
|
+
|
43
|
+
def run
|
44
|
+
# This check will pass by default.
|
45
|
+
pass
|
46
|
+
|
47
|
+
# Run this check on the tree from every file.
|
48
|
+
@kb[:trees].each { |file, tree| check(file, tree) }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
################################################################################
|
2
|
-
# Copyright (c) 2011,
|
2
|
+
# Copyright (c) 2011-2014, Tenable Network Security
|
3
3
|
# All rights reserved.
|
4
4
|
#
|
5
5
|
# Redistribution and use in source and binary forms, with or without
|
@@ -1,5 +1,5 @@
|
|
1
1
|
################################################################################
|
2
|
-
# Copyright (c) 2011-
|
2
|
+
# Copyright (c) 2011-2014, Tenable Network Security
|
3
3
|
# All rights reserved.
|
4
4
|
#
|
5
5
|
# Redistribution and use in source and binary forms, with or without
|
@@ -39,7 +39,8 @@ module Pedant
|
|
39
39
|
tree = @kb[:trees][@kb[:main]]
|
40
40
|
|
41
41
|
tree.all(:Call).each do |node|
|
42
|
-
next unless node.name.name == 'script_set_attribute'
|
42
|
+
next unless node.name.ident.name == 'script_set_attribute'
|
43
|
+
next unless node.name.indexes == []
|
43
44
|
next unless node.arg.has_key? 'attribute'
|
44
45
|
|
45
46
|
# Pull out the attribute argument.
|
@@ -52,7 +53,7 @@ module Pedant
|
|
52
53
|
next if !arg.is_a? Nasl::String
|
53
54
|
|
54
55
|
# Ensure that the plugin type is valid.
|
55
|
-
unless ['combined', 'local', 'reputation', 'remote', 'settings', 'thirdparty'].include? arg.text
|
56
|
+
unless ['combined', 'local', 'reputation', 'remote', 'settings', 'summary', 'thirdparty'].include? arg.text
|
56
57
|
report(:info, "Plugin is of unknown type #{arg.text}:\n#{arg.context(node)}")
|
57
58
|
return fail
|
58
59
|
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
################################################################################
|
2
|
+
# Copyright (c) 2012, Mak Kolybabi
|
3
|
+
# All rights reserved.
|
4
|
+
#
|
5
|
+
# Redistribution and use in source and binary forms, with or without
|
6
|
+
# modification, are permitted provided that the following conditions are met:
|
7
|
+
#
|
8
|
+
# 1. Redistributions of source code must retain the above copyright notice, this
|
9
|
+
# list of conditions and the following disclaimer.
|
10
|
+
#
|
11
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
12
|
+
# this list of conditions and the following disclaimer in the documentation
|
13
|
+
# and/or other materials provided with the distribution.
|
14
|
+
#
|
15
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
16
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
17
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
18
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
19
|
+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
20
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
21
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
22
|
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
23
|
+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
24
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
25
|
+
################################################################################
|
26
|
+
|
27
|
+
module Pedant
|
28
|
+
class CheckScriptCategory < Check
|
29
|
+
def self.requires
|
30
|
+
super + [:main, :trees]
|
31
|
+
end
|
32
|
+
|
33
|
+
def run
|
34
|
+
# This check only applies to plugins.
|
35
|
+
return skip unless @kb[:main].extname == '.nasl'
|
36
|
+
|
37
|
+
sc_nodes = []
|
38
|
+
tree = @kb[:trees][@kb[:main]]
|
39
|
+
|
40
|
+
tree.all(:Call).each do |node|
|
41
|
+
next unless node.name.ident.name == 'script_category'
|
42
|
+
next unless node.name.indexes == []
|
43
|
+
sc_nodes << node
|
44
|
+
end
|
45
|
+
|
46
|
+
if sc_nodes.length == 0
|
47
|
+
report(:error, "Plugin does not specify a script_category.")
|
48
|
+
return fail
|
49
|
+
elsif sc_nodes.length > 1
|
50
|
+
report(:error, "Plugin specifies multiple script categories:")
|
51
|
+
sc_nodes.each { |call| report(:error, call.context()) }
|
52
|
+
return fail
|
53
|
+
end
|
54
|
+
|
55
|
+
sc_node = sc_nodes.first
|
56
|
+
|
57
|
+
if sc_node.args.empty?
|
58
|
+
report(:error, "script_category() was called with no arguments:\n#{sc_node.context()}")
|
59
|
+
return fail
|
60
|
+
end
|
61
|
+
|
62
|
+
if sc_node.args.length > 1
|
63
|
+
report(:error, "script_category() was called with too many arguments:\n#{sc_node.context()}")
|
64
|
+
return fail
|
65
|
+
end
|
66
|
+
|
67
|
+
# Pull out argument
|
68
|
+
arg = sc_node.args.first.expr
|
69
|
+
|
70
|
+
unless sc_node.args.first.expr.is_a? Nasl::Lvalue
|
71
|
+
report(
|
72
|
+
:error,
|
73
|
+
"script_category() was called with the wrong type of argument.\n" +
|
74
|
+
"A variable (not a string literal) starting with ACT_ must be provided:\n" +
|
75
|
+
arg.context(sc_node)
|
76
|
+
)
|
77
|
+
return fail
|
78
|
+
end
|
79
|
+
|
80
|
+
# Ensure that the script category is valid.
|
81
|
+
unless [
|
82
|
+
"ACT_INIT",
|
83
|
+
"ACT_SCANNER",
|
84
|
+
"ACT_SETTINGS",
|
85
|
+
"ACT_GATHER_INFO",
|
86
|
+
"ACT_ATTACK",
|
87
|
+
"ACT_MIXED",
|
88
|
+
"ACT_DESTRUCTIVE_ATTACK",
|
89
|
+
"ACT_COMPLIANCE_CHECK",
|
90
|
+
"ACT_PATCH_SETUP",
|
91
|
+
"ACT_PATCH_APPLY",
|
92
|
+
"ACT_PATCH_POST_APPLY",
|
93
|
+
"ACT_THIRD_PARTY_INFO",
|
94
|
+
"ACT_DENIAL",
|
95
|
+
"ACT_KILL_HOST",
|
96
|
+
"ACT_FLOOD",
|
97
|
+
"ACT_END"
|
98
|
+
].include? arg.ident.name
|
99
|
+
report(
|
100
|
+
:error,
|
101
|
+
"Plugin belongs to unknown category #{arg.ident.name}:\n" +
|
102
|
+
arg.context(sc_node)
|
103
|
+
)
|
104
|
+
return fail
|
105
|
+
end
|
106
|
+
|
107
|
+
report(:info, "Plugin belongs to script category #{arg.ident.name}:\n#{arg.context(sc_node)}")
|
108
|
+
pass
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -39,7 +39,8 @@ module Pedant
|
|
39
39
|
tree = @kb[:trees][@kb[:main]]
|
40
40
|
|
41
41
|
tree.all(:Call).each do |node|
|
42
|
-
next unless node.name.name == 'script_family'
|
42
|
+
next unless node.name.ident.name == 'script_family'
|
43
|
+
next unless node.name.indexes == []
|
43
44
|
next if node.args.empty?
|
44
45
|
next unless node.args.first.expr.is_a? Nasl::String
|
45
46
|
|
@@ -47,21 +48,57 @@ module Pedant
|
|
47
48
|
arg = node.args.first.expr
|
48
49
|
|
49
50
|
# Ensure that the script family is valid.
|
50
|
-
unless [
|
51
|
-
"
|
52
|
-
"
|
53
|
-
"
|
54
|
-
"
|
55
|
-
"
|
56
|
-
"
|
57
|
-
"
|
58
|
-
"
|
59
|
-
"
|
60
|
-
"
|
61
|
-
"
|
62
|
-
"
|
51
|
+
unless [
|
52
|
+
"AIX Local Security Checks",
|
53
|
+
"Backdoors",
|
54
|
+
"Brute force attacks",
|
55
|
+
"CentOS Local Security Checks",
|
56
|
+
"CGI abuses",
|
57
|
+
"CGI abuses : XSS",
|
58
|
+
"CISCO",
|
59
|
+
"Databases",
|
60
|
+
"Debian Local Security Checks",
|
61
|
+
"Default Unix Accounts",
|
62
|
+
"Denial of Service",
|
63
|
+
"DNS",
|
64
|
+
"Fedora Local Security Checks",
|
65
|
+
#"Finger abuses", # removed december 2011
|
66
|
+
"Firewalls",
|
67
|
+
"FreeBSD Local Security Checks",
|
68
|
+
"FTP",
|
69
|
+
"Gain a shell remotely",
|
70
|
+
"General",
|
71
|
+
"Gentoo Local Security Checks",
|
72
|
+
"HP-UX Local Security Checks",
|
73
|
+
"Junos Local Security Checks",
|
74
|
+
"MacOS X Local Security Checks",
|
75
|
+
"Mandriva Local Security Checks",
|
76
|
+
"Misc.",
|
77
|
+
"Mobile Devices",
|
78
|
+
"Netware",
|
79
|
+
"Peer-To-Peer File Sharing",
|
80
|
+
"Policy Compliance",
|
81
|
+
"Port scanners",
|
82
|
+
"Red Hat Local Security Checks",
|
83
|
+
"RPC",
|
84
|
+
"SCADA",
|
85
|
+
"Scientific Linux Local Security Checks",
|
86
|
+
"Service detection",
|
87
|
+
"Settings",
|
88
|
+
"Slackware Local Security Checks",
|
89
|
+
"SMTP problems",
|
90
|
+
"SNMP",
|
91
|
+
"Solaris Local Security Checks",
|
92
|
+
"SuSE Local Security Checks",
|
93
|
+
"Ubuntu Local Security Checks",
|
94
|
+
"VMware ESX Local Security Checks",
|
95
|
+
"Web Servers",
|
96
|
+
"Windows",
|
97
|
+
"Windows : Microsoft Bulletins",
|
98
|
+
"Windows : User management"
|
99
|
+
].include? arg.text
|
63
100
|
|
64
|
-
report(:info, "Plugin belongs to unknown #{arg.text}:\n#{arg.context(node)}")
|
101
|
+
report(:info, "Plugin belongs to unknown family #{arg.text}:\n#{arg.context(node)}")
|
65
102
|
return fail
|
66
103
|
end
|
67
104
|
|
@@ -78,7 +115,7 @@ module Pedant
|
|
78
115
|
report(:info, "Plugin belongs to script family #{arg.text}:\n#{arg.context(call)}")
|
79
116
|
pass
|
80
117
|
else
|
81
|
-
report(:error, "Plugin specifies multiple script
|
118
|
+
report(:error, "Plugin specifies multiple script families.")
|
82
119
|
args.each { |arg, call| report(:error, arg.context(call)) }
|
83
120
|
fail
|
84
121
|
end
|