Fix ruby 3.1 crashes when garbage collecting meterpreter resources
This commit is contained in:
@@ -199,6 +199,8 @@ class Framework
|
||||
#
|
||||
# @return [Metasploit::Framework::DataService::DataProxy]
|
||||
def db
|
||||
return @db if @db
|
||||
|
||||
synchronize {
|
||||
@db ||= get_db
|
||||
}
|
||||
@@ -209,6 +211,8 @@ class Framework
|
||||
#
|
||||
# @return [Msf::SessionManager]
|
||||
def sessions
|
||||
return @sessions if @sessions
|
||||
|
||||
synchronize {
|
||||
@sessions ||= Msf::SessionManager.new(self)
|
||||
}
|
||||
@@ -219,6 +223,8 @@ class Framework
|
||||
#
|
||||
# @return [Msf::ThreadManager]
|
||||
def threads
|
||||
return @threads if @threads
|
||||
|
||||
synchronize {
|
||||
@threads ||= Msf::ThreadManager.new(self)
|
||||
}
|
||||
|
||||
@@ -153,11 +153,16 @@ class Channel
|
||||
def self.finalize(client, cid)
|
||||
proc {
|
||||
unless cid.nil?
|
||||
begin
|
||||
self._close(client, cid)
|
||||
rescue => e
|
||||
elog("finalize method for Channel failed", error: e)
|
||||
deferred_close_proc = proc do
|
||||
begin
|
||||
self._close(client, cid)
|
||||
rescue => e
|
||||
elog("finalize method for Channel failed", error: e)
|
||||
end
|
||||
end
|
||||
|
||||
# Schedule the finalizing logic out-of-band; as this logic might be called in the context of a Signal.trap, which can't synchronize mutexes
|
||||
client.framework.sessions.schedule(deferred_close_proc)
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
@@ -67,11 +67,16 @@ class EventLog
|
||||
|
||||
def self.finalize(client,handle)
|
||||
proc do
|
||||
begin
|
||||
self.close(client,handle)
|
||||
rescue => e
|
||||
elog("finalize method for EventLog failed", error: e)
|
||||
deferred_close_proc = proc do
|
||||
begin
|
||||
self.close(client,handle)
|
||||
rescue => e
|
||||
elog("finalize method for EventLog failed", error: e)
|
||||
end
|
||||
end
|
||||
|
||||
# Schedule the finalizing logic out-of-band; as this logic might be called in the context of a Signal.trap, which can't synchronize mutexes
|
||||
client.framework.sessions.schedule(deferred_close_proc)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -337,11 +337,16 @@ class Process < Rex::Post::Process
|
||||
|
||||
def self.finalize(client, handle)
|
||||
proc do
|
||||
begin
|
||||
self.close(client, handle)
|
||||
rescue => e
|
||||
elog("finalize method for Process failed", error: e)
|
||||
deferred_close_proc = proc do
|
||||
begin
|
||||
self.close(client, handle)
|
||||
rescue => e
|
||||
elog("finalize method for Process failed", error: e)
|
||||
end
|
||||
end
|
||||
|
||||
# Schedule the finalizing logic out-of-band; as this logic might be called in the context of a Signal.trap, which can't synchronize mutexes
|
||||
client.framework.sessions.schedule(deferred_close_proc)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -366,7 +371,7 @@ class Process < Rex::Post::Process
|
||||
request = Packet.create_request(COMMAND_ID_STDAPI_SYS_PROCESS_CLOSE)
|
||||
request.add_tlv(TLV_TYPE_HANDLE, handle)
|
||||
client.send_request(request, nil)
|
||||
handle = nil;
|
||||
handle = nil
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
@@ -36,11 +36,16 @@ class RegistryKey
|
||||
|
||||
def self.finalize(client,hkey)
|
||||
proc do
|
||||
begin
|
||||
self.close(client,hkey)
|
||||
rescue => e
|
||||
elog("finalize method for RegistryKey failed", error: e)
|
||||
deferred_close_proc = proc do
|
||||
begin
|
||||
self.close(client,hkey)
|
||||
rescue => e
|
||||
elog("finalize method for RegistryKey failed", error: e)
|
||||
end
|
||||
end
|
||||
|
||||
# Schedule the finalizing logic out-of-band; as this logic might be called in the context of a Signal.trap, which can't synchronize mutexes
|
||||
client.framework.sessions.schedule(deferred_close_proc)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
+10
-4
@@ -35,11 +35,17 @@ class RemoteRegistryKey
|
||||
|
||||
def self.finalize(client, hkey)
|
||||
proc do
|
||||
begin
|
||||
self.close(client, hkey)
|
||||
rescue => e
|
||||
elog("finalize method for RemoteRegistryKey failed", error: e)
|
||||
# Schedule the finalizing logic out-of-band; as this logic might be called in the context of a Signal.trap, which can't synchronize mutexes
|
||||
client.framework.sessions.schedule do
|
||||
begin
|
||||
self.close(client, hkey)
|
||||
rescue => e
|
||||
elog("finalize method for RemoteRegistryKey failed", error: e)
|
||||
end
|
||||
end
|
||||
|
||||
# Schedule the finalizing logic out-of-band; as this logic might be called in the context of a Signal.trap, which can't synchronize mutexes
|
||||
client.framework.sessions.schedule(deferred_close_proc)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -41,11 +41,16 @@ class Thread < Rex::Post::Thread
|
||||
|
||||
def self.finalize(client,handle)
|
||||
proc do
|
||||
begin
|
||||
self.close(client, handle)
|
||||
rescue => e
|
||||
elog("finalize method for thread failed", error: e)
|
||||
deferred_close_proc = proc do
|
||||
begin
|
||||
self.close(client, handle)
|
||||
rescue => e
|
||||
elog("finalize method for thread failed", error: e)
|
||||
end
|
||||
end
|
||||
|
||||
# Schedule the finalizing logic out-of-band; as this logic might be called in the context of a Signal.trap, which can't synchronize mutexes
|
||||
client.framework.sessions.schedule(deferred_close_proc)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user