diff --git a/lib/msf/core/handler/reverse_https.rb b/lib/msf/core/handler/reverse_https.rb index 8e36c8d16b..772c63b39b 100644 --- a/lib/msf/core/handler/reverse_https.rb +++ b/lib/msf/core/handler/reverse_https.rb @@ -89,11 +89,10 @@ module ReverseHttps Rex::ServiceManager.stop_service(service) end + attr_accessor :service # :nodoc: protected - attr_accessor :service # :nodoc: - # # Parses the HTTPS request # @@ -125,10 +124,13 @@ protected # Short-circuit the payload's handle_connection processing for create_session create_session(cli, { :skip_ssl => true, :target_id => target_id }) + # Specify this socket as keep-alive to prevent an immediate kill + cli.keepalive = true # Remove this socket from the polled client list in the server - obj.service.clients.delete(cli) + obj.service.listener.clients.delete(cli) + cli.instance_eval("def close; $stderr.puts caller.inspect; end") return else diff --git a/lib/rex/io/stream_server.rb b/lib/rex/io/stream_server.rb index 6553df143e..10040bffa9 100644 --- a/lib/rex/io/stream_server.rb +++ b/lib/rex/io/stream_server.rb @@ -96,20 +96,20 @@ module StreamServer end end end - + # # This method waits on the server listener thread # def wait self.listener_thread.join if self.listener_thread - end + end ## # # Callback procedures. # ## - + # # This callback procedure can be set and will be called when new clients # connect. @@ -126,17 +126,17 @@ module StreamServer # attr_accessor :on_client_close_proc -protected - attr_accessor :clients # :nodoc: attr_accessor :listener_thread, :clients_thread # :nodoc: +protected + # # This method monitors the listener socket for new connections and calls # the +on_client_connect+ callback routine. # def monitor_listener - + begin sd = Kernel.select([ fd ], nil, nil, 0.25) @@ -151,7 +151,7 @@ protected self.clients << cli on_client_connect(cli) - + # Skip exceptions caused by accept() [ SSL ] rescue ::EOFError, ::Errno::ECONNRESET, ::Errno::ENOTCONN, ::Errno::ECONNABORTED end @@ -185,15 +185,15 @@ protected on_client_close(fd) close_client(fd) rescue ::Interrupt - raise $! + raise $! rescue ::Exception close_client(fd) elog("Error in stream server client monitor: #{$!}") rlog(ExceptionCallStack) - + end } - + rescue ::Rex::StreamClosedError => e # Remove the closed stream from the list clients.delete(e.stream) @@ -201,11 +201,12 @@ protected raise $! rescue ::Exception elog("Error in stream server client monitor: #{$!}") - rlog(ExceptionCallStack) + rlog(ExceptionCallStack) end while true end end -end end +end + diff --git a/lib/rex/proto/http/server.rb b/lib/rex/proto/http/server.rb index 48e25f08d5..123512ab4f 100644 --- a/lib/rex/proto/http/server.rb +++ b/lib/rex/proto/http/server.rb @@ -255,11 +255,10 @@ class Server end attr_accessor :listen_port, :listen_host, :server_name, :context, :ssl + attr_accessor :listener, :resources protected - attr_accessor :listener, :resources - # # Extends new clients with the ServerClient module and initializes them. #