ronin-sql 0.2.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (154) hide show
  1. data/.document +4 -0
  2. data/.gitignore +11 -0
  3. data/.rspec +1 -0
  4. data/.yardopts +1 -0
  5. data/COPYING.txt +623 -288
  6. data/{History.txt → ChangeLog.md} +33 -35
  7. data/Gemfile +25 -0
  8. data/README.md +110 -0
  9. data/Rakefile +30 -20
  10. data/bin/ronin-sql +18 -5
  11. data/gemspec.yml +16 -0
  12. data/lib/ronin/formatting/extensions/sql.rb +4 -3
  13. data/lib/ronin/formatting/extensions/sql/string.rb +83 -10
  14. data/lib/ronin/formatting/sql.rb +4 -3
  15. data/lib/ronin/sql.rb +5 -12
  16. data/lib/ronin/{code/sql/create_index.rb → sql/binary_expr.rb} +25 -18
  17. data/lib/ronin/sql/clause.rb +72 -0
  18. data/lib/ronin/sql/clauses.rb +297 -0
  19. data/lib/ronin/sql/emittable.rb +84 -0
  20. data/lib/ronin/sql/emitter.rb +375 -0
  21. data/lib/ronin/sql/field.rb +106 -0
  22. data/lib/ronin/{code/sql/as.rb → sql/fields.rb} +36 -17
  23. data/lib/ronin/{code/sql/binary_expr.rb → sql/function.rb} +27 -27
  24. data/lib/ronin/sql/functions.rb +989 -0
  25. data/lib/ronin/sql/injection.rb +125 -157
  26. data/lib/ronin/{code/sql/default_values_clause.rb → sql/literal.rb} +13 -11
  27. data/lib/ronin/sql/literals.rb +72 -0
  28. data/lib/ronin/sql/operators.rb +332 -0
  29. data/lib/ronin/sql/sql.rb +86 -0
  30. data/lib/ronin/sql/statement.rb +70 -0
  31. data/lib/ronin/sql/statement_list.rb +110 -0
  32. data/lib/ronin/sql/statements.rb +115 -0
  33. data/lib/ronin/{code/sql/desc.rb → sql/unary_expr.rb} +11 -11
  34. data/lib/ronin/sql/version.rb +5 -4
  35. data/ronin-sql.gemspec +61 -0
  36. data/spec/formatting/sql/string_spec.rb +172 -0
  37. data/spec/spec_helper.rb +1 -4
  38. data/spec/sql/binary_expr.rb +5 -0
  39. data/spec/sql/binary_expr_examples.rb +25 -0
  40. data/spec/sql/clause_examples.rb +43 -0
  41. data/spec/sql/clause_spec.rb +31 -0
  42. data/spec/sql/clauses_spec.rb +43 -0
  43. data/spec/sql/emittable_spec.rb +41 -0
  44. data/spec/sql/emitter_spec.rb +472 -0
  45. data/spec/sql/field_spec.rb +103 -0
  46. data/spec/sql/fields_spec.rb +40 -0
  47. data/spec/sql/function_examples.rb +30 -0
  48. data/spec/sql/function_spec.rb +25 -0
  49. data/spec/sql/functions_spec.rb +110 -0
  50. data/spec/sql/injection_spec.rb +233 -0
  51. data/spec/sql/literal_spec.rb +5 -0
  52. data/spec/sql/literals_spec.rb +46 -0
  53. data/spec/sql/operators_spec.rb +44 -0
  54. data/spec/sql/sql_spec.rb +18 -0
  55. data/spec/sql/statement_examples.rb +39 -0
  56. data/spec/sql/statement_list_spec.rb +48 -0
  57. data/spec/sql/statement_sql.rb +38 -0
  58. data/spec/sql/statements_spec.rb +22 -0
  59. data/spec/sql/unary_expr.rb +5 -0
  60. data/spec/sql/unary_expr_examples.rb +20 -0
  61. metadata +116 -217
  62. data.tar.gz.sig +0 -0
  63. data/Manifest.txt +0 -108
  64. data/README.txt +0 -112
  65. data/lib/ronin/code/sql.rb +0 -22
  66. data/lib/ronin/code/sql/add_column_clause.rb +0 -42
  67. data/lib/ronin/code/sql/alter_table.rb +0 -52
  68. data/lib/ronin/code/sql/asc.rb +0 -36
  69. data/lib/ronin/code/sql/between.rb +0 -66
  70. data/lib/ronin/code/sql/clause.rb +0 -35
  71. data/lib/ronin/code/sql/code.rb +0 -35
  72. data/lib/ronin/code/sql/common_dialect.rb +0 -66
  73. data/lib/ronin/code/sql/create.rb +0 -74
  74. data/lib/ronin/code/sql/create_table.rb +0 -44
  75. data/lib/ronin/code/sql/create_view.rb +0 -41
  76. data/lib/ronin/code/sql/delete.rb +0 -52
  77. data/lib/ronin/code/sql/dialect.rb +0 -282
  78. data/lib/ronin/code/sql/drop.rb +0 -55
  79. data/lib/ronin/code/sql/drop_index.rb +0 -41
  80. data/lib/ronin/code/sql/drop_table.rb +0 -41
  81. data/lib/ronin/code/sql/drop_view.rb +0 -41
  82. data/lib/ronin/code/sql/emittable.rb +0 -100
  83. data/lib/ronin/code/sql/exceptions.rb +0 -24
  84. data/lib/ronin/code/sql/exceptions/unknown_clause.rb +0 -29
  85. data/lib/ronin/code/sql/exceptions/unknown_dialect.rb +0 -29
  86. data/lib/ronin/code/sql/exceptions/unknown_statement.rb +0 -29
  87. data/lib/ronin/code/sql/expr.rb +0 -102
  88. data/lib/ronin/code/sql/field.rb +0 -101
  89. data/lib/ronin/code/sql/fields_clause.rb +0 -46
  90. data/lib/ronin/code/sql/from_clause.rb +0 -42
  91. data/lib/ronin/code/sql/function.rb +0 -53
  92. data/lib/ronin/code/sql/group_by_clause.rb +0 -46
  93. data/lib/ronin/code/sql/having_clause.rb +0 -46
  94. data/lib/ronin/code/sql/in.rb +0 -47
  95. data/lib/ronin/code/sql/injected_statement.rb +0 -100
  96. data/lib/ronin/code/sql/injection.rb +0 -203
  97. data/lib/ronin/code/sql/insert.rb +0 -54
  98. data/lib/ronin/code/sql/intersect_clause.rb +0 -42
  99. data/lib/ronin/code/sql/join_clause.rb +0 -123
  100. data/lib/ronin/code/sql/like.rb +0 -73
  101. data/lib/ronin/code/sql/limit_clause.rb +0 -42
  102. data/lib/ronin/code/sql/modifier.rb +0 -48
  103. data/lib/ronin/code/sql/offset_clause.rb +0 -42
  104. data/lib/ronin/code/sql/on_clause.rb +0 -55
  105. data/lib/ronin/code/sql/order_by_clause.rb +0 -42
  106. data/lib/ronin/code/sql/program.rb +0 -225
  107. data/lib/ronin/code/sql/rename_to_clause.rb +0 -42
  108. data/lib/ronin/code/sql/replace.rb +0 -54
  109. data/lib/ronin/code/sql/select.rb +0 -103
  110. data/lib/ronin/code/sql/set_clause.rb +0 -42
  111. data/lib/ronin/code/sql/statement.rb +0 -180
  112. data/lib/ronin/code/sql/token.rb +0 -62
  113. data/lib/ronin/code/sql/unary_expr.rb +0 -47
  114. data/lib/ronin/code/sql/union_all_clause.rb +0 -42
  115. data/lib/ronin/code/sql/union_clause.rb +0 -42
  116. data/lib/ronin/code/sql/update.rb +0 -52
  117. data/lib/ronin/code/sql/values_clause.rb +0 -46
  118. data/lib/ronin/code/sql/where_clause.rb +0 -42
  119. data/lib/ronin/sql/error.rb +0 -26
  120. data/lib/ronin/sql/error/error.rb +0 -62
  121. data/lib/ronin/sql/error/extensions.rb +0 -22
  122. data/lib/ronin/sql/error/extensions/string.rb +0 -77
  123. data/lib/ronin/sql/error/message.rb +0 -62
  124. data/lib/ronin/sql/error/pattern.rb +0 -104
  125. data/lib/ronin/sql/error/patterns.rb +0 -99
  126. data/lib/ronin/sql/extensions.rb +0 -22
  127. data/lib/ronin/sql/extensions/uri.rb +0 -22
  128. data/lib/ronin/sql/extensions/uri/http.rb +0 -107
  129. data/spec/code/sql/common_dialect_spec.rb +0 -205
  130. data/spec/code/sql/create_examples.rb +0 -19
  131. data/spec/code/sql/create_index_spec.rb +0 -25
  132. data/spec/code/sql/create_table_spec.rb +0 -27
  133. data/spec/code/sql/create_view_spec.rb +0 -16
  134. data/spec/code/sql/delete_spec.rb +0 -14
  135. data/spec/code/sql/drop_examples.rb +0 -10
  136. data/spec/code/sql/drop_index_spec.rb +0 -16
  137. data/spec/code/sql/drop_table_spec.rb +0 -16
  138. data/spec/code/sql/drop_view_spec.rb +0 -16
  139. data/spec/code/sql/has_default_values_clause_examples.rb +0 -10
  140. data/spec/code/sql/has_fields_clause_examples.rb +0 -15
  141. data/spec/code/sql/has_from_clause_examples.rb +0 -13
  142. data/spec/code/sql/has_values_clause_examples.rb +0 -15
  143. data/spec/code/sql/has_where_clause_examples.rb +0 -15
  144. data/spec/code/sql/insert_spec.rb +0 -21
  145. data/spec/code/sql/replace_spec.rb +0 -21
  146. data/spec/code/sql/select_spec.rb +0 -105
  147. data/spec/code/sql/update_spec.rb +0 -26
  148. data/spec/helpers/code.rb +0 -14
  149. data/spec/sql/error_spec.rb +0 -24
  150. data/spec/sql/extensions/uri/http_spec.rb +0 -34
  151. data/spec/sql_spec.rb +0 -9
  152. data/tasks/spec.rb +0 -10
  153. data/tasks/yard.rb +0 -13
  154. metadata.gz.sig +0 -0
@@ -1,203 +0,0 @@
1
- #
2
- # Ronin SQL - A Ronin library providing support for SQL related security
3
- # tasks.
4
- #
5
- # Copyright (c) 2007-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
6
- #
7
- # This program is free software; you can redistribute it and/or modify
8
- # it under the terms of the GNU General Public License as published by
9
- # the Free Software Foundation; either version 2 of the License, or
10
- # (at your option) any later version.
11
- #
12
- # This program is distributed in the hope that it will be useful,
13
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- # GNU General Public License for more details.
16
- #
17
- # You should have received a copy of the GNU General Public License
18
- # along with this program; if not, write to the Free Software
19
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
- #
21
-
22
- require 'ronin/code/sql/program'
23
- require 'ronin/code/sql/injected_statement'
24
- require 'ronin/formatting/text'
25
-
26
- module Ronin
27
- module Code
28
- module SQL
29
- class Injection < Program
30
-
31
- # Comment-Obfustication
32
- attr_accessor :comment_evasion
33
-
34
- # Swapcase-Obfusciation
35
- attr_accessor :case_evasion
36
-
37
- # Data to escape a previous expression with
38
- attr_accessor :escape
39
-
40
- # Specifies whether or not to close an open string
41
- attr_accessor :close_string
42
-
43
- # Specifies whether or not to close an open parenthesis
44
- attr_accessor :close_parens
45
-
46
- # Specifies whether or not to end a previous statement
47
- attr_accessor :end_statement
48
-
49
- def initialize(options={},&block)
50
- if options.has_key?(:comment_evasion)
51
- @comment_evasion = options[:comment_evasion]
52
- else
53
- @comment_evasion = false
54
- end
55
-
56
- if options.has_key?(:case_evasion)
57
- @case_evasion = options[:case_evasion]
58
- else
59
- @case_evasion = false
60
- end
61
-
62
- @escape = options[:escape]
63
-
64
- if options.has_key?(:close_string)
65
- @close_string = options[:close_string]
66
- else
67
- @close_string = false
68
- end
69
-
70
- if options.has_key?(:close_parens)
71
- @close_parens = options[:close_parens]
72
- else
73
- @close_parens = false
74
- end
75
-
76
- if options.has_key?(:end_statement)
77
- @end_statement = options[:end_statement]
78
- else
79
- @end_statement = false
80
- end
81
-
82
- super(options) do
83
- @expression = InjectedStatement.new(@dialect)
84
- end
85
-
86
- instance_eval(&block) if block
87
- end
88
-
89
- #
90
- # Returns the expression that will be injected into the effected
91
- # statement. If a _block_ is given, it will be evaluated within
92
- # the expression.
93
- #
94
- def expression(&block)
95
- @expression.instance_eval(&block) if block
96
- return @expression
97
- end
98
-
99
- def sql(&block)
100
- @dialect.instance_eval(&block) if block
101
- end
102
-
103
- def compile
104
- injection = super.rstrip
105
-
106
- comment = lambda { [injection, '--'].join(space_token) }
107
-
108
- if (@close_parens && @close_string)
109
- if injection =~ /'\s*\)$/
110
- return injection.gsub(/'\s*\)$/,'')
111
- else
112
- return comment.call
113
- end
114
- end
115
-
116
- if @close_string
117
- if injection[-1..-1] == "'"
118
- return injection.chop
119
- else
120
- return comment.call
121
- end
122
- end
123
-
124
- return injection
125
- end
126
-
127
- alias to_s compile
128
-
129
- protected
130
-
131
- def space_token
132
- if @comment_evasion
133
- return '/**/'
134
- else
135
- return super
136
- end
137
- end
138
-
139
- def format_token(token)
140
- token = super(token)
141
-
142
- if @case_evasion
143
- token = token.random_case
144
- end
145
-
146
- return token
147
- end
148
-
149
- def each_string(&block)
150
- escape_value = ''
151
-
152
- if @close_string
153
- # format the escape string, since we are escaping out of a
154
- # string
155
- escape_value << format(@escape) if @escape
156
- else
157
- # do not format the escape string when we are not escaping
158
- # out of a string
159
- escape_value << @escape.to_s if @escape
160
- end
161
-
162
- if @close_string
163
- if escape_value[0..0] == "'"
164
- escape_value = escape_value[1..-1]
165
- else
166
- escape_value << "'"
167
- end
168
- end
169
-
170
- escape_value << ')' if @close_parens
171
-
172
- block.call(escape_value) unless escape_value.empty?
173
-
174
- return super(&block)
175
- end
176
-
177
- def each_token(&block)
178
- if @expression
179
- @expression.emit.each(&block)
180
-
181
- block.call(Token.separator)
182
- elsif @end_statement
183
- block.call(Token.separator)
184
- end
185
-
186
- return super(&block)
187
- end
188
-
189
- #
190
- # Relays missed method calls to the injected expression.
191
- #
192
- def method_missing(name,*arguments,&block)
193
- if @expression.public_methods(false).include?(name.to_s)
194
- return @expression.send(name,*arguments,&block)
195
- end
196
-
197
- return super(name,*arguments,&block)
198
- end
199
-
200
- end
201
- end
202
- end
203
- end
@@ -1,54 +0,0 @@
1
- #
2
- # Ronin SQL - A Ronin library providing support for SQL related security
3
- # tasks.
4
- #
5
- # Copyright (c) 2007-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
6
- #
7
- # This program is free software; you can redistribute it and/or modify
8
- # it under the terms of the GNU General Public License as published by
9
- # the Free Software Foundation; either version 2 of the License, or
10
- # (at your option) any later version.
11
- #
12
- # This program is distributed in the hope that it will be useful,
13
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- # GNU General Public License for more details.
16
- #
17
- # You should have received a copy of the GNU General Public License
18
- # along with this program; if not, write to the Free Software
19
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
- #
21
-
22
- require 'ronin/code/sql/statement'
23
- require 'ronin/code/sql/fields_clause'
24
- require 'ronin/code/sql/values_clause'
25
- require 'ronin/code/sql/default_values_clause'
26
-
27
- module Ronin
28
- module Code
29
- module SQL
30
- class Insert < Statement
31
-
32
- clause :fields, FieldsClause
33
- clause :default_values, DefaultValuesClause
34
- clause :values, ValuesClause
35
-
36
- def initialize(dialect,table=nil,options={},&block)
37
- @table = table
38
-
39
- super(dialect,options,&block)
40
- end
41
-
42
- def table(name=nil)
43
- @table = name if name
44
- return @table
45
- end
46
-
47
- def emit
48
- emit_token('INSERT INTO') + emit_value(@table) + super
49
- end
50
-
51
- end
52
- end
53
- end
54
- end
@@ -1,42 +0,0 @@
1
- #
2
- # Ronin SQL - A Ronin library providing support for SQL related security
3
- # tasks.
4
- #
5
- # Copyright (c) 2007-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
6
- #
7
- # This program is free software; you can redistribute it and/or modify
8
- # it under the terms of the GNU General Public License as published by
9
- # the Free Software Foundation; either version 2 of the License, or
10
- # (at your option) any later version.
11
- #
12
- # This program is distributed in the hope that it will be useful,
13
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- # GNU General Public License for more details.
16
- #
17
- # You should have received a copy of the GNU General Public License
18
- # along with this program; if not, write to the Free Software
19
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
- #
21
-
22
- require 'ronin/code/sql/clause'
23
-
24
- module Ronin
25
- module Code
26
- module SQL
27
- class IntersectClause < Clause
28
-
29
- attr_accessor :select
30
-
31
- def initialize(select)
32
- @select = select
33
- end
34
-
35
- def emit
36
- emit_token('INTERSECT') + @select.emit
37
- end
38
-
39
- end
40
- end
41
- end
42
- end
@@ -1,123 +0,0 @@
1
- #
2
- # Ronin SQL - A Ronin library providing support for SQL related security
3
- # tasks.
4
- #
5
- # Copyright (c) 2007-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
6
- #
7
- # This program is free software; you can redistribute it and/or modify
8
- # it under the terms of the GNU General Public License as published by
9
- # the Free Software Foundation; either version 2 of the License, or
10
- # (at your option) any later version.
11
- #
12
- # This program is distributed in the hope that it will be useful,
13
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- # GNU General Public License for more details.
16
- #
17
- # You should have received a copy of the GNU General Public License
18
- # along with this program; if not, write to the Free Software
19
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
- #
21
-
22
- require 'ronin/code/sql/clause'
23
-
24
- module Ronin
25
- module Code
26
- module SQL
27
- class JoinClause < Clause
28
-
29
- # Table to join with
30
- attr_accessor :table
31
-
32
- # Whether the join is natural or not
33
- attr_accessor :natural
34
-
35
- # Direction of the join
36
- attr_accessor :direction
37
-
38
- # Side of the join
39
- attr_accessor :side
40
-
41
- def initialize(table,options={})
42
- @table = table
43
- @natural = options[:natural]
44
-
45
- if options[:left]
46
- @direction = :left
47
- elsif options[:right]
48
- @direction = :right
49
- elsif options[:full]
50
- @direction = :full
51
- end
52
-
53
- if options[:inner]
54
- @side = :inner
55
- elsif options[:outer]
56
- @side = :outer
57
- elsif options[:cross]
58
- @side = :cross
59
- end
60
- end
61
-
62
- def left
63
- @direction = :left
64
- return self
65
- end
66
-
67
- def right
68
- @direction = :right
69
- return self
70
- end
71
-
72
- def full
73
- @direction = :full
74
- return self
75
- end
76
-
77
- def inner
78
- @side = :inner
79
- return self
80
- end
81
-
82
- def outer
83
- @side = :outer
84
- return self
85
- end
86
-
87
- def cross
88
- @side = :cross
89
- return self
90
- end
91
-
92
- def emit
93
- tokens = []
94
-
95
- tokens += emit_token('NATURAL') if @natural
96
-
97
- case @direction
98
- when :left, 'left'
99
- tokens += emit_token('LEFT')
100
- when :right, 'right'
101
- tokens += emit_token('RIGHT')
102
- when :full, 'full'
103
- tokens += emit_token('FULL')
104
- end
105
-
106
- case @side
107
- when :inner, 'inner'
108
- tokens += emit_token('INNER')
109
- when :outer, 'outer'
110
- tokens += emit_token('OUTER')
111
- when :cross, 'cross'
112
- tokens += emit_token('CROSS')
113
- end
114
-
115
- tokens += emit_token('JOIN')
116
-
117
- return tokens + emit_value(@table)
118
- end
119
-
120
- end
121
- end
122
- end
123
- end
@@ -1,73 +0,0 @@
1
- #
2
- # Ronin SQL - A Ronin library providing support for SQL related security
3
- # tasks.
4
- #
5
- # Copyright (c) 2007-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
6
- #
7
- # This program is free software; you can redistribute it and/or modify
8
- # it under the terms of the GNU General Public License as published by
9
- # the Free Software Foundation; either version 2 of the License, or
10
- # (at your option) any later version.
11
- #
12
- # This program is distributed in the hope that it will be useful,
13
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- # GNU General Public License for more details.
16
- #
17
- # You should have received a copy of the GNU General Public License
18
- # along with this program; if not, write to the Free Software
19
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
- #
21
-
22
- require 'ronin/code/sql/expr'
23
-
24
- module Ronin
25
- module Code
26
- module SQL
27
- class Like < Expr
28
-
29
- # Operator
30
- attr_reader :op
31
-
32
- # Left-hand side
33
- attr_reader :left
34
-
35
- # Right-hand side
36
- attr_reader :right
37
-
38
- def initialize(op,left,right,escape=nil)
39
- @op = op
40
- @left = left
41
- @right = right
42
- @escape = escape
43
- @negated = false
44
- end
45
-
46
- def escape(str)
47
- @escape = str
48
- end
49
-
50
- def not!
51
- @negated = true
52
- end
53
-
54
- def emit
55
- tokens = emit_value(@left)
56
-
57
- tokens += emit_token('NOT') if @negated
58
-
59
- tokens += emit_token(@op)
60
- tokens += emit_value(@right)
61
-
62
- if @escape
63
- tokens += emit_token('ESCAPE')
64
- tokens << @escape.to_s[0..0]
65
- end
66
-
67
- return tokens
68
- end
69
-
70
- end
71
- end
72
- end
73
- end