Class: Msf::RPC::RPC_Session
- Defined in:
- lib/msf/core/rpc/v10/rpc_session.rb
Instance Attribute Summary
Attributes inherited from RPC_Base
#framework, #job_status_tracker, #service, #tokens, #users
Instance Method Summary collapse
-
#rpc_compatible_modules(sid) ⇒ Hash
Returns all the compatible post modules for this session.
-
#rpc_list ⇒ Hash
Returns a list of sessions that belong to the framework instance used by the RPC service.
-
#rpc_meterpreter_directory_separator(sid) ⇒ Hash
Returns the separator used by the meterpreter.
-
#rpc_meterpreter_read(sid) ⇒ Hash
Reads the output from a meterpreter session (such as a command output).
-
#rpc_meterpreter_run_single(sid, data) ⇒ Hash
Runs a meterpreter command even if interacting with a shell or other channel.
-
#rpc_meterpreter_script(sid, data) ⇒ Hash
deprecated
Deprecated.
Metasploit no longer maintains or accepts meterpreter scripts. Please try to use post modules instead.
-
#rpc_meterpreter_session_detach(sid) ⇒ Hash
Detaches from a meterpreter session.
-
#rpc_meterpreter_session_kill(sid) ⇒ Hash
Kills a meterpreter session.
-
#rpc_meterpreter_tabs(sid, line) ⇒ Hash
Returns a tab-completed version of your meterpreter prompt input.
-
#rpc_meterpreter_transport_change(sid, opts = {}) ⇒ Boolean
Changes the Transport of a given Meterpreter Session.
-
#rpc_meterpreter_write(sid, data) ⇒ Hash
Sends an input to a meterpreter prompt.
-
#rpc_ring_clear(sid) ⇒ Hash
Clears a shell session.
-
#rpc_ring_last(sid) ⇒ Hash
Returns the last sequence (last issued ReadPointer) for a shell session.
-
#rpc_ring_put(sid, data) ⇒ Hash
Sends an input to a session (such as a command).
-
#rpc_ring_read(sid, ptr = nil) ⇒ Hash
Reads from a session (such as a command output).
-
#rpc_shell_read(sid, ptr = nil) ⇒ Hash
Reads the output of a shell session (such as a command output).
-
#rpc_shell_upgrade(sid, lhost, lport) ⇒ Hash
Upgrades a shell to a meterpreter.
-
#rpc_shell_write(sid, data) ⇒ Hash
Writes to a shell session (such as a command).
-
#rpc_stop(sid) ⇒ Hash
Stops a session.
Methods inherited from RPC_Base
Constructor Details
This class inherits a constructor from Msf::RPC::RPC_Base
Instance Method Details
#rpc_compatible_modules(sid) ⇒ Hash
Returns all the compatible post modules for this session.
444 445 446 447 448 449 450 451 452 453 454 455 |
# File 'lib/msf/core/rpc/v10/rpc_session.rb', line 444 def rpc_compatible_modules( sid) ret = [] mtype = "post" names = self.framework.post.keys.map{ |x| "post/#{x}" } names.each do |mname| m = _find_module(mtype, mname) next if not m.session_compatible?(sid) ret << m.fullname end { "modules" => ret } end |
#rpc_list ⇒ Hash
Returns a list of sessions that belong to the framework instance used by the RPC service.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/msf/core/rpc/v10/rpc_session.rb', line 29 def rpc_list res = {} self.framework.sessions.each do |sess| i,s = sess res[s.sid] = { 'type' => s.type.to_s, 'tunnel_local' => s.tunnel_local.to_s, 'tunnel_peer' => s.tunnel_peer.to_s, 'via_exploit' => s.via_exploit.to_s, 'via_payload' => s.via_payload.to_s, 'desc' => s.desc.to_s, 'info' => s.info.to_s, 'workspace' => s.workspace.to_s, 'session_host' => s.session_host.to_s, 'session_port' => s.session_port.to_i, 'target_host' => s.target_host.to_s, 'username' => s.username.to_s, 'uuid' => s.uuid.to_s, 'exploit_uuid' => s.exploit_uuid.to_s, 'routes' => s.routes.join(","), 'arch' => s.arch.to_s } if(s.type.to_s == "meterpreter") res[s.sid]['platform'] = s.platform.to_s end end res end |
#rpc_meterpreter_directory_separator(sid) ⇒ Hash
Returns the separator used by the meterpreter.
430 431 432 433 434 |
# File 'lib/msf/core/rpc/v10/rpc_session.rb', line 430 def rpc_meterpreter_directory_separator(sid) s = _valid_session(sid,"meterpreter") { "separator" => s.fs.file.separator } end |
#rpc_meterpreter_read(sid) ⇒ Hash
Multiple concurrent callers writing and reading the same Meterperter session can lead to a conflict, where one caller gets the others output and vice versa. Concurrent access to a Meterpreter session is best handled by post modules.
Reads the output from a meterpreter session (such as a command output).
157 158 159 160 161 162 163 164 165 166 |
# File 'lib/msf/core/rpc/v10/rpc_session.rb', line 157 def rpc_meterpreter_read( sid) s = _valid_session(sid,"meterpreter") if not s.user_output.respond_to? :dump_buffer s.init_ui(Rex::Ui::Text::Input::Buffer.new, Rex::Ui::Text::Output::Buffer.new) end data = s.user_output.dump_buffer { "data" => data } end |
#rpc_meterpreter_run_single(sid, data) ⇒ Hash
Runs a meterpreter command even if interacting with a shell or other channel. You will want to use the #rpc_meterpreter_read to retrieve the output.
358 359 360 361 362 363 364 365 366 367 |
# File 'lib/msf/core/rpc/v10/rpc_session.rb', line 358 def rpc_meterpreter_run_single( sid, data) s = _valid_session(sid,"meterpreter") if not s.user_output.respond_to? :dump_buffer s.init_ui(Rex::Ui::Text::Input::Buffer.new, Rex::Ui::Text::Output::Buffer.new) end self.framework.threads.spawn("MeterpreterRunSingle", false, s) { |sess| sess.console.run_single(data) } { "result" => "success" } end |
#rpc_meterpreter_script(sid, data) ⇒ Hash
Metasploit no longer maintains or accepts meterpreter scripts. Please try to use post modules instead.
Runs a meterpreter script.
381 382 383 |
# File 'lib/msf/core/rpc/v10/rpc_session.rb', line 381 def rpc_meterpreter_script( sid, data) rpc_meterpreter_run_single( sid, "run #{data}") end |
#rpc_meterpreter_session_detach(sid) ⇒ Hash
Detaches from a meterpreter session. Serves the same purpose as [CTRL]+.
292 293 294 295 296 297 298 299 300 301 |
# File 'lib/msf/core/rpc/v10/rpc_session.rb', line 292 def rpc_meterpreter_session_detach(sid) s = _valid_session(sid,"meterpreter") s.channels.each_value do |ch| if(ch.respond_to?('interacting') && ch.interacting) ch.detach() return { "result" => "success" } end end { "result" => "failure" } end |
#rpc_meterpreter_session_kill(sid) ⇒ Hash
Kills a meterpreter session. Serves the same purpose as [CTRL]+.
* 'result' [String] Either 'success' or 'failure'.
315 316 317 318 319 320 321 322 323 324 |
# File 'lib/msf/core/rpc/v10/rpc_session.rb', line 315 def rpc_meterpreter_session_kill(sid) s = _valid_session(sid,"meterpreter") s.channels.each_value do |ch| if(ch.respond_to?('interacting') && ch.interacting) ch._close return { "result" => "success" } end end { "result" => "failure" } end |
#rpc_meterpreter_tabs(sid, line) ⇒ Hash
Returns a tab-completed version of your meterpreter prompt input.
340 341 342 343 |
# File 'lib/msf/core/rpc/v10/rpc_session.rb', line 340 def rpc_meterpreter_tabs(sid, line) s = _valid_session(sid,"meterpreter") { "tabs" => s.console.tab_complete(line) } end |
#rpc_meterpreter_transport_change(sid, opts = {}) ⇒ Boolean
Changes the Transport of a given Meterpreter Session
403 404 405 406 407 408 409 410 411 412 413 414 415 |
# File 'lib/msf/core/rpc/v10/rpc_session.rb', line 403 def rpc_meterpreter_transport_change(sid,opts={}) session = _valid_session(sid,"meterpreter") real_opts = {} opts.each_pair do |key, value| real_opts[key.to_sym] = value end real_opts[:uuid] = session.payload_uuid result = session.core.transport_change(real_opts) if result == true rpc_stop(sid) end result end |
#rpc_meterpreter_write(sid, data) ⇒ Hash
Multiple concurrent callers writing and reading the same Meterperter session can lead to a conflict, where one caller gets the others output and vice versa. Concurrent access to a Meterpreter session is best handled by post modules.
Sends an input to a meterpreter prompt. You may want to use #rpc_meterpreter_read to retrieve the output.
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/msf/core/rpc/v10/rpc_session.rb', line 262 def rpc_meterpreter_write( sid, data) s = _valid_session(sid,"meterpreter") if not s.user_output.respond_to? :dump_buffer s.init_ui(Rex::Ui::Text::Input::Buffer.new, Rex::Ui::Text::Output::Buffer.new) end interacting = false s.channels.each_value do |ch| interacting ||= ch.respond_to?('interacting') && ch.interacting end if interacting s.user_input.put(data + "\n") else self.framework.threads.spawn("MeterpreterRunSingle", false, s) { |sess| sess.console.run_single(data) } end { "result" => "success" } end |
#rpc_ring_clear(sid) ⇒ Hash
Clears a shell session. This may be useful to reclaim memory for idle background sessions.
241 242 243 |
# File 'lib/msf/core/rpc/v10/rpc_session.rb', line 241 def rpc_ring_clear(sid) { "result" => "success" } end |
#rpc_ring_last(sid) ⇒ Hash
Returns the last sequence (last issued ReadPointer) for a shell session.
225 226 227 228 |
# File 'lib/msf/core/rpc/v10/rpc_session.rb', line 225 def rpc_ring_last(sid) s = _valid_session(sid,"ring") { "seq" => 0 } end |
#rpc_ring_put(sid, data) ⇒ Hash
Sends an input to a session (such as a command).
205 206 207 208 209 210 211 212 213 |
# File 'lib/msf/core/rpc/v10/rpc_session.rb', line 205 def rpc_ring_put(sid, data) s = _valid_session(sid,"ring") begin res = s.shell_write(data) { "write_count" => res.to_s} rescue ::Exception => e error(500, "Session Disconnected: #{e.class} #{e}") end end |
#rpc_ring_read(sid, ptr = nil) ⇒ Hash
Reads from a session (such as a command output).
182 183 184 185 186 187 188 189 190 |
# File 'lib/msf/core/rpc/v10/rpc_session.rb', line 182 def rpc_ring_read(sid, ptr = nil) s = _valid_session(sid,"ring") begin res = s.shell_read() { "seq" => 0, "data" => res.to_s } rescue ::Exception => e error(500, "Session Disconnected: #{e.class} #{e}") end end |
#rpc_shell_read(sid, ptr = nil) ⇒ Hash
Reads the output of a shell session (such as a command output).
89 90 91 92 93 94 95 96 97 |
# File 'lib/msf/core/rpc/v10/rpc_session.rb', line 89 def rpc_shell_read( sid, ptr=nil) s = _valid_session(sid,"shell") begin res = s.shell_read() { "seq" => 0, "data" => res.to_s} rescue ::Exception => e error(500, "Session Disconnected: #{e.class} #{e}") end end |
#rpc_shell_upgrade(sid, lhost, lport) ⇒ Hash
This uses post/multi/manage/shell_to_meterpreter.
Upgrades a shell to a meterpreter.
135 136 137 138 139 140 141 |
# File 'lib/msf/core/rpc/v10/rpc_session.rb', line 135 def rpc_shell_upgrade( sid, lhost, lport) s = _valid_session(sid,"shell") s.exploit_datastore['LHOST'] = lhost s.exploit_datastore['LPORT'] = lport s.execute_script('post/multi/manage/shell_to_meterpreter') { "result" => "success" } end |
#rpc_shell_write(sid, data) ⇒ Hash
Writes to a shell session (such as a command). Note that you will to manually add a newline at the enf of your input so the system will process it. You may want to use #rpc_shell_read to retrieve the output.
114 115 116 117 118 119 120 121 122 |
# File 'lib/msf/core/rpc/v10/rpc_session.rb', line 114 def rpc_shell_write( sid, data) s = _valid_session(sid,"shell") begin res = s.shell_write(data) { "write_count" => res.to_s} rescue ::Exception => e error(500, "Session Disconnected: #{e.class} #{e}") end end |
#rpc_stop(sid) ⇒ Hash
Stops a session.
65 66 67 68 69 70 71 72 73 |
# File 'lib/msf/core/rpc/v10/rpc_session.rb', line 65 def rpc_stop( sid) s = self.framework.sessions[sid.to_i] if(not s) error(500, "Unknown Session ID") end s.kill rescue nil { "result" => "success" } end |