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
@@ -0,0 +1,195 @@
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/platform/exceptions/overlay_not_found'
25
+ require 'ronin/platform/overlay_cache'
26
+ require 'ronin/platform/object_cache'
27
+ require 'ronin/platform/extension_cache'
28
+
29
+ module Ronin
30
+ module Platform
31
+ #
32
+ # Load the overlay cache from the given _path_. If a _block_ is
33
+ # given it will be passed the current overlay cache.
34
+ #
35
+ # Overlay.load_overlays('/custom/overlays/cache.yaml')
36
+ # # => #<Ronin::Platform::OverlayCache: ...>
37
+ #
38
+ def Platform.load_overlays(path)
39
+ @@ronin_overlay_cache = OverlayCache.new(path)
40
+ end
41
+
42
+ #
43
+ # Returns the current overlay cache, or loads the default overlay
44
+ # cache if not already loaded.
45
+ #
46
+ def Platform.overlays
47
+ @@ronin_overlay_cache ||= OverlayCache.new
48
+ end
49
+
50
+ #
51
+ # Adds a new Overlay with the given _options_. If a _block_ is given
52
+ # it will be passed the newly added overlay.
53
+ #
54
+ # _options_ must contain the following key:
55
+ # <tt>:path</tt>:: The path of the overlay.
56
+ #
57
+ # _options_ may contain the following key:
58
+ # <tt>:media</tt>:: The media of the overlay.
59
+ # <tt>:uri</tt>:: The URI of the overlay.
60
+ #
61
+ def Platform.add(options={},&block)
62
+ path = options[:path]
63
+
64
+ unless path
65
+ raise(ArgumentError,":path must be passed to Platform.add",caller)
66
+ end
67
+
68
+ path = path.to_s
69
+
70
+ unless File.directory?(path)
71
+ raise(OverlayNotFound,"overlay #{path.dump} cannot be found",caller)
72
+ end
73
+
74
+ media = options[:media]
75
+ uri = options[:uri]
76
+
77
+ overlay = Overlay.new(path,media,uri)
78
+
79
+ Platform.overlays.add(overlay) do
80
+ ObjectCache.cache(overlay.objects_dir)
81
+ end
82
+
83
+ return overlay
84
+ end
85
+
86
+ #
87
+ # Installs an Overlay specified by _options_ into the
88
+ # OverlayCache::CACHE_DIR. If a _block_ is given, it will be
89
+ # passed the newly created overlay after it has been added to
90
+ # the overlay cache.
91
+ #
92
+ # _options_ must contain the following key:
93
+ # <tt>:uri</tt>:: The URI of the overlay.
94
+ #
95
+ # _options_ may contain the following key:
96
+ # <tt>:media</tt>:: The media of the overlay.
97
+ #
98
+ def Platform.install(options={},&block)
99
+ options = options.merge(:into => OverlayCache::CACHE_DIR)
100
+
101
+ Repertoire.checkout(options) do |path,media,uri|
102
+ return Platform.add(:path => path, :media => media, :uri => uri)
103
+ end
104
+ end
105
+
106
+ #
107
+ # Updates all previously installed overlays. If a _block_ is given
108
+ # it will be called after the overlays have been updated.
109
+ #
110
+ def Platform.update(&block)
111
+ Platform.overlays.update do |overlay|
112
+ ObjectCache.mirror(overlay.objects_dir)
113
+ end
114
+
115
+ block.call if block
116
+ return nil
117
+ end
118
+
119
+ #
120
+ # Removes the overlay with the specified _name_. If no overlay
121
+ # has the specified _name_, an OverlayNotFound exception will be
122
+ # raised. If a _block_ is given, it will be called after the overlay
123
+ # has been removed.
124
+ #
125
+ def Platform.remove(name,&block)
126
+ Platform.overlays.remove(name,&block)
127
+ return nil
128
+ end
129
+
130
+ #
131
+ # Uninstalls the overlay with the specified _name_. If no overlay
132
+ # has the specified _name_, an OverlayNotFound exception will be
133
+ # raised. If a _block_ is given, it will be called after the overlay
134
+ # has been uninstalled.
135
+ #
136
+ def Platform.uninstall(name,&block)
137
+ Platform.remove(name) do |overlay|
138
+ ObjectCache.expunge(overlay.objects_dir)
139
+ end
140
+
141
+ block.call if block
142
+ return nil
143
+ end
144
+
145
+ #
146
+ # Returns the names of all extensions within the overlay cache.
147
+ #
148
+ def Platform.extension_names
149
+ names = []
150
+
151
+ Platform.overlays.each_overlay do |overlay|
152
+ overlay.extensions.each do |name|
153
+ names << name unless names.include?(name)
154
+ end
155
+ end
156
+
157
+ return names
158
+ end
159
+
160
+ #
161
+ # Returns +true+ if the cache has the extension with the matching
162
+ # _name_, returns +false+ otherwise.
163
+ #
164
+ def Platform.has_extension?(name)
165
+ Platform.overlays.each_overlay do |overlay|
166
+ return true if overlay.has_extension?(name)
167
+ end
168
+
169
+ return false
170
+ end
171
+
172
+ #
173
+ # Returns a +Hash+ of all loaded extensions. Extensions can be loaded
174
+ # on-the-fly by accessing the +Hash+.
175
+ #
176
+ # Platform.extensions['shellcode']
177
+ # # => #<Ronin::Platform::Extension: ...>
178
+ #
179
+ def Platform.extensions
180
+ @@ronin_extension_cache ||= ExtensionCache.new
181
+ end
182
+
183
+ #
184
+ # Loads the extension with the specified _name_. If a _block_ is given
185
+ # it will be passed the loaded extension. If the extension cannot be
186
+ # loaded, an ExtensionNotFound exception will be raised.
187
+ #
188
+ def Platform.extension(name,&block)
189
+ ext = Platform.extensions[name]
190
+
191
+ block.call(ext) if block
192
+ return ext
193
+ end
194
+ end
195
+ end
@@ -21,27 +21,28 @@
21
21
  #++
22
22
  #
23
23
 
24
- require 'ronin/cache/cache'
24
+ require 'ronin/platform/platform'
25
25
 
26
26
  module Ronin
27
27
  protected
28
28
 
29
29
  #
30
- # Provides transparent access to Cache.extension.
30
+ # Provides transparent access to Platform.extension.
31
31
  #
32
- # Ronin.shellcode # => Cache::Extension
32
+ # Ronin.shellcode
33
+ # # => #<Ronin::Platform::Extension: ...>
33
34
  #
34
35
  # Ronin.shellcode do |ext|
35
36
  # ...
36
37
  # end
37
38
  #
38
39
  def Ronin.method_missing(sym,*args,&block)
39
- if args.length==0
40
+ if args.length == 0
40
41
  name = sym.id2name
41
42
 
42
43
  # return an extension if available
43
- if Cache.has_extension?(name)
44
- return Cache.extension(name,&block)
44
+ if Platform.has_extension?(name)
45
+ return Platform.extension(name,&block)
45
46
  end
46
47
  end
47
48
 
data/lib/ronin/target.rb CHANGED
@@ -20,7 +20,7 @@
20
20
  #
21
21
 
22
22
  require 'ronin/model'
23
- require 'ronin/platform'
23
+ require 'ronin/os'
24
24
  require 'ronin/arch'
25
25
 
26
26
  module Ronin
@@ -31,14 +31,14 @@ module Ronin
31
31
  # Primary key
32
32
  property :id, Serial
33
33
 
34
- # Targeted platform
35
- belongs_to :platform
36
-
37
34
  # Targeted architecture
38
35
  belongs_to :arch
39
36
 
37
+ # Targeted OS
38
+ belongs_to :os, :class_name => 'OS'
39
+
40
40
  # Validates
41
- validates_present :platform, :arch
41
+ validates_present :arch, :os
42
42
 
43
43
  end
44
44
  end
data/lib/ronin/ui.rb CHANGED
@@ -21,5 +21,8 @@
21
21
  #++
22
22
  #
23
23
 
24
- require 'ronin/ui/console'
24
+ require 'ronin/ui/diagnostics'
25
25
  require 'ronin/ui/hexdump'
26
+ require 'ronin/ui/console'
27
+ require 'ronin/ui/shell'
28
+
@@ -21,7 +21,6 @@
21
21
  #++
22
22
  #
23
23
 
24
- require 'ronin/ui/command_line/command'
25
24
  require 'ronin/ui/command_line/commands/default'
26
25
  require 'ronin/ui/command_line/exceptions/unknown_command'
27
26
  require 'ronin/ui/console'
@@ -22,7 +22,7 @@
22
22
  #
23
23
 
24
24
  require 'ronin/ui/command_line/command'
25
- require 'ronin/cache/overlay'
25
+ require 'ronin/platform/overlay'
26
26
 
27
27
  module Ronin
28
28
  module UI
@@ -31,10 +31,22 @@ module Ronin
31
31
 
32
32
  command :add
33
33
 
34
+ def initialize
35
+ @cache = nil
36
+ @media = nil
37
+ @uri = nil
38
+
39
+ super
40
+ end
41
+
34
42
  def define_options(opts)
35
43
  opts.usage = 'PATH [options]'
36
44
 
37
45
  opts.options do
46
+ opts.on('-C','--cache DIR','Specify an alternate overlay cache') do |dir|
47
+ @cache = dir
48
+ end
49
+
38
50
  opts.on('-m','--media MEDIA','Spedify the media-type of the overlay') do |media|
39
51
  @media = media
40
52
  end
@@ -60,12 +72,15 @@ module Ronin
60
72
  fail('only one overlay path maybe specified')
61
73
  end
62
74
 
63
- path = args.first
75
+ Platform.load_overlays(@cache) if @cache
64
76
 
65
- Cache::Overlay.save_cache do
66
- Cache::Overlay.add(path,@media,@uri) do |overlay|
67
- puts "Overlay #{overlay.name.dump} added."
68
- end
77
+ overlay_options = {:path => path.first}
78
+
79
+ overlay_options[:media] = @media if @media
80
+ overlay_options[:uri] = @uri if @uri
81
+
82
+ Platform.add(overlay_options) do |overlay|
83
+ puts "Overlay #{overlay.name.dump} added."
69
84
  end
70
85
  end
71
86
 
@@ -22,7 +22,8 @@
22
22
  #
23
23
 
24
24
  require 'ronin/ui/command_line/command'
25
- require 'ronin/cache/overlay'
25
+ require 'ronin/ui/console'
26
+ require 'ronin/database'
26
27
 
27
28
  module Ronin
28
29
  module UI
@@ -32,6 +33,10 @@ module Ronin
32
33
  def define_options(opts)
33
34
  opts.usage = '<command> [options]'
34
35
  opts.options do
36
+ opts.on('-d','--database URI','The URI for the Database') do |uri|
37
+ Database.config = uri.to_s
38
+ end
39
+
35
40
  opts.on('-r','--require LIB','require the specified library or path') do |lib|
36
41
  Console.auto_load << lib.to_s
37
42
  end
@@ -22,7 +22,7 @@
22
22
  #
23
23
 
24
24
  require 'ronin/ui/command_line/command'
25
- require 'ronin/cache/extension'
25
+ require 'ronin/platform/extension'
26
26
  require 'ronin/config'
27
27
 
28
28
  require 'fileutils'
@@ -54,8 +54,8 @@ module Ronin
54
54
  def arguments(*args)
55
55
  args.each do |path|
56
56
  path = File.expand_path(path)
57
- extension_path = File.join(path,Cache::Extension::EXTENSION_FILE)
58
- lib_dir = File.join(path,Cache::Extension::LIB_DIR)
57
+ extension_path = File.join(path,Platform::Extension::EXTENSION_FILE)
58
+ lib_dir = File.join(path,Platform::Extension::LIB_DIR)
59
59
  template_path = File.join(Config::STATIC_DIR,'extension.rb')
60
60
 
61
61
  FileUtils.mkdir_p(path)
@@ -22,7 +22,7 @@
22
22
  #
23
23
 
24
24
  require 'ronin/ui/command_line/command'
25
- require 'ronin/cache/overlay'
25
+ require 'ronin/platform/overlay'
26
26
 
27
27
  module Ronin
28
28
  module UI
@@ -31,10 +31,21 @@ module Ronin
31
31
 
32
32
  command :install
33
33
 
34
+ def initialize
35
+ @cache = nil
36
+ @media = nil
37
+
38
+ super
39
+ end
40
+
34
41
  def define_options(opts)
35
42
  opts.usage = 'URI [options]'
36
43
 
37
44
  opts.options do
45
+ opts.on('-C','--cache DIR','Specify an alternate overlay cache') do |dir|
46
+ @cache = dir
47
+ end
48
+
38
49
  opts.on('-m','--media [MEDIA]','Spedify the media-type of the overlay') do |media|
39
50
  @media = media
40
51
  end
@@ -54,10 +65,10 @@ module Ronin
54
65
 
55
66
  uri = args.first
56
67
 
57
- Cache::Overlay.save_cache do
58
- Cache::Overlay.install(:uri => uri, :media => @media) do |overlay|
59
- puts "Overlay #{overlay.name.dump} has been installed."
60
- end
68
+ Platform.load_overlays(@cache) if @cache
69
+
70
+ Platform.install(:uri => uri, :media => @media) do |overlay|
71
+ puts "Overlay #{overlay.name.dump} has been installed."
61
72
  end
62
73
  end
63
74
 
@@ -22,7 +22,7 @@
22
22
  #
23
23
 
24
24
  require 'ronin/ui/command_line/command'
25
- require 'ronin/cache/overlay'
25
+ require 'ronin/platform/overlay'
26
26
 
27
27
  module Ronin
28
28
  module UI
@@ -31,10 +31,21 @@ module Ronin
31
31
 
32
32
  command :list, :ls
33
33
 
34
+ def initialize
35
+ @cache = nil
36
+ @verbose = false
37
+
38
+ super
39
+ end
40
+
34
41
  def define_options(opts)
35
42
  opts.usage = '[NAME ...] [options]'
36
43
 
37
44
  opts.options do
45
+ opts.on('-C','--cache DIR','Specify an alternate overlay cache') do |dir|
46
+ @cache = dir
47
+ end
48
+
38
49
  opts.on('-v','--verbose','Enable verbose output') do
39
50
  @verbose = true
40
51
  end
@@ -48,15 +59,20 @@ module Ronin
48
59
  end
49
60
 
50
61
  def arguments(*args)
62
+ Platform.load_overlays(@cache) if @cache
63
+
51
64
  if args.empty?
52
- # list all repositories by name
53
- Cache::Overlay.each { |overlay| puts " #{overlay}" }
65
+ # list all overlays by name
66
+ Platform.overlays.each_overlay do |overlay|
67
+ puts " #{overlay}"
68
+ end
69
+
54
70
  return
55
71
  end
56
72
 
57
- # list specified repositories
73
+ # list specified overlays
58
74
  args.each do |name|
59
- overlay = Cache::Overlay.get(name)
75
+ overlay = Platform.overlays.get(name)
60
76
 
61
77
  puts "[ #{overlay.name} ]\n\n"
62
78
 
@@ -65,6 +81,12 @@ module Ronin
65
81
  puts " URI: #{overlay.uri}" if overlay.uri
66
82
 
67
83
  if @verbose
84
+ putc "\n"
85
+
86
+ if overlay.title
87
+ puts " Title: #{overlay.title}"
88
+ end
89
+
68
90
  if overlay.source
69
91
  puts " Source URI: #{overlay.source}"
70
92
  end
@@ -79,16 +101,17 @@ module Ronin
79
101
 
80
102
  unless overlay.extensions.empty?
81
103
  puts " Extensions:\n\n"
82
- overlay.each_extension { |ext| puts " #{ext}" }
104
+ overlay.extensions.each { |ext| puts " #{ext}" }
105
+ putc "\n"
83
106
  end
84
107
 
85
108
  if overlay.description
86
109
  puts " Description:\n\n #{overlay.description}\n\n"
87
110
  else
88
- puts "\n"
111
+ putc "\n"
89
112
  end
90
113
  else
91
- puts "\n"
114
+ putc "\n"
92
115
  end
93
116
  end
94
117
  end