Files
metasploit-gs/lib/msf/base/sessions/command_shell.rb
T

86 lines
1.2 KiB
Ruby
Raw Normal View History

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
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-11-15 15:11:43 +00:00
# The shell will have been initialized by default.
#
def init_shell
return true
end
#
2005-11-15 15:11:43 +00:00
# Read from the command shell.
#
def read_shell(length = nil)
if length.nil?
rv = rstream.get
else
rv = rstream.read(length)
end
return rv
end
#
2005-11-15 15:11:43 +00:00
# Writes to the command shell.
#
def write_shell(buf)
rstream.write(buf)
end
#
2005-11-15 15:11:43 +00:00
# Closes the shell.
#
def close_shell()
rstream.close
end
end
end
2008-10-19 21:03:39 +00:00
end