ronin-sql 0.1.1 → 0.2.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/History.txt +43 -0
- data/Manifest.txt +76 -23
- data/README.txt +31 -6
- data/Rakefile +2 -2
- data/lib/ronin/code/sql/{keyword.rb → add_column_clause.rb} +9 -13
- data/lib/ronin/code/sql/as.rb +47 -0
- data/lib/ronin/code/sql/asc.rb +38 -0
- data/lib/ronin/code/sql/between.rb +18 -12
- data/lib/ronin/code/sql/binary_expr.rb +12 -5
- data/lib/ronin/code/sql/clause.rb +37 -0
- data/lib/ronin/code/sql/code.rb +1 -1
- data/lib/ronin/code/sql/common_dialect.rb +16 -10
- data/lib/ronin/code/sql/create.rb +68 -0
- data/lib/ronin/code/sql/create_index.rb +9 -39
- data/lib/ronin/code/sql/create_table.rb +9 -56
- data/lib/ronin/code/sql/create_view.rb +7 -29
- data/lib/ronin/code/sql/default_values_clause.rb +38 -0
- data/lib/ronin/code/sql/delete.rb +10 -25
- data/lib/ronin/code/sql/desc.rb +38 -0
- data/lib/ronin/code/sql/dialect.rb +172 -52
- data/lib/ronin/code/sql/{builder.rb → drop.rb} +16 -20
- data/lib/ronin/code/sql/drop_index.rb +43 -0
- data/lib/ronin/code/sql/drop_table.rb +8 -16
- data/lib/ronin/code/sql/drop_view.rb +43 -0
- data/lib/ronin/code/sql/emittable.rb +102 -0
- data/lib/ronin/code/sql/exceptions/unknown_clause.rb +31 -0
- data/lib/ronin/code/sql/exceptions/unknown_dialect.rb +2 -2
- data/lib/ronin/code/sql/exceptions/unknown_statement.rb +31 -0
- data/lib/ronin/code/sql/exceptions.rb +3 -1
- data/lib/ronin/code/sql/expr.rb +7 -96
- data/lib/ronin/code/sql/field.rb +40 -23
- data/lib/ronin/code/sql/fields_clause.rb +48 -0
- data/lib/ronin/code/sql/from_clause.rb +44 -0
- data/lib/ronin/code/sql/function.rb +15 -12
- data/lib/ronin/code/sql/group_by_clause.rb +48 -0
- data/lib/ronin/code/sql/having_clause.rb +48 -0
- data/lib/ronin/code/sql/in.rb +9 -9
- data/lib/ronin/code/sql/injected_statement.rb +102 -0
- data/lib/ronin/code/sql/injection.rb +171 -5
- data/lib/ronin/code/sql/insert.rb +15 -45
- data/lib/ronin/code/sql/intersect_clause.rb +44 -0
- data/lib/ronin/code/sql/join_clause.rb +125 -0
- data/lib/ronin/code/sql/{like_expr.rb → like.rb} +19 -31
- data/lib/ronin/code/sql/limit_clause.rb +44 -0
- data/lib/ronin/code/sql/modifier.rb +50 -0
- data/lib/ronin/code/sql/offset_clause.rb +44 -0
- data/lib/ronin/code/sql/on_clause.rb +57 -0
- data/lib/ronin/code/sql/order_by_clause.rb +44 -0
- data/lib/ronin/code/sql/program.rb +170 -23
- data/lib/ronin/code/sql/rename_to_clause.rb +44 -0
- data/lib/ronin/code/sql/replace.rb +15 -17
- data/lib/ronin/code/sql/select.rb +46 -141
- data/lib/ronin/code/sql/set_clause.rb +44 -0
- data/lib/ronin/code/sql/statement.rb +117 -47
- data/lib/ronin/code/sql/token.rb +64 -0
- data/lib/ronin/code/sql/unary_expr.rb +9 -5
- data/lib/ronin/code/sql/union_all_clause.rb +44 -0
- data/lib/ronin/code/sql/union_clause.rb +44 -0
- data/lib/ronin/code/sql/update.rb +10 -31
- data/lib/ronin/code/sql/values_clause.rb +48 -0
- data/lib/ronin/code/sql/where_clause.rb +44 -0
- data/lib/ronin/code/sql.rb +1 -1
- data/lib/ronin/sql/error/error.rb +64 -0
- data/lib/ronin/sql/error/message.rb +64 -0
- data/lib/ronin/sql/error/pattern.rb +106 -0
- data/lib/ronin/sql/error/patterns.rb +100 -0
- data/lib/ronin/sql/error.rb +5 -30
- data/lib/ronin/sql/extensions/uri/http.rb +76 -21
- data/lib/ronin/sql/extensions/uri.rb +1 -1
- data/lib/ronin/sql/extensions.rb +2 -1
- data/lib/ronin/sql/injection.rb +213 -0
- data/lib/ronin/sql/version.rb +2 -2
- data/lib/ronin/sql.rb +7 -2
- data/spec/code/sql/create_examples.rb +19 -0
- data/spec/code/sql/create_index_spec.rb +25 -0
- data/spec/code/sql/create_table_spec.rb +27 -0
- data/spec/code/sql/create_view_spec.rb +16 -0
- data/spec/code/sql/delete_spec.rb +14 -0
- data/spec/code/sql/drop_examples.rb +10 -0
- data/spec/code/sql/drop_index_spec.rb +16 -0
- data/spec/code/sql/drop_table_spec.rb +16 -0
- data/spec/code/sql/drop_view_spec.rb +16 -0
- data/spec/code/sql/has_default_values_clause_examples.rb +10 -0
- data/spec/code/sql/has_fields_clause_examples.rb +15 -0
- data/spec/code/sql/has_from_clause_examples.rb +13 -0
- data/spec/code/sql/has_values_clause_examples.rb +15 -0
- data/spec/code/sql/has_where_clause_examples.rb +15 -0
- data/spec/code/sql/insert_spec.rb +21 -0
- data/spec/code/sql/replace_spec.rb +21 -0
- data/spec/code/sql/select_spec.rb +105 -0
- data/spec/code/sql/update_spec.rb +26 -0
- data/spec/helpers/code.rb +14 -0
- data/spec/sql/error_spec.rb +24 -0
- data/spec/sql/extensions/string_spec.rb +28 -0
- data/spec/sql_spec.rb +9 -0
- data/tasks/spec.rb +2 -0
- metadata +82 -29
- data/lib/ronin/code/sql/injection_builder.rb +0 -137
- data/lib/ronin/code/sql/injection_style.rb +0 -79
- data/lib/ronin/code/sql/style.rb +0 -170
- data/lib/ronin/sql/sql.rb +0 -83
@@ -0,0 +1,48 @@
|
|
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 FieldsClause < Clause
|
30
|
+
|
31
|
+
# Fields of the clause
|
32
|
+
attr_accessor :fields
|
33
|
+
|
34
|
+
#
|
35
|
+
# Creates a new FieldsClause object with the specified _fields_.
|
36
|
+
#
|
37
|
+
def initialize(*fields)
|
38
|
+
@fields = fields
|
39
|
+
end
|
40
|
+
|
41
|
+
def emit
|
42
|
+
emit_row(@fields)
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
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 FromClause < Clause
|
30
|
+
|
31
|
+
attr_accessor :table
|
32
|
+
|
33
|
+
def initialize(table)
|
34
|
+
@table = table
|
35
|
+
end
|
36
|
+
|
37
|
+
def emit
|
38
|
+
emit_token('FROM') + emit_value(@table)
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
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-
|
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
|
@@ -28,22 +28,25 @@ module Ronin
|
|
28
28
|
module SQL
|
29
29
|
class Function < Expr
|
30
30
|
|
31
|
-
|
32
|
-
|
31
|
+
# Name of the function
|
32
|
+
attr_reader :name
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
@fields = fields
|
37
|
-
end
|
34
|
+
# Fields passed to the function
|
35
|
+
attr_reader :fields
|
38
36
|
|
39
|
-
def
|
40
|
-
|
37
|
+
def initialize(name,*fields)
|
38
|
+
@name = name
|
39
|
+
@fields = fields
|
41
40
|
end
|
42
41
|
|
43
|
-
|
42
|
+
def emit
|
43
|
+
tokens = emit_token(@name)
|
44
|
+
|
45
|
+
tokens << Token.open_paren
|
46
|
+
tokens += emit_list(@fields)
|
47
|
+
tokens << Token.close_paren
|
44
48
|
|
45
|
-
|
46
|
-
return compile_list(@fields) unless @fields.empty?
|
49
|
+
return tokens
|
47
50
|
end
|
48
51
|
|
49
52
|
end
|
@@ -0,0 +1,48 @@
|
|
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 GroupByClause < Clause
|
30
|
+
|
31
|
+
# Fields to group
|
32
|
+
attr_accessor :fields
|
33
|
+
|
34
|
+
#
|
35
|
+
# Creates a new GroupByClause object with the specified _fields_.
|
36
|
+
#
|
37
|
+
def initialize(*fields)
|
38
|
+
@fields = fields
|
39
|
+
end
|
40
|
+
|
41
|
+
def emit
|
42
|
+
emit_token('GROUP BY') + emit_list(@fields)
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,48 @@
|
|
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 HavingClause < Clause
|
30
|
+
|
31
|
+
# Expression of the having clause
|
32
|
+
attr_accessor :expr
|
33
|
+
|
34
|
+
#
|
35
|
+
# Creates a new HavingClause object with the specified _expr_.
|
36
|
+
#
|
37
|
+
def initialize(expr)
|
38
|
+
@expr = expr
|
39
|
+
end
|
40
|
+
|
41
|
+
def emit
|
42
|
+
emit_token('HAVING') + emit_value(@expr)
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/ronin/code/sql/in.rb
CHANGED
@@ -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-
|
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
|
@@ -28,21 +28,21 @@ module Ronin
|
|
28
28
|
module SQL
|
29
29
|
class In < Expr
|
30
30
|
|
31
|
-
|
32
|
-
|
31
|
+
# Field
|
32
|
+
attr_reader :field
|
33
33
|
|
34
|
+
# Range
|
35
|
+
attr_reader :range
|
36
|
+
|
37
|
+
def initialize(field,*range)
|
34
38
|
@field = field
|
35
39
|
@range = range
|
36
40
|
end
|
37
41
|
|
38
|
-
def
|
39
|
-
|
42
|
+
def emit
|
43
|
+
emit_value(@field) + emit_token('IN') + emit_values(@range)
|
40
44
|
end
|
41
45
|
|
42
|
-
protected
|
43
|
-
|
44
|
-
keyword :in
|
45
|
-
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
@@ -0,0 +1,102 @@
|
|
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/statement'
|
25
|
+
|
26
|
+
module Ronin
|
27
|
+
module Code
|
28
|
+
module SQL
|
29
|
+
class InjectedStatement < Statement
|
30
|
+
|
31
|
+
# Injected expressions
|
32
|
+
attr_reader :expressions
|
33
|
+
|
34
|
+
def initialize(dialect,&block)
|
35
|
+
@expressions = []
|
36
|
+
|
37
|
+
super(dialect,&block)
|
38
|
+
end
|
39
|
+
|
40
|
+
def inject_and(expr)
|
41
|
+
@expressions += [Token.new('AND'), expr]
|
42
|
+
return self
|
43
|
+
end
|
44
|
+
|
45
|
+
def inject_or(expr)
|
46
|
+
@expressions += [Token.new('OR'), expr]
|
47
|
+
return self
|
48
|
+
end
|
49
|
+
|
50
|
+
def all_rows(value=1)
|
51
|
+
inject_or(BinaryExpr.new('=',value,value))
|
52
|
+
end
|
53
|
+
|
54
|
+
def exact_rows(value=1)
|
55
|
+
inject_and(BinaryExpr.new('=',value,value))
|
56
|
+
end
|
57
|
+
|
58
|
+
def no_rows
|
59
|
+
inject_and(BinaryExpr.new('=',1,0))
|
60
|
+
end
|
61
|
+
|
62
|
+
def has_column?(name)
|
63
|
+
inject_or(field(name).is_not?(null))
|
64
|
+
end
|
65
|
+
|
66
|
+
def has_table?(table)
|
67
|
+
inject_and(select(:from => table,:fields => count(all)) == 1)
|
68
|
+
end
|
69
|
+
|
70
|
+
def uses_column?(name)
|
71
|
+
group_by(name)
|
72
|
+
|
73
|
+
having(BinaryExpr.new('=',1,1))
|
74
|
+
return self
|
75
|
+
end
|
76
|
+
|
77
|
+
def uses_table?(table)
|
78
|
+
inject_or(table.is_not?(null))
|
79
|
+
end
|
80
|
+
|
81
|
+
def emit
|
82
|
+
emit_values(@expressions) + super
|
83
|
+
end
|
84
|
+
|
85
|
+
protected
|
86
|
+
|
87
|
+
def clause(name,*arguments)
|
88
|
+
dialect.caluse(name,*arguments)
|
89
|
+
end
|
90
|
+
|
91
|
+
def method_missing(name,*arguments,&block)
|
92
|
+
if (@dialect.has_clause?(name) && block.nil?)
|
93
|
+
return @dialect.clause(name,*arguments)
|
94
|
+
end
|
95
|
+
|
96
|
+
return super(name,*arguments,&block)
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -1,8 +1,9 @@
|
|
1
1
|
#
|
2
|
+
#--
|
2
3
|
# Ronin SQL - A Ronin library providing support for SQL related security
|
3
4
|
# tasks.
|
4
5
|
#
|
5
|
-
# Copyright (c) 2007-
|
6
|
+
# Copyright (c) 2007-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
|
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
|
@@ -17,20 +18,185 @@
|
|
17
18
|
# You should have received a copy of the GNU General Public License
|
18
19
|
# along with this program; if not, write to the Free Software
|
19
20
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
21
|
+
#++
|
20
22
|
#
|
21
23
|
|
22
24
|
require 'ronin/code/sql/program'
|
23
|
-
require 'ronin/code/sql/
|
24
|
-
require 'ronin/
|
25
|
-
require 'ronin/extensions/string'
|
25
|
+
require 'ronin/code/sql/injected_statement'
|
26
|
+
require 'ronin/formatting/text'
|
26
27
|
|
27
28
|
module Ronin
|
28
29
|
module Code
|
29
30
|
module SQL
|
30
31
|
class Injection < Program
|
31
32
|
|
33
|
+
# Comment-Obfustication
|
34
|
+
attr_accessor :comment_evasion
|
35
|
+
|
36
|
+
# Swapcase-Obfusciation
|
37
|
+
attr_accessor :case_evasion
|
38
|
+
|
39
|
+
# Data to escape a previous expression with
|
40
|
+
attr_accessor :escape
|
41
|
+
|
42
|
+
# Specifies whether or not to close an open string
|
43
|
+
attr_accessor :close_string
|
44
|
+
|
45
|
+
# Specifies whether or not to close an open parenthesis
|
46
|
+
attr_accessor :close_parens
|
47
|
+
|
48
|
+
# Specifies whether or not to end a previous statement
|
49
|
+
attr_accessor :end_statement
|
50
|
+
|
32
51
|
def initialize(options={},&block)
|
33
|
-
|
52
|
+
if options.has_key?(:comment_evasion)
|
53
|
+
@comment_evasion = options[:comment_evasion]
|
54
|
+
else
|
55
|
+
@comment_evasion = false
|
56
|
+
end
|
57
|
+
|
58
|
+
if options.has_key?(:case_evasion)
|
59
|
+
@case_evasion = options[:case_evasion]
|
60
|
+
else
|
61
|
+
@case_evasion = false
|
62
|
+
end
|
63
|
+
|
64
|
+
@escape = options[:escape]
|
65
|
+
|
66
|
+
if options.has_key?(:close_string)
|
67
|
+
@close_string = options[:close_string]
|
68
|
+
else
|
69
|
+
@close_string = false
|
70
|
+
end
|
71
|
+
|
72
|
+
if options.has_key?(:close_parens)
|
73
|
+
@close_parens = options[:close_parens]
|
74
|
+
else
|
75
|
+
@close_parens = false
|
76
|
+
end
|
77
|
+
|
78
|
+
if options.has_key?(:end_statement)
|
79
|
+
@end_statement = options[:end_statement]
|
80
|
+
else
|
81
|
+
@end_statement = false
|
82
|
+
end
|
83
|
+
|
84
|
+
super(options) do
|
85
|
+
@expression = InjectedStatement.new(@dialect)
|
86
|
+
end
|
87
|
+
|
88
|
+
instance_eval(&block) if block
|
89
|
+
end
|
90
|
+
|
91
|
+
#
|
92
|
+
# Returns the expression that will be injected into the effected
|
93
|
+
# statement. If a _block_ is given, it will be evaluated within
|
94
|
+
# the expression.
|
95
|
+
#
|
96
|
+
def expression(&block)
|
97
|
+
@expression.instance_eval(&block) if block
|
98
|
+
return @expression
|
99
|
+
end
|
100
|
+
|
101
|
+
def sql(&block)
|
102
|
+
@dialect.instance_eval(&block) if block
|
103
|
+
end
|
104
|
+
|
105
|
+
def compile
|
106
|
+
injection = super.rstrip
|
107
|
+
|
108
|
+
comment = lambda { [injection, '--'].join(space_token) }
|
109
|
+
|
110
|
+
if (@close_parens && @close_string)
|
111
|
+
if injection =~ /'\s*\)$/
|
112
|
+
return injection.gsub(/'\s*\)$/,'')
|
113
|
+
else
|
114
|
+
return comment.call
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
if @close_string
|
119
|
+
if injection[-1..-1] == "'"
|
120
|
+
return injection.chop
|
121
|
+
else
|
122
|
+
return comment.call
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
return injection
|
127
|
+
end
|
128
|
+
|
129
|
+
alias to_s compile
|
130
|
+
|
131
|
+
protected
|
132
|
+
|
133
|
+
def space_token
|
134
|
+
if @comment_evasion
|
135
|
+
return '/**/'
|
136
|
+
else
|
137
|
+
return super
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def format_token(token)
|
142
|
+
token = super(token)
|
143
|
+
|
144
|
+
if @case_evasion
|
145
|
+
token = token.random_case
|
146
|
+
end
|
147
|
+
|
148
|
+
return token
|
149
|
+
end
|
150
|
+
|
151
|
+
def each_string(&block)
|
152
|
+
escape_value = ''
|
153
|
+
|
154
|
+
if @close_string
|
155
|
+
# format the escape string, since we are escaping out of a
|
156
|
+
# string
|
157
|
+
escape_value << format(@escape) if @escape
|
158
|
+
else
|
159
|
+
# do not format the escape string when we are not escaping
|
160
|
+
# out of a string
|
161
|
+
escape_value << @escape.to_s if @escape
|
162
|
+
end
|
163
|
+
|
164
|
+
if @close_string
|
165
|
+
if escape_value[0..0] == "'"
|
166
|
+
escape_value = escape_value[1..-1]
|
167
|
+
else
|
168
|
+
escape_value << "'"
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
escape_value << ')' if @close_parens
|
173
|
+
|
174
|
+
block.call(escape_value) unless escape_value.empty?
|
175
|
+
|
176
|
+
return super(&block)
|
177
|
+
end
|
178
|
+
|
179
|
+
def each_token(&block)
|
180
|
+
if @expression
|
181
|
+
@expression.emit.each(&block)
|
182
|
+
|
183
|
+
block.call(Token.separator)
|
184
|
+
elsif @end_statement
|
185
|
+
block.call(Token.separator)
|
186
|
+
end
|
187
|
+
|
188
|
+
return super(&block)
|
189
|
+
end
|
190
|
+
|
191
|
+
#
|
192
|
+
# Relays missed method calls to the injected expression.
|
193
|
+
#
|
194
|
+
def method_missing(name,*arguments,&block)
|
195
|
+
if @expression.public_methods(false).include?(name.to_s)
|
196
|
+
return @expression.send(name,*arguments,&block)
|
197
|
+
end
|
198
|
+
|
199
|
+
return super(name,*arguments,&block)
|
34
200
|
end
|
35
201
|
|
36
202
|
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-
|
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
|
@@ -22,64 +22,34 @@
|
|
22
22
|
#
|
23
23
|
|
24
24
|
require 'ronin/code/sql/statement'
|
25
|
+
require 'ronin/code/sql/fields_clause'
|
26
|
+
require 'ronin/code/sql/values_clause'
|
27
|
+
require 'ronin/code/sql/default_values_clause'
|
25
28
|
|
26
29
|
module Ronin
|
27
30
|
module Code
|
28
31
|
module SQL
|
29
32
|
class Insert < Statement
|
30
33
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
@values = opts[:values]
|
35
|
-
@from = opts[:from]
|
34
|
+
clause :fields, FieldsClause
|
35
|
+
clause :default_values, DefaultValuesClause
|
36
|
+
clause :values, ValuesClause
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
def into(table)
|
41
|
-
@table = table
|
42
|
-
return self
|
43
|
-
end
|
38
|
+
def initialize(dialect,options={},&block)
|
39
|
+
@table = options[:table]
|
44
40
|
|
45
|
-
|
46
|
-
@fields = fields
|
47
|
-
return self
|
41
|
+
super(dialect,options,&block)
|
48
42
|
end
|
49
43
|
|
50
|
-
def
|
51
|
-
|
52
|
-
|
53
|
-
else
|
54
|
-
@values = values
|
55
|
-
end
|
56
|
-
return self
|
44
|
+
def table(name)
|
45
|
+
@table = name
|
46
|
+
return value
|
57
47
|
end
|
58
48
|
|
59
|
-
def
|
60
|
-
@
|
61
|
-
return self
|
49
|
+
def emit
|
50
|
+
emit_token('INSERT INTO') + emit_value(@table) + super
|
62
51
|
end
|
63
52
|
|
64
|
-
def compile
|
65
|
-
if @values.kind_of?(Hash)
|
66
|
-
return compile_expr(keyword_insert,@table,compile_row(@values.keys),keyword_values,compile_datalist(@values.values))
|
67
|
-
elsif @from
|
68
|
-
return compile_expr(keyword_insert,@table,compile_row(@fields),@from)
|
69
|
-
else
|
70
|
-
if @fields
|
71
|
-
return compile_expr(keyword_insert,@table,compile_row(@fields),keyword_values,compile_datalist(@values))
|
72
|
-
else
|
73
|
-
return compile_expr(keyword_insert,@table,keyword_values,compile_datalist(@values))
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
protected
|
79
|
-
|
80
|
-
keyword :insert, 'INSERT INTO'
|
81
|
-
keyword :values
|
82
|
-
|
83
53
|
end
|
84
54
|
end
|
85
55
|
end
|