Further progress towards mobile sessions

git-svn-id: file:///home/svn/framework3/trunk@4425 4d416f70-5f16-0410-b530-b9f4589650da
unstable
HD Moore 2007-02-18 05:07:56 +00:00
parent 80c4bcd5ab
commit 075b3c1c82
4 changed files with 23 additions and 34 deletions

View File

@ -663,11 +663,7 @@ class Core
self.active_session = session self.active_session = session
# Set the session's input and output handles session.interact(driver.input.dup, driver.output)
session.init_ui(driver.input.dup, driver.output)
# Interact
session.interact()
self.active_session = nil self.active_session = nil

View File

@ -25,12 +25,9 @@ class Console < MyGlade
# Create the pipe interface # Create the pipe interface
@pipe = Rex::IO::BidirectionalPipe.new @pipe = Rex::IO::BidirectionalPipe.new
# Initialize the session
@session.init_ui(@pipe, @pipe)
# Start the session interaction # Start the session interaction
@t_run = Thread.new do @t_run = Thread.new do
@session.interact() @session.interact(@pipe, @pipe)
end end
# Create a subscriber with a callback for the UI # Create a subscriber with a callback for the UI
@ -46,9 +43,6 @@ class Console < MyGlade
# Kill the interaction thread # Kill the interaction thread
@t_run.kill @t_run.kill
# Reset the session UI handles
@session.reset_ui
# Close the pipes # Close the pipes
@pipe.close @pipe.close

View File

@ -85,12 +85,14 @@ class Driver < Msf::Ui::Driver
def write_session(id, buf) def write_session(id, buf)
ses = self.framework.sessions[id] ses = self.framework.sessions[id]
return if not ses return if not ses
return if not ses.user_input
ses.user_input.put(buf) ses.user_input.put(buf)
end end
def read_session(id) def read_session(id)
ses = self.framework.sessions[id] ses = self.framework.sessions[id]
return if not ses return if not ses
return if not ses.user_output
ses.user_output.read_subscriber('session_reader') ses.user_output.read_subscriber('session_reader')
end end
@ -102,10 +104,9 @@ class Driver < Msf::Ui::Driver
return if not ses return if not ses
# Has this session already been detached? # Has this session already been detached?
if (ses.user_output)
return if ses.user_output.has_subscriber?('session_reader') return if ses.user_output.has_subscriber?('session_reader')
end
# Detach session if necessary
ses.detach()
# Create a new pipe # Create a new pipe
spipe = WebConsole::WebConsolePipe.new spipe = WebConsole::WebConsolePipe.new
@ -114,12 +115,8 @@ class Driver < Msf::Ui::Driver
# Create a read subscriber # Create a read subscriber
spipe.create_subscriber('session_reader') spipe.create_subscriber('session_reader')
# Replace the input/output handles
ses.user_input = spipe.input
ses.user_output = spipe
Thread.new do Thread.new do
ses.interact ses.interact(spipe.input, spipe)
end end
end end

View File

@ -20,13 +20,15 @@ module Interactive
# forwarding input from user_input to rstream and forwarding input from # forwarding input from user_input to rstream and forwarding input from
# rstream to user_output. # rstream to user_output.
# #
def interact def interact(user_input, user_output)
# Prevent two thread from interacting at once # Detach from any existing console
if(self.interacting) if(self.interacting)
raise RuntimeError, "This session is already interacting with another console" detach()
end end
init_ui(user_input, user_output)
self.interacting = true self.interacting = true
self.completed = false self.completed = false
@ -76,6 +78,7 @@ module Interactive
reset_ui() reset_ui()
ensure ensure
# Mark this as completed # Mark this as completed
self.completed = true self.completed = true
end end
@ -90,9 +93,8 @@ module Interactive
def detach def detach
if (self.interacting) if (self.interacting)
self.interacting = false self.interacting = false
stime = Time.now.to_f while(not self.completed)
while(Time.now.to_f > stime + 5 and not self.completed) select(nil, nil, nil, 0.25)
select(nil, nil, nil, 0.10)
end end
end end
end end
@ -181,7 +183,7 @@ protected
while self.interacting while self.interacting
# Select input and rstream # Select input and rstream
sd = Rex::ThreadSafe.select([ _local_fd, _remote_fd(stream) ], nil, nil, 0.25) sd = Rex::ThreadSafe.select([ _local_fd, _remote_fd(stream) ], nil, nil, 0.50)
# Cycle through the items that have data # Cycle through the items that have data
# From the stream? Write to user_output. # From the stream? Write to user_output.