@@ -59,7 +59,6 @@ def initialize(info = {})
5959 OptBool . new ( 'ReverseListenerThreaded' , [ true , 'Handle every connection in a new thread (experimental)' , false ] )
6060 ] , Msf ::Handler ::ReverseTcp )
6161
62- self . handler_queue = ::Queue . new
6362 self . conn_threads = [ ]
6463 end
6564
@@ -137,32 +136,41 @@ def cleanup_handler
137136 # Starts monitoring for an inbound connection.
138137 #
139138 def start_handler
139+ queue = ::Queue . new
140+
140141 local_port = bind_port
141- self . listener_thread = framework . threads . spawn ( "ReverseTcpHandlerListener-#{ local_port } " , false ) {
142- client = nil
143142
144- begin
143+ self . listener_thread = framework . threads . spawn ( "ReverseTcpHandlerListener-#{ local_port } " , false , queue ) { |lqueue |
144+ loop do
145145 # Accept a client connection
146146 begin
147147 client = self . listener_sock . accept
148- rescue
149- wlog ( "Exception raised during listener accept: #{ $!} \n \n #{ $@. join ( "\n " ) } " )
148+ if ! client
149+ wlog ( "ReverseTcpHandlerListener-#{ local_port } : No client received in call to accept, exiting..." )
150+ break
151+ end
152+
153+ self . pending_connections += 1
154+ lqueue . push ( client )
155+ rescue ::Exception
156+ wlog ( "ReverseTcpHandlerListener-#{ local_port } : Exception raised during listener accept: #{ $!} \n \n #{ $@. join ( "\n " ) } " )
150157 break
151158 end
152-
153- # Increment the has connection counter
154- self . pending_connections += 1
155-
156- self . handler_queue . push ( client )
157- end while true
159+ end
158160 }
159161
160- self . handler_thread = framework . threads . spawn ( "ReverseTcpHandlerWorker-#{ local_port } " , false ) {
161- while true
162- client = self . handler_queue . pop
162+ self . handler_thread = framework . threads . spawn ( "ReverseTcpHandlerWorker-#{ local_port } " , false , queue ) { |cqueue |
163+ loop do
163164 begin
165+ client = cqueue . pop
166+
167+ if ! client
168+ elog ( "ReverseTcpHandlerWorker-#{ local_port } : Queue returned an empty result, exiting..." )
169+ break
170+ end
171+
164172 if datastore [ 'ReverseListenerThreaded' ]
165- self . conn_threads << framework . threads . spawn ( "ReverseTcpHandlerSession-#{ local_port } -#{ client . peerhost } " , false , client ) { | client_copy |
173+ self . conn_threads << framework . threads . spawn ( "ReverseTcpHandlerSession-#{ local_port } -#{ client . peerhost } " , false , client ) { |client_copy |
166174 handle_connection ( wrap_aes_socket ( client_copy ) )
167175 }
168176 else
@@ -273,7 +281,6 @@ def bind_address
273281 attr_accessor :listener_sock # :nodoc:
274282 attr_accessor :listener_thread # :nodoc:
275283 attr_accessor :handler_thread # :nodoc:
276- attr_accessor :handler_queue # :nodoc:
277284 attr_accessor :conn_threads # :nodoc:
278285end
279286
0 commit comments