2005-07-16 07:32:11 +00:00
|
|
|
require 'msf/base'
|
|
|
|
|
|
|
|
module Msf
|
|
|
|
module Sessions
|
|
|
|
|
|
|
|
###
|
|
|
|
#
|
|
|
|
# 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 CommandShell
|
|
|
|
|
|
|
|
#
|
|
|
|
# This interface supports basic interaction.
|
|
|
|
#
|
|
|
|
include Msf::Session::Basic
|
|
|
|
|
|
|
|
#
|
|
|
|
# This interface supports interacting with a single command shell.
|
|
|
|
#
|
|
|
|
include Msf::Session::Provider::SingleCommandShell
|
|
|
|
|
2005-11-15 15:11:43 +00:00
|
|
|
#
|
|
|
|
# Returns the type of session.
|
|
|
|
#
|
2005-07-19 14:33:25 +00:00
|
|
|
def self.type
|
|
|
|
"shell"
|
|
|
|
end
|
|
|
|
|
2005-11-15 15:11:43 +00:00
|
|
|
#
|
|
|
|
# Returns the session description.
|
|
|
|
#
|
2005-07-16 08:12:58 +00:00
|
|
|
def desc
|
2005-07-16 16:06:44 +00:00
|
|
|
"Command shell"
|
2005-07-16 08:12:58 +00:00
|
|
|
end
|
|
|
|
|
2008-09-24 04:41:51 +00:00
|
|
|
def run_cmd(cmd)
|
|
|
|
write_shell(cmd)
|
|
|
|
return rstream.get
|
|
|
|
end
|
2005-11-15 15:11:43 +00:00
|
|
|
#
|
|
|
|
# Calls the class method.
|
|
|
|
#
|
2005-07-16 08:12:58 +00:00
|
|
|
def type
|
2005-07-19 14:33:25 +00:00
|
|
|
self.class.type
|
2005-07-16 08:12:58 +00:00
|
|
|
end
|
|
|
|
|
2005-07-16 07:32:11 +00:00
|
|
|
#
|
2005-11-15 15:11:43 +00:00
|
|
|
# The shell will have been initialized by default.
|
2005-07-16 07:32:11 +00:00
|
|
|
#
|
|
|
|
def init_shell
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
2005-11-15 15:11:43 +00:00
|
|
|
# Read from the command shell.
|
2005-07-16 07:32:11 +00:00
|
|
|
#
|
|
|
|
def read_shell(length = nil)
|
2008-09-24 04:41:51 +00:00
|
|
|
if length.nil?
|
|
|
|
rv = rstream.get
|
|
|
|
else
|
|
|
|
rv = rstream.read(length)
|
|
|
|
end
|
|
|
|
return rv
|
2005-07-16 07:32:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
2005-11-15 15:11:43 +00:00
|
|
|
# Writes to the command shell.
|
2005-07-16 07:32:11 +00:00
|
|
|
#
|
|
|
|
def write_shell(buf)
|
|
|
|
rstream.write(buf)
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
2005-11-15 15:11:43 +00:00
|
|
|
# Closes the shell.
|
2005-07-16 07:32:11 +00:00
|
|
|
#
|
|
|
|
def close_shell()
|
|
|
|
rstream.close
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2009-12-22 18:52:48 +00:00
|
|
|
end
|