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.
- data/History.txt +53 -0
- data/Manifest.txt +26 -18
- data/README.txt +12 -19
- data/Rakefile +9 -9
- data/TODO.txt +5 -5
- data/lib/ronin/cacheable.rb +246 -0
- data/lib/ronin/database/database.rb +21 -3
- data/lib/ronin/database/exceptions/invalid_config.rb +1 -1
- data/lib/ronin/environment.rb +5 -2
- data/lib/ronin/extensions.rb +2 -0
- data/lib/ronin/{models.rb → extensions/array.rb} +19 -6
- data/lib/ronin/extensions/ip_addr.rb +127 -0
- data/lib/ronin/{objectify/exceptions/object_context_not_found.rb → extensions/kernel.rb} +14 -3
- data/lib/ronin/extensions/uri/query_params.rb +4 -2
- data/lib/ronin/formatting/extensions/binary/integer.rb +6 -0
- data/lib/ronin/formatting/extensions/binary/string.rb +14 -12
- data/lib/ronin/formatting/extensions/text/string.rb +37 -19
- data/lib/ronin/has_license.rb +4 -2
- data/lib/ronin/model.rb +0 -1
- data/lib/ronin/network/extensions/http/net.rb +30 -3
- data/lib/ronin/network/extensions/telnet/net.rb +0 -18
- data/lib/ronin/network/http/exceptions/unknown_request.rb +1 -1
- data/lib/ronin/platform/exceptions/extension_not_found.rb +1 -1
- data/lib/ronin/platform/exceptions/overlay_cached.rb +1 -1
- data/lib/ronin/platform/exceptions/overlay_not_found.rb +1 -1
- data/lib/ronin/platform/extension.rb +18 -3
- data/lib/ronin/platform/extension_cache.rb +7 -1
- data/lib/ronin/platform/object_cache.rb +13 -12
- data/lib/ronin/platform/overlay.rb +14 -6
- data/lib/ronin/platform/overlay_cache.rb +11 -5
- data/lib/ronin/product.rb +20 -3
- data/lib/ronin/ronin.rb +0 -15
- data/lib/ronin/rpc/exceptions/response_missing.rb +1 -1
- data/lib/ronin/sessions/esmtp.rb +1 -10
- data/lib/ronin/{objectify.rb → sessions/exceptions.rb} +3 -3
- data/lib/ronin/{objectify/exceptions/unknown_object_context.rb → sessions/exceptions/variable_missing.rb} +4 -4
- data/lib/ronin/sessions/http.rb +3 -10
- data/lib/ronin/sessions/imap.rb +1 -10
- data/lib/ronin/sessions/pop3.rb +1 -9
- data/lib/ronin/sessions/session.rb +11 -21
- data/lib/ronin/sessions/smtp.rb +1 -10
- data/lib/ronin/sessions/tcp.rb +10 -13
- data/lib/ronin/sessions/telnet.rb +2 -17
- data/lib/ronin/sessions/udp.rb +6 -11
- data/lib/ronin/static/finders.rb +24 -0
- data/lib/ronin/ui/command_line/command_line.rb +41 -21
- data/lib/ronin/ui/command_line/commands/help.rb +7 -3
- data/lib/ronin/ui/command_line/commands/ls.rb +1 -1
- data/lib/ronin/ui/command_line/commands/rm.rb +1 -1
- data/lib/ronin/ui/command_line/exceptions/unknown_command.rb +1 -1
- data/lib/ronin/ui/diagnostics.rb +12 -5
- data/lib/ronin/ui/hexdump/extensions/file.rb +3 -1
- data/lib/ronin/ui/hexdump/hexdump.rb +1 -1
- data/lib/ronin/ui/verbose.rb +14 -0
- data/lib/ronin/version.rb +1 -1
- data/spec/cacheable_spec.rb +150 -0
- data/spec/classes/cacheable_model.rb +15 -0
- data/spec/classes/licensed_model.rb +12 -0
- data/spec/code/classes/thing.rb +13 -0
- data/spec/code/reference_spec.rb +1 -14
- data/spec/extensions/array_spec.rb +34 -0
- data/spec/extensions/ip_addr_spec.rb +44 -0
- data/spec/extensions/kernel_spec.rb +19 -0
- data/spec/extensions/uri/query_params_spec.rb +8 -0
- data/spec/formatting/binary/string_spec.rb +1 -1
- data/spec/formatting/digest/string_spec.rb +84 -0
- data/spec/formatting/http/string_spec.rb +84 -0
- data/spec/formatting/text/string_spec.rb +51 -0
- data/spec/has_license_spec.rb +29 -0
- data/spec/helpers/cacheable.rb +7 -0
- data/spec/helpers/contexts/ronin_cacheable_model.rb +13 -0
- data/spec/helpers/database.rb +5 -0
- data/spec/platform/helpers/overlays/hello/lib/init.rb +1 -0
- data/spec/platform/helpers/overlays/hello/lib/stuff/another_test.rb +6 -0
- data/spec/platform/helpers/overlays/hello/lib/stuff/test.rb +4 -0
- data/spec/platform/overlay_cache_spec.rb +1 -1
- data/spec/platform/overlay_spec.rb +28 -0
- data/spec/product_spec.rb +7 -0
- data/spec/sessions/classes/test_session.rb +11 -0
- data/spec/sessions/classes/uses_test_session.rb +10 -0
- data/spec/sessions/session_spec.rb +13 -44
- data/spec/spec_helper.rb +0 -5
- data/spec/static/{helpers → classes}/static_class.rb +0 -0
- data/spec/static/helpers/static.rb +0 -1
- data/spec/static/static_spec.rb +1 -0
- metadata +44 -35
- data/lib/ronin/objectify/exceptions.rb +0 -25
- data/lib/ronin/objectify/objectify.rb +0 -240
- data/lib/ronin/target.rb +0 -44
- data/lib/ronin/ui/command_line/param_parser.rb +0 -93
- data/spec/formatting/digest_spec.rb +0 -54
- data/spec/formatting/http_spec.rb +0 -53
- data/spec/formatting/text_spec.rb +0 -40
- data/spec/helpers.rb +0 -0
- data/spec/objectify/objectify_spec.rb +0 -31
- data/spec/target_spec.rb +0 -16
- data/spec/ui/command_line/helpers/example_command.rb +0 -21
- data/spec/ui/command_line/param_parser_spec.rb +0 -49
data/lib/ronin/sessions/esmtp.rb
CHANGED
|
@@ -29,15 +29,6 @@ module Ronin
|
|
|
29
29
|
module ESMTP
|
|
30
30
|
include Session
|
|
31
31
|
|
|
32
|
-
setup_session do
|
|
33
|
-
parameter :host, :description => 'ESMTP host'
|
|
34
|
-
parameter :port, :description => 'ESMTP port'
|
|
35
|
-
|
|
36
|
-
parameter :esmtp_login, :description => 'ESMTP login'
|
|
37
|
-
parameter :esmtp_user, :description => 'ESMTP user'
|
|
38
|
-
parameter :esmtp_password, :description => 'ESMTP password'
|
|
39
|
-
end
|
|
40
|
-
|
|
41
32
|
protected
|
|
42
33
|
|
|
43
34
|
def esmtp_message(options={},&block)
|
|
@@ -45,7 +36,7 @@ module Ronin
|
|
|
45
36
|
end
|
|
46
37
|
|
|
47
38
|
def esmtp_connect(options={},&block)
|
|
48
|
-
|
|
39
|
+
require_variable :host
|
|
49
40
|
|
|
50
41
|
options[:port] ||= @port
|
|
51
42
|
options[:login] ||= @esmtp_login
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#
|
|
2
2
|
#--
|
|
3
|
-
# Ronin - A
|
|
4
|
-
# exploration tasks.
|
|
3
|
+
# Ronin - A ruby development platform designed for information security
|
|
4
|
+
# and data exploration tasks.
|
|
5
5
|
#
|
|
6
6
|
# Copyright (c) 2006-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
|
|
7
7
|
#
|
|
@@ -21,4 +21,4 @@
|
|
|
21
21
|
#++
|
|
22
22
|
#
|
|
23
23
|
|
|
24
|
-
require 'ronin/
|
|
24
|
+
require 'ronin/sessions/exceptions/variable_missing'
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#
|
|
2
2
|
#--
|
|
3
|
-
# Ronin - A
|
|
4
|
-
# exploration tasks.
|
|
3
|
+
# Ronin - A ruby development platform designed for information security
|
|
4
|
+
# and data exploration tasks.
|
|
5
5
|
#
|
|
6
6
|
# Copyright (c) 2006-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
|
|
7
7
|
#
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
#
|
|
23
23
|
|
|
24
24
|
module Ronin
|
|
25
|
-
module
|
|
26
|
-
class
|
|
25
|
+
module Sessions
|
|
26
|
+
class VariableMissing < RuntimeError
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
29
|
end
|
data/lib/ronin/sessions/http.rb
CHANGED
|
@@ -23,22 +23,12 @@
|
|
|
23
23
|
|
|
24
24
|
require 'ronin/sessions/session'
|
|
25
25
|
require 'ronin/network/http'
|
|
26
|
-
require 'ronin/network/extensions/http'
|
|
27
26
|
|
|
28
27
|
module Ronin
|
|
29
28
|
module Sessions
|
|
30
29
|
module HTTP
|
|
31
30
|
include Session
|
|
32
31
|
|
|
33
|
-
setup_session do
|
|
34
|
-
parameter :http_user, :description => 'HTTP user'
|
|
35
|
-
parameter :http_password, :description => 'HTTP password'
|
|
36
|
-
|
|
37
|
-
parameter :http_proxy, :description => 'HTTP Proxy'
|
|
38
|
-
|
|
39
|
-
parameter :http_user_agent, :description => 'Web User-Agent'
|
|
40
|
-
end
|
|
41
|
-
|
|
42
32
|
protected
|
|
43
33
|
|
|
44
34
|
#
|
|
@@ -131,6 +121,9 @@ module Ronin
|
|
|
131
121
|
private
|
|
132
122
|
|
|
133
123
|
def http_merge_options(options={})
|
|
124
|
+
options[:host] ||= @http_host if @http_host
|
|
125
|
+
options[:port] ||= @http_port if @http_port
|
|
126
|
+
|
|
134
127
|
options[:user] ||= @http_user if @http_user
|
|
135
128
|
options[:password] ||= @http_password if @http_password
|
|
136
129
|
|
data/lib/ronin/sessions/imap.rb
CHANGED
|
@@ -29,19 +29,10 @@ module Ronin
|
|
|
29
29
|
module IMAP
|
|
30
30
|
include Session
|
|
31
31
|
|
|
32
|
-
setup_session do
|
|
33
|
-
parameter :host, :description => 'IMAP host'
|
|
34
|
-
parameter :port, :description => 'IMAP port'
|
|
35
|
-
|
|
36
|
-
parameter :imap_auth, :description => 'IMAP authentication mode'
|
|
37
|
-
parameter :imap_user, :description => 'IMAP user'
|
|
38
|
-
parameter :imap_password, :description => 'IMAP password'
|
|
39
|
-
end
|
|
40
|
-
|
|
41
32
|
protected
|
|
42
33
|
|
|
43
34
|
def imap_connect(options={},&block)
|
|
44
|
-
|
|
35
|
+
require_variable :host
|
|
45
36
|
|
|
46
37
|
options[:port] ||= @port
|
|
47
38
|
options[:auth] ||= @imap_auth
|
data/lib/ronin/sessions/pop3.rb
CHANGED
|
@@ -29,18 +29,10 @@ module Ronin
|
|
|
29
29
|
module POP3
|
|
30
30
|
include Session
|
|
31
31
|
|
|
32
|
-
setup_session do
|
|
33
|
-
parameter :host, :description => 'POP3 host'
|
|
34
|
-
parameter :port, :description => 'POP3 port'
|
|
35
|
-
|
|
36
|
-
parameter :pop3_user, :description => 'POP3 user'
|
|
37
|
-
parameter :pop3_password, :description => 'POP3 password'
|
|
38
|
-
end
|
|
39
|
-
|
|
40
32
|
protected
|
|
41
33
|
|
|
42
34
|
def pop3_connect(options={},&block)
|
|
43
|
-
|
|
35
|
+
require_variable :host
|
|
44
36
|
|
|
45
37
|
options[:port] ||= @port
|
|
46
38
|
options[:user] ||= @pop3_user
|
|
@@ -21,33 +21,23 @@
|
|
|
21
21
|
#++
|
|
22
22
|
#
|
|
23
23
|
|
|
24
|
-
require 'ronin/
|
|
25
|
-
|
|
26
|
-
require 'parameters'
|
|
24
|
+
require 'ronin/sessions/exceptions/variable_missing'
|
|
27
25
|
|
|
28
26
|
module Ronin
|
|
29
27
|
module Sessions
|
|
30
28
|
module Session
|
|
31
|
-
|
|
32
|
-
base.module_eval do
|
|
33
|
-
def self.setup_session(&block)
|
|
34
|
-
#
|
|
35
|
-
# Includes Parameters and runs the _block_.
|
|
36
|
-
#
|
|
37
|
-
metaclass_def(:included) do |base_class|
|
|
38
|
-
base_class.class_eval { include Parameters }
|
|
39
|
-
base_class.class_eval(&block)
|
|
40
|
-
end
|
|
29
|
+
protected
|
|
41
30
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
end
|
|
31
|
+
#
|
|
32
|
+
# Raises a VariableMissing exception if the instance variable with
|
|
33
|
+
# the specified _name_ is not defined, returns +true+ otherwise.
|
|
34
|
+
#
|
|
35
|
+
def require_variable(name)
|
|
36
|
+
if instance_variable_get("@#{name}").nil?
|
|
37
|
+
raise(VariableMissing,"the session variable @#{name} was not set",caller)
|
|
50
38
|
end
|
|
39
|
+
|
|
40
|
+
return true
|
|
51
41
|
end
|
|
52
42
|
end
|
|
53
43
|
end
|
data/lib/ronin/sessions/smtp.rb
CHANGED
|
@@ -29,15 +29,6 @@ module Ronin
|
|
|
29
29
|
module SMTP
|
|
30
30
|
include Session
|
|
31
31
|
|
|
32
|
-
setup_session do
|
|
33
|
-
parameter :host, :description => 'SMTP host'
|
|
34
|
-
parameter :port, :description => 'SMTP port'
|
|
35
|
-
|
|
36
|
-
parameter :smtp_login, :description => 'SMTP login'
|
|
37
|
-
parameter :smtp_user, :description => 'SMTP user'
|
|
38
|
-
parameter :smtp_password, :description => 'SMTP password'
|
|
39
|
-
end
|
|
40
|
-
|
|
41
32
|
protected
|
|
42
33
|
|
|
43
34
|
def smtp_message(options={},&block)
|
|
@@ -45,7 +36,7 @@ module Ronin
|
|
|
45
36
|
end
|
|
46
37
|
|
|
47
38
|
def smtp_connect(options={},&block)
|
|
48
|
-
|
|
39
|
+
require_variable :host
|
|
49
40
|
|
|
50
41
|
options[:port] ||= @port
|
|
51
42
|
options[:login] ||= @smtp_login
|
data/lib/ronin/sessions/tcp.rb
CHANGED
|
@@ -29,14 +29,6 @@ module Ronin
|
|
|
29
29
|
module TCP
|
|
30
30
|
include Session
|
|
31
31
|
|
|
32
|
-
setup_session do
|
|
33
|
-
parameter :local_host, :description => 'TCP local host'
|
|
34
|
-
parameter :local_port, :description => 'TCP local port'
|
|
35
|
-
|
|
36
|
-
parameter :host, :description => 'TCP remote host'
|
|
37
|
-
parameter :port, :description => 'TCP remote port'
|
|
38
|
-
end
|
|
39
|
-
|
|
40
32
|
protected
|
|
41
33
|
|
|
42
34
|
#
|
|
@@ -48,7 +40,8 @@ module Ronin
|
|
|
48
40
|
# object.
|
|
49
41
|
#
|
|
50
42
|
def tcp_connect(&block)
|
|
51
|
-
|
|
43
|
+
require_variable :host
|
|
44
|
+
require_variable :port
|
|
52
45
|
|
|
53
46
|
return ::Net.tcp_connect(@host,@port,@local_host,@local_port,&block)
|
|
54
47
|
end
|
|
@@ -59,7 +52,8 @@ module Ronin
|
|
|
59
52
|
# it will be passed the newly created TCPSocket object.
|
|
60
53
|
#
|
|
61
54
|
def tcp_connect_and_send(data,&block)
|
|
62
|
-
|
|
55
|
+
require_variable :host
|
|
56
|
+
require_variable :port
|
|
63
57
|
|
|
64
58
|
return ::Net.tcp_connect_and_send(data,@host,@port,@local_host,@local_port,&block)
|
|
65
59
|
end
|
|
@@ -71,7 +65,8 @@ module Ronin
|
|
|
71
65
|
# has returned, the TCPSocket object will be closed.
|
|
72
66
|
#
|
|
73
67
|
def tcp_session(&block)
|
|
74
|
-
|
|
68
|
+
require_variable :host
|
|
69
|
+
require_variable :port
|
|
75
70
|
|
|
76
71
|
return Net.tcp_session(@host,@port,@local_host,@local_port,&block)
|
|
77
72
|
end
|
|
@@ -83,7 +78,8 @@ module Ronin
|
|
|
83
78
|
# banner String.
|
|
84
79
|
#
|
|
85
80
|
def tcp_banner(&block)
|
|
86
|
-
|
|
81
|
+
require_variable :host
|
|
82
|
+
require_variable :port
|
|
87
83
|
|
|
88
84
|
return ::Net.tcp_banner(@host,@port,@local_host,@local_port,&block)
|
|
89
85
|
end
|
|
@@ -94,7 +90,8 @@ module Ronin
|
|
|
94
90
|
# connection. Returns +true+ if the data was successfully sent.
|
|
95
91
|
#
|
|
96
92
|
def tcp_send(data)
|
|
97
|
-
|
|
93
|
+
require_variable :host
|
|
94
|
+
require_variable :port
|
|
98
95
|
|
|
99
96
|
return ::Net.tcp_send(data,@host,@port,@local_host,@local_port)
|
|
100
97
|
end
|
|
@@ -26,28 +26,13 @@ require 'ronin/network/telnet'
|
|
|
26
26
|
|
|
27
27
|
module Ronin
|
|
28
28
|
module Sessions
|
|
29
|
-
module
|
|
29
|
+
module Telnet
|
|
30
30
|
include Session
|
|
31
31
|
|
|
32
|
-
setup_session do
|
|
33
|
-
parameter :host, :description => 'Telnet host'
|
|
34
|
-
parameter :port,
|
|
35
|
-
:default => lambda {
|
|
36
|
-
Ronin::Network::Telnet.default_port
|
|
37
|
-
},
|
|
38
|
-
:description => 'Telnet port'
|
|
39
|
-
|
|
40
|
-
parameter :telnet_user, :description => 'Telnet user'
|
|
41
|
-
parameter :telnet_password, :description => 'Telnet password'
|
|
42
|
-
|
|
43
|
-
parameter :telnet_proxy, :description => 'Telnet proxy'
|
|
44
|
-
parameter :telnet_ssl, :description => 'Telnet SSL options'
|
|
45
|
-
end
|
|
46
|
-
|
|
47
32
|
protected
|
|
48
33
|
|
|
49
34
|
def telnet_connect(options={},&block)
|
|
50
|
-
|
|
35
|
+
require_variable :host
|
|
51
36
|
|
|
52
37
|
options[:port] ||= @port
|
|
53
38
|
options[:user] ||= @telnet_user
|
data/lib/ronin/sessions/udp.rb
CHANGED
|
@@ -29,14 +29,6 @@ module Ronin
|
|
|
29
29
|
module UDP
|
|
30
30
|
include Session
|
|
31
31
|
|
|
32
|
-
setup_session do
|
|
33
|
-
parameter :local_host, :description => 'local host'
|
|
34
|
-
parameter :local_port, :description => 'local port'
|
|
35
|
-
|
|
36
|
-
parameter :host, :description => 'remote host'
|
|
37
|
-
parameter :port, :description => 'remote port'
|
|
38
|
-
end
|
|
39
|
-
|
|
40
32
|
protected
|
|
41
33
|
|
|
42
34
|
#
|
|
@@ -46,7 +38,8 @@ module Ronin
|
|
|
46
38
|
# of the UDP connection. A UDPSocket object will be returned.
|
|
47
39
|
#
|
|
48
40
|
def udp_connect(&block)
|
|
49
|
-
|
|
41
|
+
require_variable :host
|
|
42
|
+
require_variable :port
|
|
50
43
|
|
|
51
44
|
return ::Net.udp_connect(@host,@port,@local_host,@local_port,&block)
|
|
52
45
|
end
|
|
@@ -57,7 +50,8 @@ module Ronin
|
|
|
57
50
|
# it will be passed the newly created UDPSocket object.
|
|
58
51
|
#
|
|
59
52
|
def udp_connect_and_send(data,&block)
|
|
60
|
-
|
|
53
|
+
require_variable :host
|
|
54
|
+
require_variable :port
|
|
61
55
|
|
|
62
56
|
return ::Net.udp_connect_and_send(data,@host,@port,@local_host,@local_port,&block)
|
|
63
57
|
end
|
|
@@ -69,7 +63,8 @@ module Ronin
|
|
|
69
63
|
# has returned, the UDPSocket object will be closed.
|
|
70
64
|
#
|
|
71
65
|
def udp_session(&block)
|
|
72
|
-
|
|
66
|
+
require_variable :host
|
|
67
|
+
require_variable :port
|
|
73
68
|
|
|
74
69
|
return ::Net.udp_session(@host,@port,@local_host,@local_port,&block)
|
|
75
70
|
end
|
data/lib/ronin/static/finders.rb
CHANGED
|
@@ -101,6 +101,14 @@ module Ronin
|
|
|
101
101
|
return paths
|
|
102
102
|
end
|
|
103
103
|
|
|
104
|
+
#
|
|
105
|
+
# Passes all matching static paths for the specified _path_ to the
|
|
106
|
+
# given _block_.
|
|
107
|
+
#
|
|
108
|
+
def each_static_path(path,&block)
|
|
109
|
+
static_find_all(path).each(&block)
|
|
110
|
+
end
|
|
111
|
+
|
|
104
112
|
#
|
|
105
113
|
# Returns all matching static files for the specified _path_.
|
|
106
114
|
#
|
|
@@ -114,6 +122,14 @@ module Ronin
|
|
|
114
122
|
return paths
|
|
115
123
|
end
|
|
116
124
|
|
|
125
|
+
#
|
|
126
|
+
# Passes each matching static file for the specified _path_ to the
|
|
127
|
+
# given _block_.
|
|
128
|
+
#
|
|
129
|
+
def each_static_file(path,&block)
|
|
130
|
+
find_static_files(path).each(&block)
|
|
131
|
+
end
|
|
132
|
+
|
|
117
133
|
#
|
|
118
134
|
# Returns all matching static directories for the specified _path_.
|
|
119
135
|
#
|
|
@@ -127,6 +143,14 @@ module Ronin
|
|
|
127
143
|
return paths
|
|
128
144
|
end
|
|
129
145
|
|
|
146
|
+
#
|
|
147
|
+
# Passes each matching static directory for the specified _path_ to
|
|
148
|
+
# the given _block_.
|
|
149
|
+
#
|
|
150
|
+
def each_static_dir(path,&block)
|
|
151
|
+
find_static_dirs(path).each(&block)
|
|
152
|
+
end
|
|
153
|
+
|
|
130
154
|
#
|
|
131
155
|
# Returns all matching static paths for the specified _pattern_.
|
|
132
156
|
#
|
|
@@ -22,28 +22,33 @@
|
|
|
22
22
|
#
|
|
23
23
|
|
|
24
24
|
require 'ronin/ui/command_line/exceptions/unknown_command'
|
|
25
|
-
require 'ronin/ui/command_line/commands/console'
|
|
26
|
-
require 'ronin/ui/console'
|
|
27
25
|
|
|
28
26
|
require 'reverse_require'
|
|
27
|
+
require 'extlib'
|
|
29
28
|
|
|
30
29
|
module Ronin
|
|
31
30
|
module UI
|
|
32
31
|
module CommandLine
|
|
32
|
+
# Directory which stores the commands
|
|
33
|
+
COMMANDS_DIR = File.join('ronin','ui','command_line','commands')
|
|
34
|
+
|
|
35
|
+
# Name of the default to run
|
|
36
|
+
DEFAULT_COMMAND = 'console'
|
|
37
|
+
|
|
33
38
|
#
|
|
34
39
|
# Returns the commands registered with the command-line utility.
|
|
35
40
|
#
|
|
36
41
|
def CommandLine.commands
|
|
37
42
|
unless class_variable_defined?('@@ronin_commands')
|
|
38
|
-
|
|
43
|
+
pattern = File.join('lib',COMMANDS_DIR,'*.rb')
|
|
44
|
+
paths = Gem.find_resources(pattern)
|
|
39
45
|
|
|
40
|
-
@@ronin_commands =
|
|
46
|
+
@@ronin_commands = []
|
|
41
47
|
|
|
42
48
|
paths.each do |path|
|
|
43
|
-
|
|
44
|
-
name = File.basename(path).gsub(/^ronin-/,'')
|
|
49
|
+
name = File.basename(path).gsub(/\.rb$/,'')
|
|
45
50
|
|
|
46
|
-
@@ronin_commands
|
|
51
|
+
@@ronin_commands << name unless @@ronin_commands.include?(name)
|
|
47
52
|
end
|
|
48
53
|
end
|
|
49
54
|
|
|
@@ -51,11 +56,11 @@ module Ronin
|
|
|
51
56
|
end
|
|
52
57
|
|
|
53
58
|
#
|
|
54
|
-
# Returns +true+ if
|
|
55
|
-
#
|
|
59
|
+
# Returns +true+ if a command exists with the specified _name_,
|
|
60
|
+
# returns +false+ otherwise.
|
|
56
61
|
#
|
|
57
62
|
def CommandLine.has_command?(name)
|
|
58
|
-
CommandLine.commands.
|
|
63
|
+
CommandLine.commands.include?(name.to_s)
|
|
59
64
|
end
|
|
60
65
|
|
|
61
66
|
#
|
|
@@ -65,11 +70,25 @@ module Ronin
|
|
|
65
70
|
def CommandLine.get_command(name)
|
|
66
71
|
name = name.to_s
|
|
67
72
|
|
|
68
|
-
|
|
73
|
+
begin
|
|
74
|
+
require File.join(COMMANDS_DIR,name)
|
|
75
|
+
rescue LoadError
|
|
76
|
+
raise(UnknownCommand,"unable to load the command #{name.dump}",caller)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
class_name = name.to_const_string
|
|
80
|
+
|
|
81
|
+
unless Commands.const_defined?(class_name)
|
|
69
82
|
raise(UnknownCommand,"unknown command #{name.dump}",caller)
|
|
70
83
|
end
|
|
71
84
|
|
|
72
|
-
|
|
85
|
+
command = Commands.const_get(class_name)
|
|
86
|
+
|
|
87
|
+
unless command.respond_to?(:run)
|
|
88
|
+
raise(UnknownCommand,"command #{name.dump} must provide a 'run' method",caller)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
return command
|
|
73
92
|
end
|
|
74
93
|
|
|
75
94
|
#
|
|
@@ -78,18 +97,19 @@ module Ronin
|
|
|
78
97
|
# attempt to find and execute the Command with the same name.
|
|
79
98
|
#
|
|
80
99
|
def CommandLine.run(*argv)
|
|
81
|
-
if (argv.empty? || argv[0
|
|
82
|
-
|
|
100
|
+
if (argv.empty? || argv.first[0..0]=='-')
|
|
101
|
+
name = DEFAULT_COMMAND
|
|
102
|
+
argv = ARGV
|
|
83
103
|
else
|
|
84
|
-
|
|
104
|
+
name = argv.first
|
|
85
105
|
argv = argv[1..-1]
|
|
106
|
+
end
|
|
86
107
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
end
|
|
108
|
+
begin
|
|
109
|
+
CommandLine.get_command(name).run(*argv)
|
|
110
|
+
rescue UnknownCommand => e
|
|
111
|
+
STDERR.puts e
|
|
112
|
+
exit -1
|
|
93
113
|
end
|
|
94
114
|
|
|
95
115
|
return true
|