2012-06-29 05:18:28 +00:00
|
|
|
# -*- coding: binary -*-
|
2011-05-12 20:03:55 +00:00
|
|
|
require 'rex/ui'
|
|
|
|
require 'rex/io/ring_buffer'
|
2005-09-24 18:02:24 +00:00
|
|
|
|
2005-07-16 07:32:11 +00:00
|
|
|
module Msf
|
|
|
|
module Session
|
|
|
|
|
|
|
|
###
|
|
|
|
#
|
|
|
|
# This class implements the stubs that are needed to provide an interactive
|
|
|
|
# session.
|
|
|
|
#
|
|
|
|
###
|
|
|
|
module Interactive
|
|
|
|
|
2013-08-30 21:28:33 +00:00
|
|
|
#
|
|
|
|
# Interactive sessions by default may interact with the local user input
|
|
|
|
# and output.
|
|
|
|
#
|
|
|
|
include Rex::Ui::Interactive
|
|
|
|
|
|
|
|
#
|
|
|
|
# Initializes the session.
|
|
|
|
#
|
|
|
|
def initialize(rstream, opts={})
|
|
|
|
# A nil is passed in the case of non-stream interactive sessions (Meterpreter)
|
|
|
|
if rstream
|
|
|
|
self.rstream = rstream
|
|
|
|
self.ring = Rex::IO::RingBuffer.new(rstream, {:size => opts[:ring_size] || 100 })
|
|
|
|
end
|
|
|
|
super()
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Returns that, yes, indeed, this session supports going interactive with
|
|
|
|
# the user.
|
|
|
|
#
|
|
|
|
def interactive?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Returns the local information.
|
|
|
|
#
|
|
|
|
def tunnel_local
|
|
|
|
return @local_info if @local_info
|
|
|
|
begin
|
|
|
|
@local_info = rstream.localinfo
|
|
|
|
rescue ::Exception
|
|
|
|
@local_info = '127.0.0.1'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Returns the remote peer information.
|
|
|
|
#
|
|
|
|
def tunnel_peer
|
|
|
|
return @peer_info if @peer_info
|
|
|
|
begin
|
|
|
|
@peer_info = rstream.peerinfo
|
|
|
|
rescue ::Exception
|
|
|
|
@peer_info = '127.0.0.1'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Run an arbitrary command as if it came from user input.
|
|
|
|
#
|
|
|
|
def run_cmd(cmd)
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Terminate the session
|
|
|
|
#
|
|
|
|
def kill
|
|
|
|
self.reset_ui
|
|
|
|
self.cleanup
|
|
|
|
super()
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Closes rstream.
|
|
|
|
#
|
|
|
|
def cleanup
|
|
|
|
begin
|
|
|
|
self.interacting = false if self.interactive?
|
|
|
|
rstream.close if (rstream)
|
|
|
|
rescue ::Exception
|
|
|
|
end
|
|
|
|
|
|
|
|
rstream = nil
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# The remote stream handle. Must inherit from Rex::IO::Stream.
|
|
|
|
#
|
|
|
|
attr_accessor :rstream
|
|
|
|
|
|
|
|
#
|
|
|
|
# The RingBuffer object used to allow concurrent access to this session
|
|
|
|
#
|
|
|
|
attr_accessor :ring
|
2005-07-17 02:04:39 +00:00
|
|
|
|
|
|
|
protected
|
|
|
|
|
2013-08-30 21:28:33 +00:00
|
|
|
#
|
|
|
|
# Stub method that is meant to handler interaction.
|
|
|
|
#
|
|
|
|
def _interact
|
|
|
|
framework.events.on_session_interact(self)
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Check to see if the user wants to abort.
|
|
|
|
#
|
|
|
|
def _interrupt
|
|
|
|
begin
|
|
|
|
user_want_abort?
|
|
|
|
rescue Interrupt
|
|
|
|
# The user hit ctrl-c while we were handling a ctrl-c. Ignore
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Check to see if we should suspend.
|
|
|
|
#
|
|
|
|
def _suspend
|
|
|
|
# Ask the user if they would like to background the session
|
|
|
|
if (prompt_yesno("Background session #{name}?") == true)
|
|
|
|
self.interacting = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# If the session reaches EOF, deregister it.
|
|
|
|
#
|
|
|
|
def _interact_complete
|
|
|
|
framework.events.on_session_interact_completed()
|
|
|
|
framework.sessions.deregister(self, "User exit")
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Checks to see if the user wants to abort.
|
|
|
|
#
|
|
|
|
def user_want_abort?
|
|
|
|
prompt_yesno("Abort session #{name}?")
|
|
|
|
end
|
2005-07-16 07:32:11 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2009-12-22 18:52:48 +00:00
|
|
|
end
|
2010-03-21 04:24:27 +00:00
|
|
|
|