lib/rex/post/meterpreter/packet_dispatcher.rb in librex-0.0.4 vs lib/rex/post/meterpreter/packet_dispatcher.rb in librex-0.0.5

- old
+ new

@@ -56,11 +56,22 @@ bytes = 0 raw = packet.to_r if (raw) - bytes = self.sock.write(raw) + begin + bytes = self.sock.write(raw) + rescue ::Exception => e + # Mark the session itself as dead + self.alive = false + + # Indicate that the dispatcher should shut down too + @finish = true + + # Reraise the error to the top-level caller + raise e + end end return bytes end @@ -127,10 +138,10 @@ self.alive = true # Spawn a thread for receiving packets self.receiver_thread = ::Thread.new do - while (true) + while (self.alive) begin rv = Rex::ThreadSafe.select([ self.sock.fd ], nil, nil, 0.25) ping_time = 60 # If there's nothing to read, and it's been awhile since we # saw a packet, we need to send a ping. We wait