ronin 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,19 @@
1
+ require 'ronin/extensions/kernel'
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Kernel do
6
+ it "should provide Kernel#try" do
7
+ Kernel.respond_to?('try').should == true
8
+ end
9
+
10
+ describe "try" do
11
+ it "should return the result of the block if nothing is raised" do
12
+ try { 2 + 2 }.should == 4
13
+ end
14
+
15
+ it "should return nil if an exception is raised" do
16
+ try { 2 + 'a' }.should be_nil
17
+ end
18
+ end
19
+ end
@@ -35,4 +35,12 @@ describe URI::QueryParams do
35
35
  @uri.query = 'u=3'
36
36
  @uri.query_params['u'].should == '3'
37
37
  end
38
+
39
+ it "should properly escape query param values" do
40
+ @uri.query_params['x'] = '1&2'
41
+ @uri.query_params['y'] = 'one=two'
42
+ @uri.query_params['z'] = '?'
43
+
44
+ @uri.to_s.should == "http://www.test.com/page.php?x=1%262&y=one%3Dtwo&z=%3F"
45
+ end
38
46
  end
@@ -107,7 +107,7 @@ describe String do
107
107
  end
108
108
 
109
109
  it "should not contain the key used in the xor" do
110
- @string.include?(@key).should_not == true
110
+ @string.include?(@key.chr).should_not == true
111
111
  end
112
112
 
113
113
  it "should not equal the original string" do
@@ -0,0 +1,84 @@
1
+ require 'ronin/formatting/digest'
2
+
3
+ require 'spec_helper'
4
+
5
+ describe String do
6
+ before(:all) do
7
+ @string = "test"
8
+ end
9
+
10
+ it "should provide String#md5" do
11
+ @string.respond_to?('md5').should == true
12
+ end
13
+
14
+ it "should provide String#sha1" do
15
+ @string.respond_to?('sha1').should == true
16
+ end
17
+
18
+ it "should provide String#sha2" do
19
+ @string.respond_to?('sha2').should == true
20
+ end
21
+
22
+ it "should provide String#sha256" do
23
+ @string.respond_to?('sha256').should == true
24
+ end
25
+
26
+ it "should provide String#sha512" do
27
+ @string.respond_to?('sha512').should == true
28
+ end
29
+
30
+ describe "md5" do
31
+ before(:all) do
32
+ @digest_plain_text = "test"
33
+ @digest_md5 = "098f6bcd4621d373cade4e832627b4f6"
34
+ end
35
+
36
+ it "should return the MD5 digest of itself" do
37
+ @digest_plain_text.md5.should == @digest_md5
38
+ end
39
+ end
40
+
41
+ describe "sha1" do
42
+ before(:all) do
43
+ @digest_plain_text = "test"
44
+ @digest_sha1 = "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3"
45
+ end
46
+
47
+ it "should return the SHA1 digest of itself" do
48
+ @digest_plain_text.sha1.should == @digest_sha1
49
+ end
50
+ end
51
+
52
+ describe "sha2" do
53
+ before(:all) do
54
+ @digest_plain_text = "test"
55
+ @digest_sha2 = "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"
56
+ end
57
+
58
+ it "should return the SHA2 digest of itself" do
59
+ @digest_plain_text.sha2.should == @digest_sha2
60
+ end
61
+ end
62
+
63
+ describe "sha256" do
64
+ before(:all) do
65
+ @digest_plain_text = "test"
66
+ @digest_sha256 = "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"
67
+ end
68
+
69
+ it "should return the SHA256 digest of itself" do
70
+ @digest_plain_text.sha256.should == @digest_sha256
71
+ end
72
+ end
73
+
74
+ describe "sha512" do
75
+ before(:all) do
76
+ @digest_plain_text = "test"
77
+ @digest_sha512 = "ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff"
78
+ end
79
+
80
+ it "should return the SHA512 digest of itself" do
81
+ @digest_plain_text.sha512.should == @digest_sha512
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,84 @@
1
+ require 'ronin/formatting/http'
2
+
3
+ require 'spec_helper'
4
+
5
+ describe String do
6
+ before(:all) do
7
+ @string = "mod % 3"
8
+ end
9
+
10
+ it "should provide String#uri_encode" do
11
+ @string.respond_to?('uri_encode').should == true
12
+ end
13
+
14
+ it "should provide String#uri_decode" do
15
+ @string.respond_to?('uri_decode').should == true
16
+ end
17
+
18
+ it "should provide String#uri_escape" do
19
+ @string.respond_to?('uri_escape').should == true
20
+ end
21
+
22
+ it "should provide String#uri_unescape" do
23
+ @string.respond_to?('uri_unescape').should == true
24
+ end
25
+
26
+ it "should provide String#format_http" do
27
+ @string.respond_to?('format_http').should == true
28
+ end
29
+
30
+ describe "uri_encode" do
31
+ before(:all) do
32
+ @uri_unencoded = "mod % 3"
33
+ @uri_encoded = "mod%20%25%203"
34
+ end
35
+
36
+ it "should URI encode itself" do
37
+ @uri_unencoded.uri_encode.should == @uri_encoded
38
+ end
39
+ end
40
+
41
+ describe "uri_decode" do
42
+ before(:all) do
43
+ @uri_unencoded = "mod % 3"
44
+ @uri_encoded = "mod%20%25%203"
45
+ end
46
+
47
+ it "should URI decode itself" do
48
+ @uri_encoded.uri_decode.should == @uri_unencoded
49
+ end
50
+ end
51
+
52
+ describe "uri_escape" do
53
+ before(:all) do
54
+ @uri_unescaped = "x + y"
55
+ @uri_escaped = "x+%2B+y"
56
+ end
57
+
58
+ it "should URI escape itself" do
59
+ @uri_unescaped.uri_escape.should == @uri_escaped
60
+ end
61
+ end
62
+
63
+ describe "uri_unescape" do
64
+ before(:all) do
65
+ @uri_unescaped = "x + y"
66
+ @uri_escaped = "x+%2B+y"
67
+ end
68
+
69
+ it "should URI unescape itself" do
70
+ @uri_escaped.uri_unescape.should == @uri_unescaped
71
+ end
72
+ end
73
+
74
+ describe "format_http" do
75
+ before(:all) do
76
+ @uri_unencoded = "mod % 3"
77
+ @uri_http_encoded = "%6d%6f%64%20%25%20%33"
78
+ end
79
+
80
+ it "should format each byte of the String" do
81
+ @uri_unencoded.format_http.should == @uri_http_encoded
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,51 @@
1
+ require 'ronin/formatting/text'
2
+
3
+ require 'spec_helper'
4
+
5
+ describe String do
6
+ before(:all) do
7
+ @string = "hello"
8
+ end
9
+
10
+ it "should provide String#format_chars" do
11
+ @string.respond_to?('format_chars').should == true
12
+ end
13
+
14
+ it "should provide String#format_bytes" do
15
+ @string.respond_to?('format_bytes').should == true
16
+ end
17
+
18
+ it "should provide String#random_case" do
19
+ @string.respond_to?('random_case').should == true
20
+ end
21
+
22
+ describe "format_chars" do
23
+ it "should format each character in the String" do
24
+ @string.format_chars { |c|
25
+ "_#{c}"
26
+ }.should == "_h_e_l_l_o"
27
+ end
28
+ end
29
+
30
+ describe "format_bytes" do
31
+ it "should format each byte in the String" do
32
+ @string.format_bytes { |b|
33
+ sprintf("%%%x",b)
34
+ }.should == "%68%65%6c%6c%6f"
35
+ end
36
+ end
37
+
38
+ describe "random_case" do
39
+ it "should capitalize each character when :probability is 1.0" do
40
+ new_string = @string.random_case(:probability => 1.0)
41
+
42
+ @string.upcase.should == new_string
43
+ end
44
+
45
+ it "should not capitalize any characters when :probability is 0.0" do
46
+ new_string = @string.random_case(:probability => 0.0)
47
+
48
+ @string.should == new_string
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,29 @@
1
+ require 'ronin/has_license'
2
+
3
+ require 'spec_helper'
4
+ require 'classes/licensed_model'
5
+
6
+ describe HasLicense do
7
+ before(:all) do
8
+ LicensedModel.auto_migrate!
9
+ end
10
+
11
+ it "should have a license" do
12
+ model = LicensedModel.new(:content => 'bla')
13
+ model.license = License.gpl_2
14
+ model.save!
15
+
16
+ model.license.should == License.gpl_2
17
+ end
18
+
19
+ it "should provide helper methods for querying licensed models" do
20
+ model = LicensedModel.new(:content => 'stuff here')
21
+ model.license = License.gpl_2
22
+ model.save!
23
+ model.reload
24
+
25
+ LicensedModel.all(
26
+ :content.like => '%stuff%'
27
+ ).licensed_under(:gpl_2).first.should == model
28
+ end
29
+ end
@@ -0,0 +1,7 @@
1
+ require 'classes/cacheable_model'
2
+
3
+ require 'tmpdir'
4
+ require 'fileutils'
5
+
6
+ CACHEABLE_FILE = File.expand_path(File.join(File.dirname(__FILE__),'contexts','ronin_cacheable_model.rb'))
7
+ CACHEABLE_PATH = File.join(Dir.tmpdir,File.basename(CACHEABLE_FILE))
@@ -0,0 +1,13 @@
1
+ ronin_cacheable_model do
2
+
3
+ @config = true
4
+
5
+ cache do
6
+ self.content = 'this is a test'
7
+ end
8
+
9
+ def greeting
10
+ 'hello'
11
+ end
12
+
13
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ require 'ronin/database'
4
+
5
+ Database.setup({ :adapter => 'sqlite3', :database => ':memory:' })
@@ -0,0 +1 @@
1
+ $hello_overlay_loaded = true
@@ -0,0 +1,6 @@
1
+ require 'stuff/test'
2
+
3
+ module Stuff
4
+ class AnotherTest < Test
5
+ end
6
+ end
@@ -0,0 +1,4 @@
1
+ module Stuff
2
+ class Test
3
+ end
4
+ end
@@ -53,7 +53,7 @@ describe Platform::OverlayCache do
53
53
  end
54
54
 
55
55
  it "should have extensions" do
56
- @cache.extensions.should == ['test', 'hello', 'random']
56
+ @cache.extensions.should == ['hello', 'random', 'test']
57
57
  end
58
58
 
59
59
  it "should provide the paths to specific extensions" do
@@ -32,4 +32,32 @@ describe Platform::Overlay do
32
32
  @overlay.description.should == %{This is a test overlay used in Ronin's specs.}
33
33
  end
34
34
  end
35
+
36
+ describe "activate!" do
37
+ before(:all) do
38
+ @overlay = Platform::Overlay.new(File.join(OVERLAY_CACHE,'hello'))
39
+ @overlay.activate!
40
+ end
41
+
42
+ it "should load the init.rb file if present" do
43
+ $hello_overlay_loaded.should == true
44
+ end
45
+
46
+ it "should make the lib directory accessible to Kernel#require" do
47
+ require('stuff/test').should == true
48
+ end
49
+ end
50
+
51
+ describe "deactivate!" do
52
+ before(:all) do
53
+ @overlay = Platform::Overlay.new(File.join(OVERLAY_CACHE,'hello'))
54
+ @overlay.deactivate!
55
+ end
56
+
57
+ it "should make the lib directory unaccessible to Kernel#require" do
58
+ lambda {
59
+ require 'stuff/another_test'
60
+ }.should raise_error(LoadError)
61
+ end
62
+ end
35
63
  end
data/spec/product_spec.rb CHANGED
@@ -13,4 +13,11 @@ describe Product do
13
13
  @product.version = '0.1.0'
14
14
  @product.should be_valid
15
15
  end
16
+
17
+ it "should default the vendor to the name of the product" do
18
+ @product = Product.new(:name => 'Adobe', :version => '0.1.0')
19
+ @product.vendor.should == @product.name
20
+
21
+ @product.should be_valid
22
+ end
16
23
  end
@@ -0,0 +1,11 @@
1
+ require 'ronin/sessions/session'
2
+
3
+ module TestSession
4
+ include Sessions::Session
5
+
6
+ def connect
7
+ require_variable :host
8
+
9
+ return @host
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ require 'sessions/classes/test_session'
2
+
3
+ class UsesTestSession
4
+
5
+ include TestSession
6
+
7
+ # The host variable
8
+ attr_accessor :host
9
+
10
+ end
@@ -1,56 +1,25 @@
1
1
  require 'ronin/sessions/session'
2
2
 
3
3
  require 'spec_helper'
4
+ require 'sessions/classes/test_session'
5
+ require 'sessions/classes/uses_test_session'
4
6
 
5
7
  describe Sessions::Session do
6
- before(:all) do
7
- module TestSession
8
- include Sessions::Session
9
-
10
- setup_session do
11
- parameter :var, :default => :stuff, :description => 'Test parameter'
12
- end
13
-
14
- def test_one
15
- 'this_is_a_test'
16
- end
17
- end
18
-
19
- class TestSessionClass
20
- include TestSession
21
- end
22
-
23
- class TestSessionObject
24
- end
25
-
26
- @session_obj = TestSessionObject.new
27
- @session_obj.extend TestSession
28
- end
29
-
30
- it "should add self.setup_session to a Module" do
31
- TestSession.methods.include?('setup_session').should == true
32
- end
33
-
34
- describe "setup_session" do
35
- it "should add self.included and self.extended methods once setup_session is called" do
36
- TestSession.methods.include?('included').should == true
37
- TestSession.methods.include?('extended').should == true
8
+ describe "require_variable" do
9
+ before(:each) do
10
+ @obj = UsesTestSession.new
11
+ @obj.host = 'www.example.com'
38
12
  end
39
13
 
40
- it "should run the setup_session proc once included" do
41
- TestSessionClass.var.should == :stuff
14
+ it "should raise a VariableMissing exception if a variable is nil" do
15
+ lambda {
16
+ @obj.host = nil
17
+ @obj.connect
18
+ }.should raise_error(Sessions::VariableMissing)
42
19
  end
43
20
 
44
- it "should run the setup_session proc once extended" do
45
- @session_obj.var.should == :stuff
21
+ it "should do nothing if the variable is not nil" do
22
+ @obj.connect.should == @obj.host
46
23
  end
47
24
  end
48
-
49
- it "should include Parameters once included" do
50
- TestSessionClass.include?(Parameters).should == true
51
- end
52
-
53
- it "should extend Parameters once extended" do
54
- @session_obj.kind_of?(Parameters).should == true
55
- end
56
25
  end