@@ -7,11 +7,24 @@ module Msf
7
7
module RPC
8
8
class RPC_Console < RPC_Base
9
9
10
+ # Initializes the RPC console
11
+ #
12
+ # @return [Msf::Ui::Web::Driver]
10
13
def initialize ( *args )
11
14
super
12
15
@console_driver = Msf ::Ui ::Web ::Driver . new ( :framework => framework )
13
16
end
14
17
18
+ # Creates a new framework console.
19
+ #
20
+ # @param [Hash] opts (Optional) See Msf::Ui::Web::Driver#create_console
21
+ # @return [Hash] Information about the new console, such as:
22
+ # * 'id' [Fixnum] The console's ID.
23
+ # * 'prompt' [String] The framework prompt (example: 'msf > ')
24
+ # * 'busy' [TrueClass] The console's busy state, or
25
+ # * 'busy' [FalseClass] The console's busy state.
26
+ # @example Here's how you would use this from the client:
27
+ # rpc.call('console.create')
15
28
def rpc_create ( opts = { } )
16
29
cid = @console_driver . create_console ( opts )
17
30
{
@@ -21,6 +34,17 @@ def rpc_create(opts={})
21
34
}
22
35
end
23
36
37
+
38
+ # Returns a list of framework consoles.
39
+ #
40
+ # @return [Hash] Console information.
41
+ # * 'consoles' [Array] consoles, each element is another hash that includes:
42
+ # * 'id' [Fixnum] The console's ID
43
+ # * 'prompt' [String] The framework prompt (example: 'msf > ')
44
+ # * 'busy' [TrueClass] The console's busy state, or
45
+ # * 'busy' [FalseClass] The console's busy state.
46
+ # @example Here's how you would use this from the client:
47
+ # rpc.call('console.list')
24
48
def rpc_list
25
49
ret = [ ]
26
50
@console_driver . consoles . each_key do |cid |
@@ -33,13 +57,36 @@ def rpc_list
33
57
{ 'consoles' => ret }
34
58
end
35
59
60
+
61
+ # Deletes a framework console.
62
+ #
63
+ # @param [Fixnum] cid Framework console ID.
64
+ # @return [Hash] A result indicating whether the action was successful or not.
65
+ # * 'result' [String] Either 'success' or 'failure'.
66
+ # @example Here's how you would use this from the client:
67
+ # rpc.call('console.destroy', 1)
36
68
def rpc_destroy ( cid )
37
69
cid = cid . to_s
38
70
return { 'result' => 'failure' } if not @console_driver . consoles [ cid ]
39
71
res = @console_driver . destroy_console ( cid )
40
72
{ 'result' => res ? 'success' : 'failure' }
41
73
end
42
74
75
+
76
+ # Returns the framework console output.
77
+ #
78
+ # @param [Fixnum] cid Framework console ID.
79
+ # @return [Hash] There are two different hashes you might get:
80
+ #
81
+ # If the console ID is invalid, you will get a hash like the following:
82
+ # * 'result' [String] A value that says 'failure'.
83
+ # If the console ID is valid, you will get a hash like the following:
84
+ # * 'data' [String] The output the framework console produces (example: the banner)
85
+ # * 'prompt' [String] The framework prompt (example: 'msf > ')
86
+ # * 'busy' [TrueClass] The console's busy state, or
87
+ # * 'busy' [FalseClass] The console's busy state.
88
+ # @example Here's how you would use this from the client:
89
+ # rpc.call('console.read', 1)
43
90
def rpc_read ( cid )
44
91
cid = cid . to_s
45
92
return { 'result' => 'failure' } if not @console_driver . consoles [ cid ]
@@ -50,25 +97,77 @@ def rpc_read(cid)
50
97
}
51
98
end
52
99
100
+
101
+ # Sends an input (such as a command) to the framework console.
102
+ #
103
+ # @param [Fixnum] cid Framework console ID.
104
+ # @param [String] data User input.
105
+ # @return [Hash] There are two different hashes you might get:
106
+ #
107
+ # If the console ID is invalid, you will get a hash like the following:
108
+ # * 'result' [String] A value that says 'failure'.
109
+ # If the console ID is invalid, you will get a hash like the following:
110
+ # * 'wrote' [Fixnum] Number of bytes sent.
111
+ # @note Remember to add a newline (\\r\\n) at the end of input, otherwise
112
+ # the console will not do anything. And you will need to use the
113
+ # #rpc_read method to retrieve the output again.
114
+ # @example Here's how you would use this from the client:
115
+ # # This will show the current module's options.
116
+ # rpc.call('console.write', 4, "show options\r\n")
53
117
def rpc_write ( cid , data )
54
118
cid = cid . to_s
55
119
return { 'result' => 'failure' } if not @console_driver . consoles [ cid ]
56
120
{ "wrote" => @console_driver . write_console ( cid , data || '' ) }
57
121
end
58
122
123
+
124
+ # Returns the tab-completed version of your input (such as a module path).
125
+ #
126
+ # @param [Fixnum] cid Framework console ID.
127
+ # @param [String] line Command.
128
+ # @return [Hash] There are two different hashes you might get:
129
+ #
130
+ # If the console ID is invalid, you will get a hash like the following:
131
+ # * 'result' [String] A value that says 'failure'.
132
+ # If the console ID is valid, you will get a hash like the following:
133
+ # * 'tabs' [String] The tab-completed version of the command.
134
+ # @example Here's how you would use this from the client:
135
+ # # This will return:
136
+ # # {"tabs"=>["use exploit/windows/smb/ms08_067_netapi"]}
137
+ # rpc.call('console.tabs', 4, "use exploit/windows/smb/ms08_067_")
59
138
def rpc_tabs ( cid , line )
60
139
cid = cid . to_s
61
140
return { 'result' => 'failure' } if not @console_driver . consoles [ cid ]
62
141
{ "tabs" => @console_driver . consoles [ cid ] . tab_complete ( line ) }
63
142
end
64
143
144
+
145
+ # Kills a framework session.
146
+ #
147
+ # @param [Fixnum] cid Framework console ID.
148
+ # @return [Hash] There are two different hashes you might get:
149
+ #
150
+ # If the console ID is invalid, you will get a hash like the following:
151
+ # * 'result' [String] A value that says 'failure'.
152
+ # If the console ID is valid, you will get the following that indicates the action was successful.
153
+ # * 'result' [String] A value that says 'success'.
65
154
def rpc_session_kill ( cid )
66
155
cid = cid . to_s
67
156
return { 'result' => 'failure' } if not @console_driver . consoles [ cid ]
68
157
@console_driver . consoles [ cid ] . session_kill
69
158
{ 'result' => 'success' }
70
159
end
71
160
161
+
162
+ # Detaches a framework session.
163
+ #
164
+ # @param [Fixnum] cid Framework console ID.
165
+ # @return [Hash] There are two different hashes you might get:
166
+ #
167
+ # If the console ID is invalid, you will get a hash like the following:
168
+ # * 'result' [String] A value that says 'failure'.
169
+ # If the console ID is valid, you will get the following that indicates the action was successful.
170
+ # * 'result' [String] A value that says 'success'.
72
171
def rpc_session_detach ( cid )
73
172
cid = cid . to_s
74
173
return { 'result' => 'failure' } if not @console_driver . consoles [ cid ]
0 commit comments