nasl 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +107 -0
- data/Rakefile +21 -2
- data/lib/nasl/cli.rb +1 -0
- data/lib/nasl/command.rb +5 -1
- data/lib/nasl/commands/benchmark.rb +4 -8
- data/lib/nasl/commands/parse.rb +3 -5
- data/lib/nasl/commands/tokenize.rb +3 -1
- data/lib/nasl/commands/xml.rb +0 -3
- data/lib/nasl/grammar.racc +24 -24
- data/lib/nasl/parser/argument.rb +3 -2
- data/lib/nasl/parser/assigment.rb +3 -3
- data/lib/nasl/parser/block.rb +1 -1
- data/lib/nasl/parser/break.rb +1 -1
- data/lib/nasl/parser/call.rb +2 -2
- data/lib/nasl/parser/comment.rb +1 -1
- data/lib/nasl/parser/continue.rb +1 -1
- data/lib/nasl/parser/decrement.rb +2 -2
- data/lib/nasl/parser/empty.rb +1 -1
- data/lib/nasl/parser/export.rb +1 -1
- data/lib/nasl/parser/expression.rb +3 -3
- data/lib/nasl/parser/for.rb +5 -5
- data/lib/nasl/parser/foreach.rb +3 -3
- data/lib/nasl/parser/function.rb +3 -3
- data/lib/nasl/parser/global.rb +1 -1
- data/lib/nasl/parser/identifier.rb +1 -1
- data/lib/nasl/parser/if.rb +4 -4
- data/lib/nasl/parser/import.rb +1 -1
- data/lib/nasl/parser/include.rb +2 -2
- data/lib/nasl/parser/increment.rb +2 -2
- data/lib/nasl/parser/integer.rb +1 -1
- data/lib/nasl/parser/ip.rb +1 -1
- data/lib/nasl/parser/local.rb +1 -1
- data/lib/nasl/parser/lvalue.rb +2 -2
- data/lib/nasl/parser/node.rb +10 -7
- data/lib/nasl/parser/repeat.rb +2 -2
- data/lib/nasl/parser/repetition.rb +2 -2
- data/lib/nasl/parser/return.rb +1 -1
- data/lib/nasl/parser/string.rb +2 -6
- data/lib/nasl/parser/undefined.rb +1 -1
- data/lib/nasl/parser/while.rb +2 -2
- data/lib/nasl/version.rb +1 -1
- data/nasl.gemspec +9 -5
- data/test/unit/parser/test_assignment.rb +2 -2
- metadata +81 -10
data/README.md
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
Installation
|
2
|
+
============
|
3
|
+
|
4
|
+
Git
|
5
|
+
---
|
6
|
+
|
7
|
+
Installing the source from Git is done as follows:
|
8
|
+
|
9
|
+
git clone git://github.com/tenable/nasl.git
|
10
|
+
|
11
|
+
Gem
|
12
|
+
---
|
13
|
+
|
14
|
+
Installing the package from RubyGems is done as follows:
|
15
|
+
|
16
|
+
gem install nasl
|
17
|
+
|
18
|
+
Usage
|
19
|
+
=====
|
20
|
+
|
21
|
+
Standalone
|
22
|
+
----------
|
23
|
+
|
24
|
+
To avoid conflicting with the NASL interpreter, the NASL gem's binary is
|
25
|
+
installed as <nasl-parse>. As an application, it has very few actions that it
|
26
|
+
can perform.
|
27
|
+
|
28
|
+
# Benchmark: This benchmarks the time taken to parse the input path(s) over a
|
29
|
+
number of iterations. The number of iterations can be adjusted by the <-i>
|
30
|
+
switch.
|
31
|
+
|
32
|
+
% nasl-parse -i 10 benchmark /opt/nessus/lib/nessus/plugins/ssl_certificate_chain.nasl
|
33
|
+
-------------------------[ ssl_certificate_chain.nasl ]-------------------------
|
34
|
+
Rehearsal --------------------------------------------
|
35
|
+
Tokenize 1.687500 0.000000 1.687500 ( 1.688397)
|
36
|
+
Parse 1.835938 0.015625 1.851562 ( 1.857094)
|
37
|
+
----------------------------------- total: 3.539062sec
|
38
|
+
|
39
|
+
user system total real
|
40
|
+
Tokenize 1.304688 0.015625 1.320312 ( 1.319951)
|
41
|
+
Parse 1.046875 0.000000 1.046875 ( 1.046957)
|
42
|
+
-------------------------[ ssl_certificate_chain.nasl ]-------------------------
|
43
|
+
|
44
|
+
# Parse: This parses the input path(s) and indicates whether the parse was
|
45
|
+
successful.
|
46
|
+
|
47
|
+
% nasl-parse parse /opt/nessus/lib/nessus/plugins/ssl_certificate_chain.nasl
|
48
|
+
-------------------------[ ssl_certificate_chain.nasl ]-------------------------
|
49
|
+
Successfully parsed the contents of the file.
|
50
|
+
-------------------------[ ssl_certificate_chain.nasl ]-------------------------
|
51
|
+
|
52
|
+
# Test: This runs unit tests distributed with the application. Specific unit
|
53
|
+
tests can be specified on the command line, otherwise all tests will be run.
|
54
|
+
|
55
|
+
% nasl-parse test
|
56
|
+
Run options:
|
57
|
+
|
58
|
+
# Running tests:
|
59
|
+
|
60
|
+
.............................................................................
|
61
|
+
|
62
|
+
Finished tests in 11.773983s, 6.5398 tests/s, 33493.8487 assertions/s.
|
63
|
+
|
64
|
+
77 tests, 394356 assertions, 0 failures, 0 errors, 0 skips
|
65
|
+
|
66
|
+
# Tokenize: This tokenizes the input path(s) and prints the token/byte-range
|
67
|
+
pairs to stdout.
|
68
|
+
|
69
|
+
% nasl-parse tokenize /opt/nessus/lib/nessus/plugins/ssl_certificate_chain.nasl
|
70
|
+
-------------------------[ ssl_certificate_chain.nasl ]-------------------------
|
71
|
+
[COMMENT, 0...1076]
|
72
|
+
[IF, 1076...1079]
|
73
|
+
[LPAREN, 1079...1080]
|
74
|
+
[IDENT, 1080...1091]
|
75
|
+
[CMP_LT, 1091...1093]
|
76
|
+
...
|
77
|
+
-------------------------[ ssl_certificate_chain.nasl ]-------------------------
|
78
|
+
|
79
|
+
# XML: This parses the input path(s), and then prints an XML representation of
|
80
|
+
the parse tree to stdout.
|
81
|
+
|
82
|
+
% nasl-parse xml /opt/nessus/lib/nessus/plugins/ssl_certificate_chain.nasl
|
83
|
+
-------------------------[ ssl_certificate_chain.nasl ]-------------------------
|
84
|
+
<tree>
|
85
|
+
<if>
|
86
|
+
<expression>
|
87
|
+
<op><</op>
|
88
|
+
<lvalue>
|
89
|
+
...
|
90
|
+
-------------------------[ ssl_certificate_chain.nasl ]-------------------------
|
91
|
+
|
92
|
+
Library
|
93
|
+
-------
|
94
|
+
|
95
|
+
The primary users of this gem are [Pedant][pedant] and [Nasldoc][nasldoc]. Other
|
96
|
+
uses are encouraged, of course! The <Parser> class is the most useful part,
|
97
|
+
obviously, and can be used as follows:
|
98
|
+
|
99
|
+
require 'nasl'
|
100
|
+
|
101
|
+
tree = Nasl::Parser.new.parse(file_contents, path_to_file)
|
102
|
+
|
103
|
+
That's all there is to it. If there are any errors, it'll throw an instance of
|
104
|
+
<ParseException> that will include as much context about the error as possible.
|
105
|
+
|
106
|
+
[nasldoc]: https://github.com/tenable/nasldoc
|
107
|
+
[pedant]: https://github.com/tenable/pedant
|
data/Rakefile
CHANGED
@@ -1,8 +1,27 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
|
2
|
+
|
1
3
|
require 'bundler/gem_tasks'
|
4
|
+
require 'rake'
|
5
|
+
require 'rake/clean'
|
2
6
|
require 'rake/testtask'
|
3
7
|
|
4
8
|
Rake::TestTask.new do |t|
|
5
9
|
t.libs << 'test'
|
6
|
-
t.test_files = FileList['test/**/
|
7
|
-
|
10
|
+
t.test_files = FileList['test/**/test_*.rb']
|
11
|
+
end
|
12
|
+
|
13
|
+
rule(%r{\.tab\.rb$} => lambda { |f| f.sub(/\.tab.rb/, '.racc') }) do |t|
|
14
|
+
sh "racc #{t.source}"
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Generate grammar modules from Racc source."
|
18
|
+
task :grammars => FileList['**/*.racc'].ext('.tab.rb')
|
19
|
+
|
20
|
+
desc "Produce a fully-functional application."
|
21
|
+
task :compile => [:grammars, :test]
|
22
|
+
|
23
|
+
task :build => :compile do
|
24
|
+
system "gem build nasl.gemspec"
|
8
25
|
end
|
26
|
+
|
27
|
+
task :default => :compile
|
data/lib/nasl/cli.rb
CHANGED
@@ -86,6 +86,7 @@ module Nasl
|
|
86
86
|
puts " benchmark Benchmarks the parsing of the input path(s)."
|
87
87
|
puts " parse Parses the input path(s)."
|
88
88
|
puts " test Runs the specified unit tests, all are selected by default."
|
89
|
+
puts " tokenize Tokenizes the input path(s)."
|
89
90
|
puts " xml Parses the input path(s) and displays them as XML."
|
90
91
|
end
|
91
92
|
end
|
data/lib/nasl/command.rb
CHANGED
@@ -89,7 +89,11 @@ module Nasl
|
|
89
89
|
if self.respond_to? :analyze_all then
|
90
90
|
analyze_all(cfg, dirents, args)
|
91
91
|
else
|
92
|
-
dirents.each
|
92
|
+
dirents.each do |d|
|
93
|
+
puts banner(d.basename)
|
94
|
+
analyze(cfg, d, args)
|
95
|
+
puts banner(d.basename)
|
96
|
+
end
|
93
97
|
end
|
94
98
|
end
|
95
99
|
end
|
@@ -33,23 +33,19 @@ module Nasl
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def self.analyze(cfg, path, args)
|
36
|
-
puts banner(path.basename)
|
37
|
-
|
38
36
|
Benchmark.bmbm do |b|
|
39
37
|
# Read in the file outside of the benchmark, to avoid contaminating it
|
40
38
|
# with filesystem operations.
|
41
39
|
contents = File.open(path, "rb").read
|
42
40
|
|
43
41
|
b.report("Tokenize") do
|
44
|
-
cfg[:iterations].times { Tokenizer.new(contents).
|
42
|
+
cfg[:iterations].times { Tokenizer.new(contents, path).get_tokens }
|
45
43
|
end
|
46
44
|
|
47
|
-
|
48
|
-
|
49
|
-
|
45
|
+
b.report("Parse") do
|
46
|
+
cfg[:iterations].times { Parser.new.parse(contents) }
|
47
|
+
end
|
50
48
|
end
|
51
|
-
|
52
|
-
puts banner(path.basename)
|
53
49
|
end
|
54
50
|
end
|
55
51
|
end
|
data/lib/nasl/commands/parse.rb
CHANGED
@@ -24,8 +24,6 @@
|
|
24
24
|
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
25
25
|
################################################################################
|
26
26
|
|
27
|
-
require 'rainbow'
|
28
|
-
|
29
27
|
module Nasl
|
30
28
|
class CommandParse < Command
|
31
29
|
def self.binding
|
@@ -36,20 +34,20 @@ module Nasl
|
|
36
34
|
begin
|
37
35
|
contents = File.open(path, "rb").read
|
38
36
|
rescue
|
39
|
-
puts
|
37
|
+
puts "Failed to read in the contents of the file."
|
40
38
|
return
|
41
39
|
end
|
42
40
|
|
43
41
|
begin
|
44
42
|
Parser.new.parse(contents, path)
|
45
43
|
rescue Exception => e
|
46
|
-
puts
|
44
|
+
puts "Failed to parse the contents of the file."
|
47
45
|
puts e.message
|
48
46
|
puts e.backtrace
|
49
47
|
return
|
50
48
|
end
|
51
49
|
|
52
|
-
puts
|
50
|
+
puts "Successfully parsed the contents of the file."
|
53
51
|
end
|
54
52
|
end
|
55
53
|
end
|
@@ -34,7 +34,9 @@ module Nasl
|
|
34
34
|
contents = File.open(path, "rb").read
|
35
35
|
|
36
36
|
begin
|
37
|
-
Tokenizer.new(contents, path).get_tokens
|
37
|
+
Tokenizer.new(contents, path).get_tokens.each do |t|
|
38
|
+
puts "[#{(t.first.to_s + ',').ljust(10)}#{t.last.region.to_s.rjust(20)}]"
|
39
|
+
end
|
38
40
|
rescue TokenException => e
|
39
41
|
puts "The tokenizer raised the following exceptions when processing #{path}:"
|
40
42
|
puts e.message
|
data/lib/nasl/commands/xml.rb
CHANGED
data/lib/nasl/grammar.racc
CHANGED
@@ -151,7 +151,7 @@ rule
|
|
151
151
|
##############################################################################
|
152
152
|
|
153
153
|
assign : assign_exp SEMICOLON
|
154
|
-
{
|
154
|
+
{ val[0] }
|
155
155
|
;
|
156
156
|
|
157
157
|
break : BREAK SEMICOLON
|
@@ -159,7 +159,7 @@ rule
|
|
159
159
|
;
|
160
160
|
|
161
161
|
call : call_exp SEMICOLON
|
162
|
-
{
|
162
|
+
{ val[0] }
|
163
163
|
;
|
164
164
|
|
165
165
|
continue : CONTINUE SEMICOLON
|
@@ -167,7 +167,7 @@ rule
|
|
167
167
|
;
|
168
168
|
|
169
169
|
decr : decr_exp SEMICOLON
|
170
|
-
{
|
170
|
+
{ val[0] }
|
171
171
|
;
|
172
172
|
|
173
173
|
empty : SEMICOLON
|
@@ -179,7 +179,7 @@ rule
|
|
179
179
|
;
|
180
180
|
|
181
181
|
incr : incr_exp SEMICOLON
|
182
|
-
{
|
182
|
+
{ val[0] }
|
183
183
|
;
|
184
184
|
|
185
185
|
import : IMPORT LPAREN string RPAREN SEMICOLON
|
@@ -195,7 +195,7 @@ rule
|
|
195
195
|
;
|
196
196
|
|
197
197
|
rep : call_exp REP expr SEMICOLON
|
198
|
-
{ n(:Repetition, n(:Call,
|
198
|
+
{ n(:Repetition, n(:Call, val[0]), *val[1..-1]) }
|
199
199
|
;
|
200
200
|
|
201
201
|
return : RETURN expr SEMICOLON
|
@@ -241,40 +241,40 @@ rule
|
|
241
241
|
##############################################################################
|
242
242
|
|
243
243
|
assign_exp : lval ASS_EQ expr
|
244
|
-
{ val }
|
244
|
+
{ n(:Assignment, *val) }
|
245
245
|
| lval ADD_EQ expr
|
246
|
-
{ val }
|
246
|
+
{ n(:Assignment, *val) }
|
247
247
|
| lval SUB_EQ expr
|
248
|
-
{ val }
|
248
|
+
{ n(:Assignment, *val) }
|
249
249
|
| lval MUL_EQ expr
|
250
|
-
{ val }
|
250
|
+
{ n(:Assignment, *val) }
|
251
251
|
| lval DIV_EQ expr
|
252
|
-
{ val }
|
252
|
+
{ n(:Assignment, *val) }
|
253
253
|
| lval MOD_EQ expr
|
254
|
-
{ val }
|
254
|
+
{ n(:Assignment, *val) }
|
255
255
|
| lval SRL_EQ expr
|
256
|
-
{ val }
|
256
|
+
{ n(:Assignment, *val) }
|
257
257
|
| lval SRA_EQ expr
|
258
|
-
{ val }
|
258
|
+
{ n(:Assignment, *val) }
|
259
259
|
| lval SLL_EQ expr
|
260
|
-
{ val }
|
260
|
+
{ n(:Assignment, *val) }
|
261
261
|
;
|
262
262
|
|
263
263
|
call_exp : ident LPAREN args RPAREN
|
264
|
-
{ val }
|
264
|
+
{ n(:Call, *val) }
|
265
265
|
| ident LPAREN RPAREN
|
266
|
-
{ val }
|
266
|
+
{ n(:Call, *val) }
|
267
267
|
|
268
268
|
decr_exp : DECR lval
|
269
|
-
{ val }
|
269
|
+
{ n(:Decrement, val[0]) }
|
270
270
|
| lval DECR
|
271
|
-
{ val }
|
271
|
+
{ n(:Decrement, val[0]) }
|
272
272
|
;
|
273
273
|
|
274
274
|
incr_exp : INCR lval
|
275
|
-
{ val }
|
275
|
+
{ n(:Increment, val[0]) }
|
276
276
|
| lval INCR
|
277
|
-
{ val }
|
277
|
+
{ n(:Increment, val[0]) }
|
278
278
|
;
|
279
279
|
|
280
280
|
expr : LPAREN expr RPAREN
|
@@ -314,9 +314,9 @@ rule
|
|
314
314
|
| expr BIT_SLL expr
|
315
315
|
{ n(:Expression, *val) }
|
316
316
|
| incr_exp
|
317
|
-
{
|
317
|
+
{ val[0] }
|
318
318
|
| decr_exp
|
319
|
-
{
|
319
|
+
{ val[0] }
|
320
320
|
| expr SUBSTR_EQ expr
|
321
321
|
{ n(:Expression, *val) }
|
322
322
|
| expr SUBSTR_NE expr
|
@@ -338,11 +338,11 @@ rule
|
|
338
338
|
| expr CMP_LE expr
|
339
339
|
{ n(:Expression, *val) }
|
340
340
|
| assign_exp
|
341
|
-
{
|
341
|
+
{ val[0] }
|
342
342
|
| string
|
343
343
|
{ val[0] }
|
344
344
|
| call_exp
|
345
|
-
{
|
345
|
+
{ val[0] }
|
346
346
|
| lval
|
347
347
|
{ val[0] }
|
348
348
|
| ip
|
data/lib/nasl/parser/argument.rb
CHANGED
data/lib/nasl/parser/block.rb
CHANGED
data/lib/nasl/parser/break.rb
CHANGED
data/lib/nasl/parser/call.rb
CHANGED
data/lib/nasl/parser/comment.rb
CHANGED
data/lib/nasl/parser/continue.rb
CHANGED
data/lib/nasl/parser/empty.rb
CHANGED
data/lib/nasl/parser/export.rb
CHANGED
@@ -33,7 +33,7 @@ module Nasl
|
|
33
33
|
def initialize(tree, *tokens)
|
34
34
|
super
|
35
35
|
|
36
|
-
@
|
36
|
+
@children << :op
|
37
37
|
|
38
38
|
if @tokens.first.is_a?(Token) && @tokens.first.type == :LPAREN
|
39
39
|
@op = '()'
|
@@ -44,13 +44,13 @@ module Nasl
|
|
44
44
|
@lhs = nil
|
45
45
|
@rhs = @tokens.last
|
46
46
|
else
|
47
|
-
@
|
47
|
+
@children << :lhs
|
48
48
|
@lhs = @tokens[0]
|
49
49
|
@op = @tokens[1]
|
50
50
|
@rhs = @tokens[2]
|
51
51
|
end
|
52
52
|
|
53
|
-
@
|
53
|
+
@children << :rhs
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
data/lib/nasl/parser/for.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
!################################################################################
|
2
2
|
# Copyright (c) 2011-2012, Mak Kolybabi
|
3
3
|
# All rights reserved.
|
4
4
|
#
|
@@ -38,10 +38,10 @@ module Nasl
|
|
38
38
|
@each = @tokens[6]
|
39
39
|
@body = @tokens[8]
|
40
40
|
|
41
|
-
@
|
42
|
-
@
|
43
|
-
@
|
44
|
-
@
|
41
|
+
@children << :init
|
42
|
+
@children << :cond
|
43
|
+
@children << :each
|
44
|
+
@children << :body
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
data/lib/nasl/parser/foreach.rb
CHANGED
data/lib/nasl/parser/function.rb
CHANGED
@@ -37,9 +37,9 @@ module Nasl
|
|
37
37
|
@params = if @tokens.length == 6 then @tokens[3] else [] end
|
38
38
|
@body = @tokens.last
|
39
39
|
|
40
|
-
@
|
41
|
-
@
|
42
|
-
@
|
40
|
+
@children << :name
|
41
|
+
@children << :params
|
42
|
+
@children << :body
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
data/lib/nasl/parser/global.rb
CHANGED
data/lib/nasl/parser/if.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
!################################################################################
|
2
2
|
# Copyright (c) 2011-2012, Mak Kolybabi
|
3
3
|
# All rights reserved.
|
4
4
|
#
|
@@ -37,9 +37,9 @@ module Nasl
|
|
37
37
|
@true = @tokens[4]
|
38
38
|
@false = if @tokens.length == 7 then @tokens.last else nil end
|
39
39
|
|
40
|
-
@
|
41
|
-
@
|
42
|
-
@
|
40
|
+
@children << :cond
|
41
|
+
@children << :true
|
42
|
+
@children << :false
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
data/lib/nasl/parser/import.rb
CHANGED
data/lib/nasl/parser/include.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
!################################################################################
|
2
2
|
# Copyright (c) 2011-2012, Mak Kolybabi
|
3
3
|
# All rights reserved.
|
4
4
|
#
|
@@ -35,7 +35,7 @@ module Nasl
|
|
35
35
|
|
36
36
|
@filename = @tokens[2]
|
37
37
|
|
38
|
-
@
|
38
|
+
@children << :filename
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
data/lib/nasl/parser/integer.rb
CHANGED
data/lib/nasl/parser/ip.rb
CHANGED
data/lib/nasl/parser/local.rb
CHANGED
data/lib/nasl/parser/lvalue.rb
CHANGED
data/lib/nasl/parser/node.rb
CHANGED
@@ -32,9 +32,9 @@ module Nasl
|
|
32
32
|
# Register new node in the tree.
|
33
33
|
tree.register(self)
|
34
34
|
|
35
|
-
# Create the
|
36
|
-
# to XML.
|
35
|
+
# Create the arrays which are used for converting the parse tree to XML.
|
37
36
|
@attributes = []
|
37
|
+
@children = []
|
38
38
|
|
39
39
|
# Store all of the tokens that made up this node.
|
40
40
|
@tokens = tokens
|
@@ -56,22 +56,25 @@ module Nasl
|
|
56
56
|
name = self.class.name.split('::').last
|
57
57
|
name = name.gsub(/(.)([A-Z])/, '\1_\2').downcase
|
58
58
|
|
59
|
+
# Create a hash from the attribute array.
|
60
|
+
attr = Hash[@attributes.map{ |el| [el, self.send(el)] }]
|
61
|
+
|
59
62
|
# If there are no attributes, make a modified opening tag.
|
60
|
-
return xml.tag!(name) if @
|
63
|
+
return xml.tag!(name, attr) if @children.empty?
|
61
64
|
|
62
65
|
# Create the tag representing this node.
|
63
|
-
xml.tag!(name) do
|
64
|
-
@
|
66
|
+
xml.tag!(name, attr) do
|
67
|
+
@children.each do |name|
|
65
68
|
# Retrieve the object that the symbol indicates.
|
66
69
|
obj = self.send(name)
|
67
70
|
|
68
|
-
# Skip over
|
71
|
+
# Skip over empty children.
|
69
72
|
next if obj.nil?
|
70
73
|
|
71
74
|
# Handle objects that are arrays holding nodes, or basic types that
|
72
75
|
# aren't nodes.
|
73
76
|
if obj.is_a? Array
|
74
|
-
obj.each { |
|
77
|
+
obj.each { |el| el.to_xml(xml) }
|
75
78
|
elsif obj.is_a? Node
|
76
79
|
obj.to_xml(xml)
|
77
80
|
else
|
data/lib/nasl/parser/repeat.rb
CHANGED
data/lib/nasl/parser/return.rb
CHANGED
data/lib/nasl/parser/string.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
!################################################################################
|
2
2
|
# Copyright (c) 2011-2012, Mak Kolybabi
|
3
3
|
# All rights reserved.
|
4
4
|
#
|
@@ -38,11 +38,7 @@ module Nasl
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def to_xml(xml)
|
41
|
-
|
42
|
-
xml.data(@text)
|
43
|
-
else
|
44
|
-
xml.string(@text)
|
45
|
-
end
|
41
|
+
xml.method_missing(@type.downcase, @text)
|
46
42
|
end
|
47
43
|
end
|
48
44
|
end
|
data/lib/nasl/parser/while.rb
CHANGED
data/lib/nasl/version.rb
CHANGED
data/nasl.gemspec
CHANGED
@@ -1,25 +1,29 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
|
3
4
|
require 'nasl/version'
|
4
5
|
|
5
6
|
Gem::Specification.new do |s|
|
6
7
|
s.name = 'nasl'
|
7
8
|
s.version = Nasl::VERSION
|
9
|
+
s.license = "BSD"
|
10
|
+
s.homepage = 'http://github.com/tenable/nasl'
|
11
|
+
s.summary = 'A parser for the Nessus Attack Scripting Language.'
|
12
|
+
s.description = File.open('README.md').read
|
13
|
+
|
8
14
|
s.authors = ['Mak Kolybabi']
|
9
15
|
s.email = ['mak@kolybabi.com']
|
10
|
-
s.homepage = 'http://github.com/mogigoma/nasl'
|
11
|
-
s.summary = %q{A parser for the Nessus Attack Scripting Language.}
|
12
16
|
|
13
17
|
s.rubyforge_project = 'nasl'
|
14
18
|
|
15
|
-
s.files = `git ls-files`.split("\n") +
|
16
|
-
s.test_files = `git ls-files --
|
19
|
+
s.files = `git ls-files`.split("\n") + Dir.glob('**/*.tab.rb')
|
20
|
+
s.test_files = `git ls-files -- test/*`.split("\n")
|
17
21
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
22
|
s.require_paths = ['lib']
|
19
23
|
|
24
|
+
s.add_development_dependency 'racc'
|
20
25
|
s.add_development_dependency 'rake'
|
21
26
|
|
22
27
|
s.add_runtime_dependency 'builder'
|
23
|
-
s.add_runtime_dependency 'racc'
|
24
28
|
s.add_runtime_dependency 'rainbow'
|
25
29
|
end
|
@@ -37,7 +37,7 @@ class TestAssignment < Test::Unit::TestCase
|
|
37
37
|
def test_string
|
38
38
|
same(
|
39
39
|
"q = '';",
|
40
|
-
'<tree><assignment><op>=</op><lvalue><identifier name="q"/></lvalue><data
|
40
|
+
'<tree><assignment><op>=</op><lvalue><identifier name="q"/></lvalue><data/></assignment></tree>'
|
41
41
|
)
|
42
42
|
same(
|
43
43
|
"q = 'foo';",
|
@@ -45,7 +45,7 @@ class TestAssignment < Test::Unit::TestCase
|
|
45
45
|
)
|
46
46
|
same(
|
47
47
|
'q = "";',
|
48
|
-
'<tree><assignment><op>=</op><lvalue><identifier name="q"/></lvalue><string
|
48
|
+
'<tree><assignment><op>=</op><lvalue><identifier name="q"/></lvalue><string/></assignment></tree>'
|
49
49
|
)
|
50
50
|
same(
|
51
51
|
'q = "foo";',
|
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.0.
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,10 +9,10 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
15
|
+
name: racc
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
@@ -28,14 +28,14 @@ dependencies:
|
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
|
-
name:
|
31
|
+
name: rake
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
35
35
|
- - ! '>='
|
36
36
|
- !ruby/object:Gem::Version
|
37
37
|
version: '0'
|
38
|
-
type: :
|
38
|
+
type: :development
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
@@ -44,7 +44,7 @@ dependencies:
|
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
47
|
+
name: builder
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
@@ -75,7 +75,48 @@ dependencies:
|
|
75
75
|
- - ! '>='
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
|
-
description:
|
78
|
+
description: ! "Installation\n============\n\nGit\n---\n\nInstalling the source from
|
79
|
+
Git is done as follows:\n\n git clone git://github.com/tenable/nasl.git\n\nGem\n---\n\nInstalling
|
80
|
+
the package from RubyGems is done as follows:\n\n gem install nasl\n\nUsage\n=====\n\nStandalone\n----------\n\nTo
|
81
|
+
avoid conflicting with the NASL interpreter, the NASL gem's binary is\ninstalled
|
82
|
+
as <nasl-parse>. As an application, it has very few actions that it\ncan perform.\n\n#
|
83
|
+
Benchmark: This benchmarks the time taken to parse the input path(s) over a\n number
|
84
|
+
of iterations. The number of iterations can be adjusted by the <-i>\n switch.\n\n
|
85
|
+
\ % nasl-parse -i 10 benchmark /opt/nessus/lib/nessus/plugins/ssl_certificate_chain.nasl\n
|
86
|
+
\ -------------------------[ ssl_certificate_chain.nasl ]-------------------------\n
|
87
|
+
\ Rehearsal --------------------------------------------\n Tokenize 1.687500
|
88
|
+
\ 0.000000 1.687500 ( 1.688397)\n Parse 1.835938 0.015625 1.851562
|
89
|
+
( 1.857094)\n ----------------------------------- total: 3.539062sec\n\n user
|
90
|
+
\ system total real\n Tokenize 1.304688 0.015625 1.320312
|
91
|
+
( 1.319951)\n Parse 1.046875 0.000000 1.046875 ( 1.046957)\n -------------------------[
|
92
|
+
ssl_certificate_chain.nasl ]-------------------------\n\n# Parse: This parses the
|
93
|
+
input path(s) and indicates whether the parse was\n successful.\n\n % nasl-parse
|
94
|
+
parse /opt/nessus/lib/nessus/plugins/ssl_certificate_chain.nasl\n -------------------------[
|
95
|
+
ssl_certificate_chain.nasl ]-------------------------\n Successfully parsed the
|
96
|
+
contents of the file.\n -------------------------[ ssl_certificate_chain.nasl
|
97
|
+
]-------------------------\n\n# Test: This runs unit tests distributed with the
|
98
|
+
application. Specific unit\n tests can be specified on the command line, otherwise
|
99
|
+
all tests will be run.\n\n % nasl-parse test\n Run options:\n \n # Running
|
100
|
+
tests:\n \n .............................................................................\n
|
101
|
+
\ \n Finished tests in 11.773983s, 6.5398 tests/s, 33493.8487 assertions/s.\n
|
102
|
+
\ \n 77 tests, 394356 assertions, 0 failures, 0 errors, 0 skips\n\n# Tokenize:
|
103
|
+
This tokenizes the input path(s) and prints the token/byte-range\n pairs to stdout.\n\n
|
104
|
+
\ % nasl-parse tokenize /opt/nessus/lib/nessus/plugins/ssl_certificate_chain.nasl\n
|
105
|
+
\ -------------------------[ ssl_certificate_chain.nasl ]-------------------------\n
|
106
|
+
\ [COMMENT, 0...1076]\n [IF, 1076...1079]\n [LPAREN,
|
107
|
+
\ 1079...1080]\n [IDENT, 1080...1091]\n [CMP_LT, 1091...1093]\n
|
108
|
+
\ ...\n -------------------------[ ssl_certificate_chain.nasl ]-------------------------\n\n#
|
109
|
+
XML: This parses the input path(s), and then prints an XML representation of\n the
|
110
|
+
parse tree to stdout.\n\n % nasl-parse xml /opt/nessus/lib/nessus/plugins/ssl_certificate_chain.nasl\n
|
111
|
+
\ -------------------------[ ssl_certificate_chain.nasl ]-------------------------\n
|
112
|
+
\ <tree>\n <if>\n <expression>\n <op><</op>\n <lvalue>\n
|
113
|
+
\ ...\n -------------------------[ ssl_certificate_chain.nasl ]-------------------------\n\nLibrary\n-------\n\nThe
|
114
|
+
primary users of this gem are [Pedant][pedant] and [Nasldoc][nasldoc]. Other\nuses
|
115
|
+
are encouraged, of course! The <Parser> class is the most useful part,\nobviously,
|
116
|
+
and can be used as follows:\n\n require 'nasl'\n\n tree = Nasl::Parser.new.parse(file_contents,
|
117
|
+
path_to_file)\n\nThat's all there is to it. If there are any errors, it'll throw
|
118
|
+
an instance of\n<ParseException> that will include as much context about the error
|
119
|
+
as possible.\n\n[nasldoc]: https://github.com/tenable/nasldoc\n[pedant]: https://github.com/tenable/pedant\n"
|
79
120
|
email:
|
80
121
|
- mak@kolybabi.com
|
81
122
|
executables:
|
@@ -85,6 +126,7 @@ extra_rdoc_files: []
|
|
85
126
|
files:
|
86
127
|
- .gitignore
|
87
128
|
- Gemfile
|
129
|
+
- README.md
|
88
130
|
- Rakefile
|
89
131
|
- bin/nasl-parse
|
90
132
|
- lib/nasl.rb
|
@@ -158,8 +200,9 @@ files:
|
|
158
200
|
- test/unit/tokenizer/test_integer.rb
|
159
201
|
- test/unit/tokenizer/test_string.rb
|
160
202
|
- lib/nasl/grammar.tab.rb
|
161
|
-
homepage: http://github.com/
|
162
|
-
licenses:
|
203
|
+
homepage: http://github.com/tenable/nasl
|
204
|
+
licenses:
|
205
|
+
- BSD
|
163
206
|
post_install_message:
|
164
207
|
rdoc_options: []
|
165
208
|
require_paths:
|
@@ -170,16 +213,44 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
170
213
|
- - ! '>='
|
171
214
|
- !ruby/object:Gem::Version
|
172
215
|
version: '0'
|
216
|
+
segments:
|
217
|
+
- 0
|
218
|
+
hash: -1091891794194809699
|
173
219
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
174
220
|
none: false
|
175
221
|
requirements:
|
176
222
|
- - ! '>='
|
177
223
|
- !ruby/object:Gem::Version
|
178
224
|
version: '0'
|
225
|
+
segments:
|
226
|
+
- 0
|
227
|
+
hash: -1091891794194809699
|
179
228
|
requirements: []
|
180
229
|
rubyforge_project: nasl
|
181
230
|
rubygems_version: 1.8.24
|
182
231
|
signing_key:
|
183
232
|
specification_version: 3
|
184
233
|
summary: A parser for the Nessus Attack Scripting Language.
|
185
|
-
test_files:
|
234
|
+
test_files:
|
235
|
+
- test/test_helper.rb
|
236
|
+
- test/unit/parser/test_assignment.rb
|
237
|
+
- test/unit/parser/test_blank.rb
|
238
|
+
- test/unit/parser/test_block.rb
|
239
|
+
- test/unit/parser/test_call.rb
|
240
|
+
- test/unit/parser/test_comment.rb
|
241
|
+
- test/unit/parser/test_constant.rb
|
242
|
+
- test/unit/parser/test_empty.rb
|
243
|
+
- test/unit/parser/test_expressions.rb
|
244
|
+
- test/unit/parser/test_function.rb
|
245
|
+
- test/unit/parser/test_if.rb
|
246
|
+
- test/unit/parser/test_include.rb
|
247
|
+
- test/unit/parser/test_incr_decr.rb
|
248
|
+
- test/unit/parser/test_ip.rb
|
249
|
+
- test/unit/parser/test_return.rb
|
250
|
+
- test/unit/parser/test_string.rb
|
251
|
+
- test/unit/parser/test_whitespace.rb
|
252
|
+
- test/unit/test_context.rb
|
253
|
+
- test/unit/tokenizer/test_comment.rb
|
254
|
+
- test/unit/tokenizer/test_empty.rb
|
255
|
+
- test/unit/tokenizer/test_integer.rb
|
256
|
+
- test/unit/tokenizer/test_string.rb
|