2010-10-08 19:36:34 +00:00
|
|
|
##
|
|
|
|
# $Id$
|
|
|
|
##
|
|
|
|
|
2009-01-13 07:02:02 +00:00
|
|
|
require 'msf/base'
|
|
|
|
|
|
|
|
module Msf
|
|
|
|
module Sessions
|
|
|
|
|
|
|
|
###
|
2010-10-08 19:36:34 +00:00
|
|
|
#
|
2009-01-13 07:02:02 +00:00
|
|
|
# This class provides basic interaction with a command shell on the remote
|
|
|
|
# endpoint. This session is initialized with a stream that will be used
|
|
|
|
# as the pipe for reading and writing the command shell.
|
|
|
|
#
|
|
|
|
###
|
|
|
|
class TTY
|
|
|
|
|
|
|
|
#
|
|
|
|
# This interface supports basic interaction.
|
|
|
|
#
|
|
|
|
include Msf::Session::Basic
|
|
|
|
|
|
|
|
#
|
|
|
|
# This interface supports interacting with a single command shell.
|
|
|
|
#
|
|
|
|
include Msf::Session::Provider::SingleCommandShell
|
|
|
|
|
|
|
|
#
|
|
|
|
# Returns the type of session.
|
|
|
|
#
|
|
|
|
def self.type
|
|
|
|
"tty"
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Returns the session description.
|
|
|
|
#
|
|
|
|
def desc
|
|
|
|
"Interactive TTY"
|
|
|
|
end
|
|
|
|
|
|
|
|
def run_cmd(cmd)
|
2010-02-24 01:19:59 +00:00
|
|
|
shell_write(cmd)
|
2009-01-13 07:02:02 +00:00
|
|
|
return rstream.get
|
|
|
|
end
|
|
|
|
#
|
|
|
|
# Calls the class method.
|
|
|
|
#
|
|
|
|
def type
|
|
|
|
self.class.type
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# The shell will have been initialized by default.
|
|
|
|
#
|
2010-02-24 01:19:59 +00:00
|
|
|
def shell_init
|
2009-01-13 07:02:02 +00:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Read from the command shell.
|
|
|
|
#
|
2010-02-24 01:19:59 +00:00
|
|
|
def shell_read(length = nil)
|
2009-01-13 07:02:02 +00:00
|
|
|
if length.nil?
|
|
|
|
rv = rstream.get
|
|
|
|
else
|
|
|
|
rv = rstream.read(length)
|
|
|
|
end
|
|
|
|
return rv
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Writes to the command shell.
|
|
|
|
#
|
2010-02-24 01:19:59 +00:00
|
|
|
def shell_write(buf)
|
2009-01-13 07:02:02 +00:00
|
|
|
rstream.write(buf)
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Closes the shell.
|
|
|
|
#
|
2010-02-24 01:19:59 +00:00
|
|
|
def shell_close()
|
2009-01-13 07:02:02 +00:00
|
|
|
rstream.close
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|