Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
FunnyWolf committed Mar 20, 2024
1 parent f09119a commit 9d0778b
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lib/rex/post/meterpreter/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,36 @@ def initialize(sock, opts={})
# Cleans up the meterpreter instance, terminating the dispatcher thread.
#
def cleanup_meterpreter
# clean portfwd config
service = self.pfservice

# If we have any open port forwards, we need to close them down
# otherwise we'll end up with local listeners which aren't connected
# to valid channels in the migrated meterpreter instance.
existing_relays = []

if service
service.each_tcp_relay do |lhost, lport, rhost, rport, opts|
next unless opts['MeterpreterRelay']
if existing_relays.empty?
print_status('Removing existing TCP relays...')
end
if (service.stop_tcp_relay(lport, lhost))
print_status("Successfully stopped TCP relay on #{lhost || '0.0.0.0'}:#{lport}")
existing_relays << {
:lport => lport,
:opts => opts
}
else
print_error("Failed to stop TCP relay on #{lhost || '0.0.0.0'}:#{lport}")
next
end
end
unless existing_relays.empty?
print_status("#{existing_relays.length} TCP relay(s) removed.")
end
end

if self.pivot_session
self.pivot_session.remove_pivot_session(self.session_guid)
end
Expand Down

0 comments on commit 9d0778b

Please sign in to comment.