2005-07-16 07:32:11 +00:00
|
|
|
module Msf
|
|
|
|
module Session
|
|
|
|
|
|
|
|
###
|
|
|
|
#
|
|
|
|
# Interactive
|
|
|
|
# -----------
|
|
|
|
#
|
|
|
|
# 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::Subscriber
|
|
|
|
|
2005-07-16 07:32:11 +00:00
|
|
|
#
|
|
|
|
# Returns that, yes, indeed, this session supports going interactive with
|
|
|
|
# the user.
|
|
|
|
#
|
|
|
|
def interactive?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Starts interacting with the session.
|
|
|
|
#
|
|
|
|
def interact
|
2005-07-17 02:04:39 +00:00
|
|
|
self.interacting = true
|
2005-07-16 07:32:11 +00:00
|
|
|
end
|
|
|
|
|
2005-07-17 02:04:39 +00:00
|
|
|
#
|
|
|
|
# Whether or not the session is currently being interacted with
|
|
|
|
#
|
|
|
|
attr_reader :interacting
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
attr_writer :interacting
|
|
|
|
#
|
|
|
|
# The original suspend proc.
|
|
|
|
#
|
|
|
|
attr_accessor :orig_suspend
|
|
|
|
|
|
|
|
#
|
|
|
|
# Checks to see if the user wants to abort
|
|
|
|
#
|
|
|
|
def user_want_abort?
|
|
|
|
prompt_yesno("Abort session #{name}? [y/N] ")
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Installs a signal handler to monitor suspend signal notifications.
|
|
|
|
#
|
|
|
|
def handle_suspend
|
|
|
|
if (orig_suspend == nil)
|
|
|
|
self.orig_suspend = Signal.trap("TSTP") {
|
|
|
|
# Ask the user if they would like to background the session
|
|
|
|
if (prompt_yesno("Background session #{name}? [y/N] ") == true)
|
|
|
|
self.interacting = false
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Restores the previously installed signal handler for suspend
|
|
|
|
# notifications.
|
|
|
|
#
|
|
|
|
def restore_suspend
|
|
|
|
if (orig_suspend)
|
|
|
|
Signal.trap("TSTP", orig_suspend)
|
|
|
|
|
|
|
|
self.orig_suspend = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def prompt(query)
|
2005-07-17 07:06:05 +00:00
|
|
|
if (user_output and user_input)
|
|
|
|
user_output.print("\n" + query)
|
|
|
|
user_input.gets
|
|
|
|
end
|
2005-07-17 02:04:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Check the return value of the prompt
|
|
|
|
#
|
|
|
|
def prompt_yesno(query)
|
|
|
|
(prompt(query) =~ /^y/i) ? true : false
|
|
|
|
end
|
2005-07-16 07:32:11 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|