Skip to content

Commit 4d58e49

Browse files
author
HD Moore
committed
Land rapid7#5600, update session info after migrate
2 parents 827d241 + 151fa2f commit 4d58e49

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

lib/msf/base/sessions/meterpreter.rb

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -319,25 +319,28 @@ def is_valid_session?(timeout=10)
319319
false
320320
end
321321

322+
def update_session_info
323+
username = self.sys.config.getuid
324+
sysinfo = self.sys.config.sysinfo
325+
326+
safe_info = "#{username} @ #{sysinfo['Computer']}"
327+
safe_info.force_encoding("ASCII-8BIT") if safe_info.respond_to?(:force_encoding)
328+
# Should probably be using Rex::Text.ascii_safe_hex but leave
329+
# this as is for now since "\xNN" is arguably uglier than "_"
330+
# showing up in various places in the UI.
331+
safe_info.gsub!(/[\x00-\x08\x0b\x0c\x0e-\x19\x7f-\xff]+/n,"_")
332+
self.info = safe_info
333+
end
334+
322335
#
323336
# Populate the session information.
324337
#
325338
# Also reports a session_fingerprint note for host os normalization.
326339
#
327-
def load_session_info()
340+
def load_session_info
328341
begin
329342
::Timeout.timeout(60) do
330-
# Gather username/system information
331-
username = self.sys.config.getuid
332-
sysinfo = self.sys.config.sysinfo
333-
334-
safe_info = "#{username} @ #{sysinfo['Computer']}"
335-
safe_info.force_encoding("ASCII-8BIT") if safe_info.respond_to?(:force_encoding)
336-
# Should probably be using Rex::Text.ascii_safe_hex but leave
337-
# this as is for now since "\xNN" is arguably uglier than "_"
338-
# showing up in various places in the UI.
339-
safe_info.gsub!(/[\x00-\x08\x0b\x0c\x0e-\x19\x7f-\xff]+/n,"_")
340-
self.info = safe_info
343+
update_session_info
341344

342345
hobj = nil
343346

lib/rex/post/meterpreter/ui/console/command_dispatcher/core.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,9 @@ def cmd_migrate(*args)
835835

836836
print_status("Migration completed successfully.")
837837

838+
# Update session info (we may have a new username)
839+
client.update_session_info
840+
838841
unless existing_relays.empty?
839842
print_status("Recreating TCP relay(s)...")
840843
existing_relays.each do |r|

0 commit comments

Comments
 (0)