Fix ruby 3.1 crashes when garbage collecting meterpreter resources

This commit is contained in:
adfoster-r7
2023-05-05 13:50:38 +01:00
parent 41c75c2e30
commit 069ad805c1
7 changed files with 62 additions and 25 deletions
+6
View File
@@ -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)
}
+9 -4
View File
@@ -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
@@ -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