2012-06-29 05:18:28 +00:00
|
|
|
# -*- coding: binary -*-
|
2010-05-21 06:20:10 +00:00
|
|
|
|
|
|
|
###
|
|
|
|
#
|
|
|
|
# This module exposes a simple method to create an payload in an executable.
|
|
|
|
#
|
|
|
|
###
|
|
|
|
|
|
|
|
module Msf
|
|
|
|
module Exploit::EXE
|
|
|
|
|
|
|
|
def initialize(info = {})
|
|
|
|
super
|
|
|
|
|
2012-04-14 00:41:08 +00:00
|
|
|
# NOTE: Any new options here should also be dealt with in
|
|
|
|
# EncodedPayload#encoded_exe in lib/msf/core/encoded_payload.rb
|
2010-05-26 22:39:56 +00:00
|
|
|
register_advanced_options(
|
2010-05-21 06:20:10 +00:00
|
|
|
[
|
2012-01-09 16:58:18 +00:00
|
|
|
OptPath.new( 'EXE::Custom', [ false, 'Use custom exe instead of automatically generating a payload exe']),
|
2012-01-10 10:36:47 +00:00
|
|
|
OptPath.new( 'EXE::Path', [ false, 'The directory in which to look for the executable template' ]),
|
|
|
|
OptPath.new( 'EXE::Template', [ false, 'The executable template file name.' ]),
|
2010-09-21 00:13:30 +00:00
|
|
|
OptBool.new( 'EXE::Inject', [ false, 'Set to preserve the original EXE function' ]),
|
2010-09-21 02:34:43 +00:00
|
|
|
OptBool.new( 'EXE::OldMethod', [ false, 'Set to use the substitution EXE generation method.' ]),
|
2010-09-21 00:13:30 +00:00
|
|
|
OptBool.new( 'EXE::FallBack', [ false, 'Use the default template in case the specified one is missing' ])
|
2010-05-26 22:39:56 +00:00
|
|
|
], self.class)
|
2010-05-21 06:20:10 +00:00
|
|
|
end
|
|
|
|
|
2011-07-23 00:00:04 +00:00
|
|
|
def get_custom_exe
|
2012-01-10 10:36:47 +00:00
|
|
|
print_status("Using custom executable #{datastore["EXE::Custom"]}, RHOST and RPORT settings will be ignored!")
|
2011-07-23 14:04:40 +00:00
|
|
|
datastore['DisablePayloadHandler'] = true
|
2011-07-23 00:00:04 +00:00
|
|
|
file = ::File.open(datastore['EXE::Custom'],'rb')
|
2011-07-23 01:40:25 +00:00
|
|
|
exe = file.read(file.stat.size)
|
2011-07-23 00:00:04 +00:00
|
|
|
file.close
|
|
|
|
exe
|
|
|
|
end
|
|
|
|
|
2010-09-20 04:37:25 +00:00
|
|
|
def generate_payload_exe(opts = {})
|
2011-07-23 00:00:04 +00:00
|
|
|
return get_custom_exe if datastore.include? 'EXE::Custom'
|
|
|
|
|
2010-09-22 20:55:26 +00:00
|
|
|
exe_init_options(opts)
|
2010-05-21 06:20:10 +00:00
|
|
|
|
2010-09-22 20:55:26 +00:00
|
|
|
pl = opts[:code]
|
|
|
|
pl ||= payload.encoded
|
2010-05-26 22:39:56 +00:00
|
|
|
|
|
|
|
# Fall back to x86...
|
2010-09-23 01:43:42 +00:00
|
|
|
if not opts[:arch] or opts[:arch].length < 1
|
|
|
|
opts[:arch] = [ ARCH_X86 ]
|
|
|
|
end
|
2010-09-22 20:55:26 +00:00
|
|
|
# Ensure we have an array
|
|
|
|
if not opts[:arch].kind_of? Array
|
|
|
|
opts[:arch] = [ opts[:arch] ]
|
2010-05-21 06:20:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Transform the PlatformList
|
2010-09-22 20:55:26 +00:00
|
|
|
if (opts[:platform].kind_of? Msf::Module::PlatformList)
|
|
|
|
opts[:platform] = opts[:platform].platforms
|
2010-05-21 06:20:10 +00:00
|
|
|
end
|
|
|
|
|
2010-09-22 20:55:26 +00:00
|
|
|
exe = Msf::Util::EXE.to_executable(framework, opts[:arch], opts[:platform], pl, opts)
|
2010-09-21 00:13:30 +00:00
|
|
|
exe_post_generation(opts)
|
|
|
|
exe
|
|
|
|
end
|
|
|
|
|
|
|
|
def generate_payload_exe_service(opts = {})
|
2011-07-23 00:00:04 +00:00
|
|
|
return get_custom_exe if datastore.include? 'EXE::Custom'
|
|
|
|
|
2010-09-22 20:55:26 +00:00
|
|
|
exe_init_options(opts)
|
2010-09-21 00:13:30 +00:00
|
|
|
|
|
|
|
# NOTE: Only Windows is supported here.
|
|
|
|
pl = opts[:code]
|
|
|
|
pl ||= payload.encoded
|
|
|
|
|
|
|
|
if opts[:arch] and opts[:arch] == ARCH_X64
|
|
|
|
exe = Msf::Util::EXE.to_win64pe_service(framework, pl, opts)
|
|
|
|
else
|
|
|
|
exe = Msf::Util::EXE.to_win32pe_service(framework, pl, opts)
|
|
|
|
end
|
|
|
|
|
|
|
|
exe_post_generation(opts)
|
|
|
|
exe
|
|
|
|
end
|
|
|
|
|
|
|
|
def generate_payload_dll(opts = {})
|
2011-07-23 00:00:04 +00:00
|
|
|
return get_custom_exe if datastore.include? 'EXE::Custom'
|
|
|
|
|
2010-09-22 20:55:26 +00:00
|
|
|
exe_init_options(opts)
|
2010-09-21 00:13:30 +00:00
|
|
|
|
|
|
|
# NOTE: Only Windows is supported here.
|
|
|
|
pl = opts[:code]
|
|
|
|
pl ||= payload.encoded
|
|
|
|
|
|
|
|
if opts[:arch] and opts[:arch] == ARCH_X64
|
|
|
|
dll = Msf::Util::EXE.to_win64pe_dll(framework, pl, opts)
|
|
|
|
else
|
|
|
|
dll = Msf::Util::EXE.to_win32pe_dll(framework, pl, opts)
|
|
|
|
end
|
|
|
|
|
|
|
|
exe_post_generation(opts)
|
|
|
|
dll
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
2010-09-22 20:55:26 +00:00
|
|
|
def exe_init_options(opts)
|
2010-09-21 00:13:30 +00:00
|
|
|
opts.merge!(
|
|
|
|
{
|
|
|
|
:template_path => datastore['EXE::Path'],
|
|
|
|
:template => datastore['EXE::Template'],
|
|
|
|
:inject => datastore['EXE::Inject'],
|
2010-09-21 02:34:43 +00:00
|
|
|
:fallback => datastore['EXE::FallBack'],
|
2010-09-21 02:59:42 +00:00
|
|
|
:sub_method => datastore['EXE::OldMethod']
|
2010-09-21 00:13:30 +00:00
|
|
|
})
|
2010-09-22 20:55:26 +00:00
|
|
|
|
|
|
|
# Prefer the target's platform/architecture information, but use
|
|
|
|
# the module's if no target specific information exists
|
|
|
|
opts[:platform] ||= target_platform if self.respond_to? :target_platform
|
|
|
|
opts[:platform] ||= platform if self.respond_to? :platform
|
|
|
|
opts[:arch] ||= target_arch if self.respond_to? :target_arch
|
|
|
|
opts[:arch] ||= arch if self.respond_to? :arch
|
2010-09-21 00:13:30 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def exe_post_generation(opts)
|
|
|
|
if (opts[:fellback])
|
|
|
|
print_status("Warning: Falling back to default template: #{opts[:fellback]}")
|
|
|
|
end
|
2010-05-21 06:20:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|