Files
metasploit-gs/lib/msf/core/session/interactive.rb
T

129 lines
1.8 KiB
Ruby
Raw Normal View History

2005-09-24 18:02:24 +00:00
require 'rex/ui'
module Msf
module Session
###
#
# This class implements the stubs that are needed to provide an interactive
# session.
#
###
module Interactive
2005-07-17 07:06:05 +00:00
#
# Interactive sessions by default may interact with the local user input
# and output.
#
include Rex::Ui::Interactive
2005-07-17 07:06:05 +00:00
2005-07-18 04:07:56 +00:00
#
2005-11-15 15:11:43 +00:00
# Initializes the session.
2005-07-18 04:07:56 +00:00
#
def initialize(rstream)
self.rstream = rstream
end
#
# Returns that, yes, indeed, this session supports going interactive with
# the user.
#
def interactive?
true
end
#
2005-11-15 15:11:43 +00:00
# Returns the local information.
2005-07-18 04:07:56 +00:00
#
def tunnel_local
rstream.localinfo
end
#
2005-11-15 15:11:43 +00:00
# Returns the remote peer information.
2005-07-18 04:07:56 +00:00
#
def tunnel_peer
2005-11-03 00:18:12 +00:00
begin
rstream.peerinfo
rescue
framework.sessions.deregister(self)
2005-11-03 00:18:12 +00:00
end
2005-07-18 04:07:56 +00:00
end
#
# Run an arbitrary command as if it came from user input.
#
def run_cmd(cmd)
end
2005-07-18 04:07:56 +00:00
#
# Terminate the session
#
def kill
self.interacting = false if self.interactive?
self.reset_ui
self.cleanup
super()
end
2005-07-18 04:07:56 +00:00
#
# Closes rstream.
#
def cleanup
2005-12-12 07:07:19 +00:00
begin
rstream.close if (rstream)
rescue
end
2005-07-18 04:07:56 +00:00
rstream = nil
end
#
# The remote stream handle. Must inherit from Rex::IO::Stream.
#
attr_accessor :rstream
protected
2005-07-18 04:07:56 +00:00
#
2005-11-15 15:11:43 +00:00
# Stub method that is meant to handler interaction.
2005-07-18 04:07:56 +00:00
#
def _interact
end
#
2005-11-15 15:11:43 +00:00
# Check to see if the user wants to abort.
#
def _interrupt
user_want_abort?
end
#
2005-11-15 15:11:43 +00:00
# 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.sessions.deregister(self)
end
#
2005-11-15 15:11:43 +00:00
# Checks to see if the user wants to abort.
#
def user_want_abort?
prompt_yesno("Abort session #{name}?")
end
end
end
end