@@ -59,7 +59,6 @@ def initialize(info = {})
59
59
OptBool . new ( 'ReverseListenerThreaded' , [ true , 'Handle every connection in a new thread (experimental)' , false ] )
60
60
] , Msf ::Handler ::ReverseTcp )
61
61
62
- self . handler_queue = ::Queue . new
63
62
self . conn_threads = [ ]
64
63
end
65
64
@@ -137,32 +136,41 @@ def cleanup_handler
137
136
# Starts monitoring for an inbound connection.
138
137
#
139
138
def start_handler
139
+ queue = ::Queue . new
140
+
140
141
local_port = bind_port
141
- self . listener_thread = framework . threads . spawn ( "ReverseTcpHandlerListener-#{ local_port } " , false ) {
142
- client = nil
143
142
144
- begin
143
+ self . listener_thread = framework . threads . spawn ( "ReverseTcpHandlerListener-#{ local_port } " , false , queue ) { |lqueue |
144
+ loop do
145
145
# Accept a client connection
146
146
begin
147
147
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 " ) } " )
150
157
break
151
158
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
158
160
}
159
161
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
163
164
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
+
164
172
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 |
166
174
handle_connection ( wrap_aes_socket ( client_copy ) , { datastore : datastore } )
167
175
}
168
176
else
@@ -273,7 +281,6 @@ def bind_address
273
281
attr_accessor :listener_sock # :nodoc:
274
282
attr_accessor :listener_thread # :nodoc:
275
283
attr_accessor :handler_thread # :nodoc:
276
- attr_accessor :handler_queue # :nodoc:
277
284
attr_accessor :conn_threads # :nodoc:
278
285
end
279
286
0 commit comments