ronin-sql 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING.txt +339 -0
- data/History.txt +7 -0
- data/Manifest.txt +45 -0
- data/README.txt +66 -0
- data/Rakefile +14 -0
- data/lib/ronin/code/sql.rb +24 -0
- data/lib/ronin/code/sql/between.rb +62 -0
- data/lib/ronin/code/sql/binary_expr.rb +46 -0
- data/lib/ronin/code/sql/builder.rb +61 -0
- data/lib/ronin/code/sql/code.rb +35 -0
- data/lib/ronin/code/sql/common_dialect.rb +62 -0
- data/lib/ronin/code/sql/create_index.rb +76 -0
- data/lib/ronin/code/sql/create_table.rb +93 -0
- data/lib/ronin/code/sql/create_view.rb +65 -0
- data/lib/ronin/code/sql/delete.rb +64 -0
- data/lib/ronin/code/sql/dialect.rb +162 -0
- data/lib/ronin/code/sql/drop_table.rb +51 -0
- data/lib/ronin/code/sql/exceptions.rb +24 -0
- data/lib/ronin/code/sql/exceptions/unknown_dialect.rb +31 -0
- data/lib/ronin/code/sql/expr.rb +193 -0
- data/lib/ronin/code/sql/field.rb +86 -0
- data/lib/ronin/code/sql/function.rb +52 -0
- data/lib/ronin/code/sql/in.rb +49 -0
- data/lib/ronin/code/sql/injection.rb +39 -0
- data/lib/ronin/code/sql/injection_builder.rb +137 -0
- data/lib/ronin/code/sql/injection_style.rb +79 -0
- data/lib/ronin/code/sql/insert.rb +86 -0
- data/lib/ronin/code/sql/keyword.rb +48 -0
- data/lib/ronin/code/sql/like_expr.rb +87 -0
- data/lib/ronin/code/sql/program.rb +79 -0
- data/lib/ronin/code/sql/replace.rb +58 -0
- data/lib/ronin/code/sql/select.rb +187 -0
- data/lib/ronin/code/sql/statement.rb +112 -0
- data/lib/ronin/code/sql/style.rb +170 -0
- data/lib/ronin/code/sql/unary_expr.rb +45 -0
- data/lib/ronin/code/sql/update.rb +75 -0
- data/lib/ronin/sql.rb +28 -0
- data/lib/ronin/sql/error.rb +52 -0
- data/lib/ronin/sql/extensions.rb +24 -0
- data/lib/ronin/sql/extensions/uri.rb +24 -0
- data/lib/ronin/sql/extensions/uri/http.rb +69 -0
- data/lib/ronin/sql/sql.rb +83 -0
- data/lib/ronin/sql/version.rb +29 -0
- data/spec/spec_helper.rb +5 -0
- data/tasks/spec.rb +7 -0
- metadata +121 -0
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
require './tasks/spec.rb'
|
6
|
+
require './lib/ronin/sql/version.rb'
|
7
|
+
|
8
|
+
Hoe.new('ronin-sql', Ronin::SQL::VERSION) do |p|
|
9
|
+
p.rubyforge_name = 'ronin'
|
10
|
+
p.developer('Postmodern Modulus III','postmodern.mod3@gmail.com')
|
11
|
+
p.extra_deps = [['ronin', '>=0.0.9']]
|
12
|
+
end
|
13
|
+
|
14
|
+
# vim: syntax=Ruby
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#
|
2
|
+
#--
|
3
|
+
# Ronin SQL - A Ronin library providing support for SQL related security
|
4
|
+
# tasks.
|
5
|
+
#
|
6
|
+
# Copyright (c) 2007-2008 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/code'
|
@@ -0,0 +1,62 @@
|
|
1
|
+
#
|
2
|
+
#--
|
3
|
+
# Ronin SQL - A Ronin library providing support for SQL related security
|
4
|
+
# tasks.
|
5
|
+
#
|
6
|
+
# Copyright (c) 2007-2008 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/expr'
|
25
|
+
|
26
|
+
module Ronin
|
27
|
+
module Code
|
28
|
+
module SQL
|
29
|
+
class Between < Expr
|
30
|
+
|
31
|
+
def initialize(expr,lower,higher)
|
32
|
+
super(expr.style)
|
33
|
+
|
34
|
+
@expr = expr
|
35
|
+
@lower = lower
|
36
|
+
@higher = higher
|
37
|
+
@negated = false
|
38
|
+
end
|
39
|
+
|
40
|
+
def not!
|
41
|
+
@negated = true
|
42
|
+
return self
|
43
|
+
end
|
44
|
+
|
45
|
+
def compile
|
46
|
+
compile_expr(@expr,negated?,keyword_between,@lower,keyword_and,@higher)
|
47
|
+
end
|
48
|
+
|
49
|
+
protected
|
50
|
+
|
51
|
+
keyword :between
|
52
|
+
keyword :and
|
53
|
+
keyword :not
|
54
|
+
|
55
|
+
def negated?
|
56
|
+
keyword_not if @negated
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
#
|
2
|
+
#--
|
3
|
+
# Ronin SQL - A Ronin library providing support for SQL related security
|
4
|
+
# tasks.
|
5
|
+
#
|
6
|
+
# Copyright (c) 2007-2008 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/expr'
|
25
|
+
|
26
|
+
module Ronin
|
27
|
+
module Code
|
28
|
+
module SQL
|
29
|
+
class BinaryExpr < Expr
|
30
|
+
|
31
|
+
def initialize(style,op,left,right)
|
32
|
+
super(style)
|
33
|
+
|
34
|
+
@op = op
|
35
|
+
@left = left
|
36
|
+
@right = right
|
37
|
+
end
|
38
|
+
|
39
|
+
def compile
|
40
|
+
compile_expr(compile_data(@left),compile_keyword(@op),compile_data(@right))
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
#
|
2
|
+
#--
|
3
|
+
# Ronin SQL - A Ronin library providing support for SQL related security
|
4
|
+
# tasks.
|
5
|
+
#
|
6
|
+
# Copyright (c) 2007-2008 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/dialect'
|
26
|
+
require 'ronin/code/sql/common_dialect'
|
27
|
+
require 'ronin/code/sql/style'
|
28
|
+
|
29
|
+
module Ronin
|
30
|
+
module Code
|
31
|
+
module SQL
|
32
|
+
class Builder < Statement
|
33
|
+
|
34
|
+
def initialize(style,options={},&block)
|
35
|
+
@commands = []
|
36
|
+
|
37
|
+
super(style,&block)
|
38
|
+
end
|
39
|
+
|
40
|
+
def compile
|
41
|
+
@style.compile_statements(@commands)
|
42
|
+
end
|
43
|
+
|
44
|
+
protected
|
45
|
+
|
46
|
+
def command(cmd)
|
47
|
+
@commands << cmd
|
48
|
+
return self
|
49
|
+
end
|
50
|
+
|
51
|
+
def method_missing(sym,*args,&block)
|
52
|
+
result = super(sym,*args,&block)
|
53
|
+
|
54
|
+
@commands << result if result.kind_of?(Statement)
|
55
|
+
return result
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
#
|
2
|
+
# Ronin SQL - A Ronin library providing support for SQL related security
|
3
|
+
# tasks.
|
4
|
+
#
|
5
|
+
# Copyright (c) 2007-2008 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/injection'
|
24
|
+
|
25
|
+
module Ronin
|
26
|
+
module Code
|
27
|
+
def Code.sql(options={},&block)
|
28
|
+
SQL::Program.new(options,&block)
|
29
|
+
end
|
30
|
+
|
31
|
+
def Code.sql_injection(options={},&block)
|
32
|
+
SQL::Injection.new(options,&block)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
#
|
2
|
+
#--
|
3
|
+
# Ronin SQL - A Ronin library providing support for SQL related security
|
4
|
+
# tasks.
|
5
|
+
#
|
6
|
+
# Copyright (c) 2007-2008 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/dialect'
|
25
|
+
require 'ronin/code/sql/create_table'
|
26
|
+
require 'ronin/code/sql/create_index'
|
27
|
+
require 'ronin/code/sql/create_view'
|
28
|
+
require 'ronin/code/sql/insert'
|
29
|
+
require 'ronin/code/sql/select'
|
30
|
+
require 'ronin/code/sql/update'
|
31
|
+
require 'ronin/code/sql/delete'
|
32
|
+
require 'ronin/code/sql/drop_table'
|
33
|
+
|
34
|
+
module Ronin
|
35
|
+
module Code
|
36
|
+
module SQL
|
37
|
+
class CommonDialect < Dialect
|
38
|
+
|
39
|
+
dialect :common
|
40
|
+
|
41
|
+
primitives :yes, :no, :on, :off, :null
|
42
|
+
|
43
|
+
data_type :int
|
44
|
+
data_type :varchar, :length => true
|
45
|
+
data_type :text
|
46
|
+
data_type :record
|
47
|
+
|
48
|
+
aggregators :count, :min, :max, :sum, :avg
|
49
|
+
|
50
|
+
command :create_type, CreateTable
|
51
|
+
command :create_index, CreateIndex
|
52
|
+
command :create_view, CreateView
|
53
|
+
command :insert, Insert
|
54
|
+
command :select_from, Select
|
55
|
+
command :update, Update
|
56
|
+
command :delete, Delete
|
57
|
+
command :drop_table, DropTable
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
#
|
2
|
+
#--
|
3
|
+
# Ronin SQL - A Ronin library providing support for SQL related security
|
4
|
+
# tasks.
|
5
|
+
#
|
6
|
+
# Copyright (c) 2007-2008 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 CreateIndex < Statement
|
30
|
+
|
31
|
+
option :unqiue, "UNIQUE"
|
32
|
+
option :if_not_exists, "IF NOT EXISTS"
|
33
|
+
|
34
|
+
def initialize(style,index=nil,table=nil,columns={},&block)
|
35
|
+
@index = index
|
36
|
+
@table = table
|
37
|
+
@columns = columns
|
38
|
+
|
39
|
+
super(style,&block)
|
40
|
+
end
|
41
|
+
|
42
|
+
def index(field)
|
43
|
+
@index = field
|
44
|
+
return self
|
45
|
+
end
|
46
|
+
|
47
|
+
def table(field)
|
48
|
+
@table = field
|
49
|
+
return self
|
50
|
+
end
|
51
|
+
|
52
|
+
def column(name,type)
|
53
|
+
@columns[name.to_s] = type.to_s
|
54
|
+
return self
|
55
|
+
end
|
56
|
+
|
57
|
+
def compile(dialect=nil,multiline=false)
|
58
|
+
format_columns = lambda {
|
59
|
+
@columns.map { |name,type|
|
60
|
+
"#{name} #{type}"
|
61
|
+
}
|
62
|
+
}
|
63
|
+
|
64
|
+
return compile_expr(keyword_create,unique?,keyword_index,if_not_exists?,@index,keyword_on,@table,compile_row(format_columns.call))
|
65
|
+
end
|
66
|
+
|
67
|
+
protected
|
68
|
+
|
69
|
+
keyword :create
|
70
|
+
keyword :index
|
71
|
+
keyword :on
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
#
|
2
|
+
#--
|
3
|
+
# Ronin SQL - A Ronin library providing support for SQL related security
|
4
|
+
# tasks.
|
5
|
+
#
|
6
|
+
# Copyright (c) 2007-2008 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/select'
|
26
|
+
|
27
|
+
module Ronin
|
28
|
+
module Code
|
29
|
+
module SQL
|
30
|
+
class CreateTable < Statement
|
31
|
+
|
32
|
+
option :temp, "TEMP"
|
33
|
+
option :if_not_exists, "IF NOT EXISTS"
|
34
|
+
|
35
|
+
def initialize(style,table=nil,opts={:columns => {}, :not_null => {}, :as => nil},&block)
|
36
|
+
@table = table
|
37
|
+
@columns = opts[:columns]
|
38
|
+
@not_null = opts[:not_null]
|
39
|
+
@as = opts[:as]
|
40
|
+
|
41
|
+
super(style,&block)
|
42
|
+
end
|
43
|
+
|
44
|
+
def table(field)
|
45
|
+
@table = field
|
46
|
+
return self
|
47
|
+
end
|
48
|
+
|
49
|
+
def as(table=nil,opts={:fields => nil, :where => nil},&block)
|
50
|
+
@as = Select.new(@style,table,opts,&block)
|
51
|
+
return self
|
52
|
+
end
|
53
|
+
|
54
|
+
def column(name,type,null=false)
|
55
|
+
name = name.to_s
|
56
|
+
@columns[name] = type.to_s
|
57
|
+
@not_null[name] = null
|
58
|
+
return self
|
59
|
+
end
|
60
|
+
|
61
|
+
def primary_key(field)
|
62
|
+
@primary_key = field
|
63
|
+
return self
|
64
|
+
end
|
65
|
+
|
66
|
+
def compile
|
67
|
+
format_columns = lambda {
|
68
|
+
@columns.map { |name,type|
|
69
|
+
if @not_null[name]
|
70
|
+
"#{name} #{type} NOT NULL"
|
71
|
+
else
|
72
|
+
"#{name} #{type}"
|
73
|
+
end
|
74
|
+
}
|
75
|
+
}
|
76
|
+
|
77
|
+
return compile_expr(keyword_create,temp?,keyword_table,if_not_exists?,@table,compile_row(format_columns.call))
|
78
|
+
end
|
79
|
+
|
80
|
+
protected
|
81
|
+
|
82
|
+
keyword :create
|
83
|
+
keyword :table
|
84
|
+
keyword :primary_key
|
85
|
+
|
86
|
+
def primary_key?
|
87
|
+
compile_expr(keyword_primary_key,@primary_key) if @primary_key
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|