Further progress towards mobile sessions
git-svn-id: file:///home/svn/framework3/trunk@4425 4d416f70-5f16-0410-b530-b9f4589650daunstable
parent
80c4bcd5ab
commit
075b3c1c82
|
@ -662,13 +662,9 @@ class Core
|
||||||
print_status("Starting interaction with #{session.name}...\n") if (quiet == false)
|
print_status("Starting interaction with #{session.name}...\n") if (quiet == false)
|
||||||
|
|
||||||
self.active_session = session
|
self.active_session = session
|
||||||
|
|
||||||
# Set the session's input and output handles
|
|
||||||
session.init_ui(driver.input.dup, driver.output)
|
|
||||||
|
|
||||||
# Interact
|
session.interact(driver.input.dup, driver.output)
|
||||||
session.interact()
|
|
||||||
|
|
||||||
self.active_session = nil
|
self.active_session = nil
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
|
@ -24,13 +24,10 @@ 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
|
||||||
|
|
||||||
|
|
|
@ -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?
|
||||||
return if ses.user_output.has_subscriber?('session_reader')
|
if (ses.user_output)
|
||||||
|
return if ses.user_output.has_subscriber?('session_reader')
|
||||||
# Detach session if necessary
|
end
|
||||||
ses.detach()
|
|
||||||
|
|
||||||
# Create a new pipe
|
# Create a new pipe
|
||||||
spipe = WebConsole::WebConsolePipe.new
|
spipe = WebConsole::WebConsolePipe.new
|
||||||
|
@ -113,13 +114,9 @@ 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
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
@ -71,15 +73,16 @@ module Interactive
|
||||||
# Shutdown the readline thread
|
# Shutdown the readline thread
|
||||||
# XXX disabled
|
# XXX disabled
|
||||||
# user_input.readline_stop() if user_input.supports_readline
|
# user_input.readline_stop() if user_input.supports_readline
|
||||||
|
|
||||||
# Detach from the input/output handles
|
# Detach from the input/output handles
|
||||||
reset_ui()
|
reset_ui()
|
||||||
|
|
||||||
ensure
|
ensure
|
||||||
|
|
||||||
# Mark this as completed
|
# Mark this as completed
|
||||||
self.completed = true
|
self.completed = true
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return whether or not EOF was reached
|
# Return whether or not EOF was reached
|
||||||
return eof
|
return eof
|
||||||
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.
|
||||||
|
|
Loading…
Reference in New Issue