ronin-sql 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. data/History.txt +43 -0
  2. data/Manifest.txt +76 -23
  3. data/README.txt +31 -6
  4. data/Rakefile +2 -2
  5. data/lib/ronin/code/sql/{keyword.rb → add_column_clause.rb} +9 -13
  6. data/lib/ronin/code/sql/as.rb +47 -0
  7. data/lib/ronin/code/sql/asc.rb +38 -0
  8. data/lib/ronin/code/sql/between.rb +18 -12
  9. data/lib/ronin/code/sql/binary_expr.rb +12 -5
  10. data/lib/ronin/code/sql/clause.rb +37 -0
  11. data/lib/ronin/code/sql/code.rb +1 -1
  12. data/lib/ronin/code/sql/common_dialect.rb +16 -10
  13. data/lib/ronin/code/sql/create.rb +68 -0
  14. data/lib/ronin/code/sql/create_index.rb +9 -39
  15. data/lib/ronin/code/sql/create_table.rb +9 -56
  16. data/lib/ronin/code/sql/create_view.rb +7 -29
  17. data/lib/ronin/code/sql/default_values_clause.rb +38 -0
  18. data/lib/ronin/code/sql/delete.rb +10 -25
  19. data/lib/ronin/code/sql/desc.rb +38 -0
  20. data/lib/ronin/code/sql/dialect.rb +172 -52
  21. data/lib/ronin/code/sql/{builder.rb → drop.rb} +16 -20
  22. data/lib/ronin/code/sql/drop_index.rb +43 -0
  23. data/lib/ronin/code/sql/drop_table.rb +8 -16
  24. data/lib/ronin/code/sql/drop_view.rb +43 -0
  25. data/lib/ronin/code/sql/emittable.rb +102 -0
  26. data/lib/ronin/code/sql/exceptions/unknown_clause.rb +31 -0
  27. data/lib/ronin/code/sql/exceptions/unknown_dialect.rb +2 -2
  28. data/lib/ronin/code/sql/exceptions/unknown_statement.rb +31 -0
  29. data/lib/ronin/code/sql/exceptions.rb +3 -1
  30. data/lib/ronin/code/sql/expr.rb +7 -96
  31. data/lib/ronin/code/sql/field.rb +40 -23
  32. data/lib/ronin/code/sql/fields_clause.rb +48 -0
  33. data/lib/ronin/code/sql/from_clause.rb +44 -0
  34. data/lib/ronin/code/sql/function.rb +15 -12
  35. data/lib/ronin/code/sql/group_by_clause.rb +48 -0
  36. data/lib/ronin/code/sql/having_clause.rb +48 -0
  37. data/lib/ronin/code/sql/in.rb +9 -9
  38. data/lib/ronin/code/sql/injected_statement.rb +102 -0
  39. data/lib/ronin/code/sql/injection.rb +171 -5
  40. data/lib/ronin/code/sql/insert.rb +15 -45
  41. data/lib/ronin/code/sql/intersect_clause.rb +44 -0
  42. data/lib/ronin/code/sql/join_clause.rb +125 -0
  43. data/lib/ronin/code/sql/{like_expr.rb → like.rb} +19 -31
  44. data/lib/ronin/code/sql/limit_clause.rb +44 -0
  45. data/lib/ronin/code/sql/modifier.rb +50 -0
  46. data/lib/ronin/code/sql/offset_clause.rb +44 -0
  47. data/lib/ronin/code/sql/on_clause.rb +57 -0
  48. data/lib/ronin/code/sql/order_by_clause.rb +44 -0
  49. data/lib/ronin/code/sql/program.rb +170 -23
  50. data/lib/ronin/code/sql/rename_to_clause.rb +44 -0
  51. data/lib/ronin/code/sql/replace.rb +15 -17
  52. data/lib/ronin/code/sql/select.rb +46 -141
  53. data/lib/ronin/code/sql/set_clause.rb +44 -0
  54. data/lib/ronin/code/sql/statement.rb +117 -47
  55. data/lib/ronin/code/sql/token.rb +64 -0
  56. data/lib/ronin/code/sql/unary_expr.rb +9 -5
  57. data/lib/ronin/code/sql/union_all_clause.rb +44 -0
  58. data/lib/ronin/code/sql/union_clause.rb +44 -0
  59. data/lib/ronin/code/sql/update.rb +10 -31
  60. data/lib/ronin/code/sql/values_clause.rb +48 -0
  61. data/lib/ronin/code/sql/where_clause.rb +44 -0
  62. data/lib/ronin/code/sql.rb +1 -1
  63. data/lib/ronin/sql/error/error.rb +64 -0
  64. data/lib/ronin/sql/error/message.rb +64 -0
  65. data/lib/ronin/sql/error/pattern.rb +106 -0
  66. data/lib/ronin/sql/error/patterns.rb +100 -0
  67. data/lib/ronin/sql/error.rb +5 -30
  68. data/lib/ronin/sql/extensions/uri/http.rb +76 -21
  69. data/lib/ronin/sql/extensions/uri.rb +1 -1
  70. data/lib/ronin/sql/extensions.rb +2 -1
  71. data/lib/ronin/sql/injection.rb +213 -0
  72. data/lib/ronin/sql/version.rb +2 -2
  73. data/lib/ronin/sql.rb +7 -2
  74. data/spec/code/sql/create_examples.rb +19 -0
  75. data/spec/code/sql/create_index_spec.rb +25 -0
  76. data/spec/code/sql/create_table_spec.rb +27 -0
  77. data/spec/code/sql/create_view_spec.rb +16 -0
  78. data/spec/code/sql/delete_spec.rb +14 -0
  79. data/spec/code/sql/drop_examples.rb +10 -0
  80. data/spec/code/sql/drop_index_spec.rb +16 -0
  81. data/spec/code/sql/drop_table_spec.rb +16 -0
  82. data/spec/code/sql/drop_view_spec.rb +16 -0
  83. data/spec/code/sql/has_default_values_clause_examples.rb +10 -0
  84. data/spec/code/sql/has_fields_clause_examples.rb +15 -0
  85. data/spec/code/sql/has_from_clause_examples.rb +13 -0
  86. data/spec/code/sql/has_values_clause_examples.rb +15 -0
  87. data/spec/code/sql/has_where_clause_examples.rb +15 -0
  88. data/spec/code/sql/insert_spec.rb +21 -0
  89. data/spec/code/sql/replace_spec.rb +21 -0
  90. data/spec/code/sql/select_spec.rb +105 -0
  91. data/spec/code/sql/update_spec.rb +26 -0
  92. data/spec/helpers/code.rb +14 -0
  93. data/spec/sql/error_spec.rb +24 -0
  94. data/spec/sql/extensions/string_spec.rb +28 -0
  95. data/spec/sql_spec.rb +9 -0
  96. data/tasks/spec.rb +2 -0
  97. metadata +82 -29
  98. data/lib/ronin/code/sql/injection_builder.rb +0 -137
  99. data/lib/ronin/code/sql/injection_style.rb +0 -79
  100. data/lib/ronin/code/sql/style.rb +0 -170
  101. data/lib/ronin/sql/sql.rb +0 -83
@@ -0,0 +1,44 @@
1
+ #
2
+ #--
3
+ # Ronin SQL - A Ronin library providing support for SQL related security
4
+ # tasks.
5
+ #
6
+ # Copyright (c) 2007-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
7
+ #
8
+ # This program is free software; you can redistribute it and/or modify
9
+ # it under the terms of the GNU General Public License as published by
10
+ # the Free Software Foundation; either version 2 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # This program is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License
19
+ # along with this program; if not, write to the Free Software
20
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
+ #++
22
+ #
23
+
24
+ require 'ronin/code/sql/clause'
25
+
26
+ module Ronin
27
+ module Code
28
+ module SQL
29
+ class IntersectClause < Clause
30
+
31
+ attr_accessor :select
32
+
33
+ def initialize(select)
34
+ @select = select
35
+ end
36
+
37
+ def emit
38
+ emit_token('INTERSECT') + @select.emit
39
+ end
40
+
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,125 @@
1
+ #
2
+ #--
3
+ # Ronin SQL - A Ronin library providing support for SQL related security
4
+ # tasks.
5
+ #
6
+ # Copyright (c) 2007-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
7
+ #
8
+ # This program is free software; you can redistribute it and/or modify
9
+ # it under the terms of the GNU General Public License as published by
10
+ # the Free Software Foundation; either version 2 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # This program is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License
19
+ # along with this program; if not, write to the Free Software
20
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
+ #++
22
+ #
23
+
24
+ require 'ronin/code/sql/clause'
25
+
26
+ module Ronin
27
+ module Code
28
+ module SQL
29
+ class JoinClause < Clause
30
+
31
+ # Table to join with
32
+ attr_accessor :table
33
+
34
+ # Whether the join is natural or not
35
+ attr_accessor :natural
36
+
37
+ # Direction of the join
38
+ attr_accessor :direction
39
+
40
+ # Side of the join
41
+ attr_accessor :side
42
+
43
+ def initialize(table,options={})
44
+ @table = table
45
+ @natural = options[:natural]
46
+
47
+ if options[:left]
48
+ @direction = :left
49
+ elsif options[:right]
50
+ @direction = :right
51
+ elsif options[:full]
52
+ @direction = :full
53
+ end
54
+
55
+ if options[:inner]
56
+ @side = :inner
57
+ elsif options[:outer]
58
+ @side = :outer
59
+ elsif options[:cross]
60
+ @side = :cross
61
+ end
62
+ end
63
+
64
+ def left
65
+ @direction = :left
66
+ return self
67
+ end
68
+
69
+ def right
70
+ @direction = :right
71
+ return self
72
+ end
73
+
74
+ def full
75
+ @direction = :full
76
+ return self
77
+ end
78
+
79
+ def inner
80
+ @side = :inner
81
+ return self
82
+ end
83
+
84
+ def outer
85
+ @side = :outer
86
+ return self
87
+ end
88
+
89
+ def cross
90
+ @side = :cross
91
+ return self
92
+ end
93
+
94
+ def emit
95
+ tokens = []
96
+
97
+ tokens += emit_token('NATURAL') if @natural
98
+
99
+ case @direction
100
+ when :left, 'left'
101
+ tokens += emit_token('LEFT')
102
+ when :right, 'right'
103
+ tokens += emit_token('RIGHT')
104
+ when :full, 'full'
105
+ tokens += emit_token('FULL')
106
+ end
107
+
108
+ case @side
109
+ when :inner, 'inner'
110
+ tokens += emit_token('INNER')
111
+ when :outer, 'outer'
112
+ tokens += emit_token('OUTER')
113
+ when :cross, 'cross'
114
+ tokens += emit_token('CROSS')
115
+ end
116
+
117
+ tokens += emit_token('JOIN')
118
+
119
+ return tokens + emit_value(@table)
120
+ end
121
+
122
+ end
123
+ end
124
+ end
125
+ end
@@ -3,7 +3,7 @@
3
3
  # Ronin SQL - A Ronin library providing support for SQL related security
4
4
  # tasks.
5
5
  #
6
- # Copyright (c) 2007-2008 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ # Copyright (c) 2007-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
7
7
  #
8
8
  # This program is free software; you can redistribute it and/or modify
9
9
  # it under the terms of the GNU General Public License as published by
@@ -26,11 +26,18 @@ require 'ronin/code/sql/expr'
26
26
  module Ronin
27
27
  module Code
28
28
  module SQL
29
- class LikeExpr < Expr
29
+ class Like < Expr
30
30
 
31
- def initialize(style,op,left,right,escape=nil)
32
- super(style)
31
+ # Operator
32
+ attr_reader :op
33
33
 
34
+ # Left-hand side
35
+ attr_reader :left
36
+
37
+ # Right-hand side
38
+ attr_reader :right
39
+
40
+ def initialize(op,left,right,escape=nil)
34
41
  @op = op
35
42
  @left = left
36
43
  @right = right
@@ -46,39 +53,20 @@ module Ronin
46
53
  @negated = true
47
54
  end
48
55
 
49
- def compile
50
- compile_expr(@left,negated?,@op,compile_pattern(@right),escaped?)
51
- end
56
+ def emit
57
+ tokens = emit_value(@left)
52
58
 
53
- protected
59
+ tokens += emit_token('NOT') if @negated
54
60
 
55
- keyword :escape
56
- keyword :not
57
-
58
- def escape_pattern(pattern)
59
- pattern = pattern.to_s
61
+ tokens += emit_token(@op)
62
+ tokens += emit_value(@right)
60
63
 
61
64
  if @escape
62
- return quote_data(pattern)
63
- else
64
- return quote_data("%#{pattern}%")
65
- end
66
- end
67
-
68
- def compile_pattern(pattern)
69
- if pattern.kind_of?(Regexp)
70
- return escape_pattern(pattern.source)
71
- else
72
- return escape_pattern(pattern)
65
+ tokens += emit_token('ESCAPE')
66
+ tokens << @escape.to_s[0..0]
73
67
  end
74
- end
75
-
76
- def escaped?
77
- compile_expr(keyword_escape,"'#{@escape.to_s[0..0]}'") if @escape
78
- end
79
68
 
80
- def negated?
81
- keyword_not if @negated
69
+ return tokens
82
70
  end
83
71
 
84
72
  end
@@ -0,0 +1,44 @@
1
+ #
2
+ #--
3
+ # Ronin SQL - A Ronin library providing support for SQL related security
4
+ # tasks.
5
+ #
6
+ # Copyright (c) 2007-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
7
+ #
8
+ # This program is free software; you can redistribute it and/or modify
9
+ # it under the terms of the GNU General Public License as published by
10
+ # the Free Software Foundation; either version 2 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # This program is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License
19
+ # along with this program; if not, write to the Free Software
20
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
+ #++
22
+ #
23
+
24
+ require 'ronin/code/sql/clause'
25
+
26
+ module Ronin
27
+ module Code
28
+ module SQL
29
+ class LimitClause < Clause
30
+
31
+ attr_accessor :value
32
+
33
+ def initialize(value)
34
+ @value = value
35
+ end
36
+
37
+ def emit
38
+ emit_token('LIMIT') + emit_value(@value)
39
+ end
40
+
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,50 @@
1
+ #
2
+ #--
3
+ # Ronin SQL - A Ronin library providing support for SQL related security
4
+ # tasks.
5
+ #
6
+ # Copyright (c) 2007-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
7
+ #
8
+ # This program is free software; you can redistribute it and/or modify
9
+ # it under the terms of the GNU General Public License as published by
10
+ # the Free Software Foundation; either version 2 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # This program is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License
19
+ # along with this program; if not, write to the Free Software
20
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
+ #++
22
+ #
23
+
24
+ require 'ronin/code/sql/emittable'
25
+
26
+ module Ronin
27
+ module Code
28
+ module SQL
29
+ class Modifier
30
+
31
+ include Emittable
32
+
33
+ # Modifier name
34
+ attr_reader :name
35
+
36
+ # Expression
37
+ attr_reader :expr
38
+
39
+ def initialize(expr,name)
40
+ @expr = expr
41
+ @name = name
42
+ end
43
+
44
+ def emit
45
+ emit_value(@expr) + emit_token(@name)
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,44 @@
1
+ #
2
+ #--
3
+ # Ronin SQL - A Ronin library providing support for SQL related security
4
+ # tasks.
5
+ #
6
+ # Copyright (c) 2007-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
7
+ #
8
+ # This program is free software; you can redistribute it and/or modify
9
+ # it under the terms of the GNU General Public License as published by
10
+ # the Free Software Foundation; either version 2 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # This program is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License
19
+ # along with this program; if not, write to the Free Software
20
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
+ #++
22
+ #
23
+
24
+ require 'ronin/code/sql/clause'
25
+
26
+ module Ronin
27
+ module Code
28
+ module SQL
29
+ class OffsetClause < Clause
30
+
31
+ attr_accessor :value
32
+
33
+ def initialize(value)
34
+ @value = value
35
+ end
36
+
37
+ def emit
38
+ emit_token('OFFSET') + emit_value(@value)
39
+ end
40
+
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,57 @@
1
+ #
2
+ #--
3
+ # Ronin SQL - A Ronin library providing support for SQL related security
4
+ # tasks.
5
+ #
6
+ # Copyright (c) 2007-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
7
+ #
8
+ # This program is free software; you can redistribute it and/or modify
9
+ # it under the terms of the GNU General Public License as published by
10
+ # the Free Software Foundation; either version 2 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # This program is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License
19
+ # along with this program; if not, write to the Free Software
20
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
+ #++
22
+ #
23
+
24
+ require 'ronin/code/sql/clause'
25
+
26
+ module Ronin
27
+ module Code
28
+ module SQL
29
+ class OnClause < Clause
30
+
31
+ # Table for the ON clause
32
+ attr_accessor :table
33
+
34
+ # Fields for the ON clause
35
+ attr_accessor :fields
36
+
37
+ #
38
+ # Creates a new OnClause object with the specified _table_ name
39
+ # and the given _fields_.
40
+ #
41
+ def initialize(table,fields=[])
42
+ @table = table
43
+ @fields = fields
44
+ end
45
+
46
+ def emit
47
+ tokens = emit_token('ON') + emit_value(@table)
48
+
49
+ tokens += emit_row(@fields) unless @fields.empty?
50
+
51
+ return tokens
52
+ end
53
+
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,44 @@
1
+ #
2
+ #--
3
+ # Ronin SQL - A Ronin library providing support for SQL related security
4
+ # tasks.
5
+ #
6
+ # Copyright (c) 2007-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
7
+ #
8
+ # This program is free software; you can redistribute it and/or modify
9
+ # it under the terms of the GNU General Public License as published by
10
+ # the Free Software Foundation; either version 2 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # This program is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License
19
+ # along with this program; if not, write to the Free Software
20
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
+ #++
22
+ #
23
+
24
+ require 'ronin/code/sql/clause'
25
+
26
+ module Ronin
27
+ module Code
28
+ module SQL
29
+ class OrderByClause < Clause
30
+
31
+ attr_accessor :fields
32
+
33
+ def initialize(*fields)
34
+ @fields = fields
35
+ end
36
+
37
+ def emit
38
+ emit_token('ORDER BY') + emit_row(@fields)
39
+ end
40
+
41
+ end
42
+ end
43
+ end
44
+ end