ronin 0.2.2 → 0.2.3

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 (98) hide show
  1. data/History.txt +53 -0
  2. data/Manifest.txt +26 -18
  3. data/README.txt +12 -19
  4. data/Rakefile +9 -9
  5. data/TODO.txt +5 -5
  6. data/lib/ronin/cacheable.rb +246 -0
  7. data/lib/ronin/database/database.rb +21 -3
  8. data/lib/ronin/database/exceptions/invalid_config.rb +1 -1
  9. data/lib/ronin/environment.rb +5 -2
  10. data/lib/ronin/extensions.rb +2 -0
  11. data/lib/ronin/{models.rb → extensions/array.rb} +19 -6
  12. data/lib/ronin/extensions/ip_addr.rb +127 -0
  13. data/lib/ronin/{objectify/exceptions/object_context_not_found.rb → extensions/kernel.rb} +14 -3
  14. data/lib/ronin/extensions/uri/query_params.rb +4 -2
  15. data/lib/ronin/formatting/extensions/binary/integer.rb +6 -0
  16. data/lib/ronin/formatting/extensions/binary/string.rb +14 -12
  17. data/lib/ronin/formatting/extensions/text/string.rb +37 -19
  18. data/lib/ronin/has_license.rb +4 -2
  19. data/lib/ronin/model.rb +0 -1
  20. data/lib/ronin/network/extensions/http/net.rb +30 -3
  21. data/lib/ronin/network/extensions/telnet/net.rb +0 -18
  22. data/lib/ronin/network/http/exceptions/unknown_request.rb +1 -1
  23. data/lib/ronin/platform/exceptions/extension_not_found.rb +1 -1
  24. data/lib/ronin/platform/exceptions/overlay_cached.rb +1 -1
  25. data/lib/ronin/platform/exceptions/overlay_not_found.rb +1 -1
  26. data/lib/ronin/platform/extension.rb +18 -3
  27. data/lib/ronin/platform/extension_cache.rb +7 -1
  28. data/lib/ronin/platform/object_cache.rb +13 -12
  29. data/lib/ronin/platform/overlay.rb +14 -6
  30. data/lib/ronin/platform/overlay_cache.rb +11 -5
  31. data/lib/ronin/product.rb +20 -3
  32. data/lib/ronin/ronin.rb +0 -15
  33. data/lib/ronin/rpc/exceptions/response_missing.rb +1 -1
  34. data/lib/ronin/sessions/esmtp.rb +1 -10
  35. data/lib/ronin/{objectify.rb → sessions/exceptions.rb} +3 -3
  36. data/lib/ronin/{objectify/exceptions/unknown_object_context.rb → sessions/exceptions/variable_missing.rb} +4 -4
  37. data/lib/ronin/sessions/http.rb +3 -10
  38. data/lib/ronin/sessions/imap.rb +1 -10
  39. data/lib/ronin/sessions/pop3.rb +1 -9
  40. data/lib/ronin/sessions/session.rb +11 -21
  41. data/lib/ronin/sessions/smtp.rb +1 -10
  42. data/lib/ronin/sessions/tcp.rb +10 -13
  43. data/lib/ronin/sessions/telnet.rb +2 -17
  44. data/lib/ronin/sessions/udp.rb +6 -11
  45. data/lib/ronin/static/finders.rb +24 -0
  46. data/lib/ronin/ui/command_line/command_line.rb +41 -21
  47. data/lib/ronin/ui/command_line/commands/help.rb +7 -3
  48. data/lib/ronin/ui/command_line/commands/ls.rb +1 -1
  49. data/lib/ronin/ui/command_line/commands/rm.rb +1 -1
  50. data/lib/ronin/ui/command_line/exceptions/unknown_command.rb +1 -1
  51. data/lib/ronin/ui/diagnostics.rb +12 -5
  52. data/lib/ronin/ui/hexdump/extensions/file.rb +3 -1
  53. data/lib/ronin/ui/hexdump/hexdump.rb +1 -1
  54. data/lib/ronin/ui/verbose.rb +14 -0
  55. data/lib/ronin/version.rb +1 -1
  56. data/spec/cacheable_spec.rb +150 -0
  57. data/spec/classes/cacheable_model.rb +15 -0
  58. data/spec/classes/licensed_model.rb +12 -0
  59. data/spec/code/classes/thing.rb +13 -0
  60. data/spec/code/reference_spec.rb +1 -14
  61. data/spec/extensions/array_spec.rb +34 -0
  62. data/spec/extensions/ip_addr_spec.rb +44 -0
  63. data/spec/extensions/kernel_spec.rb +19 -0
  64. data/spec/extensions/uri/query_params_spec.rb +8 -0
  65. data/spec/formatting/binary/string_spec.rb +1 -1
  66. data/spec/formatting/digest/string_spec.rb +84 -0
  67. data/spec/formatting/http/string_spec.rb +84 -0
  68. data/spec/formatting/text/string_spec.rb +51 -0
  69. data/spec/has_license_spec.rb +29 -0
  70. data/spec/helpers/cacheable.rb +7 -0
  71. data/spec/helpers/contexts/ronin_cacheable_model.rb +13 -0
  72. data/spec/helpers/database.rb +5 -0
  73. data/spec/platform/helpers/overlays/hello/lib/init.rb +1 -0
  74. data/spec/platform/helpers/overlays/hello/lib/stuff/another_test.rb +6 -0
  75. data/spec/platform/helpers/overlays/hello/lib/stuff/test.rb +4 -0
  76. data/spec/platform/overlay_cache_spec.rb +1 -1
  77. data/spec/platform/overlay_spec.rb +28 -0
  78. data/spec/product_spec.rb +7 -0
  79. data/spec/sessions/classes/test_session.rb +11 -0
  80. data/spec/sessions/classes/uses_test_session.rb +10 -0
  81. data/spec/sessions/session_spec.rb +13 -44
  82. data/spec/spec_helper.rb +0 -5
  83. data/spec/static/{helpers → classes}/static_class.rb +0 -0
  84. data/spec/static/helpers/static.rb +0 -1
  85. data/spec/static/static_spec.rb +1 -0
  86. metadata +44 -35
  87. data/lib/ronin/objectify/exceptions.rb +0 -25
  88. data/lib/ronin/objectify/objectify.rb +0 -240
  89. data/lib/ronin/target.rb +0 -44
  90. data/lib/ronin/ui/command_line/param_parser.rb +0 -93
  91. data/spec/formatting/digest_spec.rb +0 -54
  92. data/spec/formatting/http_spec.rb +0 -53
  93. data/spec/formatting/text_spec.rb +0 -40
  94. data/spec/helpers.rb +0 -0
  95. data/spec/objectify/objectify_spec.rb +0 -31
  96. data/spec/target_spec.rb +0 -16
  97. data/spec/ui/command_line/helpers/example_command.rb +0 -21
  98. data/spec/ui/command_line/param_parser_spec.rb +0 -49
@@ -51,11 +51,15 @@ module Ronin
51
51
  topic = args.first
52
52
 
53
53
  if topic
54
- CommandLine.run(topic,'--help')
54
+ begin
55
+ CommandLine.get_command(topic).run('--help')
56
+ rescue UnknownCommand
57
+ fail("unknown sub-command #{topic.dump}")
58
+ end
55
59
  else
56
- puts 'Available commands:'
60
+ puts 'Available sub-commands:'
57
61
 
58
- CommandLine.commands.keys.sort.each do |name|
62
+ CommandLine.commands.sort.each do |name|
59
63
  puts " #{name}"
60
64
  end
61
65
  end
@@ -28,7 +28,7 @@ module Ronin
28
28
  module UI
29
29
  module CommandLine
30
30
  module Commands
31
- class LS < Command
31
+ class Ls < Command
32
32
 
33
33
  def defaults
34
34
  @cache = nil
@@ -28,7 +28,7 @@ module Ronin
28
28
  module UI
29
29
  module CommandLine
30
30
  module Commands
31
- class RM < Command
31
+ class Rm < Command
32
32
 
33
33
  def defaults
34
34
  @cache = nil
@@ -24,7 +24,7 @@
24
24
  module Ronin
25
25
  module UI
26
26
  module CommandLine
27
- class UnknownCommand < RuntimeError
27
+ class UnknownCommand < StandardError
28
28
  end
29
29
  end
30
30
  end
@@ -32,13 +32,22 @@ module Ronin
32
32
  # Prints the given _messages_ as info diagnostics.
33
33
  #
34
34
  def print_info(*messages)
35
+ STDERR.puts(*(messages.map { |mesg| "[-] #{mesg}" }))
36
+ end
37
+
38
+ #
39
+ # Prints the given _messages_ as debugging diagnostics,
40
+ # if Ronin::UI::Verbose was enabled.
41
+ #
42
+ def print_debug(*messages)
35
43
  if Verbose.enabled?
36
- STDERR.puts(*(messages.map { |mesg| "[-] #{mesg}" }))
44
+ STDERR.puts(*(messages.map { |mesg| "[+] #{mesg}" }))
37
45
  end
38
46
  end
39
47
 
40
48
  #
41
- # Prints the given _messages_ as warning diagnostics.
49
+ # Prints the given _messages_ as warning diagnostics,
50
+ # if Ronin::UI::Verbose was enabled.
42
51
  #
43
52
  def print_warning(*messages)
44
53
  if Verbose.enabled?
@@ -50,9 +59,7 @@ module Ronin
50
59
  # Prints the given _messages_ as error diagnostics.
51
60
  #
52
61
  def print_error(*messages)
53
- if Verbose.enabled?
54
- STDERR.puts(*(messages.map { |mesg| "[!] #{mesg}" }))
55
- end
62
+ STDERR.puts(*(messages.map { |mesg| "[!] #{mesg}" }))
56
63
  end
57
64
  end
58
65
  end
@@ -30,7 +30,9 @@ class File
30
30
  # to the given _output_ stream.
31
31
  #
32
32
  def self.hexdump(path,output=STDOUT)
33
- Ronin::UI::Hexdump.dump(self.open(path),output)
33
+ self.open(path) do |file|
34
+ Ronin::UI::Hexdump.dump(file,output)
35
+ end
34
36
  end
35
37
 
36
38
  end
@@ -39,7 +39,7 @@ module Ronin
39
39
  index,
40
40
  hex_segment.join(' ').ljust(47).insert(23,' '),
41
41
  print_segment
42
- )
42
+ )
43
43
  }
44
44
 
45
45
  object.each_byte do |b|
@@ -24,18 +24,32 @@
24
24
  module Ronin
25
25
  module UI
26
26
  module Verbose
27
+ #
28
+ # Enables verbose mode.
29
+ #
27
30
  def Verbose.enable!
28
31
  @@ronin_verbose = true
29
32
  end
30
33
 
34
+ #
35
+ # Returns +true+ if verbose mode is enabled, returns +false+
36
+ # otherwise.
37
+ #
31
38
  def Verbose.enabled?
32
39
  (@@ronin_verbose ||= false) == true
33
40
  end
34
41
 
42
+ #
43
+ # Disables verbose mode.
44
+ #
35
45
  def Verbose.disable!
36
46
  @@ronin_verbose = false
37
47
  end
38
48
 
49
+ #
50
+ # Returns +true+ if verbose mode is disabled, returns +false+
51
+ # otherwise.
52
+ #
39
53
  def Verbose.disabled?
40
54
  (@@ronin_verbose ||= false) == false
41
55
  end
data/lib/ronin/version.rb CHANGED
@@ -23,5 +23,5 @@
23
23
 
24
24
  module Ronin
25
25
  # Ronin version
26
- VERSION = '0.2.2'
26
+ VERSION = '0.2.3'
27
27
  end
@@ -0,0 +1,150 @@
1
+ require 'ronin/cacheable'
2
+
3
+ require 'spec_helper'
4
+ require 'classes/cacheable_model'
5
+ require 'helpers/cacheable'
6
+
7
+ describe Cacheable do
8
+ before(:all) do
9
+ CacheableModel.auto_migrate!
10
+ end
11
+
12
+ it "should maintain a list of models which are cacheable" do
13
+ Cacheable.models.include?(CacheableModel).should == true
14
+ end
15
+
16
+ it "should be able to load arbitrary objects from a file" do
17
+ objs = Cacheable.load_all_from(CACHEABLE_FILE)
18
+
19
+ objs.length.should == 1
20
+ objs.first.content.should == 'this is a test'
21
+ end
22
+
23
+ it "should be able to cache arbitrary objects from a file" do
24
+ objs = Cacheable.cache_all(CACHEABLE_FILE)
25
+
26
+ objs.length.should == 1
27
+ objs.first.content.should == 'this is a test'
28
+ end
29
+
30
+ describe "load_from" do
31
+ before(:all) do
32
+ CacheableModel.auto_migrate!
33
+
34
+ @obj = CacheableModel.load_from(CACHEABLE_FILE)
35
+ end
36
+
37
+ it "should set the cached_path property" do
38
+ @obj.cached_path.should == Pathname.new(CACHEABLE_FILE)
39
+ end
40
+
41
+ it "should set the cached_timestamp property" do
42
+ @obj.cached_timestamp.should == File.mtime(CACHEABLE_FILE).to_i
43
+ end
44
+
45
+ it "should prepare the object to be cached" do
46
+ @obj.content.should == 'this is a test'
47
+ end
48
+
49
+ it "should preserve instance variables" do
50
+ @obj.config.should == true
51
+ end
52
+
53
+ it "should preserve instance methods" do
54
+ @obj.greeting.should == 'hello'
55
+ end
56
+ end
57
+
58
+ describe "new files" do
59
+ before(:all) do
60
+ CacheableModel.auto_migrate!
61
+ FileUtils.cp CACHEABLE_FILE, CACHEABLE_PATH
62
+ end
63
+
64
+ it "should be able to cache new files" do
65
+ obj = CacheableModel.cache(CACHEABLE_PATH)
66
+
67
+ obj.should_not be_dirty
68
+ obj.id.should == 1
69
+ end
70
+
71
+ it "should call the cache method before saving the new object" do
72
+ model = CacheableModel.first
73
+
74
+ model.content.should == 'this is a test'
75
+ end
76
+ end
77
+
78
+ describe "unmodified files" do
79
+ before(:all) do
80
+ CacheableModel.auto_migrate!
81
+ CacheableModel.cache(CACHEABLE_PATH)
82
+ end
83
+
84
+ it "should not re-cache unmodified files" do
85
+ model = CacheableModel.first
86
+
87
+ (model.sync!).should == false
88
+ end
89
+ end
90
+
91
+ describe "modified files" do
92
+ before(:all) do
93
+ CacheableModel.auto_migrate!
94
+
95
+ model = CacheableModel.cache(CACHEABLE_PATH)
96
+ model.cached_timestamp -= 10
97
+ model.save!
98
+ end
99
+
100
+ it "should re-cache modified files" do
101
+ model = CacheableModel.first
102
+
103
+ (model.sync!).should == true
104
+ end
105
+ end
106
+
107
+ describe "cached files" do
108
+ before(:all) do
109
+ CacheableModel.auto_migrate!
110
+ CacheableModel.cache(CACHEABLE_FILE)
111
+ end
112
+
113
+ it "should be able to load the original object" do
114
+ model = CacheableModel.first
115
+
116
+ model.load_original!
117
+ model.greeting.should == 'hello'
118
+ end
119
+
120
+ it "should load the original object on demand" do
121
+ model = CacheableModel.first
122
+ model.greeting.should == 'hello'
123
+ end
124
+
125
+ it "should only load the original object once" do
126
+ model = CacheableModel.first
127
+ model.load_original!
128
+
129
+ model.config = false
130
+ model.load_original!
131
+
132
+ model.config.should == false
133
+ end
134
+ end
135
+
136
+ describe "missing files" do
137
+ before(:all) do
138
+ CacheableModel.auto_migrate!
139
+ CacheableModel.cache(CACHEABLE_PATH)
140
+
141
+ FileUtils.rm CACHEABLE_PATH
142
+ end
143
+
144
+ it "should be able to expunge cached objects for missing files" do
145
+ CacheableModel.first.sync!
146
+
147
+ CacheableModel.all(:cached_path => CACHEABLE_PATH).should be_empty
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,15 @@
1
+ require 'ronin/cacheable'
2
+
3
+ class CacheableModel
4
+
5
+ include Ronin::Cacheable
6
+
7
+ contextify :ronin_cacheable_model
8
+
9
+ property :id, Serial
10
+
11
+ property :content, String
12
+
13
+ attr_accessor :config
14
+
15
+ end
@@ -0,0 +1,12 @@
1
+ require 'ronin/has_license'
2
+
3
+ class LicensedModel
4
+
5
+ include Model
6
+ include HasLicense
7
+
8
+ property :id, Serial
9
+
10
+ property :content, String
11
+
12
+ end
@@ -0,0 +1,13 @@
1
+ class Thing
2
+
3
+ def exposed
4
+ 1
5
+ end
6
+
7
+ protected
8
+
9
+ def not_exposed
10
+ 2
11
+ end
12
+
13
+ end
@@ -1,23 +1,10 @@
1
1
  require 'ronin/code/reference'
2
2
 
3
3
  require 'spec_helper'
4
+ require 'code/classes/thing'
4
5
 
5
6
  describe Code::Reference do
6
7
  before(:all) do
7
- class Thing
8
-
9
- def exposed
10
- 1
11
- end
12
-
13
- protected
14
-
15
- def not_exposed
16
- 2
17
- end
18
-
19
- end
20
-
21
8
  @object = Thing.new
22
9
  @ref = Code::Reference.new(@object)
23
10
  end
@@ -0,0 +1,34 @@
1
+ require 'ronin/extensions/array'
2
+
3
+ describe Array do
4
+ it "should provide Array#power_set" do
5
+ [].respond_to?(:power_set).should == true
6
+ end
7
+
8
+ describe "power_set" do
9
+ before(:all) do
10
+ @array = [1,2,3]
11
+ @set = @array.power_set
12
+ end
13
+
14
+ it "should contain an empty set" do
15
+ @set.include?([]).should == true
16
+ end
17
+
18
+ it "should contain singleton sets of all the elements" do
19
+ @set.include?([1]).should == true
20
+ @set.include?([2]).should == true
21
+ @set.include?([3]).should == true
22
+ end
23
+
24
+ it "should include the sub-sets of the original set" do
25
+ @set.include?([1,2]).should == true
26
+ @set.include?([1,3]).should == true
27
+ @set.include?([2,3]).should == true
28
+ end
29
+
30
+ it "should include the original set itself" do
31
+ @set.include?(@array).should == true
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,44 @@
1
+ require 'ronin/extensions/ip_addr'
2
+
3
+ require 'spec_helper'
4
+
5
+ describe IPAddr do
6
+ describe "CIDR addresses" do
7
+ before(:all) do
8
+ @fixed_addr = IPAddr.new('10.1.1.2')
9
+ @class_c = IPAddr.new('10.1.1.2/24')
10
+ end
11
+
12
+ it "should only iterate over one IP address for an address" do
13
+ addresses = @fixed_addr.map { |ip| IPAddr.new(ip) }
14
+
15
+ addresses.length.should == 1
16
+ @fixed_addr.include?(addresses.first)
17
+ end
18
+
19
+ it "should iterate over all IP addresses contained within the IP range" do
20
+ @class_c.each do |ip|
21
+ @class_c.include?(IPAddr.new(ip)).should == true
22
+ end
23
+ end
24
+ end
25
+
26
+ describe "globbed addresses" do
27
+ before(:all) do
28
+ @ipv4_range = '10.1.1-5.1'
29
+ @ipv6_range = '::ff::02-0a::c3'
30
+ end
31
+
32
+ it "should iterate over all IP addresses in an IPv4 range" do
33
+ IPAddr.each(@ipv4_range) do |ip|
34
+ ip =~ /^10\.1\.[1-5]\.1$/
35
+ end
36
+ end
37
+
38
+ it "should iterate over all IP addresses in an IPv6 range" do
39
+ IPAddr.each(@ipv6_range) do |ip|
40
+ ip =~ /^::ff::0[2-9a]::c3$/
41
+ end
42
+ end
43
+ end
44
+ end