ronin 0.0.9
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/COPYING.txt +339 -0
- data/History.txt +34 -0
- data/Manifest.txt +157 -0
- data/README.txt +131 -0
- data/Rakefile +23 -0
- data/TODO.txt +6 -0
- data/bin/ronin +12 -0
- data/lib/ronin.rb +35 -0
- data/lib/ronin/arch.rb +86 -0
- data/lib/ronin/author.rb +88 -0
- data/lib/ronin/cache.rb +27 -0
- data/lib/ronin/cache/config.rb +34 -0
- data/lib/ronin/cache/exceptions.rb +25 -0
- data/lib/ronin/cache/exceptions/extension_not_found.rb +29 -0
- data/lib/ronin/cache/exceptions/overlay_cached.rb +29 -0
- data/lib/ronin/cache/exceptions/overlay_not_found.rb +29 -0
- data/lib/ronin/cache/extension.rb +706 -0
- data/lib/ronin/cache/extension_cache.rb +108 -0
- data/lib/ronin/cache/overlay.rb +418 -0
- data/lib/ronin/cache/overlay_cache.rb +228 -0
- data/lib/ronin/cache/ronin.rb +50 -0
- data/lib/ronin/chars.rb +25 -0
- data/lib/ronin/chars/char_set.rb +121 -0
- data/lib/ronin/chars/chars.rb +180 -0
- data/lib/ronin/config.rb +31 -0
- data/lib/ronin/console.rb +127 -0
- data/lib/ronin/context.rb +233 -0
- data/lib/ronin/database.rb +122 -0
- data/lib/ronin/environment.rb +39 -0
- data/lib/ronin/exceptions/context_not_found.rb +27 -0
- data/lib/ronin/exceptions/invalid_database_config.rb +27 -0
- data/lib/ronin/exceptions/object_context_not_found.rb +27 -0
- data/lib/ronin/exceptions/unknown_context.rb +27 -0
- data/lib/ronin/exceptions/unknown_object_context.rb +27 -0
- data/lib/ronin/extensions.rb +28 -0
- data/lib/ronin/extensions/hash.rb +62 -0
- data/lib/ronin/extensions/kernel.rb +34 -0
- data/lib/ronin/extensions/meta.rb +24 -0
- data/lib/ronin/extensions/meta/object.rb +24 -0
- data/lib/ronin/extensions/string.rb +37 -0
- data/lib/ronin/extensions/uri.rb +24 -0
- data/lib/ronin/extensions/uri/http.rb +78 -0
- data/lib/ronin/extensions/uri/query_params.rb +97 -0
- data/lib/ronin/formatting.rb +29 -0
- data/lib/ronin/formatting/binary.rb +24 -0
- data/lib/ronin/formatting/digest.rb +24 -0
- data/lib/ronin/formatting/extensions.rb +26 -0
- data/lib/ronin/formatting/extensions/binary.rb +25 -0
- data/lib/ronin/formatting/extensions/binary/integer.rb +59 -0
- data/lib/ronin/formatting/extensions/binary/string.rb +73 -0
- data/lib/ronin/formatting/extensions/digest.rb +24 -0
- data/lib/ronin/formatting/extensions/digest/string.rb +65 -0
- data/lib/ronin/formatting/extensions/html.rb +24 -0
- data/lib/ronin/formatting/extensions/html/string.rb +75 -0
- data/lib/ronin/formatting/extensions/http.rb +24 -0
- data/lib/ronin/formatting/extensions/http/string.rb +69 -0
- data/lib/ronin/formatting/extensions/text.rb +24 -0
- data/lib/ronin/formatting/extensions/text/string.rb +96 -0
- data/lib/ronin/formatting/html.rb +24 -0
- data/lib/ronin/formatting/http.rb +24 -0
- data/lib/ronin/formatting/text.rb +24 -0
- data/lib/ronin/license.rb +87 -0
- data/lib/ronin/model.rb +44 -0
- data/lib/ronin/models.rb +34 -0
- data/lib/ronin/network.rb +31 -0
- data/lib/ronin/network/esmtp.rb +24 -0
- data/lib/ronin/network/extensions.rb +31 -0
- data/lib/ronin/network/extensions/esmtp.rb +24 -0
- data/lib/ronin/network/extensions/esmtp/net.rb +68 -0
- data/lib/ronin/network/extensions/http.rb +24 -0
- data/lib/ronin/network/extensions/http/net.rb +303 -0
- data/lib/ronin/network/extensions/imap.rb +24 -0
- data/lib/ronin/network/extensions/imap/net.rb +92 -0
- data/lib/ronin/network/extensions/pop3.rb +24 -0
- data/lib/ronin/network/extensions/pop3/net.rb +65 -0
- data/lib/ronin/network/extensions/smtp.rb +24 -0
- data/lib/ronin/network/extensions/smtp/net.rb +80 -0
- data/lib/ronin/network/extensions/tcp.rb +24 -0
- data/lib/ronin/network/extensions/tcp/net.rb +94 -0
- data/lib/ronin/network/extensions/telnet.rb +24 -0
- data/lib/ronin/network/extensions/telnet/net.rb +132 -0
- data/lib/ronin/network/extensions/udp.rb +24 -0
- data/lib/ronin/network/extensions/udp/net.rb +99 -0
- data/lib/ronin/network/http.rb +128 -0
- data/lib/ronin/network/http/exceptions.rb +24 -0
- data/lib/ronin/network/http/exceptions/unknown_request.rb +31 -0
- data/lib/ronin/network/imap.rb +47 -0
- data/lib/ronin/network/pop3.rb +47 -0
- data/lib/ronin/network/smtp.rb +26 -0
- data/lib/ronin/network/smtp/email.rb +126 -0
- data/lib/ronin/network/smtp/smtp.rb +55 -0
- data/lib/ronin/network/tcp.rb +24 -0
- data/lib/ronin/network/telnet.rb +95 -0
- data/lib/ronin/network/udp.rb +24 -0
- data/lib/ronin/object_context.rb +257 -0
- data/lib/ronin/objects.rb +29 -0
- data/lib/ronin/parameters.rb +27 -0
- data/lib/ronin/parameters/class_param.rb +45 -0
- data/lib/ronin/parameters/exceptions.rb +25 -0
- data/lib/ronin/parameters/exceptions/missing_param.rb +29 -0
- data/lib/ronin/parameters/exceptions/param_not_found.rb +29 -0
- data/lib/ronin/parameters/instance_param.rb +57 -0
- data/lib/ronin/parameters/param.rb +45 -0
- data/lib/ronin/parameters/parameters.rb +275 -0
- data/lib/ronin/path.rb +70 -0
- data/lib/ronin/pending_context.rb +42 -0
- data/lib/ronin/persistence.rb +32 -0
- data/lib/ronin/platform.rb +95 -0
- data/lib/ronin/product.rb +56 -0
- data/lib/ronin/ronin.rb +49 -0
- data/lib/ronin/rpc.rb +27 -0
- data/lib/ronin/rpc/call.rb +75 -0
- data/lib/ronin/rpc/client.rb +91 -0
- data/lib/ronin/rpc/console.rb +79 -0
- data/lib/ronin/rpc/exceptions.rb +25 -0
- data/lib/ronin/rpc/exceptions/not_implemented.rb +29 -0
- data/lib/ronin/rpc/exceptions/response_missing.rb +29 -0
- data/lib/ronin/rpc/interactive.rb +55 -0
- data/lib/ronin/rpc/interactive_console.rb +58 -0
- data/lib/ronin/rpc/interactive_shell.rb +59 -0
- data/lib/ronin/rpc/response.rb +57 -0
- data/lib/ronin/rpc/service.rb +69 -0
- data/lib/ronin/rpc/shell.rb +66 -0
- data/lib/ronin/runner.rb +24 -0
- data/lib/ronin/runner/program.rb +26 -0
- data/lib/ronin/runner/program/command.rb +204 -0
- data/lib/ronin/runner/program/commands.rb +33 -0
- data/lib/ronin/runner/program/commands/add.rb +73 -0
- data/lib/ronin/runner/program/commands/help.rb +52 -0
- data/lib/ronin/runner/program/commands/install.rb +65 -0
- data/lib/ronin/runner/program/commands/list.rb +81 -0
- data/lib/ronin/runner/program/commands/remove.rb +57 -0
- data/lib/ronin/runner/program/commands/uninstall.rb +57 -0
- data/lib/ronin/runner/program/commands/update.rb +55 -0
- data/lib/ronin/runner/program/exceptions.rb +24 -0
- data/lib/ronin/runner/program/exceptions/unknown_command.rb +31 -0
- data/lib/ronin/runner/program/options.rb +205 -0
- data/lib/ronin/runner/program/program.rb +173 -0
- data/lib/ronin/runner/program/runner.rb +35 -0
- data/lib/ronin/sessions.rb +32 -0
- data/lib/ronin/sessions/esmtp.rb +76 -0
- data/lib/ronin/sessions/imap.rb +73 -0
- data/lib/ronin/sessions/pop3.rb +70 -0
- data/lib/ronin/sessions/session.rb +52 -0
- data/lib/ronin/sessions/smtp.rb +76 -0
- data/lib/ronin/sessions/tcp.rb +111 -0
- data/lib/ronin/sessions/telnet.rb +76 -0
- data/lib/ronin/sessions/udp.rb +99 -0
- data/lib/ronin/sessions/web.rb +83 -0
- data/lib/ronin/shell.rb +81 -0
- data/lib/ronin/target.rb +40 -0
- data/lib/ronin/version.rb +27 -0
- data/lib/ronin/web.rb +24 -0
- data/lib/ronin/web/web.rb +265 -0
- data/spec/spec_helper.rb +9 -0
- data/tasks/spec.rb +7 -0
- metadata +324 -0
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
#
|
|
2
|
+
#--
|
|
3
|
+
# Ronin - A Ruby platform designed for information security and data
|
|
4
|
+
# exploration tasks.
|
|
5
|
+
#
|
|
6
|
+
# Copyright (c) 2006-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/cache/exceptions/overlay_cached'
|
|
25
|
+
require 'ronin/cache/exceptions/overlay_not_found'
|
|
26
|
+
require 'ronin/cache/overlay'
|
|
27
|
+
require 'ronin/cache/config'
|
|
28
|
+
|
|
29
|
+
require 'yaml'
|
|
30
|
+
|
|
31
|
+
module Ronin
|
|
32
|
+
module Cache
|
|
33
|
+
class OverlayCache < Hash
|
|
34
|
+
|
|
35
|
+
# Path of cache file
|
|
36
|
+
attr_reader :path
|
|
37
|
+
|
|
38
|
+
#
|
|
39
|
+
# Create a new Cache object with the specified _path_. The _path_
|
|
40
|
+
# defaults to <tt>Config::REPOSITORY_CACHE_PATH</tt>. If a _block_ is
|
|
41
|
+
# given, it will be passed the newly created Cache object.
|
|
42
|
+
#
|
|
43
|
+
def initialize(path=Config::REPOSITORY_CACHE_PATH,&block)
|
|
44
|
+
super()
|
|
45
|
+
|
|
46
|
+
@path = File.expand_path(path)
|
|
47
|
+
|
|
48
|
+
if File.file?(@path)
|
|
49
|
+
File.open(@path) do |file|
|
|
50
|
+
descriptions = YAML.load(file)
|
|
51
|
+
|
|
52
|
+
if descriptions.kind_of?(Array)
|
|
53
|
+
descriptions.each do |repo|
|
|
54
|
+
if repo.kind_of?(Hash)
|
|
55
|
+
add(Overlay.new(repo[:path],repo[:media],repo[:uri]))
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
block.call(self) if block
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
#
|
|
66
|
+
# Returns the names of the overlays within the cache.
|
|
67
|
+
#
|
|
68
|
+
def names
|
|
69
|
+
keys
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
#
|
|
73
|
+
# Returns the overlays within the cache.
|
|
74
|
+
#
|
|
75
|
+
def overlays
|
|
76
|
+
values
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
#
|
|
80
|
+
# Iterates over each overlay in the overlay cache, passing
|
|
81
|
+
# each to the given specified _block_.
|
|
82
|
+
#
|
|
83
|
+
def each_overlay(&block)
|
|
84
|
+
each_value(&block)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
#
|
|
88
|
+
# Returns the Ovlerays which match the specified _block_.
|
|
89
|
+
#
|
|
90
|
+
# cache.overlays_with do |repo|
|
|
91
|
+
# repo.author == 'the dude'
|
|
92
|
+
# end
|
|
93
|
+
#
|
|
94
|
+
def overlays_with(&block)
|
|
95
|
+
values.select(&block)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
#
|
|
99
|
+
# Returns +true+ if the cache contains the Overlay with the
|
|
100
|
+
# matching _name_, returns +false+ otherwise.
|
|
101
|
+
#
|
|
102
|
+
def has_overlay?(name)
|
|
103
|
+
has_key?(name.to_s)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
#
|
|
107
|
+
# Returns the Overlay with the matching _name_.
|
|
108
|
+
#
|
|
109
|
+
def get_overlay(name)
|
|
110
|
+
name = name.to_s
|
|
111
|
+
|
|
112
|
+
unless has_overlay?(name)
|
|
113
|
+
raise(OverlayNotFound,"overlay #{name.dump} is not present in cache #{self.to_s.dump}",caller)
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
return self[name]
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
#
|
|
120
|
+
# Returns the paths of the Overlays contained in the cache.
|
|
121
|
+
#
|
|
122
|
+
def paths
|
|
123
|
+
overlays.map { |repo| repo.path }
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
#
|
|
127
|
+
# Adds the _repo_ to the cache. If a _block_ is given, it will
|
|
128
|
+
# be passed the cache after the _repo_ is added. The _repo_
|
|
129
|
+
# will be returned.
|
|
130
|
+
#
|
|
131
|
+
# cache.add(repo) # => Overlay
|
|
132
|
+
#
|
|
133
|
+
# cache.add(repo) do |cache|
|
|
134
|
+
# puts "Overlay #{repo} added"
|
|
135
|
+
# end
|
|
136
|
+
#
|
|
137
|
+
def add(repo,&block)
|
|
138
|
+
if has_overlay?(repo.name)
|
|
139
|
+
raise(OverlayCached,"overlay #{repo.to_s.dump} already present in the cache #{self.to_s.dump}",caller)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
self[repo.name.to_s] = repo
|
|
143
|
+
|
|
144
|
+
block.call(self) if block
|
|
145
|
+
return self
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
#
|
|
149
|
+
# Removes the _repo_ from the cache. If a _block_ is given, it
|
|
150
|
+
# will be passed the cache. The cache will be returned, after the
|
|
151
|
+
# _repo_ is removed.
|
|
152
|
+
#
|
|
153
|
+
# cache.remove(repo) # => Cache
|
|
154
|
+
#
|
|
155
|
+
# cache.remove(repo) do |cache|
|
|
156
|
+
# puts "Overlay #{repo} removed"
|
|
157
|
+
# end
|
|
158
|
+
#
|
|
159
|
+
def remove(repo,&block)
|
|
160
|
+
unless has_overlay?(repo.name)
|
|
161
|
+
raise(OverlayNotFound,"overlay #{repo.to_s.dump} is not present in the cache #{to_s.dump}",caller)
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
delete_if { |key,value| key==repo.name }
|
|
165
|
+
|
|
166
|
+
block.call(self) if block
|
|
167
|
+
return self
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
#
|
|
171
|
+
# Updates all the cached Overlays. If a _block_ is given it will
|
|
172
|
+
# be passed the cache.
|
|
173
|
+
#
|
|
174
|
+
# update # => Cache
|
|
175
|
+
#
|
|
176
|
+
# update do |cache|
|
|
177
|
+
# puts "#{cache} is updated"
|
|
178
|
+
# end
|
|
179
|
+
#
|
|
180
|
+
def update(&block)
|
|
181
|
+
repos.each { |repo| repo.update }
|
|
182
|
+
|
|
183
|
+
block.call(self) if block
|
|
184
|
+
return self
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
#
|
|
188
|
+
# Saves the cache to the given _output_path_, where _output_path_
|
|
189
|
+
# defaults to +@path+. If a _block_ is given, it will be passed
|
|
190
|
+
# the cache before the cache has been saved.
|
|
191
|
+
#
|
|
192
|
+
def save(output_path=@path,&block)
|
|
193
|
+
parent_dir = File.dirname(output_path)
|
|
194
|
+
|
|
195
|
+
unless File.directory?(parent_dir)
|
|
196
|
+
FileUtils.mkdir_p(parent_dir)
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
block.call(self) if block
|
|
200
|
+
|
|
201
|
+
File.open(output_path,'w') do |output|
|
|
202
|
+
descriptions = overlays.map do |repo|
|
|
203
|
+
{:media_type => repo.media_type, :path => repo.path, :uri => repo.uri}
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
YAML.dump(descriptions,output)
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
return self
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
#
|
|
213
|
+
# Adds the specified _repo_ to the cache.
|
|
214
|
+
#
|
|
215
|
+
def <<(repo)
|
|
216
|
+
self[repo.name.to_s] = repo
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
#
|
|
220
|
+
# Returns the +path+ of the cache.
|
|
221
|
+
#
|
|
222
|
+
def to_s
|
|
223
|
+
@path.to_s
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
end
|
|
227
|
+
end
|
|
228
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#
|
|
2
|
+
#--
|
|
3
|
+
# Ronin - A Ruby platform designed for information security and data
|
|
4
|
+
# exploration tasks.
|
|
5
|
+
#
|
|
6
|
+
# Copyright (c) 2006-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/cache/cache'
|
|
25
|
+
|
|
26
|
+
module Ronin
|
|
27
|
+
protected
|
|
28
|
+
|
|
29
|
+
#
|
|
30
|
+
# Provides transparent access to Cache.extension.
|
|
31
|
+
#
|
|
32
|
+
# Ronin.shellcode # => Cache::Extension
|
|
33
|
+
#
|
|
34
|
+
# Ronin.shellcode do |ext|
|
|
35
|
+
# ...
|
|
36
|
+
# end
|
|
37
|
+
#
|
|
38
|
+
def Ronin.method_missing(sym,*args,&block)
|
|
39
|
+
if args.length==0
|
|
40
|
+
name = sym.id2name
|
|
41
|
+
|
|
42
|
+
# return an extension if available
|
|
43
|
+
if Cache.has_extension?(name)
|
|
44
|
+
return Cache.extension(name,&block)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
return super(sym,*args,&block)
|
|
49
|
+
end
|
|
50
|
+
end
|
data/lib/ronin/chars.rb
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#
|
|
2
|
+
#--
|
|
3
|
+
# Ronin - A Ruby platform designed for information security and data
|
|
4
|
+
# exploration tasks.
|
|
5
|
+
#
|
|
6
|
+
# Copyright (c) 2006-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/chars/char_set'
|
|
25
|
+
require 'ronin/chars/chars'
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
#
|
|
2
|
+
#--
|
|
3
|
+
# Ronin - A Ruby platform designed for information security and data
|
|
4
|
+
# exploration tasks.
|
|
5
|
+
#
|
|
6
|
+
# Copyright (c) 2006-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
|
+
module Ronin
|
|
25
|
+
module Chars
|
|
26
|
+
class CharSet < Array
|
|
27
|
+
|
|
28
|
+
#
|
|
29
|
+
# Creates a new CharSet object with the given _characters_.
|
|
30
|
+
#
|
|
31
|
+
def initialize(*characters)
|
|
32
|
+
format_char = lambda { |char|
|
|
33
|
+
if char.kind_of?(Integer)
|
|
34
|
+
char.chr
|
|
35
|
+
else
|
|
36
|
+
char.to_s
|
|
37
|
+
end
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
characters = characters.flatten.map do |char|
|
|
41
|
+
if char.kind_of?(Range)
|
|
42
|
+
char.to_a.map(&format_char)
|
|
43
|
+
else
|
|
44
|
+
format_char.call(char)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
super(characters.flatten.uniq)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
#
|
|
52
|
+
# Create a new CharSet object containing the characters that match
|
|
53
|
+
# the given _block_.
|
|
54
|
+
#
|
|
55
|
+
def select(&block)
|
|
56
|
+
CharSet.new(super(&block))
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
#
|
|
60
|
+
# Creates a new CharSet object by passing each character to the
|
|
61
|
+
# specified _block_.
|
|
62
|
+
#
|
|
63
|
+
def map(&block)
|
|
64
|
+
CharSet.new(super(&block))
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
#
|
|
68
|
+
# Returns a random char from the character set.
|
|
69
|
+
#
|
|
70
|
+
def random_char
|
|
71
|
+
self[rand(self.length)]
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
#
|
|
75
|
+
# Pass a random character to the specified _block_, _n_ times.
|
|
76
|
+
#
|
|
77
|
+
def each_random_char(n,&block)
|
|
78
|
+
n.to_i.times { block.call(random_char) }
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
#
|
|
82
|
+
# Returns an Array of the specified _length_ containing
|
|
83
|
+
# random characters from the character set.
|
|
84
|
+
#
|
|
85
|
+
def random_array(length)
|
|
86
|
+
if length.kind_of?(Range)
|
|
87
|
+
return Array.new(length.sort_by { rand }.first) { random_char }
|
|
88
|
+
else
|
|
89
|
+
return Array.new(length.to_i) { random_char }
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
#
|
|
94
|
+
# Returns a String of the specified _length_ containing
|
|
95
|
+
# random characters from the character set.
|
|
96
|
+
#
|
|
97
|
+
def random_string(length)
|
|
98
|
+
random_array(length).join
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
#
|
|
102
|
+
# Return a new CharSet that is the union of the character set and the
|
|
103
|
+
# specified _other_set_.
|
|
104
|
+
#
|
|
105
|
+
def |(other_set)
|
|
106
|
+
CharSet.new(self,other_set)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
alias + |
|
|
110
|
+
|
|
111
|
+
#
|
|
112
|
+
# Returns a new CharSet that is the intersection of the character set
|
|
113
|
+
# and the specified _other_set_.
|
|
114
|
+
#
|
|
115
|
+
def -(other_set)
|
|
116
|
+
CharSet.new(super(other_set.to_a))
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
#
|
|
2
|
+
#--
|
|
3
|
+
# Ronin - A Ruby platform designed for information security and data
|
|
4
|
+
# exploration tasks.
|
|
5
|
+
#
|
|
6
|
+
# Copyright (c) 2006-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/chars/char_set'
|
|
25
|
+
|
|
26
|
+
module Ronin
|
|
27
|
+
module Chars
|
|
28
|
+
# The numeric decimal character set
|
|
29
|
+
NUMERIC = CharSet.new('0'..'9')
|
|
30
|
+
|
|
31
|
+
# The octal character set
|
|
32
|
+
OCTAL = CharSet.new('0'..'7')
|
|
33
|
+
|
|
34
|
+
# The upper-case hexadecimal character set
|
|
35
|
+
UPPERCASE_HEXADECIMAL = NUMERIC + ('A'..'F')
|
|
36
|
+
|
|
37
|
+
# The lower-case hexadecimal character set
|
|
38
|
+
LOWERCASE_HEXADECIMAL = NUMERIC + ('a'..'f')
|
|
39
|
+
|
|
40
|
+
# The hexadecimal character set
|
|
41
|
+
HEXADECIMAL = UPPERCASE_HEXADECIMAL + LOWERCASE_HEXADECIMAL
|
|
42
|
+
|
|
43
|
+
# The upper-case alpha character set
|
|
44
|
+
UPPERCASE_ALPHA = CharSet.new('A'..'Z')
|
|
45
|
+
|
|
46
|
+
# The lower-case alpha character set
|
|
47
|
+
LOWERCASE_ALPHA = CharSet.new('a'..'z')
|
|
48
|
+
|
|
49
|
+
# The alpha character set
|
|
50
|
+
ALPHA = UPPERCASE_ALPHA + LOWERCASE_ALPHA
|
|
51
|
+
|
|
52
|
+
# The alpha-numeric character set
|
|
53
|
+
ALPHA_NUMERIC = ALPHA + NUMERIC
|
|
54
|
+
|
|
55
|
+
# The space character set
|
|
56
|
+
SPACE = CharSet.new(' ', "\f", "\n", "\r", "\t", "\v")
|
|
57
|
+
|
|
58
|
+
# The punctuation character set
|
|
59
|
+
PUNCTUATION = CharSet.new(' ', '\'', '"', '`', ',', ';', ':', '~', '-',
|
|
60
|
+
'(', ')', '[', ']', '{', '}', '.', '?', '!')
|
|
61
|
+
|
|
62
|
+
# The symbolic character set
|
|
63
|
+
SYMBOLS = PUNCTUATION + ['@', '#', '$', '%', '^', '&', '*', '_', '+',
|
|
64
|
+
'=', '|', '\\', '<', '>', '/']
|
|
65
|
+
|
|
66
|
+
# The control-char character set
|
|
67
|
+
CONTROL = CharSet.new(0..0x1f, 0x7f)
|
|
68
|
+
|
|
69
|
+
# The ASCII character set
|
|
70
|
+
ASCII = CharSet.new(0..0x7f)
|
|
71
|
+
|
|
72
|
+
# The full 8-bit character set
|
|
73
|
+
ALL = CharSet.new(0..0xff)
|
|
74
|
+
|
|
75
|
+
#
|
|
76
|
+
# The numeric decimal character set.
|
|
77
|
+
#
|
|
78
|
+
def Chars.numeric
|
|
79
|
+
NUMERIC
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
#
|
|
83
|
+
# The octal character set.
|
|
84
|
+
#
|
|
85
|
+
def Chars.octal
|
|
86
|
+
OCTAL
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
#
|
|
90
|
+
# The upper-case hexadecimal character set.
|
|
91
|
+
#
|
|
92
|
+
def Chars.uppercase_hexadecimal
|
|
93
|
+
UPPERCASE_HEXADECIMAL
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
#
|
|
97
|
+
# The lower-case hexadecimal character set.
|
|
98
|
+
#
|
|
99
|
+
def Chars.lowercase_hexadecimal
|
|
100
|
+
LOWERCASE_HEXADECIMAL
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
#
|
|
104
|
+
# The hexadecimal character set.
|
|
105
|
+
#
|
|
106
|
+
def Chars.hexadecimal
|
|
107
|
+
HEXADECIMAL
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
#
|
|
111
|
+
# The upper-case alpha character set.
|
|
112
|
+
#
|
|
113
|
+
def Chars.uppercase_alpha
|
|
114
|
+
UPPERCASE_ALPHA
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
#
|
|
118
|
+
# The lower-case alpha character set.
|
|
119
|
+
#
|
|
120
|
+
def Chars.lowercase_alpha
|
|
121
|
+
LOWERCASE_ALPHA
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
#
|
|
125
|
+
# The alpha character set.
|
|
126
|
+
#
|
|
127
|
+
def Chars.alpha
|
|
128
|
+
ALPHA
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
#
|
|
132
|
+
# The alpha-numeric character set.
|
|
133
|
+
#
|
|
134
|
+
def Chars.alpha_numeric
|
|
135
|
+
ALPHA_NUMERIC
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
#
|
|
139
|
+
# The space character set.
|
|
140
|
+
#
|
|
141
|
+
def Chars.space
|
|
142
|
+
SPACE
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
#
|
|
146
|
+
# The punctuation character set.
|
|
147
|
+
#
|
|
148
|
+
def Chars.puncation
|
|
149
|
+
PUNCTUATION
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
#
|
|
153
|
+
# The symbolic character set.
|
|
154
|
+
#
|
|
155
|
+
def Chars.symbols
|
|
156
|
+
SYMBOLS
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
#
|
|
160
|
+
# The control-char character set.
|
|
161
|
+
#
|
|
162
|
+
def Chars.control
|
|
163
|
+
CONTROL
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
#
|
|
167
|
+
# The ASCII character set.
|
|
168
|
+
#
|
|
169
|
+
def Chars.ascii
|
|
170
|
+
ASCII
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
#
|
|
174
|
+
# The full 8-bit character set.
|
|
175
|
+
#
|
|
176
|
+
def Chars.all
|
|
177
|
+
ALL
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
end
|