Skip to content

Commit e7ba6e8

Browse files
author
HD Moore
committed
Speed up dead session cleanup by skipping shutdown/cleanup
1 parent 3080feb commit e7ba6e8

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

lib/msf/base/sessions/meterpreter.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,10 @@ def reset_ui
252252
#
253253
# Terminates the session
254254
#
255-
def kill
255+
def kill(dirty=false)
256256
begin
257-
cleanup_meterpreter
258-
self.sock.close
257+
cleanup_meterpreter(dirty)
258+
self.sock.close if self.sock
259259
rescue ::Exception
260260
end
261261
framework.sessions.deregister(self)

lib/msf/base/sessions/meterpreter_options.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ def on_session(session)
7575
end
7676
end
7777

78-
session.kill if not valid
78+
# Terminate the session without cleanup if it did not validate
79+
session.kill(true) if not valid
7980

8081
}
8182

lib/rex/post/meterpreter/client.rb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,19 @@ def initialize(sock,opts={})
8484
#
8585
# Cleans up the meterpreter instance, terminating the dispatcher thread.
8686
#
87-
def cleanup_meterpreter
88-
ext.aliases.each_value do | extension |
89-
extension.cleanup if extension.respond_to?( 'cleanup' )
87+
def cleanup_meterpreter(dirty)
88+
if not dirty
89+
ext.aliases.each_value do | extension |
90+
extension.cleanup if extension.respond_to?( 'cleanup' )
91+
end
9092
end
93+
9194
dispatcher_thread.kill if dispatcher_thread
92-
core.shutdown rescue nil
95+
96+
if not dirty
97+
core.shutdown rescue nil
98+
end
99+
93100
shutdown_passive_dispatcher
94101
end
95102

0 commit comments

Comments
 (0)