Implements the readline workaround, tested with regular and meterpreter sessions

git-svn-id: file:///home/svn/framework3/trunk@5544 4d416f70-5f16-0410-b530-b9f4589650da
unstable
HD Moore 2008-06-27 20:51:36 +00:00
parent f056b9437f
commit 380aba15b0
2 changed files with 15 additions and 15 deletions

View File

@ -756,7 +756,9 @@ class Core
rescue IOError, EOFError, Rex::StreamClosedError rescue IOError, EOFError, Rex::StreamClosedError
print_status("Session stream closed.") print_status("Session stream closed.")
rescue rescue ::Interrupt
raise $!
rescue ::Exception
log_error("Session manipulation failed: #{$!} #{$!.backtrace.inspect}") log_error("Session manipulation failed: #{$!} #{$!.backtrace.inspect}")
end end

View File

@ -37,12 +37,16 @@ begin
def child_readline(wtr, prompt, history) def child_readline(wtr, prompt, history)
$0 = "<readline>" $0 = "<readline>"
line = ::Readline.readline(prompt, history) line = ::Readline.readline(prompt, history)
line = "\n" if (line and line.strip.length == 0) line = "\n" if (line and line.strip.length == 0)
wtr.write(line || "exit\n") wtr.write(line || "exit\n")
wtr.flush wtr.flush
wtr.close wtr.close
exit(0)
# Self-destruct mechanism activated
Process.kill(9, $$)
end end
# #
@ -57,7 +61,6 @@ begin
# #
def sysread(len = 1) def sysread(len = 1)
$stdin.sysread(len) $stdin.sysread(len)
end end
# #
@ -75,19 +78,15 @@ begin
# #
def pgets def pgets
# if(Rex::Compat.is_windows()) if(Rex::Compat.is_windows())
if(true)
output.prompting output.prompting
line = ::Readline.readline(prompt, true) line = ::Readline.readline(prompt, true)
HISTORY.pop if (line and line.empty?) HISTORY.pop if (line and line.empty?)
return line return line
end end
# Wrap readline in a child process and secure with a mutex
# This prevents threading hangs in the calling process. line = ""
require "thread"
@@child_mutex ||= Mutex.new
@@child_mutex.synchronize do
output.prompting output.prompting
@ -111,6 +110,7 @@ begin
::Process.waitpid(pid, 0) ::Process.waitpid(pid, 0)
# Parse the results
if line if line
HISTORY.push(line) if (not line.empty?) HISTORY.push(line) if (not line.empty?)
return line + "\n" return line + "\n"
@ -119,8 +119,6 @@ begin
return line return line
end end
# Release the readline mutex
end
end end
# #