ronin 0.1.4 → 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.
Files changed (73) hide show
  1. data/History.txt +50 -0
  2. data/Manifest.txt +31 -19
  3. data/README.txt +27 -19
  4. data/Rakefile +1 -1
  5. data/TODO.txt +1 -7
  6. data/lib/ronin.rb +1 -11
  7. data/lib/ronin/database/database.rb +1 -1
  8. data/lib/ronin/{cache/config.rb → environment.rb} +10 -8
  9. data/lib/ronin/formatting.rb +0 -1
  10. data/lib/ronin/formatting/extensions.rb +0 -1
  11. data/lib/ronin/formatting/extensions/binary/integer.rb +10 -0
  12. data/lib/ronin/formatting/extensions/binary/string.rb +11 -0
  13. data/lib/ronin/formatting/extensions/http/string.rb +1 -1
  14. data/lib/ronin/network/extensions/http/net.rb +8 -0
  15. data/lib/ronin/objectify/objectify.rb +0 -47
  16. data/lib/ronin/os.rb +89 -0
  17. data/lib/ronin/platform.rb +4 -77
  18. data/lib/ronin/{cache → platform}/exceptions.rb +2 -2
  19. data/lib/ronin/{cache → platform}/exceptions/extension_not_found.rb +1 -1
  20. data/lib/ronin/{cache → platform}/exceptions/overlay_cached.rb +1 -1
  21. data/lib/ronin/{cache → platform}/exceptions/overlay_not_found.rb +1 -1
  22. data/lib/ronin/{cache → platform}/extension.rb +68 -177
  23. data/lib/ronin/{cache → platform}/extension_cache.rb +9 -7
  24. data/lib/ronin/{cache → platform}/maintainer.rb +1 -1
  25. data/lib/ronin/platform/object_cache.rb +94 -0
  26. data/lib/ronin/platform/overlay.rb +274 -0
  27. data/lib/ronin/platform/overlay_cache.rb +318 -0
  28. data/lib/ronin/platform/platform.rb +195 -0
  29. data/lib/ronin/{cache → platform}/ronin.rb +7 -6
  30. data/lib/ronin/target.rb +5 -5
  31. data/lib/ronin/ui.rb +4 -1
  32. data/lib/ronin/ui/command_line/command_line.rb +0 -1
  33. data/lib/ronin/ui/command_line/commands/add.rb +21 -6
  34. data/lib/ronin/ui/command_line/commands/default.rb +6 -1
  35. data/lib/ronin/ui/command_line/commands/extension.rb +3 -3
  36. data/lib/ronin/ui/command_line/commands/install.rb +16 -5
  37. data/lib/ronin/ui/command_line/commands/list.rb +31 -8
  38. data/lib/ronin/ui/command_line/commands/overlay.rb +10 -9
  39. data/lib/ronin/ui/command_line/commands/remove.rb +16 -5
  40. data/lib/ronin/ui/command_line/commands/uninstall.rb +16 -5
  41. data/lib/ronin/ui/command_line/commands/update.rb +16 -3
  42. data/lib/ronin/ui/console.rb +81 -77
  43. data/lib/ronin/ui/diagnostics.rb +73 -0
  44. data/lib/ronin/version.rb +1 -1
  45. data/spec/chars/chars_spec.rb +1 -3
  46. data/spec/formatting/binary/integer_spec.rb +48 -36
  47. data/spec/formatting/binary/string_spec.rb +66 -4
  48. data/spec/os_spec.rb +24 -0
  49. data/spec/platform/extension_cache_spec.rb +42 -0
  50. data/spec/platform/extension_spec.rb +62 -0
  51. data/spec/platform/helpers/overlays.rb +18 -0
  52. data/spec/platform/helpers/overlays.yaml.erb +10 -0
  53. data/spec/platform/helpers/overlays/hello/hello/extension.rb +7 -0
  54. data/spec/platform/helpers/overlays/hello/ronin.xml +26 -0
  55. data/spec/platform/helpers/overlays/test1/ronin.xml +26 -0
  56. data/spec/platform/helpers/overlays/test1/test/extension.rb +7 -0
  57. data/spec/platform/helpers/overlays/test2/ronin.xml +26 -0
  58. data/spec/platform/helpers/overlays/test2/test/extension.rb +7 -0
  59. data/spec/platform/overlay_cache_spec.rb +63 -0
  60. data/spec/platform/platform_spec.rb +14 -0
  61. data/spec/platform/ronin_spec.rb +22 -0
  62. data/spec/target_spec.rb +1 -1
  63. data/spec/ui/diagnostics_spec.rb +17 -0
  64. metadata +34 -22
  65. data/lib/ronin/cache.rb +0 -27
  66. data/lib/ronin/cache/cache.rb +0 -78
  67. data/lib/ronin/cache/overlay.rb +0 -470
  68. data/lib/ronin/cache/overlay_cache.rb +0 -216
  69. data/lib/ronin/formatting/extensions/html.rb +0 -24
  70. data/lib/ronin/formatting/extensions/html/string.rb +0 -75
  71. data/lib/ronin/formatting/html.rb +0 -24
  72. data/spec/formatting/html_spec.rb +0 -46
  73. data/spec/platform_spec.rb +0 -24
data/lib/ronin/os.rb ADDED
@@ -0,0 +1,89 @@
1
+ #
2
+ #--
3
+ # Ronin - A Ruby platform designed for information security and data
4
+ # exploration tasks.
5
+ #
6
+ # Copyright (c) 2006-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/model'
25
+ require 'ronin/extensions/meta'
26
+ require 'ronin/extensions/string'
27
+
28
+ module Ronin
29
+ class OS
30
+
31
+ include Model
32
+
33
+ # Primary key
34
+ property :id, Serial
35
+
36
+ # Name of the Operating System
37
+ property :name, String, :index => true
38
+
39
+ # Version of the Operating System
40
+ property :version, String, :index => true
41
+
42
+ # Validates
43
+ validates_present :name, :version
44
+
45
+ #
46
+ # Returns the String form of the os.
47
+ #
48
+ # os = OS.new(:name => 'Linux', :version => '2.6.11')
49
+ # os.to_s # => "Linux 2.6.11"
50
+ #
51
+ def to_s
52
+ if self.version
53
+ return "#{self.name} #{self.version}"
54
+ else
55
+ return self.name.to_s
56
+ end
57
+ end
58
+
59
+ #
60
+ # Defines a new builtin OS of the specified _name_.
61
+ #
62
+ # OS.define('FreeBSD')
63
+ #
64
+ def OS.define(name)
65
+ name = name.to_s
66
+ method_name = name.to_method_name
67
+
68
+ meta_def(method_name) do
69
+ OS.new(:name => name)
70
+ end
71
+
72
+ meta_def("#{method_name}_version") do |version|
73
+ OS.first_or_create(:name => name, :version => version.to_s)
74
+ end
75
+
76
+ return nil
77
+ end
78
+
79
+ define 'Linux'
80
+ define 'FreeBSD'
81
+ define 'OpenBSD'
82
+ define 'NetBSD'
83
+ define 'OSX'
84
+ define 'Solaris'
85
+ define 'Windows'
86
+ define 'UNIX'
87
+
88
+ end
89
+ end
@@ -21,80 +21,7 @@
21
21
  #++
22
22
  #
23
23
 
24
- require 'ronin/model'
25
- require 'ronin/extensions/meta'
26
- require 'ronin/extensions/string'
27
-
28
- module Ronin
29
- class Platform
30
-
31
- include Model
32
-
33
- # Primary key
34
- property :id, Serial
35
-
36
- # Name of the Operating System
37
- property :os, String, :index => true
38
-
39
- # Version of the Operating System
40
- property :version, String, :index => true
41
-
42
- # Validates
43
- validates_present :os, :version
44
-
45
- #
46
- # Returns the String form of the Platform.
47
- #
48
- # platform = Platform.new("Linux","2.6.11")
49
- # platform.to_s # => "Linux 2.6.11"
50
- #
51
- def to_s
52
- if @version
53
- return "#{@os} #{@version}"
54
- else
55
- return @os.to_s
56
- end
57
- end
58
-
59
- #
60
- # Defines a new builtin Platform of the specified _name_, which will
61
- # define a new class named _name_ that inherites Platform.
62
- #
63
- # Platform.define('FreeBSD')
64
- #
65
- # Whould define the following class:
66
- #
67
- # class FreeBSD < Platform
68
- #
69
- # def initialize(version=nil)
70
- # super("FreeBSD",version)
71
- # end
72
- #
73
- # end
74
- #
75
- def Platform.define(name)
76
- name = name.to_s
77
- method_name = name.to_method_name
78
-
79
- meta_def(method_name) do
80
- Platform.new(:os => name)
81
- end
82
-
83
- meta_def("#{method_name}_version") do |version|
84
- Platform.first_or_create(:os => name, :version => version.to_s)
85
- end
86
-
87
- return nil
88
- end
89
-
90
- define 'Linux'
91
- define 'FreeBSD'
92
- define 'OpenBSD'
93
- define 'NetBSD'
94
- define 'OSX'
95
- define 'Solaris'
96
- define 'Windows'
97
- define 'UNIX'
98
-
99
- end
100
- end
24
+ require 'ronin/platform/exceptions'
25
+ require 'ronin/platform/extension'
26
+ require 'ronin/platform/overlay'
27
+ require 'ronin/platform/ronin'
@@ -21,5 +21,5 @@
21
21
  #++
22
22
  #
23
23
 
24
- require 'ronin/cache/exceptions/extension_not_found'
25
- require 'ronin/cache/exceptions/overlay_not_found'
24
+ require 'ronin/platform/exceptions/extension_not_found'
25
+ require 'ronin/platform/exceptions/overlay_not_found'
@@ -22,7 +22,7 @@
22
22
  #
23
23
 
24
24
  module Ronin
25
- module Cache
25
+ module Platform
26
26
  class ExtensionNotFound < RuntimeError
27
27
  end
28
28
  end
@@ -22,7 +22,7 @@
22
22
  #
23
23
 
24
24
  module Ronin
25
- module Cache
25
+ module Platform
26
26
  class OverlayCached < RuntimeError
27
27
  end
28
28
  end
@@ -22,7 +22,7 @@
22
22
  #
23
23
 
24
24
  module Ronin
25
- module Cache
25
+ module Platform
26
26
  class OverlayNotFound < RuntimeError
27
27
  end
28
28
  end
@@ -21,16 +21,26 @@
21
21
  #++
22
22
  #
23
23
 
24
- require 'ronin/cache/extension_cache'
25
- require 'ronin/cache/overlay'
24
+ require 'ronin/platform/exceptions/extension_not_found'
25
+ require 'ronin/platform/extension_cache'
26
+ require 'ronin/platform/platform'
27
+
28
+ require 'contextify'
26
29
 
27
30
  module Ronin
28
- module Cache
31
+ module Platform
29
32
  class Extension
30
33
 
34
+ include Contextify
35
+
36
+ contextify :ronin_extension
37
+
31
38
  # Extension file name
32
39
  EXTENSION_FILE = 'extension.rb'
33
40
 
41
+ # Extension lib/ directory
42
+ LIB_DIR = 'lib'
43
+
34
44
  # Name of extension
35
45
  attr_reader :name
36
46
 
@@ -58,126 +68,7 @@ module Ronin
58
68
  @setup_blocks = []
59
69
  @teardown_blocks = []
60
70
 
61
- block.call(self) if block
62
- end
63
-
64
- #
65
- # Returns the names of all extensions within the overlay cache.
66
- #
67
- def Extension.names
68
- Overlay.cache.overlays.map { |overlay| overlay.extensions }.flatten.uniq
69
- end
70
-
71
- #
72
- # Returns +true+ if an extension exists with the specified _name_,
73
- # returns +false+ otherwise.
74
- #
75
- def Extension.exists?(name)
76
- Extension.names.include?(name.to_s)
77
- end
78
-
79
- #
80
- # Iterates through the extension names passing each to the specified
81
- # _block_.
82
- #
83
- # Extension.each_name do |name|
84
- # puts name
85
- # end
86
- #
87
- def Extension.each_name(&block)
88
- Extension.names.each(&block)
89
- end
90
-
91
- #
92
- # Returns the paths of all extensions.
93
- #
94
- def Extension.paths
95
- paths = []
96
-
97
- Overlay.each { |repo| paths += repo.extension_paths }
98
-
99
- return paths
100
- end
101
-
102
- #
103
- # Iterates over the paths of all extensions with the specified
104
- # _name_, passing each to the specified _block_.
105
- #
106
- def Extension.each_path(&block)
107
- Extension.paths.each(&block)
108
- end
109
-
110
- #
111
- # Returns the paths of all extensions with the specified _name_.
112
- #
113
- def Extension.paths_for(name)
114
- Overlay.with_extension(name).map do |repo|
115
- File.expand_path(File.join(repo.path,name))
116
- end
117
- end
118
-
119
- #
120
- # Iterates over the paths of all extensions with the specified
121
- # _name_, passing each to the specified _block_.
122
- #
123
- def Extension.each_path_for(name,&block)
124
- Extension.paths_for(name).each(&block)
125
- end
126
-
127
- #
128
- # Adds the lib/ directory from within the specified _path_ to
129
- # $LOAD_PATH, only if the lib/ directory exists within the
130
- # specified _path_ and the directory has not already been
131
- # added to $LOAD_PATH. If a _block_ is given, it will be called
132
- # after $LOAD_PATH may or maynot have been modified.
133
- #
134
- def Extension.load_path(path,&block)
135
- lib_dir = File.expand_path(File.join(path,LIB_DIR))
136
-
137
- if File.directory?(lib_dir)
138
- $LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
139
- end
140
-
141
- block.call if block
142
- return nil
143
- end
144
-
145
- #
146
- # Similar to load_path, but adds the lib/ directories from the
147
- # paths of all extensions with the specified _name_ to $LOAD_PATH.
148
- # If a _block_ is given, it will be called after $LOAD_PATH may or
149
- # maynot have been modified.
150
- #
151
- def Extension.load_paths(name,&block)
152
- Extension.each_path_for(name) do |path|
153
- Extension.load_path(path)
154
- end
155
-
156
- block.call if block
157
- return nil
158
- end
159
-
160
- #
161
- # Loads an extension at the specified _path_ into a newly created
162
- # Extension object. If a _block_ is given, it will be passed the
163
- # newly created Extension object.
164
- #
165
- def Extension.load_from(path,&block)
166
- Extension.new(File.basename(name)) do |ext|
167
- ext.include_path(path,&block)
168
- end
169
- end
170
-
171
- #
172
- # Loads an extension at the specified _path_ into a newly created
173
- # Extension object and then runs it with the specified _block_.
174
- #
175
- # Extension.run_in('lab/exploits') do |ext|
176
- # puts ext.search('apache')
177
- # end
178
- #
179
- def Extension.run_in(path,&block)
180
- Extension.load_from(path) { |ext| ext.run(&block) }
71
+ instance_eval(&block) if block
181
72
  end
182
73
 
183
74
  #
@@ -190,7 +81,11 @@ module Ronin
190
81
  # end
191
82
  #
192
83
  def Extension.load(name,&block)
193
- Extension.new(name) { |ext| ext.include(name,&block) }
84
+ ext = Extension.new(name)
85
+ ext.include(name)
86
+
87
+ block.call(ext) if block
88
+ return ext
194
89
  end
195
90
 
196
91
  #
@@ -205,38 +100,14 @@ module Ronin
205
100
  Extension.load(name) { |ext| ext.run(&block) }
206
101
  end
207
102
 
208
- #
209
- # Returns the current ExtensionCache.
210
- #
211
- def Extension.cache
212
- @@cache ||= ExtensionCache.new
213
- end
214
-
215
- #
216
- # Returns the extension with the specified _name_ from the extension
217
- # cache. If no extension exists with the specified _name_ an
218
- # ExtensionNotFound exception will be raised.
219
- #
220
- def Extension.[](name)
221
- Extension.cache[name]
222
- end
223
-
224
- #
225
- # Returns +true+ if the extension with the specified _name_ has been
226
- # loaded into the extension cache, returns +false+ otherwise.
227
- #
228
- def Extension.loaded?(name)
229
- Extension.cache.has_extension?(name)
230
- end
231
-
232
103
  #
233
104
  # Includes all extensions of the specified _name_ into the extension.
234
105
  # If a _block_ is given, it will be passed the newly created
235
106
  # extension after the extensions of _name_ have been included.
236
107
  #
237
108
  def include(name,&block)
238
- Extension.load_paths(name) do
239
- Extension.each_path_for(name) { |path| include_path(path) }
109
+ Platform.overlays.extension_paths(name).each do |path|
110
+ include_path(path)
240
111
  end
241
112
 
242
113
  block.call(self) if block
@@ -258,15 +129,13 @@ module Ronin
258
129
  # add to the search paths
259
130
  @paths << path
260
131
 
261
- Extension.load_path(path) do
262
- extension_file = File.join(path,EXTENSION_FILE)
132
+ extension_file = File.join(path,EXTENSION_FILE)
263
133
 
264
- if File.file?(extension_file)
265
- # instance_eval the extension block
266
- context_block = Extension.load_context_block(extension_file)
134
+ if File.file?(extension_file)
135
+ # instance_eval the extension block
136
+ context_block = Extension.load_context_block(extension_file)
267
137
 
268
- instance_eval(&context_block) if context_block
269
- end
138
+ instance_eval(&context_block) if context_block
270
139
  end
271
140
 
272
141
  block.call(self) if block
@@ -287,14 +156,14 @@ module Ronin
287
156
  # Calls the setup blocks of the extension. If a _block_ is given, it
288
157
  # will be passed the extension after it has been setup.
289
158
  #
290
- # ext.perform_setup
291
- # # => #<Ronin::Cache::Extension: ...>
159
+ # ext.setup!
160
+ # # => #<Ronin::Platform::Extension: ...>
292
161
  #
293
- # ext.perform_setup do |ext|
162
+ # ext.setup! do |ext|
294
163
  # puts "Extension #{ext} has been setup..."
295
164
  # end
296
165
  #
297
- def perform_setup(&block)
166
+ def setup!(&block)
298
167
  unless @setup
299
168
  @setup_blocks.each do |setup_block|
300
169
  setup_block.call(self) if setup_block
@@ -312,7 +181,7 @@ module Ronin
312
181
  # Returns +true+ if the extension has been setup, returns +false+
313
182
  # otherwise.
314
183
  #
315
- def was_setup?
184
+ def setup?
316
185
  @setup == true
317
186
  end
318
187
 
@@ -320,14 +189,14 @@ module Ronin
320
189
  # Run the teardown blocks of the extension. If a _block_ is given,
321
190
  # it will be passed the extension before it has been tore down.
322
191
  #
323
- # ext.perform_teardown
324
- # # => #<Ronin::Cache::Extension: ...>
192
+ # ext.teardown!
193
+ # # => #<Ronin::Platform::Extension: ...>
325
194
  #
326
- # ext.perform_teardown do |ext|
195
+ # ext.teardown! do |ext|
327
196
  # puts "Extension #{ext} is being tore down..."
328
197
  # end
329
198
  #
330
- def perform_teardown(&block)
199
+ def teardown!(&block)
331
200
  block.call(self) if block
332
201
 
333
202
  unless @toredown
@@ -346,7 +215,7 @@ module Ronin
346
215
  # Returns +true+ if the extension has been toredown, returns +false+
347
216
  # otherwise.
348
217
  #
349
- def was_toredown?
218
+ def toredown?
350
219
  @toredown == true
351
220
  end
352
221
 
@@ -359,11 +228,11 @@ module Ronin
359
228
  # end
360
229
  #
361
230
  def run(&block)
362
- perform_setup
231
+ setup!
363
232
 
364
233
  block.call(self) if block
365
234
 
366
- perform_teardown
235
+ teardown!
367
236
  return self
368
237
  end
369
238
 
@@ -371,27 +240,49 @@ module Ronin
371
240
  # Find the specified _path_ from within all similar extensions.
372
241
  # If a _block_ is given, it will be passed the full path if found.
373
242
  #
374
- # ext.find_path('data/test')
243
+ # ext.find_paths('data/test')
244
+ # # => [...]
375
245
  #
376
- # ext.find_path('data/test') do |path|
246
+ # ext.find_paths('data/test') do |path|
377
247
  # puts Dir[File.join(path,'*')]
378
248
  # end
379
249
  #
380
- def find_path(path,&block)
250
+ def find_paths(path,&block)
251
+ matched_paths = []
252
+
381
253
  @paths.each do |ext_path|
382
254
  full_path = File.expand_path(File.join(ext_path,path))
383
255
 
384
256
  if File.exists?(full_path)
385
257
  block.call(full_path) if block
386
- return full_path
258
+ matched_paths << full_path
387
259
  end
388
260
  end
389
261
 
262
+ return matched_paths
263
+ end
264
+
265
+ #
266
+ # Find the specified _path_ from within the first similar extensions.
267
+ # If a _block_ is given, it will be passed the full path if found.
268
+ #
269
+ # ext.find_path('data/test')
270
+ #
271
+ # ext.find_path('data/test') do |path|
272
+ # puts Dir[File.join(path,'*')]
273
+ # end
274
+ #
275
+ def find_path(path,&block)
276
+ find_paths(path) do |full_path|
277
+ block.call(full_path) if block
278
+ return full_path
279
+ end
280
+
390
281
  return nil
391
282
  end
392
283
 
393
284
  #
394
- # Find the specified file _path_ from within all similar extensions.
285
+ # Find the specified file _path_ from within the first similar extensions.
395
286
  # If a _block_ is given, it will be passed the full file path if
396
287
  # found.
397
288
  #
@@ -403,7 +294,7 @@ module Ronin
403
294
  # end
404
295
  #
405
296
  def find_file(path,&block)
406
- find_path(path) do |full_path|
297
+ find_paths(path) do |full_path|
407
298
  if File.file?(full_path)
408
299
  block.call(full_path) if block
409
300
  return full_path
@@ -412,7 +303,7 @@ module Ronin
412
303
  end
413
304
 
414
305
  #
415
- # Find the specified directory _path_ from within all similar
306
+ # Find the specified directory _path_ from within the first similar
416
307
  # extensions. If a _block_ is given, it will be passed the full
417
308
  # directory path if found.
418
309
  #
@@ -423,7 +314,7 @@ module Ronin
423
314
  # end
424
315
  #
425
316
  def find_dir(path,&block)
426
- find_path(path) do |full_path|
317
+ find_paths(path) do |full_path|
427
318
  if File.directory?(full_path)
428
319
  block.call(full_path) if block
429
320
  return full_path