diff --git a/lib/msf/core/UnitTestSuite.rb b/lib/msf/core/UnitTestSuite.rb deleted file mode 100644 index addcffda3b..0000000000 --- a/lib/msf/core/UnitTestSuite.rb +++ /dev/null @@ -1,26 +0,0 @@ -require 'Msf/Core' - -module Msf -module Test - -### -# -# FrameworkCoreTestSuite -# ---------------------- -# -# This test suite is used to test the various core components of -# framework-core. -# -### -class FrameworkCoreTestSuite - def self.suite - suite = ::Test::Unit::TestSuite.new - - suite << Msf::Test::OptionContainerTestCase.suite - - return suite; - end -end - -end -end diff --git a/lib/msf/core/session.rb b/lib/msf/core/session.rb index 3e3f3161d4..05930ab550 100644 --- a/lib/msf/core/session.rb +++ b/lib/msf/core/session.rb @@ -41,62 +41,37 @@ end ### class Session - def initialize(framework, sid, stream = nil) - self.framework = framework - self.stream = stream - self.sid = sid - - # Call the framework event dispatcher to let it know that we've - # opened a new session - framework.events.on_session_open(self) + def initialize(conn = nil) + self.conn = conn end - # Read length supplied bytes from the stream + # + # Read length supplied bytes from the conn + # def read(length = nil) - return stream.read(length) + return conn.read(length) end - # Write the supplied buffer to the stream + # + # Write the supplied buffer to the conn + # def write(buf) - return stream.write(buf) + return conn.write(buf) end - # Close the session's stream and perform cleanup as necessary + # + # Close the session's conn and perform cleanup as necessary + # def close - # Call the framework event dispatcher to let it know that we've - # closed a session - framework.events.on_session_close(self) - - return stream.close + return conn.close end - attr_reader :sid, :stream + attr_reader :conn + attr_accessor :framework, :sid protected - attr_writer :sid, :stream - attr_accessor :framework -end - -# -# -# Built-in session classes -# -# - -### -# -# ShellSession -# ------------ -# -# This class represents a session that is associated with a command -# interpreter. Its read and write operations interact with whatever -# command interpreter it is backed against, whether it be local or -# otherwise. -# -### -class ShellSession < Session - + attr_writer :conn end end diff --git a/lib/msf/core/session_manager.rb b/lib/msf/core/session_manager.rb new file mode 100644 index 0000000000..ddca7139c1 --- /dev/null +++ b/lib/msf/core/session_manager.rb @@ -0,0 +1,86 @@ +module Msf + +### +# +# SessionManager +# -------------- +# +# The purpose of the session manager is to keep track of sessions that are +# created during the course of a framework instance's lifetime. When +# exploits succeed, the payloads they use will create a session object, +# where applicable, there will implement zero or more of the core +# supplied interfaces for interacting with that session. For instance, +# if the payload supports reading and writing from an executed process, +# the session would implement SimpleCommandShell in a method that is +# applicable to the way that the command interpreter is communicated +# with. +# +### +class SessionManager + + def initialize(framework) + self.framework = framework + self.sessions = {} + self.sid_pool = 0 + end + + # + # Returns the session object that is associated with the supplied sid + # + def [](sid) + return get(sid) + end + + # + # Registers the supplied session object with the framework and returns + # a unique session identifier to the caller. + # + def register(session) + if (session.sid) + wlog("registered session passed to register again (sid #{session.sid}).") + return nil + end + + next_sid = (sid_pool += 1) + + # Insert the session into the session hash table + sessions[next_sid] = session + + # Initialize the session's sid and framework instance pointer + session.sid = next_sid + session.framework = framework + + # Notify the framework that we have a new session opening up... + framework.events.on_session_open(session) + + return next_sid + end + + # + # Deregisters the supplied session object with the framework + # + def deregister(session) + # Tell the framework that we have a parting session + framework.events.on_session_close(session) + + # Remove it from the hash + sessions.delete(session.sid) + + # Close it down + session.close + end + + # + # Returns the session associated with the supplied sid, if any + # + def get(sid) + return sessions[sid] + end + +protected: + + attr_accessor :sid_pool, :sessions + +end + +end