diff --git a/lib/msf/ui/console/command_dispatcher/core.rb b/lib/msf/ui/console/command_dispatcher/core.rb index f56129093e..738b8214a3 100644 --- a/lib/msf/ui/console/command_dispatcher/core.rb +++ b/lib/msf/ui/console/command_dispatcher/core.rb @@ -643,7 +643,7 @@ class Core rescue IOError, EOFError, Rex::StreamClosedError print_status("Session stream closed.") rescue - log_error("Session manipulation failed: #{$!}") + log_error("Session manipulation failed: #{$!} #{$!.backtrace.inspect}") end return true diff --git a/lib/msf/ui/web/console.rb b/lib/msf/ui/web/console.rb index 59e1072354..519ffbaf90 100644 --- a/lib/msf/ui/web/console.rb +++ b/lib/msf/ui/web/console.rb @@ -18,58 +18,15 @@ class WebConsole class WebConsolePipe < Rex::IO::BidirectionalPipe - attr_accessor :input - attr_accessor :output - attr_accessor :prompt - attr_accessor :killed - - def intrinsic_shell? - true - end - - def supports_readline - false - end - - def _print_prompt - end - - - # - # Wrapper methods around input pipe - # - - - def close - self.pipe_input.close - end - - def put(*args) - self.pipe_input.put(*args) - end - - def gets - self.pipe_input.gets - end - - def pgets - self.pipe_input.gets - end - - def eof? - self.pipe_input.eof? - end - +=begin def fd(*args) # Remove the following line to enable full sessions via the console # We really should just hook the on_session() instead... raise ::RuntimeError, "Session interaction should be performed via the Sessions tab" self.pipe_input.fd(*args) end - - def sysread(*args) - self.pipe_input.sysread(*args) - end +=end + end # @@ -91,7 +48,6 @@ class WebConsole # Create a new pipe self.pipe = WebConsolePipe.new - self.pipe.input = self.pipe.pipe_input # Create a read subscriber self.pipe.create_subscriber('msfweb') diff --git a/lib/rex/io/bidirectional_pipe.rb b/lib/rex/io/bidirectional_pipe.rb index 505ba2988d..89d15360f7 100644 --- a/lib/rex/io/bidirectional_pipe.rb +++ b/lib/rex/io/bidirectional_pipe.rb @@ -12,6 +12,10 @@ class BidirectionalPipe < Rex::Ui::Text::Input @subscribers_ref = {} @subscribers_idx = 0 @pipe_input = Rex::Ui::Text::Input::Buffer.new + + # We are the shell, the input, and the output + self.output = self + self.input = self end def pipe_input @@ -64,8 +68,10 @@ class BidirectionalPipe < Rex::Ui::Text::Input @subscribers_ref[id] ? @subscribers_ref[id].call(msg) : buf.print(msg) rescue ::Exception => e $stderr.puts "Error handling subscriber #{id}: #{e.to_s} #{e.backtrace.inspect}" + raise e end } + msg end def print_error(msg) @@ -118,6 +124,9 @@ class BidirectionalPipe < Rex::Ui::Text::Input # # Wrappers for shell methods # + + attr_accessor :output, :prompt, :input + def intrinsic_shell? true end @@ -126,6 +135,10 @@ class BidirectionalPipe < Rex::Ui::Text::Input false end + def supports_color? + false + end + def pgets gets end diff --git a/lib/rex/ui/text/shell.rb b/lib/rex/ui/text/shell.rb index 8e42172238..675cfe758e 100644 --- a/lib/rex/ui/text/shell.rb +++ b/lib/rex/ui/text/shell.rb @@ -178,6 +178,8 @@ module Shell # console. # def supports_color? + return false + begin (ENV['TERM'].match(/(?:vt10[03]|xterm(?:-color)?|linux|screen)/i) != nil) rescue @@ -196,16 +198,14 @@ module Shell # Returns colorized text if it's supported, otherwise an empty string. # def colorize(*color) - # This check is busted atm... - #return (supports_color? == false) ? '' : Rex::Ui::Text::Color.ansi(color) return do_colorize(*color) end # - # Colorize regardless of terminal support. + # Colorize if this shell supports it # - def do_colorize(*color) - return Rex::Ui::Text::Color.ansi(*color) + def do_colorize(*color) + supports_color?() ? Rex::Ui::Text::Color.ansi(*color) : '' end # @@ -245,7 +245,6 @@ module Shell # def print(msg) return if (disable_output == true) - log_output(output.print(msg)) end