ronin-sql 0.2.4 → 1.0.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.
- data/.document +4 -0
- data/.gitignore +11 -0
- data/.rspec +1 -0
- data/.yardopts +1 -0
- data/COPYING.txt +623 -288
- data/{History.txt → ChangeLog.md} +33 -35
- data/Gemfile +25 -0
- data/README.md +110 -0
- data/Rakefile +30 -20
- data/bin/ronin-sql +18 -5
- data/gemspec.yml +16 -0
- data/lib/ronin/formatting/extensions/sql.rb +4 -3
- data/lib/ronin/formatting/extensions/sql/string.rb +83 -10
- data/lib/ronin/formatting/sql.rb +4 -3
- data/lib/ronin/sql.rb +5 -12
- data/lib/ronin/{code/sql/create_index.rb → sql/binary_expr.rb} +25 -18
- data/lib/ronin/sql/clause.rb +72 -0
- data/lib/ronin/sql/clauses.rb +297 -0
- data/lib/ronin/sql/emittable.rb +84 -0
- data/lib/ronin/sql/emitter.rb +375 -0
- data/lib/ronin/sql/field.rb +106 -0
- data/lib/ronin/{code/sql/as.rb → sql/fields.rb} +36 -17
- data/lib/ronin/{code/sql/binary_expr.rb → sql/function.rb} +27 -27
- data/lib/ronin/sql/functions.rb +989 -0
- data/lib/ronin/sql/injection.rb +125 -157
- data/lib/ronin/{code/sql/default_values_clause.rb → sql/literal.rb} +13 -11
- data/lib/ronin/sql/literals.rb +72 -0
- data/lib/ronin/sql/operators.rb +332 -0
- data/lib/ronin/sql/sql.rb +86 -0
- data/lib/ronin/sql/statement.rb +70 -0
- data/lib/ronin/sql/statement_list.rb +110 -0
- data/lib/ronin/sql/statements.rb +115 -0
- data/lib/ronin/{code/sql/desc.rb → sql/unary_expr.rb} +11 -11
- data/lib/ronin/sql/version.rb +5 -4
- data/ronin-sql.gemspec +61 -0
- data/spec/formatting/sql/string_spec.rb +172 -0
- data/spec/spec_helper.rb +1 -4
- data/spec/sql/binary_expr.rb +5 -0
- data/spec/sql/binary_expr_examples.rb +25 -0
- data/spec/sql/clause_examples.rb +43 -0
- data/spec/sql/clause_spec.rb +31 -0
- data/spec/sql/clauses_spec.rb +43 -0
- data/spec/sql/emittable_spec.rb +41 -0
- data/spec/sql/emitter_spec.rb +472 -0
- data/spec/sql/field_spec.rb +103 -0
- data/spec/sql/fields_spec.rb +40 -0
- data/spec/sql/function_examples.rb +30 -0
- data/spec/sql/function_spec.rb +25 -0
- data/spec/sql/functions_spec.rb +110 -0
- data/spec/sql/injection_spec.rb +233 -0
- data/spec/sql/literal_spec.rb +5 -0
- data/spec/sql/literals_spec.rb +46 -0
- data/spec/sql/operators_spec.rb +44 -0
- data/spec/sql/sql_spec.rb +18 -0
- data/spec/sql/statement_examples.rb +39 -0
- data/spec/sql/statement_list_spec.rb +48 -0
- data/spec/sql/statement_sql.rb +38 -0
- data/spec/sql/statements_spec.rb +22 -0
- data/spec/sql/unary_expr.rb +5 -0
- data/spec/sql/unary_expr_examples.rb +20 -0
- metadata +116 -217
- data.tar.gz.sig +0 -0
- data/Manifest.txt +0 -108
- data/README.txt +0 -112
- data/lib/ronin/code/sql.rb +0 -22
- data/lib/ronin/code/sql/add_column_clause.rb +0 -42
- data/lib/ronin/code/sql/alter_table.rb +0 -52
- data/lib/ronin/code/sql/asc.rb +0 -36
- data/lib/ronin/code/sql/between.rb +0 -66
- data/lib/ronin/code/sql/clause.rb +0 -35
- data/lib/ronin/code/sql/code.rb +0 -35
- data/lib/ronin/code/sql/common_dialect.rb +0 -66
- data/lib/ronin/code/sql/create.rb +0 -74
- data/lib/ronin/code/sql/create_table.rb +0 -44
- data/lib/ronin/code/sql/create_view.rb +0 -41
- data/lib/ronin/code/sql/delete.rb +0 -52
- data/lib/ronin/code/sql/dialect.rb +0 -282
- data/lib/ronin/code/sql/drop.rb +0 -55
- data/lib/ronin/code/sql/drop_index.rb +0 -41
- data/lib/ronin/code/sql/drop_table.rb +0 -41
- data/lib/ronin/code/sql/drop_view.rb +0 -41
- data/lib/ronin/code/sql/emittable.rb +0 -100
- data/lib/ronin/code/sql/exceptions.rb +0 -24
- data/lib/ronin/code/sql/exceptions/unknown_clause.rb +0 -29
- data/lib/ronin/code/sql/exceptions/unknown_dialect.rb +0 -29
- data/lib/ronin/code/sql/exceptions/unknown_statement.rb +0 -29
- data/lib/ronin/code/sql/expr.rb +0 -102
- data/lib/ronin/code/sql/field.rb +0 -101
- data/lib/ronin/code/sql/fields_clause.rb +0 -46
- data/lib/ronin/code/sql/from_clause.rb +0 -42
- data/lib/ronin/code/sql/function.rb +0 -53
- data/lib/ronin/code/sql/group_by_clause.rb +0 -46
- data/lib/ronin/code/sql/having_clause.rb +0 -46
- data/lib/ronin/code/sql/in.rb +0 -47
- data/lib/ronin/code/sql/injected_statement.rb +0 -100
- data/lib/ronin/code/sql/injection.rb +0 -203
- data/lib/ronin/code/sql/insert.rb +0 -54
- data/lib/ronin/code/sql/intersect_clause.rb +0 -42
- data/lib/ronin/code/sql/join_clause.rb +0 -123
- data/lib/ronin/code/sql/like.rb +0 -73
- data/lib/ronin/code/sql/limit_clause.rb +0 -42
- data/lib/ronin/code/sql/modifier.rb +0 -48
- data/lib/ronin/code/sql/offset_clause.rb +0 -42
- data/lib/ronin/code/sql/on_clause.rb +0 -55
- data/lib/ronin/code/sql/order_by_clause.rb +0 -42
- data/lib/ronin/code/sql/program.rb +0 -225
- data/lib/ronin/code/sql/rename_to_clause.rb +0 -42
- data/lib/ronin/code/sql/replace.rb +0 -54
- data/lib/ronin/code/sql/select.rb +0 -103
- data/lib/ronin/code/sql/set_clause.rb +0 -42
- data/lib/ronin/code/sql/statement.rb +0 -180
- data/lib/ronin/code/sql/token.rb +0 -62
- data/lib/ronin/code/sql/unary_expr.rb +0 -47
- data/lib/ronin/code/sql/union_all_clause.rb +0 -42
- data/lib/ronin/code/sql/union_clause.rb +0 -42
- data/lib/ronin/code/sql/update.rb +0 -52
- data/lib/ronin/code/sql/values_clause.rb +0 -46
- data/lib/ronin/code/sql/where_clause.rb +0 -42
- data/lib/ronin/sql/error.rb +0 -26
- data/lib/ronin/sql/error/error.rb +0 -62
- data/lib/ronin/sql/error/extensions.rb +0 -22
- data/lib/ronin/sql/error/extensions/string.rb +0 -77
- data/lib/ronin/sql/error/message.rb +0 -62
- data/lib/ronin/sql/error/pattern.rb +0 -104
- data/lib/ronin/sql/error/patterns.rb +0 -99
- data/lib/ronin/sql/extensions.rb +0 -22
- data/lib/ronin/sql/extensions/uri.rb +0 -22
- data/lib/ronin/sql/extensions/uri/http.rb +0 -107
- data/spec/code/sql/common_dialect_spec.rb +0 -205
- data/spec/code/sql/create_examples.rb +0 -19
- data/spec/code/sql/create_index_spec.rb +0 -25
- data/spec/code/sql/create_table_spec.rb +0 -27
- data/spec/code/sql/create_view_spec.rb +0 -16
- data/spec/code/sql/delete_spec.rb +0 -14
- data/spec/code/sql/drop_examples.rb +0 -10
- data/spec/code/sql/drop_index_spec.rb +0 -16
- data/spec/code/sql/drop_table_spec.rb +0 -16
- data/spec/code/sql/drop_view_spec.rb +0 -16
- data/spec/code/sql/has_default_values_clause_examples.rb +0 -10
- data/spec/code/sql/has_fields_clause_examples.rb +0 -15
- data/spec/code/sql/has_from_clause_examples.rb +0 -13
- data/spec/code/sql/has_values_clause_examples.rb +0 -15
- data/spec/code/sql/has_where_clause_examples.rb +0 -15
- data/spec/code/sql/insert_spec.rb +0 -21
- data/spec/code/sql/replace_spec.rb +0 -21
- data/spec/code/sql/select_spec.rb +0 -105
- data/spec/code/sql/update_spec.rb +0 -26
- data/spec/helpers/code.rb +0 -14
- data/spec/sql/error_spec.rb +0 -24
- data/spec/sql/extensions/uri/http_spec.rb +0 -34
- data/spec/sql_spec.rb +0 -9
- data/tasks/spec.rb +0 -10
- data/tasks/yard.rb +0 -13
- metadata.gz.sig +0 -0
data/lib/ronin/sql/injection.rb
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
#
|
|
2
|
-
# Ronin SQL - A
|
|
3
|
-
# tasks.
|
|
2
|
+
# Ronin SQL - A Ruby DSL for crafting SQL Injections.
|
|
4
3
|
#
|
|
5
|
-
# Copyright (c) 2007-
|
|
4
|
+
# Copyright (c) 2007-2013 Hal Brodigan (postmodern.mod3 at gmail.com)
|
|
5
|
+
#
|
|
6
|
+
# This file is part of Ronin SQL.
|
|
6
7
|
#
|
|
7
8
|
# This program is free software; you can redistribute it and/or modify
|
|
8
9
|
# it under the terms of the GNU General Public License as published by
|
|
@@ -19,195 +20,162 @@
|
|
|
19
20
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
20
21
|
#
|
|
21
22
|
|
|
22
|
-
require 'ronin/sql/
|
|
23
|
-
require 'ronin/
|
|
24
|
-
require 'ronin/
|
|
25
|
-
require 'ronin/
|
|
26
|
-
require 'ronin/web/extensions/nokogiri'
|
|
27
|
-
require 'ronin/web/spider'
|
|
28
|
-
|
|
29
|
-
require 'parameters'
|
|
30
|
-
require 'nokogiri'
|
|
23
|
+
require 'ronin/sql/binary_expr'
|
|
24
|
+
require 'ronin/sql/literals'
|
|
25
|
+
require 'ronin/sql/clauses'
|
|
26
|
+
require 'ronin/sql/statement_list'
|
|
31
27
|
|
|
32
28
|
module Ronin
|
|
33
29
|
module SQL
|
|
34
|
-
|
|
30
|
+
#
|
|
31
|
+
# Represents a SQL injection (SQLi).
|
|
32
|
+
#
|
|
33
|
+
class Injection < StatementList
|
|
35
34
|
|
|
36
|
-
include
|
|
37
|
-
include
|
|
35
|
+
include Literals
|
|
36
|
+
include Clauses
|
|
38
37
|
|
|
39
|
-
#
|
|
40
|
-
|
|
38
|
+
# Default place holder values.
|
|
39
|
+
PLACE_HOLDERS = {
|
|
40
|
+
integer: 1,
|
|
41
|
+
decimal: 1.0,
|
|
42
|
+
string: '1',
|
|
43
|
+
list: [nil],
|
|
44
|
+
column: :id
|
|
45
|
+
}
|
|
41
46
|
|
|
42
|
-
# The
|
|
43
|
-
attr_reader :
|
|
47
|
+
# The type of element to escape out of
|
|
48
|
+
attr_reader :escape
|
|
44
49
|
|
|
45
|
-
#
|
|
46
|
-
attr_reader :
|
|
50
|
+
# The place holder data
|
|
51
|
+
attr_reader :place_holder
|
|
47
52
|
|
|
48
|
-
#
|
|
49
|
-
|
|
50
|
-
:default => :get,
|
|
51
|
-
:description => 'HTTP request method to use'
|
|
53
|
+
# The expression that will be injected
|
|
54
|
+
attr_reader :expression
|
|
52
55
|
|
|
53
56
|
#
|
|
54
|
-
#
|
|
55
|
-
# to inject upon and the given _options_ which will be used
|
|
56
|
-
# for crafting SQL injections.
|
|
57
|
+
# Initializes a new SQL injection.
|
|
57
58
|
#
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
@url = url
|
|
62
|
-
@param = param
|
|
63
|
-
@sql_options = options
|
|
64
|
-
end
|
|
65
|
-
|
|
59
|
+
# @param [Hash] options
|
|
60
|
+
# Additional injection options.
|
|
66
61
|
#
|
|
67
|
-
#
|
|
68
|
-
#
|
|
69
|
-
# Injection. If a _block_ is given, it will be passed vulnerable SQL
|
|
70
|
-
# Injection objects as they are found.
|
|
62
|
+
# @option options [:integer, :decimal, :string, :column] :escape (:integer)
|
|
63
|
+
# The type of element to escape out of.
|
|
71
64
|
#
|
|
72
|
-
#
|
|
73
|
-
#
|
|
65
|
+
# @option options [Boolean] :terminate
|
|
66
|
+
# Specifies whether to terminate the SQLi with a comment.
|
|
74
67
|
#
|
|
75
|
-
#
|
|
76
|
-
#
|
|
77
|
-
# end
|
|
68
|
+
# @option options [String, Symbol, Integer] :place_holder
|
|
69
|
+
# Place-holder data.
|
|
78
70
|
#
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
spider.every_url_like(/\?[a-zA-Z0-9_]/) do |vuln_url|
|
|
84
|
-
found = vuln_url.sql_injections
|
|
85
|
-
|
|
86
|
-
found.each(&block) if block
|
|
87
|
-
injections += found
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
return injections
|
|
92
|
-
end
|
|
93
|
-
|
|
71
|
+
# @yield [(injection)]
|
|
72
|
+
# If a block is given, it will be evaluated within the injection.
|
|
73
|
+
# If the block accepts an argument, the block will be called with the
|
|
74
|
+
# new injection.
|
|
94
75
|
#
|
|
95
|
-
#
|
|
96
|
-
#
|
|
97
|
-
# sql_options, to create a tailored Code::SQL::Injection object.
|
|
76
|
+
# @yieldparam [Injection] injection
|
|
77
|
+
# The new injection.
|
|
98
78
|
#
|
|
99
|
-
def
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
def inject(options={},&block)
|
|
104
|
-
injection = (options[:sql] || sql(options,&block))
|
|
105
|
-
|
|
106
|
-
injection_url = URI(@url.to_s)
|
|
107
|
-
injection_url.query_params[@param.to_s] = injection
|
|
108
|
-
|
|
109
|
-
request_method = (options[:method] || @http_method)
|
|
110
|
-
options = options.merge(:url => injection_url)
|
|
111
|
-
|
|
112
|
-
if request_method == :post
|
|
113
|
-
return http_post_body(options)
|
|
114
|
-
else
|
|
115
|
-
return http_get_body(options)
|
|
79
|
+
def initialize(options={},&block)
|
|
80
|
+
@escape = options.fetch(:escape,:integer)
|
|
81
|
+
@place_holder = options.fetch(:place_holder) do
|
|
82
|
+
PLACE_HOLDERS.fetch(@escape)
|
|
116
83
|
end
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
def inject_error(options={})
|
|
120
|
-
inject({:sql => "'"}.merge(options))
|
|
121
|
-
end
|
|
122
84
|
|
|
123
|
-
|
|
124
|
-
inject_error(options).sql_error
|
|
125
|
-
end
|
|
85
|
+
@expression = @place_holder
|
|
126
86
|
|
|
127
|
-
|
|
128
|
-
Error.has_message?(inject_error(options))
|
|
87
|
+
super(&block)
|
|
129
88
|
end
|
|
130
89
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
90
|
+
#
|
|
91
|
+
# Appends an `AND` expression to the injection.
|
|
92
|
+
#
|
|
93
|
+
# @yield [(injection)]
|
|
94
|
+
# The return value of the block will be used as the right-hand side
|
|
95
|
+
# operand. If the block accepts an argument, it will be called with
|
|
96
|
+
# the injection.
|
|
97
|
+
#
|
|
98
|
+
# @yieldparam [Injection] injection
|
|
99
|
+
#
|
|
100
|
+
# @return [self]
|
|
101
|
+
#
|
|
102
|
+
def and(&block)
|
|
103
|
+
value = case block.arity
|
|
104
|
+
when 0 then instance_eval(&block)
|
|
105
|
+
else block.call(self)
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
@expression = BinaryExpr.new(@expression,:AND,value)
|
|
109
|
+
return self
|
|
143
110
|
end
|
|
144
111
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
112
|
+
#
|
|
113
|
+
# Appends an `OR` expression to the injection.
|
|
114
|
+
#
|
|
115
|
+
# @yield [(injection)]
|
|
116
|
+
# The return value of the block will be used as the right-hand side
|
|
117
|
+
# operand. If the block accepts an argument, it will be called with
|
|
118
|
+
# the injection.
|
|
119
|
+
#
|
|
120
|
+
# @yieldparam [Injection] injection
|
|
121
|
+
#
|
|
122
|
+
# @return [self]
|
|
123
|
+
#
|
|
124
|
+
def or(&block)
|
|
125
|
+
value = case block.arity
|
|
126
|
+
when 0 then instance_eval(&block)
|
|
127
|
+
else block.call(self)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
@expression = BinaryExpr.new(@expression,:OR,value)
|
|
131
|
+
return self
|
|
159
132
|
end
|
|
160
133
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
134
|
+
#
|
|
135
|
+
# Converts the SQL injection to SQL.
|
|
136
|
+
#
|
|
137
|
+
# @param [Hash] options
|
|
138
|
+
# Additional options for {Emitter#initialize}.
|
|
139
|
+
#
|
|
140
|
+
# @option options [Boolean] :terminate
|
|
141
|
+
# Specifies whether to terminate the injection with `;--`.
|
|
142
|
+
#
|
|
143
|
+
# @return [String]
|
|
144
|
+
# The raw SQL.
|
|
145
|
+
#
|
|
146
|
+
def to_sql(options={})
|
|
147
|
+
emitter = emitter(options)
|
|
148
|
+
sql = ''
|
|
173
149
|
|
|
174
|
-
|
|
175
|
-
end
|
|
150
|
+
sql << emitter.emit(@expression)
|
|
176
151
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
body2 = inject(options.merge(:symbols => {:column => column})) do
|
|
180
|
-
uses_column?(table)
|
|
152
|
+
unless clauses.empty?
|
|
153
|
+
sql << emitter.space << emitter.emit_clauses(clauses)
|
|
181
154
|
end
|
|
182
155
|
|
|
183
|
-
|
|
184
|
-
|
|
156
|
+
unless statements.empty?
|
|
157
|
+
sql << ';' << emitter.space << emitter.emit_statement_list(self)
|
|
185
158
|
end
|
|
186
159
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
body2 = inject(options.merge(:symbols => {:table => table})) do
|
|
196
|
-
uses_table?(table)
|
|
197
|
-
end
|
|
160
|
+
case @escape
|
|
161
|
+
when :string, :list
|
|
162
|
+
if (options[:terminate] || (sql[0,1] != sql[-1,1]))
|
|
163
|
+
# terminate the expression
|
|
164
|
+
sql << ';--'
|
|
165
|
+
else
|
|
166
|
+
sql = sql[0..-2]
|
|
167
|
+
end
|
|
198
168
|
|
|
199
|
-
|
|
200
|
-
|
|
169
|
+
# balance the quotes
|
|
170
|
+
sql = sql[1..-1]
|
|
171
|
+
else
|
|
172
|
+
if options[:terminate]
|
|
173
|
+
# terminate the expression
|
|
174
|
+
sql << ';--'
|
|
175
|
+
end
|
|
201
176
|
end
|
|
202
177
|
|
|
203
|
-
|
|
204
|
-
body2 = Nokogiri::HTML(body2)
|
|
205
|
-
|
|
206
|
-
return body1.total_children == body2.total_children
|
|
207
|
-
end
|
|
208
|
-
|
|
209
|
-
def to_s
|
|
210
|
-
@url.to_s
|
|
178
|
+
return sql
|
|
211
179
|
end
|
|
212
180
|
|
|
213
181
|
end
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
#
|
|
2
|
-
# Ronin SQL - A
|
|
3
|
-
# tasks.
|
|
2
|
+
# Ronin SQL - A Ruby DSL for crafting SQL Injections.
|
|
4
3
|
#
|
|
5
|
-
# Copyright (c) 2007-
|
|
4
|
+
# Copyright (c) 2007-2013 Hal Brodigan (postmodern.mod3 at gmail.com)
|
|
5
|
+
#
|
|
6
|
+
# This file is part of Ronin SQL.
|
|
6
7
|
#
|
|
7
8
|
# This program is free software; you can redistribute it and/or modify
|
|
8
9
|
# it under the terms of the GNU General Public License as published by
|
|
@@ -19,18 +20,19 @@
|
|
|
19
20
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
20
21
|
#
|
|
21
22
|
|
|
22
|
-
require 'ronin/
|
|
23
|
+
require 'ronin/sql/emittable'
|
|
24
|
+
require 'ronin/sql/operators'
|
|
23
25
|
|
|
24
26
|
module Ronin
|
|
25
|
-
module
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
module SQL
|
|
28
|
+
#
|
|
29
|
+
# Represents SQL literals.
|
|
30
|
+
#
|
|
31
|
+
class Literal < Struct.new(:value)
|
|
28
32
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
end
|
|
33
|
+
include Operators
|
|
34
|
+
include Emittable
|
|
32
35
|
|
|
33
|
-
end
|
|
34
36
|
end
|
|
35
37
|
end
|
|
36
38
|
end
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Ronin SQL - A Ruby DSL for crafting SQL Injections.
|
|
3
|
+
#
|
|
4
|
+
# Copyright (c) 2007-2013 Hal Brodigan (postmodern.mod3 at gmail.com)
|
|
5
|
+
#
|
|
6
|
+
# This file is part of Ronin SQL.
|
|
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
|
+
require 'ronin/sql/literal'
|
|
24
|
+
|
|
25
|
+
module Ronin
|
|
26
|
+
module SQL
|
|
27
|
+
#
|
|
28
|
+
# Methods for creating SQL {Literals Literal}.
|
|
29
|
+
#
|
|
30
|
+
module Literals
|
|
31
|
+
#
|
|
32
|
+
# Creates a `NULL` literal.
|
|
33
|
+
#
|
|
34
|
+
# @return [Literal]
|
|
35
|
+
# The `NULL` literal.
|
|
36
|
+
#
|
|
37
|
+
def null
|
|
38
|
+
Literal.new(:NULL)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
#
|
|
42
|
+
# Creates an Integer literal.
|
|
43
|
+
#
|
|
44
|
+
# @return [Literal<Integer>]
|
|
45
|
+
# The Integer literal.
|
|
46
|
+
#
|
|
47
|
+
def int(value)
|
|
48
|
+
Literal.new(value.to_i)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
#
|
|
52
|
+
# Creates an Float literal.
|
|
53
|
+
#
|
|
54
|
+
# @return [Literal<Float>]
|
|
55
|
+
# The Float literal.
|
|
56
|
+
#
|
|
57
|
+
def float(value)
|
|
58
|
+
Literal.new(value.to_f)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
#
|
|
62
|
+
# Creates an String literal.
|
|
63
|
+
#
|
|
64
|
+
# @return [Literal<String>]
|
|
65
|
+
# The String literal.
|
|
66
|
+
#
|
|
67
|
+
def string(value)
|
|
68
|
+
Literal.new(value.to_s)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Ronin SQL - A Ruby DSL for crafting SQL Injections.
|
|
3
|
+
#
|
|
4
|
+
# Copyright (c) 2007-2013 Hal Brodigan (postmodern.mod3 at gmail.com)
|
|
5
|
+
#
|
|
6
|
+
# This file is part of Ronin SQL.
|
|
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
|
+
module Ronin
|
|
24
|
+
module SQL
|
|
25
|
+
#
|
|
26
|
+
# Methods for creating SQL expressions.
|
|
27
|
+
#
|
|
28
|
+
# @see http://sqlite.org/lang_expr.html
|
|
29
|
+
#
|
|
30
|
+
module Operators
|
|
31
|
+
#
|
|
32
|
+
# Multiplication.
|
|
33
|
+
#
|
|
34
|
+
# @return [BinaryExpr]
|
|
35
|
+
# The new binary expression.
|
|
36
|
+
#
|
|
37
|
+
def *(other)
|
|
38
|
+
BinaryExpr.new(self,:*,other)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
#
|
|
42
|
+
# Division.
|
|
43
|
+
#
|
|
44
|
+
# @return [BinaryExpr]
|
|
45
|
+
# The new binary expression.
|
|
46
|
+
#
|
|
47
|
+
def /(other)
|
|
48
|
+
BinaryExpr.new(self,:/,other)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
#
|
|
52
|
+
# Modulus.
|
|
53
|
+
#
|
|
54
|
+
# @return [BinaryExpr]
|
|
55
|
+
# The new binary expression.
|
|
56
|
+
#
|
|
57
|
+
def %(other)
|
|
58
|
+
BinaryExpr.new(self,:%,other)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
#
|
|
62
|
+
# Addition.
|
|
63
|
+
#
|
|
64
|
+
# @return [BinaryExpr]
|
|
65
|
+
# The new binary expression.
|
|
66
|
+
#
|
|
67
|
+
def +(other)
|
|
68
|
+
BinaryExpr.new(self,:+,other)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
#
|
|
72
|
+
# Subtraction.
|
|
73
|
+
#
|
|
74
|
+
# @return [BinaryExpr]
|
|
75
|
+
# The new binary expression.
|
|
76
|
+
#
|
|
77
|
+
def -(other)
|
|
78
|
+
BinaryExpr.new(self,:-,other)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
#
|
|
82
|
+
# Bit-wise left shift.
|
|
83
|
+
#
|
|
84
|
+
# @return [BinaryExpr]
|
|
85
|
+
# The new binary expression.
|
|
86
|
+
#
|
|
87
|
+
def <<(other)
|
|
88
|
+
BinaryExpr.new(self,:<<,other)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
#
|
|
92
|
+
# Bit-wise right shift.
|
|
93
|
+
#
|
|
94
|
+
# @return [BinaryExpr]
|
|
95
|
+
# The new binary expression.
|
|
96
|
+
#
|
|
97
|
+
def >>(other)
|
|
98
|
+
BinaryExpr.new(self,:>>,other)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
#
|
|
102
|
+
# Bit-wise `AND`.
|
|
103
|
+
#
|
|
104
|
+
# @return [BinaryExpr]
|
|
105
|
+
# The new binary expression.
|
|
106
|
+
#
|
|
107
|
+
def &(other)
|
|
108
|
+
BinaryExpr.new(self,:&,other)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
#
|
|
112
|
+
# Bit-wise `OR`.
|
|
113
|
+
#
|
|
114
|
+
# @return [BinaryExpr]
|
|
115
|
+
# The new binary expression.
|
|
116
|
+
#
|
|
117
|
+
def |(other)
|
|
118
|
+
BinaryExpr.new(self,:|,other)
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
#
|
|
122
|
+
# Less than.
|
|
123
|
+
#
|
|
124
|
+
# @return [BinaryExpr]
|
|
125
|
+
# The new binary expression.
|
|
126
|
+
#
|
|
127
|
+
def <(other)
|
|
128
|
+
BinaryExpr.new(self,:<,other)
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
#
|
|
132
|
+
# Less than or equal to.
|
|
133
|
+
#
|
|
134
|
+
# @return [BinaryExpr]
|
|
135
|
+
# The new binary expression.
|
|
136
|
+
#
|
|
137
|
+
def <=(other)
|
|
138
|
+
BinaryExpr.new(self,:<=,other)
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
#
|
|
142
|
+
# Greater than.
|
|
143
|
+
#
|
|
144
|
+
# @return [BinaryExpr]
|
|
145
|
+
# The new binary expression.
|
|
146
|
+
#
|
|
147
|
+
def >(other)
|
|
148
|
+
BinaryExpr.new(self,:>,other)
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
#
|
|
152
|
+
# Greater than or equal to.
|
|
153
|
+
#
|
|
154
|
+
# @return [BinaryExpr]
|
|
155
|
+
# The new binary expression.
|
|
156
|
+
#
|
|
157
|
+
def >=(other)
|
|
158
|
+
BinaryExpr.new(self,:>=,other)
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
#
|
|
162
|
+
# Equal to.
|
|
163
|
+
#
|
|
164
|
+
# @return [BinaryExpr]
|
|
165
|
+
# The new binary expression.
|
|
166
|
+
#
|
|
167
|
+
def ==(other)
|
|
168
|
+
BinaryExpr.new(self,:"=",other)
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
#
|
|
172
|
+
# Not equal to.
|
|
173
|
+
#
|
|
174
|
+
# @return [BinaryExpr]
|
|
175
|
+
# The new binary expression.
|
|
176
|
+
#
|
|
177
|
+
def !=(other)
|
|
178
|
+
BinaryExpr.new(self,:!=,other)
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
#
|
|
182
|
+
# Alias.
|
|
183
|
+
#
|
|
184
|
+
# @return [BinaryExpr]
|
|
185
|
+
# The new binary expression.
|
|
186
|
+
#
|
|
187
|
+
def as(name)
|
|
188
|
+
BinaryExpr.new(self,:AS,name)
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
#
|
|
192
|
+
# `IS` comparison.
|
|
193
|
+
#
|
|
194
|
+
# @return [BinaryExpr]
|
|
195
|
+
# The new binary expression.
|
|
196
|
+
#
|
|
197
|
+
def is(other)
|
|
198
|
+
BinaryExpr.new(self,:IS,other)
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
#
|
|
202
|
+
# `IS NOT` comparison.
|
|
203
|
+
#
|
|
204
|
+
# @return [BinaryExpr]
|
|
205
|
+
# The new binary expression.
|
|
206
|
+
#
|
|
207
|
+
def is_not(other)
|
|
208
|
+
BinaryExpr.new(self,:"IS NOT",other)
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
#
|
|
212
|
+
# `LIKE` comparison.
|
|
213
|
+
#
|
|
214
|
+
# @return [BinaryExpr]
|
|
215
|
+
# The new binary expression.
|
|
216
|
+
#
|
|
217
|
+
def like(other)
|
|
218
|
+
BinaryExpr.new(self,:LIKE,other)
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
#
|
|
222
|
+
# `GLOB` comparison.
|
|
223
|
+
#
|
|
224
|
+
# @return [BinaryExpr]
|
|
225
|
+
# The new binary expression.
|
|
226
|
+
#
|
|
227
|
+
def glob(other)
|
|
228
|
+
BinaryExpr.new(self,:GLOB,other)
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
#
|
|
232
|
+
# `MATCH` comparison.
|
|
233
|
+
#
|
|
234
|
+
# @return [BinaryExpr]
|
|
235
|
+
# The new binary expression.
|
|
236
|
+
#
|
|
237
|
+
def match(other)
|
|
238
|
+
BinaryExpr.new(self,:MATCH,other)
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
#
|
|
242
|
+
# `REGEXP` comparison.
|
|
243
|
+
#
|
|
244
|
+
# @return [BinaryExpr]
|
|
245
|
+
# The new binary expression.
|
|
246
|
+
#
|
|
247
|
+
def regexp(other)
|
|
248
|
+
BinaryExpr.new(self,:REGEXP,other)
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
#
|
|
252
|
+
# `REGEXP` comparison.
|
|
253
|
+
#
|
|
254
|
+
# @return [BinaryExpr]
|
|
255
|
+
# The new binary expression.
|
|
256
|
+
#
|
|
257
|
+
def in(other)
|
|
258
|
+
BinaryExpr.new(self,:IN,other)
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
#
|
|
262
|
+
# Unary minus.
|
|
263
|
+
#
|
|
264
|
+
# @return [UnaryExpr]
|
|
265
|
+
# The new binary expression.
|
|
266
|
+
#
|
|
267
|
+
def -@
|
|
268
|
+
UnaryExpr.new(:-,self)
|
|
269
|
+
end
|
|
270
|
+
|
|
271
|
+
#
|
|
272
|
+
# Unary plus.
|
|
273
|
+
#
|
|
274
|
+
# @return [UnaryExpr]
|
|
275
|
+
# The new binary expression.
|
|
276
|
+
#
|
|
277
|
+
def +@
|
|
278
|
+
UnaryExpr.new(:+,self)
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
#
|
|
282
|
+
# Bit-wise negate.
|
|
283
|
+
#
|
|
284
|
+
# @return [UnaryExpr]
|
|
285
|
+
# The new binary expression.
|
|
286
|
+
#
|
|
287
|
+
def ~
|
|
288
|
+
UnaryExpr.new(:~,self)
|
|
289
|
+
end
|
|
290
|
+
|
|
291
|
+
#
|
|
292
|
+
# Logical negate.
|
|
293
|
+
#
|
|
294
|
+
# @return [UnaryExpr]
|
|
295
|
+
# The new binary expression.
|
|
296
|
+
#
|
|
297
|
+
def !
|
|
298
|
+
UnaryExpr.new(:!,self)
|
|
299
|
+
end
|
|
300
|
+
|
|
301
|
+
#
|
|
302
|
+
# Logical `NOT`.
|
|
303
|
+
#
|
|
304
|
+
# @return [UnaryExpr]
|
|
305
|
+
# The new binary expression.
|
|
306
|
+
#
|
|
307
|
+
def not
|
|
308
|
+
UnaryExpr.new(:NOT,self)
|
|
309
|
+
end
|
|
310
|
+
|
|
311
|
+
#
|
|
312
|
+
# `AND`.
|
|
313
|
+
#
|
|
314
|
+
# @return [BinaryExpr]
|
|
315
|
+
# The new binary expression.
|
|
316
|
+
#
|
|
317
|
+
def and(other)
|
|
318
|
+
BinaryExpr.new(self,:AND,other)
|
|
319
|
+
end
|
|
320
|
+
|
|
321
|
+
#
|
|
322
|
+
# `OR`.
|
|
323
|
+
#
|
|
324
|
+
# @return [BinaryExpr]
|
|
325
|
+
# The new binary expression.
|
|
326
|
+
#
|
|
327
|
+
def or(other)
|
|
328
|
+
BinaryExpr.new(self,:OR,other)
|
|
329
|
+
end
|
|
330
|
+
end
|
|
331
|
+
end
|
|
332
|
+
end
|