@@ -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 instance.
19
+ #
20
+ # @param [Hash] opts See Msf::Ui::Web::Driver#create_console
21
+ # @return [Hash] Information about the new console. It contains the following keys:
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<Hash>] consoles, each element is a 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,37 @@ def rpc_list
33
57
{ 'consoles' => ret }
34
58
end
35
59
60
+
61
+ # Deletes a framework console instance.
62
+ #
63
+ # @param [Fixnum] cid Framework console ID.
64
+ # @return [Hash] A result indicating whether the action was successful or not.
65
+ # It contains the following key:
66
+ # * 'result' [String] Either 'success' or 'failure'.
67
+ # @example Here's how you would use this from the client:
68
+ # rpc.call('console.destroy', 1)
36
69
def rpc_destroy ( cid )
37
70
cid = cid . to_s
38
71
return { 'result' => 'failure' } if not @console_driver . consoles [ cid ]
39
72
res = @console_driver . destroy_console ( cid )
40
73
{ 'result' => res ? 'success' : 'failure' }
41
74
end
42
75
76
+
77
+ # Returns the framework console output in raw form.
78
+ #
79
+ # @param [Fixnum] cid Framework console ID.
80
+ # @return [Hash] There are two different hashes you might get:
81
+ #
82
+ # If the console ID is invalid, you will get a hash like the following:
83
+ # * 'result' [String] A value that says 'failure'.
84
+ # If the console ID is valid, you will get a hash like the following:
85
+ # * 'data' [String] The output the framework console produces (example: the banner)
86
+ # * 'prompt' [String] The framework prompt (example: 'msf > ')
87
+ # * 'busy' [TrueClass] The console's busy state, or
88
+ # * 'busy' [FalseClass] The console's busy state.
89
+ # @example Here's how you would use this from the client:
90
+ # rpc.call('console.read', 1)
43
91
def rpc_read ( cid )
44
92
cid = cid . to_s
45
93
return { 'result' => 'failure' } if not @console_driver . consoles [ cid ]
@@ -50,25 +98,75 @@ def rpc_read(cid)
50
98
}
51
99
end
52
100
101
+
102
+ # Sends an input (such as a command) to the framework console.
103
+ #
104
+ # @param [Fixnum] cid Framework console ID.
105
+ # @param [String] data User input.
106
+ # @return [Hash] There are two different hashes you might get:
107
+ #
108
+ # If the console ID is invalid, you will get a hash like the following:
109
+ # * 'result' [String] A value that says 'failure'.
110
+ # If the console ID is invalid, you will get a hash like the following:
111
+ # * 'wrote' [Fixnum] Number of bytes sent.
112
+ # @note Remember to add a newline (\\r\\n) at the end of input, otherwise
113
+ # the console will not do anything. And you will need to use the
114
+ # #rpc_read method to retrieve the output again.
115
+ # @example Here's how you would use this from the client:
116
+ # # This will show the current module's options.
117
+ # rpc.call('console.write', 4, "show options\r\n")
53
118
def rpc_write ( cid , data )
54
119
cid = cid . to_s
55
120
return { 'result' => 'failure' } if not @console_driver . consoles [ cid ]
56
121
{ "wrote" => @console_driver . write_console ( cid , data || '' ) }
57
122
end
58
123
124
+
125
+ # Returns the tab-completed version of your input (such as a module path).
126
+ #
127
+ # @param [Fixnum] cid Framework console ID.
128
+ # @param [String] line Command.
129
+ # @return [Hash] There are two different hashes you might get:
130
+ #
131
+ # If the console ID is invalid, you will get a hash like the following:
132
+ # * 'result' [String] A value that says 'failure'.
133
+ # If the console ID is valid, you will get a hash like the following:
134
+ # * 'tabs' [String] The tab-completed version of the command.
135
+ # @example Here's how you would use this from the client:
136
+ # # This will return:
137
+ # # {"tabs"=>["use exploit/windows/smb/ms08_067_netapi"]}
138
+ # rpc.call('console.tabs', 4, "use exploit/windows/smb/ms08_067_")
59
139
def rpc_tabs ( cid , line )
60
140
cid = cid . to_s
61
141
return { 'result' => 'failure' } if not @console_driver . consoles [ cid ]
62
142
{ "tabs" => @console_driver . consoles [ cid ] . tab_complete ( line ) }
63
143
end
64
144
145
+
146
+ # Kills a framework session. This serves the same purpose as [CTRL]+[C] to abort an interactive session.
147
+ # You might also want to considering using the session API calls instead of this.
148
+ #
149
+ # @param [Fixnum] cid Framework console ID.
150
+ # @return [Hash] A hash indicating whether the action was successful or not. It contains:
151
+ # * 'result' [String] A message that says 'success' if the console ID is valid (and successfully killed, otherwise 'failed')
152
+ # @example Here's how you would use this from the client:
153
+ # rpc.call('console.session_kill', 4)
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. This serves the same purpose as [CTRL]+[Z] to
163
+ # background an interactive session.
164
+ #
165
+ # @param [Fixnum] cid Framework console ID.
166
+ # @return [Hash] A hash indicating whether the action was successful or not. It contains:
167
+ # * 'result' [String] A message that says 'success' if the console ID is valid (and successfully detached, otherwise 'failed')
168
+ # @example Here's how you would use this from the client:
169
+ # rpc.call('console.session_detach', 4)
72
170
def rpc_session_detach ( cid )
73
171
cid = cid . to_s
74
172
return { 'result' => 'failure' } if not @console_driver . consoles [ cid ]
0 commit comments