ronin-sql 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Manifest.txt +44 -41
- data/lib/ronin/code/sql/alter_table.rb +54 -0
- data/lib/ronin/sql/extensions/string.rb +122 -0
- data/lib/ronin/sql/version.rb +1 -1
- metadata +45 -43
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
@@ -8,67 +8,70 @@ lib/ronin/code/sql/exceptions.rb
|
|
8
8
|
lib/ronin/code/sql/exceptions/unknown_dialect.rb
|
9
9
|
lib/ronin/code/sql/exceptions/unknown_statement.rb
|
10
10
|
lib/ronin/code/sql/exceptions/unknown_clause.rb
|
11
|
-
lib/ronin/code/sql/
|
12
|
-
lib/ronin/code/sql/
|
13
|
-
lib/ronin/code/sql/modifier.rb
|
11
|
+
lib/ronin/code/sql/add_column_clause.rb
|
12
|
+
lib/ronin/code/sql/alter_table.rb
|
14
13
|
lib/ronin/code/sql/asc.rb
|
15
|
-
lib/ronin/code/sql/desc.rb
|
16
14
|
lib/ronin/code/sql/as.rb
|
17
|
-
lib/ronin/code/sql/expr.rb
|
18
|
-
lib/ronin/code/sql/unary_expr.rb
|
19
|
-
lib/ronin/code/sql/binary_expr.rb
|
20
|
-
lib/ronin/code/sql/like.rb
|
21
15
|
lib/ronin/code/sql/between.rb
|
22
|
-
lib/ronin/code/sql/
|
23
|
-
lib/ronin/code/sql/field.rb
|
16
|
+
lib/ronin/code/sql/binary_expr.rb
|
24
17
|
lib/ronin/code/sql/clause.rb
|
25
|
-
lib/ronin/code/sql/
|
26
|
-
lib/ronin/code/sql/
|
27
|
-
lib/ronin/code/sql/group_by_clause.rb
|
28
|
-
lib/ronin/code/sql/fields_clause.rb
|
29
|
-
lib/ronin/code/sql/set_clause.rb
|
30
|
-
lib/ronin/code/sql/values_clause.rb
|
31
|
-
lib/ronin/code/sql/from_clause.rb
|
32
|
-
lib/ronin/code/sql/default_values_clause.rb
|
33
|
-
lib/ronin/code/sql/join_clause.rb
|
34
|
-
lib/ronin/code/sql/order_by_clause.rb
|
35
|
-
lib/ronin/code/sql/limit_clause.rb
|
36
|
-
lib/ronin/code/sql/offset_clause.rb
|
37
|
-
lib/ronin/code/sql/union_clause.rb
|
38
|
-
lib/ronin/code/sql/having_clause.rb
|
39
|
-
lib/ronin/code/sql/union_all_clause.rb
|
40
|
-
lib/ronin/code/sql/intersect_clause.rb
|
41
|
-
lib/ronin/code/sql/rename_to_clause.rb
|
42
|
-
lib/ronin/code/sql/add_column_clause.rb
|
43
|
-
lib/ronin/code/sql/function.rb
|
44
|
-
lib/ronin/code/sql/statement.rb
|
45
|
-
lib/ronin/code/sql/create.rb
|
18
|
+
lib/ronin/code/sql/code.rb
|
19
|
+
lib/ronin/code/sql/common_dialect.rb
|
46
20
|
lib/ronin/code/sql/create_index.rb
|
21
|
+
lib/ronin/code/sql/create.rb
|
47
22
|
lib/ronin/code/sql/create_table.rb
|
48
23
|
lib/ronin/code/sql/create_view.rb
|
49
|
-
lib/ronin/code/sql/
|
50
|
-
lib/ronin/code/sql/select.rb
|
51
|
-
lib/ronin/code/sql/replace.rb
|
52
|
-
lib/ronin/code/sql/update.rb
|
24
|
+
lib/ronin/code/sql/default_values_clause.rb
|
53
25
|
lib/ronin/code/sql/delete.rb
|
54
|
-
lib/ronin/code/sql/
|
26
|
+
lib/ronin/code/sql/desc.rb
|
27
|
+
lib/ronin/code/sql/dialect.rb
|
55
28
|
lib/ronin/code/sql/drop_index.rb
|
29
|
+
lib/ronin/code/sql/drop.rb
|
56
30
|
lib/ronin/code/sql/drop_table.rb
|
57
31
|
lib/ronin/code/sql/drop_view.rb
|
58
|
-
lib/ronin/code/sql/
|
59
|
-
lib/ronin/code/sql/
|
60
|
-
lib/ronin/code/sql/
|
32
|
+
lib/ronin/code/sql/emittable.rb
|
33
|
+
lib/ronin/code/sql/exceptions.rb
|
34
|
+
lib/ronin/code/sql/expr.rb
|
35
|
+
lib/ronin/code/sql/field.rb
|
36
|
+
lib/ronin/code/sql/fields_clause.rb
|
37
|
+
lib/ronin/code/sql/from_clause.rb
|
38
|
+
lib/ronin/code/sql/function.rb
|
39
|
+
lib/ronin/code/sql/group_by_clause.rb
|
40
|
+
lib/ronin/code/sql/having_clause.rb
|
61
41
|
lib/ronin/code/sql/injected_statement.rb
|
62
42
|
lib/ronin/code/sql/injection.rb
|
63
|
-
lib/ronin/code/sql/
|
43
|
+
lib/ronin/code/sql/in.rb
|
44
|
+
lib/ronin/code/sql/insert.rb
|
45
|
+
lib/ronin/code/sql/intersect_clause.rb
|
46
|
+
lib/ronin/code/sql/join_clause.rb
|
47
|
+
lib/ronin/code/sql/like.rb
|
48
|
+
lib/ronin/code/sql/limit_clause.rb
|
49
|
+
lib/ronin/code/sql/modifier.rb
|
50
|
+
lib/ronin/code/sql/offset_clause.rb
|
51
|
+
lib/ronin/code/sql/on_clause.rb
|
52
|
+
lib/ronin/code/sql/order_by_clause.rb
|
53
|
+
lib/ronin/code/sql/program.rb
|
54
|
+
lib/ronin/code/sql/rename_to_clause.rb
|
55
|
+
lib/ronin/code/sql/replace.rb
|
56
|
+
lib/ronin/code/sql/select.rb
|
57
|
+
lib/ronin/code/sql/set_clause.rb
|
58
|
+
lib/ronin/code/sql/statement.rb
|
59
|
+
lib/ronin/code/sql/token.rb
|
60
|
+
lib/ronin/code/sql/unary_expr.rb
|
61
|
+
lib/ronin/code/sql/union_all_clause.rb
|
62
|
+
lib/ronin/code/sql/union_clause.rb
|
63
|
+
lib/ronin/code/sql/update.rb
|
64
|
+
lib/ronin/code/sql/values_clause.rb
|
65
|
+
lib/ronin/code/sql/where_clause.rb
|
64
66
|
lib/ronin/sql/extensions.rb
|
67
|
+
lib/ronin/sql/extensions/string.rb
|
65
68
|
lib/ronin/sql/extensions/uri.rb
|
66
69
|
lib/ronin/sql/extensions/uri/http.rb
|
70
|
+
lib/ronin/sql/error.rb
|
67
71
|
lib/ronin/sql/error/message.rb
|
68
72
|
lib/ronin/sql/error/pattern.rb
|
69
73
|
lib/ronin/sql/error/error.rb
|
70
74
|
lib/ronin/sql/error/patterns.rb
|
71
|
-
lib/ronin/sql/error.rb
|
72
75
|
lib/ronin/sql/injection.rb
|
73
76
|
lib/ronin/sql/version.rb
|
74
77
|
lib/ronin/sql.rb
|
@@ -0,0 +1,54 @@
|
|
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
|
+
require 'ronin/code/sql/rename_to_clause'
|
26
|
+
require 'ronin/code/sql/add_column_clause'
|
27
|
+
|
28
|
+
module Ronin
|
29
|
+
module Code
|
30
|
+
module SQL
|
31
|
+
class AlterTable < Statement
|
32
|
+
|
33
|
+
clause :rename_to, RenameToClause
|
34
|
+
clause :add_column, AddColumnClause
|
35
|
+
|
36
|
+
def initialize(options={},&block)
|
37
|
+
@table = options[:table]
|
38
|
+
|
39
|
+
super(options,&block)
|
40
|
+
end
|
41
|
+
|
42
|
+
def table(name)
|
43
|
+
@table = name
|
44
|
+
return self
|
45
|
+
end
|
46
|
+
|
47
|
+
def emit
|
48
|
+
emit_token('ALTER TABLE') + emit_value(@table) + super
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,122 @@
|
|
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/sql/error/error'
|
25
|
+
|
26
|
+
class String
|
27
|
+
|
28
|
+
#
|
29
|
+
# Returns an SQL error Message using the given _options_ if the
|
30
|
+
# String contains a SQL error Pattern. If no SQL error Pattern can be
|
31
|
+
# found within the String, +nil+ will be returned.
|
32
|
+
#
|
33
|
+
# _options_ may contain the following keys:
|
34
|
+
# <tt>:dialect</tt>:: The SQL dialect whos error messages to test for.
|
35
|
+
# <tt>:types</tt>:: A list of error pattern types to test for.
|
36
|
+
#
|
37
|
+
def sql_error(options={})
|
38
|
+
if options[:dialect]
|
39
|
+
patterns = Ronin::SQL::Error.patterns_for_dialect(options[:dialect])
|
40
|
+
elsif options[:types]
|
41
|
+
patterns = Ronin::SQL::Error.patterns_for(*options[:types])
|
42
|
+
else
|
43
|
+
patterns = Ronin::SQL::Error.patterns.values
|
44
|
+
end
|
45
|
+
|
46
|
+
patterns.each do |pattern|
|
47
|
+
if (message = pattern.match(self))
|
48
|
+
return message
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
return nil
|
53
|
+
end
|
54
|
+
|
55
|
+
#
|
56
|
+
# Returns +true+ if a SQL error Pattern can be found within the
|
57
|
+
# String using the given _options_, returns +false+ otherwise.
|
58
|
+
#
|
59
|
+
# _options_ may contain the following keys:
|
60
|
+
# <tt>:dialect</tt>:: The SQL dialect whos error messages to test for.
|
61
|
+
# <tt>:types</tt>:: A list of error pattern types to test for.
|
62
|
+
#
|
63
|
+
def sql_error?(options={})
|
64
|
+
if options[:dialect]
|
65
|
+
patterns = Error.patterns_for_dialect(options[:dialect])
|
66
|
+
elsif options[:types]
|
67
|
+
patterns = Error.patterns_for(*options[:types])
|
68
|
+
else
|
69
|
+
patterns = Error.patterns.values
|
70
|
+
end
|
71
|
+
|
72
|
+
patterns.each do |pattern|
|
73
|
+
return true if pattern =~ self
|
74
|
+
end
|
75
|
+
|
76
|
+
return false
|
77
|
+
end
|
78
|
+
|
79
|
+
#
|
80
|
+
# Returns the SQL hex-string encoded form of the String.
|
81
|
+
#
|
82
|
+
# "/etc/passwd".sql_encode
|
83
|
+
# # => "0x2f6574632f706173737764"
|
84
|
+
#
|
85
|
+
def sql_encode
|
86
|
+
return '' if empty?
|
87
|
+
|
88
|
+
hex_string = '0x'
|
89
|
+
|
90
|
+
each_byte do |b|
|
91
|
+
hex_string << ('%.2x' % b)
|
92
|
+
end
|
93
|
+
|
94
|
+
return hex_string
|
95
|
+
end
|
96
|
+
|
97
|
+
#
|
98
|
+
# Returns the SQL decoded form of the String.
|
99
|
+
#
|
100
|
+
# "'Conan O''Brian'".sql_decode
|
101
|
+
# # => "Conan O'Brian"
|
102
|
+
#
|
103
|
+
# "0x2f6574632f706173737764".sql_decode
|
104
|
+
# # => "/etc/passwd"
|
105
|
+
#
|
106
|
+
def sql_decode
|
107
|
+
if ((self[0...2] == '0x') && (length % 2 == 0))
|
108
|
+
raw = ''
|
109
|
+
|
110
|
+
self[2..-1].scan(/[0-9a-fA-F]{2}/).each do |hex_char|
|
111
|
+
raw << hex_char.hex.chr
|
112
|
+
end
|
113
|
+
|
114
|
+
return raw
|
115
|
+
elsif (self[0..0] == "'" && self[-1..-1] == "'")
|
116
|
+
self[1..-2].gsub(/\\'/,"'").gsub(/''/,"'")
|
117
|
+
else
|
118
|
+
return self
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
data/lib/ronin/sql/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ronin-sql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Postmodern
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-01-
|
12
|
+
date: 2009-01-09 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -55,67 +55,69 @@ files:
|
|
55
55
|
- lib/ronin/code/sql/exceptions/unknown_dialect.rb
|
56
56
|
- lib/ronin/code/sql/exceptions/unknown_statement.rb
|
57
57
|
- lib/ronin/code/sql/exceptions/unknown_clause.rb
|
58
|
-
- lib/ronin/code/sql/
|
59
|
-
- lib/ronin/code/sql/
|
60
|
-
- lib/ronin/code/sql/modifier.rb
|
58
|
+
- lib/ronin/code/sql/add_column_clause.rb
|
59
|
+
- lib/ronin/code/sql/alter_table.rb
|
61
60
|
- lib/ronin/code/sql/asc.rb
|
62
|
-
- lib/ronin/code/sql/desc.rb
|
63
61
|
- lib/ronin/code/sql/as.rb
|
64
|
-
- lib/ronin/code/sql/expr.rb
|
65
|
-
- lib/ronin/code/sql/unary_expr.rb
|
66
|
-
- lib/ronin/code/sql/binary_expr.rb
|
67
|
-
- lib/ronin/code/sql/like.rb
|
68
62
|
- lib/ronin/code/sql/between.rb
|
69
|
-
- lib/ronin/code/sql/
|
70
|
-
- lib/ronin/code/sql/field.rb
|
63
|
+
- lib/ronin/code/sql/binary_expr.rb
|
71
64
|
- lib/ronin/code/sql/clause.rb
|
72
|
-
- lib/ronin/code/sql/
|
73
|
-
- lib/ronin/code/sql/
|
74
|
-
- lib/ronin/code/sql/group_by_clause.rb
|
75
|
-
- lib/ronin/code/sql/fields_clause.rb
|
76
|
-
- lib/ronin/code/sql/set_clause.rb
|
77
|
-
- lib/ronin/code/sql/values_clause.rb
|
78
|
-
- lib/ronin/code/sql/from_clause.rb
|
79
|
-
- lib/ronin/code/sql/default_values_clause.rb
|
80
|
-
- lib/ronin/code/sql/join_clause.rb
|
81
|
-
- lib/ronin/code/sql/order_by_clause.rb
|
82
|
-
- lib/ronin/code/sql/limit_clause.rb
|
83
|
-
- lib/ronin/code/sql/offset_clause.rb
|
84
|
-
- lib/ronin/code/sql/union_clause.rb
|
85
|
-
- lib/ronin/code/sql/having_clause.rb
|
86
|
-
- lib/ronin/code/sql/union_all_clause.rb
|
87
|
-
- lib/ronin/code/sql/intersect_clause.rb
|
88
|
-
- lib/ronin/code/sql/rename_to_clause.rb
|
89
|
-
- lib/ronin/code/sql/add_column_clause.rb
|
90
|
-
- lib/ronin/code/sql/function.rb
|
91
|
-
- lib/ronin/code/sql/statement.rb
|
92
|
-
- lib/ronin/code/sql/create.rb
|
65
|
+
- lib/ronin/code/sql/code.rb
|
66
|
+
- lib/ronin/code/sql/common_dialect.rb
|
93
67
|
- lib/ronin/code/sql/create_index.rb
|
68
|
+
- lib/ronin/code/sql/create.rb
|
94
69
|
- lib/ronin/code/sql/create_table.rb
|
95
70
|
- lib/ronin/code/sql/create_view.rb
|
96
|
-
- lib/ronin/code/sql/
|
97
|
-
- lib/ronin/code/sql/select.rb
|
98
|
-
- lib/ronin/code/sql/replace.rb
|
99
|
-
- lib/ronin/code/sql/update.rb
|
71
|
+
- lib/ronin/code/sql/default_values_clause.rb
|
100
72
|
- lib/ronin/code/sql/delete.rb
|
101
|
-
- lib/ronin/code/sql/
|
73
|
+
- lib/ronin/code/sql/desc.rb
|
74
|
+
- lib/ronin/code/sql/dialect.rb
|
102
75
|
- lib/ronin/code/sql/drop_index.rb
|
76
|
+
- lib/ronin/code/sql/drop.rb
|
103
77
|
- lib/ronin/code/sql/drop_table.rb
|
104
78
|
- lib/ronin/code/sql/drop_view.rb
|
105
|
-
- lib/ronin/code/sql/
|
106
|
-
- lib/ronin/code/sql/
|
107
|
-
- lib/ronin/code/sql/
|
79
|
+
- lib/ronin/code/sql/emittable.rb
|
80
|
+
- lib/ronin/code/sql/expr.rb
|
81
|
+
- lib/ronin/code/sql/field.rb
|
82
|
+
- lib/ronin/code/sql/fields_clause.rb
|
83
|
+
- lib/ronin/code/sql/from_clause.rb
|
84
|
+
- lib/ronin/code/sql/function.rb
|
85
|
+
- lib/ronin/code/sql/group_by_clause.rb
|
86
|
+
- lib/ronin/code/sql/having_clause.rb
|
108
87
|
- lib/ronin/code/sql/injected_statement.rb
|
109
88
|
- lib/ronin/code/sql/injection.rb
|
110
|
-
- lib/ronin/code/sql/
|
89
|
+
- lib/ronin/code/sql/in.rb
|
90
|
+
- lib/ronin/code/sql/insert.rb
|
91
|
+
- lib/ronin/code/sql/intersect_clause.rb
|
92
|
+
- lib/ronin/code/sql/join_clause.rb
|
93
|
+
- lib/ronin/code/sql/like.rb
|
94
|
+
- lib/ronin/code/sql/limit_clause.rb
|
95
|
+
- lib/ronin/code/sql/modifier.rb
|
96
|
+
- lib/ronin/code/sql/offset_clause.rb
|
97
|
+
- lib/ronin/code/sql/on_clause.rb
|
98
|
+
- lib/ronin/code/sql/order_by_clause.rb
|
99
|
+
- lib/ronin/code/sql/program.rb
|
100
|
+
- lib/ronin/code/sql/rename_to_clause.rb
|
101
|
+
- lib/ronin/code/sql/replace.rb
|
102
|
+
- lib/ronin/code/sql/select.rb
|
103
|
+
- lib/ronin/code/sql/set_clause.rb
|
104
|
+
- lib/ronin/code/sql/statement.rb
|
105
|
+
- lib/ronin/code/sql/token.rb
|
106
|
+
- lib/ronin/code/sql/unary_expr.rb
|
107
|
+
- lib/ronin/code/sql/union_all_clause.rb
|
108
|
+
- lib/ronin/code/sql/union_clause.rb
|
109
|
+
- lib/ronin/code/sql/update.rb
|
110
|
+
- lib/ronin/code/sql/values_clause.rb
|
111
|
+
- lib/ronin/code/sql/where_clause.rb
|
111
112
|
- lib/ronin/sql/extensions.rb
|
113
|
+
- lib/ronin/sql/extensions/string.rb
|
112
114
|
- lib/ronin/sql/extensions/uri.rb
|
113
115
|
- lib/ronin/sql/extensions/uri/http.rb
|
116
|
+
- lib/ronin/sql/error.rb
|
114
117
|
- lib/ronin/sql/error/message.rb
|
115
118
|
- lib/ronin/sql/error/pattern.rb
|
116
119
|
- lib/ronin/sql/error/error.rb
|
117
120
|
- lib/ronin/sql/error/patterns.rb
|
118
|
-
- lib/ronin/sql/error.rb
|
119
121
|
- lib/ronin/sql/injection.rb
|
120
122
|
- lib/ronin/sql/version.rb
|
121
123
|
- lib/ronin/sql.rb
|