Implements the readline workaround, tested with regular and meterpreter sessions
git-svn-id: file:///home/svn/framework3/trunk@5544 4d416f70-5f16-0410-b530-b9f4589650daunstable
parent
f056b9437f
commit
380aba15b0
|
@ -756,7 +756,9 @@ class Core
|
|||
|
||||
rescue IOError, EOFError, Rex::StreamClosedError
|
||||
print_status("Session stream closed.")
|
||||
rescue
|
||||
rescue ::Interrupt
|
||||
raise $!
|
||||
rescue ::Exception
|
||||
log_error("Session manipulation failed: #{$!} #{$!.backtrace.inspect}")
|
||||
end
|
||||
|
||||
|
|
|
@ -37,12 +37,16 @@ begin
|
|||
|
||||
def child_readline(wtr, prompt, history)
|
||||
$0 = "<readline>"
|
||||
|
||||
line = ::Readline.readline(prompt, history)
|
||||
line = "\n" if (line and line.strip.length == 0)
|
||||
|
||||
wtr.write(line || "exit\n")
|
||||
wtr.flush
|
||||
wtr.close
|
||||
exit(0)
|
||||
|
||||
# Self-destruct mechanism activated
|
||||
Process.kill(9, $$)
|
||||
end
|
||||
|
||||
#
|
||||
|
@ -57,7 +61,6 @@ begin
|
|||
#
|
||||
def sysread(len = 1)
|
||||
$stdin.sysread(len)
|
||||
|
||||
end
|
||||
|
||||
#
|
||||
|
@ -75,19 +78,15 @@ begin
|
|||
#
|
||||
def pgets
|
||||
|
||||
# if(Rex::Compat.is_windows())
|
||||
if(true)
|
||||
if(Rex::Compat.is_windows())
|
||||
output.prompting
|
||||
line = ::Readline.readline(prompt, true)
|
||||
HISTORY.pop if (line and line.empty?)
|
||||
return line
|
||||
end
|
||||
|
||||
# Wrap readline in a child process and secure with a mutex
|
||||
# This prevents threading hangs in the calling process.
|
||||
require "thread"
|
||||
@@child_mutex ||= Mutex.new
|
||||
@@child_mutex.synchronize do
|
||||
|
||||
line = ""
|
||||
|
||||
output.prompting
|
||||
|
||||
|
@ -111,6 +110,7 @@ begin
|
|||
|
||||
::Process.waitpid(pid, 0)
|
||||
|
||||
# Parse the results
|
||||
if line
|
||||
HISTORY.push(line) if (not line.empty?)
|
||||
return line + "\n"
|
||||
|
@ -119,8 +119,6 @@ begin
|
|||
return line
|
||||
end
|
||||
|
||||
# Release the readline mutex
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
|
|
Loading…
Reference in New Issue