nasl 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZWMwMTc1ZTg3N2ZmZDJjYzBkN2U3NDljZWM0MGMxNDUxNzc4ZmI2Yg==
5
- data.tar.gz: !binary |-
6
- MGZmMWYyMmVkOTA3ZjhlZTUwNGY4YWI3OGJmYzA0YzlmNThlMjg0NQ==
2
+ SHA1:
3
+ metadata.gz: 199cd9a0ada92765a2e1812786f7b41eb22c3724
4
+ data.tar.gz: 0b8ff7ebf8d1b4b166dd7ffb4f71fa52d884e1aa
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- Nzc0ZjcyMTk5ZjZkNzgxZmYxMTVhNzRmNjE0ZDJhOWNlNTEwMTllMzk1NjYz
10
- ODBhNTc1NjIxYzhkNmJjZTVmMDJkMGMzMDg5YzViYzBiMjZkZTA1ZmFjM2Q1
11
- ZjRhMDFkZDg0ZDFkY2MwYTYwOGM3YWU3MzFiZjMxMmU1NWVhMWM=
12
- data.tar.gz: !binary |-
13
- MWRhZDY3MjQ4NDg5ZjQ5ZTExOTk3MjIyODJlN2IzNGZhNTliOTAwODA1ZmM4
14
- MWM5OWRkNzdmNzgyZDM3Y2JkOTMyNGY0ZTI1YzdlMWUxMTgzMWZmNjAxNzJj
15
- NWE2ZDNjZDQzMTI0MWE4M2M5ODY1YzQ2MDhhOTM3M2MyYzIwZjQ=
6
+ metadata.gz: 1cd9093af658c23660d9d662e3da33ab2ecaf97aececd1402832a92a7d779e245c2a64c7cfe1be8d71793f2f08b2f51388e03de1d2a5be0da7712bc541a6a8ab
7
+ data.tar.gz: 749a6d9e4fea7edb88eb34113496988d7cba0cfe6baffb00eeabc154a4f81ffddd2d93eccbff44b142f645d2f190f7c88559bf77d892cd9bacd5f2ac42d9801e
@@ -1,17 +1,22 @@
1
1
  language: ruby
2
+ sudo: false
2
3
 
3
4
  rvm:
4
5
  - 1.9.3
5
6
  - 2.0.0
6
7
  - 2.1.0
8
+ - 2.2.0
9
+ - 2.3.0
7
10
 
8
11
  gemfile:
9
- - Gemfile.ci
12
+ - Gemfile
10
13
 
11
14
  notifications:
12
15
  email:
13
16
  - jhammack@tenable.com
14
17
  - aweber@tenable.com
18
+ - mcoumbes@tenable.com
19
+ - aorr@tenable.com
15
20
 
16
21
  before_install:
17
22
  - gem --version
data/Gemfile CHANGED
@@ -1,6 +1,3 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem "racc", '1.4.12'
4
- gem "rake", '10.3.2'
5
- gem "builder", '3.2.2'
6
- gem "rainbow", '2.0.0'
3
+ gemspec
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Installation
2
2
 
3
+ [![Gem Version](http://img.shields.io/gem/v/nasl.svg?style=flat-square)](https://rubygems.org/gems/nasl)
4
+ [![Build Status](http://img.shields.io/travis/tenable/nasl.svg)](https://travis-ci.org/tenable/nasl)
5
+
3
6
  ## Git
4
7
 
5
8
  Installing the source from Git is done as follows:
@@ -98,5 +101,28 @@ obviously, and can be used as follows:
98
101
  That's all there is to it. If there are any errors, it'll throw an instance of
99
102
  `ParseException` that will include as much context about the error as possible.
100
103
 
104
+ Development
105
+ -----------
106
+
107
+ This project uses [Bundler](http://bundler.io/).
108
+
109
+ If you have a brand-new Debian machine, do this as root:
110
+
111
+ apt-get install ruby-dev rubygems git
112
+ gem install bundler
113
+
114
+ As your regular user:
115
+
116
+ git clone https://github.com/tenable/nasl
117
+ cd nasl
118
+ bundle install --path vendor/bundle
119
+ bundle exec rake grammars
120
+ bundle exec rake test
121
+
122
+ All the tests should pass!
123
+
124
+ To run the nasl-parse command line, do `bundle exec ./bin/nasl-parse`, which should give
125
+ a help message.
126
+
101
127
  [nasldoc]: https://github.com/tenable/nasldoc
102
128
  [pedant]: https://github.com/tenable/pedant
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011-2014, Tenable Network Security
2
+ # Copyright (c) 2011-2018, Tenable Network Security
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -74,18 +74,40 @@ rule
74
74
  { c(*val) }
75
75
  | export
76
76
  { val[0] }
77
- | COMMENT function
78
- { c(*val) }
79
- | function
80
- { val[0] }
77
+ # | COMMENT function
78
+ # { c(*val) }
79
+ # | function
80
+ # { val[0] }
81
81
  | statement
82
82
  { val[0] }
83
+ | obj_decl
84
+ { val[0] }
85
+ | namespace
86
+ { val[0] }
83
87
  ;
84
88
 
89
+ obj_statement : obj_var SEMICOLON
90
+ { val[0] }
91
+ | COMMENT obj_function
92
+ { c(*val) }
93
+ | obj_function
94
+ { val[0] }
95
+ ;
96
+ # | obj_function
97
+ # { val[0] }
98
+
85
99
  statement : simple
86
100
  { val[0] }
87
101
  | compound
88
102
  { val[0] }
103
+ | function
104
+ { val[0] }
105
+ | COMMENT function
106
+ { c(*val) }
107
+ | obj_decl
108
+ { val[0] }
109
+ | namespace
110
+ { val[0] }
89
111
  ;
90
112
 
91
113
  ##############################################################################
@@ -96,10 +118,16 @@ rule
96
118
  { n(:Export, *val) }
97
119
  ;
98
120
 
121
+ obj_function : obj_func_attr FUNCTION ident LPAREN params RPAREN block
122
+ { n(:Function, val[0], 'obj', val[1], val[2], val[3], val[4], val[5], val[6]) }
123
+ | obj_func_attr FUNCTION ident LPAREN RPAREN block
124
+ { n(:Function, val[0], 'obj', val[1], val[2], val[3], val[4], val[5]) }
125
+ ;
126
+
99
127
  function : FUNCTION ident LPAREN params RPAREN block
100
- { n(:Function, *val) }
128
+ { n(:Function, val[0], 'normal', val[1], val[2], val[3], val[4], val[5]) }
101
129
  | FUNCTION ident LPAREN RPAREN block
102
- { n(:Function, *val) }
130
+ { n(:Function, val[0], 'normal', val[1], val[2], val[3], val[4]) }
103
131
  ;
104
132
 
105
133
  simple : assign
@@ -118,6 +146,8 @@ rule
118
146
  { c(*val) }
119
147
  | global
120
148
  { val[0] }
149
+ | var_def
150
+ { val[0] }
121
151
  | import
122
152
  { val[0] }
123
153
  | include
@@ -144,8 +174,23 @@ rule
144
174
  { val[0] }
145
175
  | while
146
176
  { val[0] }
177
+ | switch
178
+ { val[0] }
179
+ | case
180
+ { val[0] }
147
181
  ;
148
182
 
183
+ namespace : NAMESPACE ident LBRACE statements RBRACE
184
+ { n(:Namespace, *val) }
185
+ | NAMESPACE ident LBRACE RBRACE
186
+ { n(:Namespace, *val) }
187
+ ;
188
+
189
+ obj_decl : OBJECT ident LBRACE obj_statements RBRACE
190
+ { n(:Object, *val) }
191
+ | NAMESPACE ident LBRACE RBRACE
192
+ { n(:Namespace, *val) }
193
+ ;
149
194
  ##############################################################################
150
195
  # Simple Statements
151
196
  ##############################################################################
@@ -178,6 +223,10 @@ rule
178
223
  { n(:Global, *val) }
179
224
  ;
180
225
 
226
+ var_def : VAR var_decls SEMICOLON
227
+ { n(:Local, *val) }
228
+ ;
229
+
181
230
  incr : incr_exp SEMICOLON
182
231
  { val[0] }
183
232
  ;
@@ -194,6 +243,10 @@ rule
194
243
  { n(:Local, *val) }
195
244
  ;
196
245
 
246
+ local : LOCAL var_decls SEMICOLON
247
+ { n(:Local, *val) }
248
+ ;
249
+
197
250
  rep : call_exp REP expr SEMICOLON
198
251
  { n(:Repetition, *val[0..-1]) }
199
252
  ;
@@ -206,16 +259,53 @@ rule
206
259
  { n(:Return, *val) }
207
260
  ;
208
261
 
262
+ obj_func_attr : /* Empty */
263
+ { nil }
264
+ | PUBLIC
265
+ { val[0] }
266
+ | PRIVATE
267
+ { val[0] }
268
+ ;
269
+
209
270
  ##############################################################################
210
271
  # Compound Statements
211
272
  ##############################################################################
212
-
213
273
  block : LBRACE statements RBRACE
214
274
  { n(:Block, *val) }
215
275
  | LBRACE RBRACE
216
276
  { n(:Block, *val) }
217
277
  ;
218
278
 
279
+ switch : SWITCH LPAREN expr RPAREN switch_block
280
+ { n(:Switch, *val) }
281
+ | SWITCH LBRACK switch_op RBRACK LPAREN expr RPAREN switch_block
282
+ { n(:Switch, *val) }
283
+ ;
284
+
285
+ case : CASE case_expr_list COLON
286
+ { n(:Case, *val) }
287
+ | CASE LBRACK switch_op RBRACK case_expr_list COLON
288
+ { n(:Case, *val) }
289
+ | DEFAULT COLON
290
+ { n(:Case, *val) }
291
+ ;
292
+
293
+ case_expr : expr
294
+ { val[0] }
295
+ ;
296
+
297
+ case_expr_list : case_expr
298
+ { val[0] }
299
+ | case_expr COMMA case_expr_list
300
+ { [val[0]] + val[2] }
301
+ ;
302
+
303
+ switch_block : LBRACE case statements RBRACE
304
+ { n(:Block, *val) }
305
+ | LBRACE RBRACE
306
+ { n(:Block, *val) }
307
+ ;
308
+
219
309
  for : FOR LPAREN field SEMICOLON expr SEMICOLON field RPAREN statement
220
310
  { n(:For, *val) }
221
311
  ;
@@ -364,13 +454,47 @@ rule
364
454
  { val[0] }
365
455
  ;
366
456
 
457
+ switch_op : SUBSTR_EQ
458
+ { val[0] }
459
+ | SUBSTR_NE
460
+ { val[0] }
461
+ | REGEX_EQ
462
+ { val[0] }
463
+ | REGEX_NE
464
+ { val[0] }
465
+ | CMP_LT
466
+ { val[0] }
467
+ | CMP_GT
468
+ { val[0] }
469
+ | CMP_EQ
470
+ { val[0] }
471
+ | CMP_NE
472
+ { val[0] }
473
+ | CMP_LE
474
+ { val[0] }
475
+ | CMP_GE
476
+ { val[0] }
477
+ | AMPERSAND
478
+ { val[0] }
479
+ | BIT_XOR
480
+ { val[0] }
481
+ | BIT_OR
482
+ { val[0] }
483
+ ;
484
+
485
+
486
+ ident_ex : ident
487
+ { val[0] }
488
+ | VAR
489
+ { val[0] }
490
+
367
491
  ##############################################################################
368
492
  # Named Components
369
493
  ##############################################################################
370
494
 
371
- arg : ident COLON expr
495
+ arg : ident_ex COLON expr
372
496
  { n(:Argument, *val) }
373
- | ident COLON ref
497
+ | ident_ex COLON ref
374
498
  { n(:Argument, *val) }
375
499
  | expr
376
500
  { n(:Argument, *val) }
@@ -480,12 +604,22 @@ rule
480
604
  { [val[0]] }
481
605
  ;
482
606
 
607
+ obj_statements : obj_statement obj_statements
608
+ { [val[0]] + val[1] }
609
+ | obj_statement
610
+ { [val[0]] }
611
+ ;
612
+
483
613
  statements : statement statements
484
614
  { [val[0]] + val[1] }
485
615
  | statement
486
616
  { [val[0]] }
487
617
  ;
488
618
 
619
+ obj_var : VAR var_decls
620
+ { n(:ObjVar, *val) }
621
+ ;
622
+
489
623
  var_decl : ident ASS_EQ expr
490
624
  { n(:Assignment, *val) }
491
625
  | ident ASS_EQ ref
@@ -546,6 +680,7 @@ require 'nasl/parser/argument'
546
680
  require 'nasl/parser/array'
547
681
  require 'nasl/parser/assigment'
548
682
  require 'nasl/parser/block'
683
+ require 'nasl/parser/namespace'
549
684
  require 'nasl/parser/break'
550
685
  require 'nasl/parser/call'
551
686
  require 'nasl/parser/comment'
@@ -577,6 +712,10 @@ require 'nasl/parser/return'
577
712
  require 'nasl/parser/string'
578
713
  require 'nasl/parser/undefined'
579
714
  require 'nasl/parser/while'
715
+ require 'nasl/parser/object'
716
+ require 'nasl/parser/switch'
717
+ require 'nasl/parser/case'
718
+ require 'nasl/parser/obj_var'
580
719
 
581
720
  ---- inner ----
582
721
 
@@ -35,7 +35,13 @@ module Nasl
35
35
  def initialize(tree, *tokens)
36
36
  super
37
37
 
38
- @body = if @tokens.length == 3 then @tokens[1] else [] end
38
+ if (@tokens.length == 4)
39
+ @body = [@tokens[1]] + @tokens[2]
40
+ elsif (@tokens.length == 3)
41
+ @body = @tokens[1]
42
+ else
43
+ @body = []
44
+ end
39
45
 
40
46
  @children << :body
41
47
  end
@@ -0,0 +1,55 @@
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
+ require 'nasl/parser/node'
28
+
29
+ module Nasl
30
+ class Case < Node
31
+ attr_reader :case_val, :case_op, :case_type
32
+
33
+ def initialize(tree, *tokens)
34
+ super
35
+
36
+ if @tokens.length == 3
37
+ @case_op = nil
38
+ @case_val = @tokens[1]
39
+ @case_type = 'normal'
40
+ elsif @tokens.length == 6
41
+ @case_op = @tokens[2]
42
+ @case_val = @tokens[4]
43
+ @case_type = 'normal_with_op'
44
+ else
45
+ @case_op = nil
46
+ @case_val = nil
47
+ @case_type = 'default'
48
+ end
49
+
50
+ @children << :case_val
51
+ @children << :case_op
52
+ @children << :case_type
53
+ end
54
+ end
55
+ end
@@ -28,18 +28,43 @@ require 'nasl/parser/node'
28
28
 
29
29
  module Nasl
30
30
  class Function < Node
31
- attr_reader :body, :name, :params
31
+ attr_reader :body, :name, :params, :attribute, :fn_type
32
32
 
33
33
  def initialize(tree, *tokens)
34
34
  super
35
35
 
36
- @name = @tokens[1]
37
- @params = if @tokens.length == 6 then @tokens[3] else [] end
38
36
  @body = @tokens.last
39
37
 
38
+ @fn_type = @tokens[1]
39
+
40
+ if @fn_type == "obj"
41
+ @name = @tokens[3]
42
+ @attribute = @tokens[0]
43
+ if @tokens.length == 8
44
+ @params = @tokens[5]
45
+ else
46
+ @params = []
47
+ end
48
+ else
49
+ @name = @tokens[2]
50
+ @attribute = []
51
+ if @tokens.length == 7
52
+ @params = @tokens[4]
53
+ else
54
+ @params = []
55
+ end
56
+ end
57
+
40
58
  @children << :name
59
+ @children << :attribute
41
60
  @children << :params
42
61
  @children << :body
62
+ @children << :fn_type
43
63
  end
64
+
65
+ def each
66
+ @body.each{ |stmt| yield stmt }
67
+ end
68
+
44
69
  end
45
70
  end