nasl 0.3.0 → 0.4.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 +5 -13
- data/.travis.yml +6 -1
- data/Gemfile +1 -4
- data/README.md +26 -0
- data/lib/nasl/grammar.racc +149 -10
- data/lib/nasl/parser/block.rb +7 -1
- data/lib/nasl/parser/case.rb +55 -0
- data/lib/nasl/parser/function.rb +28 -3
- data/lib/nasl/parser/namespace.rb +50 -0
- data/lib/nasl/parser/node.rb +11 -2
- data/lib/nasl/parser/obj_var.rb +41 -0
- data/lib/nasl/parser/object.rb +50 -0
- data/lib/nasl/parser/switch.rb +51 -0
- data/lib/nasl/token.rb +1 -1
- data/lib/nasl/tokenizer.rb +51 -14
- data/lib/nasl/version.rb +1 -1
- data/nasl.gemspec +4 -3
- data/test/unit/parser/test_namespace.rb +45 -0
- data/test/unit/parser/test_object.rb +75 -0
- data/test/unit/parser/test_switch.rb +96 -0
- data/test/unit/tokenizer/test_comment.rb +76 -1
- data/test/unit/tokenizer/test_operator_lookahead.rb +75 -0
- metadata +46 -20
- data/Gemfile.ci +0 -6
@@ -0,0 +1,96 @@
|
|
1
|
+
################################################################################
|
2
|
+
# Copyright (c) 2011-2018, 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
|
+
class TestSwitch < Test::Unit::TestCase
|
28
|
+
include Nasl::Test
|
29
|
+
|
30
|
+
def test_each
|
31
|
+
tree = parse(
|
32
|
+
<<-EOF
|
33
|
+
switch (value)
|
34
|
+
{
|
35
|
+
case 0:
|
36
|
+
b = 1;
|
37
|
+
break;
|
38
|
+
case 3:
|
39
|
+
break;
|
40
|
+
default:
|
41
|
+
a = 0;
|
42
|
+
}
|
43
|
+
switch [=~] (value1)
|
44
|
+
{
|
45
|
+
case "^abc.*":
|
46
|
+
rtrn = 1;
|
47
|
+
break;
|
48
|
+
case "^cde.*":
|
49
|
+
rtrn = 2;
|
50
|
+
break;
|
51
|
+
default:
|
52
|
+
rtrn = 1;
|
53
|
+
}
|
54
|
+
switch (value2)
|
55
|
+
{
|
56
|
+
case [=~] "^abc.*":
|
57
|
+
rtrn = 1;
|
58
|
+
break;
|
59
|
+
case [==] "cde":
|
60
|
+
rtrn = 2;
|
61
|
+
break;
|
62
|
+
default:
|
63
|
+
rtrn = 1;
|
64
|
+
}
|
65
|
+
EOF
|
66
|
+
)
|
67
|
+
assert_not_nil(tree)
|
68
|
+
|
69
|
+
cases = tree.all(:Case)
|
70
|
+
assert_not_nil(cases)
|
71
|
+
assert_equal(9, cases.length)
|
72
|
+
|
73
|
+
assert_equal(cases[0].case_op, nil)
|
74
|
+
assert_equal(cases[6].case_op.to_s, "=~")
|
75
|
+
|
76
|
+
assert_equal(cases[0].case_val.value, 0)
|
77
|
+
assert_equal(cases[4].case_val.text, "^cde.*")
|
78
|
+
assert_equal(cases[2].case_val, nil)
|
79
|
+
|
80
|
+
assert_equal(cases[6].case_type, "normal_with_op")
|
81
|
+
assert_equal(cases[0].case_type, "normal")
|
82
|
+
assert_equal(cases[2].case_type, "default")
|
83
|
+
assert_equal(cases[6].case_type, "normal_with_op")
|
84
|
+
|
85
|
+
switches = tree.all(:Switch)
|
86
|
+
assert_not_nil(switches)
|
87
|
+
assert_equal(3, switches.length)
|
88
|
+
|
89
|
+
assert_equal(switches[1].switch_op.to_s, "=~")
|
90
|
+
assert_equal(switches[0].switch_op, nil)
|
91
|
+
|
92
|
+
assert_equal(switches[0].switch_expr.tokens[0].name, "value")
|
93
|
+
assert_equal(switches[1].switch_expr.tokens[0].name, "value1")
|
94
|
+
assert_equal(switches[2].switch_expr.tokens[0].name, "value2")
|
95
|
+
end
|
96
|
+
end
|
@@ -99,6 +99,81 @@ class TestTokenizerComment < Test::Unit::TestCase
|
|
99
99
|
verify(code, [[:COMMENT, "# Comment 1"]])
|
100
100
|
end
|
101
101
|
|
102
|
+
def test_c_style_multiline_beginning_of_statement
|
103
|
+
code = "/* Simple */a=1;"
|
104
|
+
|
105
|
+
assign = [
|
106
|
+
[:COMMENT, "/* Simple */"],
|
107
|
+
[:IDENT, "a"],
|
108
|
+
[:ASS_EQ, "="],
|
109
|
+
[:INT_DEC, "1"],
|
110
|
+
[:SEMICOLON, ";"],
|
111
|
+
]
|
112
|
+
|
113
|
+
verify(code, assign)
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_c_style_multiline_in_middle_of_statement
|
117
|
+
code = <<-EOF
|
118
|
+
hello = 1/*
|
119
|
+
comment here */;
|
120
|
+
EOF
|
121
|
+
|
122
|
+
assign = [
|
123
|
+
[:IDENT, "hello"],
|
124
|
+
[:ASS_EQ, "="],
|
125
|
+
[:INT_DEC, "1"],
|
126
|
+
[:SEMICOLON, ";"],
|
127
|
+
]
|
128
|
+
|
129
|
+
verify(code, assign)
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_c_style_empty
|
133
|
+
verify("//", [[ :COMMENT, "//" ]])
|
134
|
+
verify("/**/", [[ :COMMENT, "/**/" ]])
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_c_style_multiline_after_statement
|
138
|
+
code = <<-EOF
|
139
|
+
hello = 1;/* comment here */
|
140
|
+
EOF
|
141
|
+
|
142
|
+
assign = [
|
143
|
+
[:IDENT, "hello"],
|
144
|
+
[:ASS_EQ, "="],
|
145
|
+
[:INT_DEC, "1"],
|
146
|
+
[:SEMICOLON, ";"],
|
147
|
+
]
|
148
|
+
|
149
|
+
verify(code, assign)
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_c_style_single_line_after_statement
|
153
|
+
code = <<-EOF
|
154
|
+
hello = 1;// comment here
|
155
|
+
EOF
|
156
|
+
|
157
|
+
assign = [
|
158
|
+
[:IDENT, "hello"],
|
159
|
+
[:ASS_EQ, "="],
|
160
|
+
[:INT_DEC, "1"],
|
161
|
+
[:SEMICOLON, ";"],
|
162
|
+
]
|
163
|
+
|
164
|
+
verify(code, assign)
|
165
|
+
end
|
166
|
+
|
167
|
+
def test_c_style_unterminated
|
168
|
+
code = <<-EOF
|
169
|
+
hello = 1; /* hello
|
170
|
+
EOF
|
171
|
+
|
172
|
+
assert_raise Nasl::TokenException do
|
173
|
+
tokenize(code).get_tokens
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
102
177
|
def test_hidden_before
|
103
178
|
code = <<-EOF
|
104
179
|
foo = TRUE;
|
@@ -116,7 +191,7 @@ class TestTokenizerComment < Test::Unit::TestCase
|
|
116
191
|
verify(code, assign + assign)
|
117
192
|
end
|
118
193
|
|
119
|
-
def
|
194
|
+
def test_hidden_after
|
120
195
|
code = <<-EOF
|
121
196
|
foo = TRUE;
|
122
197
|
|
@@ -0,0 +1,75 @@
|
|
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
|
+
# Test that operators which could be interpreted as two separate operators... are not.
|
28
|
+
class TestOperatorLookahead < Test::Unit::TestCase
|
29
|
+
include Nasl::Test
|
30
|
+
|
31
|
+
def assert_lookahead str
|
32
|
+
assert_equal(tokenize(str).get_token.last.to_s, str)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_arithmetic
|
36
|
+
assert_lookahead("/=")
|
37
|
+
assert_lookahead("+=")
|
38
|
+
assert_lookahead("-=")
|
39
|
+
assert_lookahead("*=")
|
40
|
+
assert_lookahead("%=")
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_equality
|
44
|
+
assert_lookahead(">=")
|
45
|
+
assert_lookahead("<=")
|
46
|
+
assert_lookahead("==")
|
47
|
+
assert_lookahead("!=")
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_substr_and_regex
|
51
|
+
assert_lookahead(">!<")
|
52
|
+
assert_lookahead("><")
|
53
|
+
assert_lookahead("!~")
|
54
|
+
assert_lookahead("=~")
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_shifts
|
58
|
+
assert_lookahead(">>=")
|
59
|
+
assert_lookahead(">>>=")
|
60
|
+
assert_lookahead("<<=")
|
61
|
+
assert_lookahead(">>>")
|
62
|
+
assert_lookahead("<<")
|
63
|
+
assert_lookahead(">>")
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_prefix_postfix
|
67
|
+
assert_lookahead("--")
|
68
|
+
assert_lookahead("++")
|
69
|
+
end
|
70
|
+
|
71
|
+
def logical
|
72
|
+
assert_lookahead("||")
|
73
|
+
assert_lookahead("&&")
|
74
|
+
end
|
75
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nasl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mak Kolybabi
|
@@ -10,64 +10,78 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2018-06-01 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: racc
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
18
18
|
requirements:
|
19
|
-
- - ~>
|
19
|
+
- - "~>"
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: '1.4'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
|
-
- - ~>
|
26
|
+
- - "~>"
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
version: '1.4'
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: rake
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
32
32
|
requirements:
|
33
|
-
- - ~>
|
33
|
+
- - "~>"
|
34
34
|
- !ruby/object:Gem::Version
|
35
|
-
version: '10.
|
35
|
+
version: '10.3'
|
36
36
|
type: :development
|
37
37
|
prerelease: false
|
38
38
|
version_requirements: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
|
-
- - ~>
|
40
|
+
- - "~>"
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: '10.
|
42
|
+
version: '10.3'
|
43
43
|
- !ruby/object:Gem::Dependency
|
44
44
|
name: builder
|
45
45
|
requirement: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
|
-
- - ~>
|
47
|
+
- - "~>"
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version: '3.
|
49
|
+
version: '3.2'
|
50
50
|
type: :runtime
|
51
51
|
prerelease: false
|
52
52
|
version_requirements: !ruby/object:Gem::Requirement
|
53
53
|
requirements:
|
54
|
-
- - ~>
|
54
|
+
- - "~>"
|
55
55
|
- !ruby/object:Gem::Version
|
56
|
-
version: '3.
|
56
|
+
version: '3.2'
|
57
57
|
- !ruby/object:Gem::Dependency
|
58
58
|
name: rainbow
|
59
59
|
requirement: !ruby/object:Gem::Requirement
|
60
60
|
requirements:
|
61
|
-
- - ~>
|
61
|
+
- - "~>"
|
62
62
|
- !ruby/object:Gem::Version
|
63
63
|
version: '2.0'
|
64
64
|
type: :runtime
|
65
65
|
prerelease: false
|
66
66
|
version_requirements: !ruby/object:Gem::Requirement
|
67
67
|
requirements:
|
68
|
-
- - ~>
|
68
|
+
- - "~>"
|
69
69
|
- !ruby/object:Gem::Version
|
70
70
|
version: '2.0'
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: test-unit-minitest
|
73
|
+
requirement: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
type: :runtime
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
71
85
|
description: A language parser for the Nessus Attack Scripting Language. Supporting
|
72
86
|
NASL v5.2.
|
73
87
|
email:
|
@@ -79,10 +93,9 @@ executables:
|
|
79
93
|
extensions: []
|
80
94
|
extra_rdoc_files: []
|
81
95
|
files:
|
82
|
-
- .gitignore
|
83
|
-
- .travis.yml
|
96
|
+
- ".gitignore"
|
97
|
+
- ".travis.yml"
|
84
98
|
- Gemfile
|
85
|
-
- Gemfile.ci
|
86
99
|
- README.md
|
87
100
|
- Rakefile
|
88
101
|
- bin/nasl-parse
|
@@ -104,6 +117,7 @@ files:
|
|
104
117
|
- lib/nasl/parser/block.rb
|
105
118
|
- lib/nasl/parser/break.rb
|
106
119
|
- lib/nasl/parser/call.rb
|
120
|
+
- lib/nasl/parser/case.rb
|
107
121
|
- lib/nasl/parser/comment.rb
|
108
122
|
- lib/nasl/parser/continue.rb
|
109
123
|
- lib/nasl/parser/decrement.rb
|
@@ -125,13 +139,17 @@ files:
|
|
125
139
|
- lib/nasl/parser/list.rb
|
126
140
|
- lib/nasl/parser/local.rb
|
127
141
|
- lib/nasl/parser/lvalue.rb
|
142
|
+
- lib/nasl/parser/namespace.rb
|
128
143
|
- lib/nasl/parser/node.rb
|
144
|
+
- lib/nasl/parser/obj_var.rb
|
145
|
+
- lib/nasl/parser/object.rb
|
129
146
|
- lib/nasl/parser/parameter.rb
|
130
147
|
- lib/nasl/parser/reference.rb
|
131
148
|
- lib/nasl/parser/repeat.rb
|
132
149
|
- lib/nasl/parser/repetition.rb
|
133
150
|
- lib/nasl/parser/return.rb
|
134
151
|
- lib/nasl/parser/string.rb
|
152
|
+
- lib/nasl/parser/switch.rb
|
135
153
|
- lib/nasl/parser/tree.rb
|
136
154
|
- lib/nasl/parser/undefined.rb
|
137
155
|
- lib/nasl/parser/while.rb
|
@@ -159,15 +177,19 @@ files:
|
|
159
177
|
- test/unit/parser/test_ip.rb
|
160
178
|
- test/unit/parser/test_list.rb
|
161
179
|
- test/unit/parser/test_local.rb
|
180
|
+
- test/unit/parser/test_namespace.rb
|
181
|
+
- test/unit/parser/test_object.rb
|
162
182
|
- test/unit/parser/test_repetition.rb
|
163
183
|
- test/unit/parser/test_return.rb
|
164
184
|
- test/unit/parser/test_string.rb
|
185
|
+
- test/unit/parser/test_switch.rb
|
165
186
|
- test/unit/parser/test_while.rb
|
166
187
|
- test/unit/parser/test_whitespace.rb
|
167
188
|
- test/unit/test_context.rb
|
168
189
|
- test/unit/tokenizer/test_comment.rb
|
169
190
|
- test/unit/tokenizer/test_empty.rb
|
170
191
|
- test/unit/tokenizer/test_integer.rb
|
192
|
+
- test/unit/tokenizer/test_operator_lookahead.rb
|
171
193
|
- test/unit/tokenizer/test_references.rb
|
172
194
|
- test/unit/tokenizer/test_string.rb
|
173
195
|
homepage: http://github.com/tenable/nasl
|
@@ -180,17 +202,17 @@ require_paths:
|
|
180
202
|
- lib
|
181
203
|
required_ruby_version: !ruby/object:Gem::Requirement
|
182
204
|
requirements:
|
183
|
-
- -
|
205
|
+
- - ">="
|
184
206
|
- !ruby/object:Gem::Version
|
185
207
|
version: '0'
|
186
208
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
187
209
|
requirements:
|
188
|
-
- -
|
210
|
+
- - ">="
|
189
211
|
- !ruby/object:Gem::Version
|
190
212
|
version: '0'
|
191
213
|
requirements: []
|
192
214
|
rubyforge_project: nasl
|
193
|
-
rubygems_version: 2.
|
215
|
+
rubygems_version: 2.2.2
|
194
216
|
signing_key:
|
195
217
|
specification_version: 4
|
196
218
|
summary: A language parser for the Nessus Attack Scripting Language.
|
@@ -214,14 +236,18 @@ test_files:
|
|
214
236
|
- test/unit/parser/test_ip.rb
|
215
237
|
- test/unit/parser/test_list.rb
|
216
238
|
- test/unit/parser/test_local.rb
|
239
|
+
- test/unit/parser/test_namespace.rb
|
240
|
+
- test/unit/parser/test_object.rb
|
217
241
|
- test/unit/parser/test_repetition.rb
|
218
242
|
- test/unit/parser/test_return.rb
|
219
243
|
- test/unit/parser/test_string.rb
|
244
|
+
- test/unit/parser/test_switch.rb
|
220
245
|
- test/unit/parser/test_while.rb
|
221
246
|
- test/unit/parser/test_whitespace.rb
|
222
247
|
- test/unit/test_context.rb
|
223
248
|
- test/unit/tokenizer/test_comment.rb
|
224
249
|
- test/unit/tokenizer/test_empty.rb
|
225
250
|
- test/unit/tokenizer/test_integer.rb
|
251
|
+
- test/unit/tokenizer/test_operator_lookahead.rb
|
226
252
|
- test/unit/tokenizer/test_references.rb
|
227
253
|
- test/unit/tokenizer/test_string.rb
|