diff --git a/lib/msf/util/exe.rb b/lib/msf/util/exe.rb index 1aa796f17d71..eefaeec741b1 100755 --- a/lib/msf/util/exe.rb +++ b/lib/msf/util/exe.rb @@ -95,6 +95,10 @@ def self.to_executable(framework, arch, plat, code='', opts={}) if (plat.index(Msf::Module::Platform::Linux)) return to_linux_x64_elf(framework, code, opts) end + + if (plat.index(Msf::Module::Platform::OSX)) + return to_osx_x64_macho(framework, code) + end end if(arch.index(ARCH_ARMLE)) @@ -575,6 +579,22 @@ def self.to_osx_x86_macho(framework, code, opts={}) return mo end + def self.to_osx_x86_macho(framework, code, opts={}) + set_template_default(opts, "template_x64_darwin.bin") + + macho = '' + + File.open(opts[:template], 'rb') { |fd| + macho = fd.read(fd.stat.size) + } + + bin = macho.index('PAYLOAD:') + raise RuntimeError, "Invalid Mac OS X x86_64 Mach-O template: missing \"PAYLOAD:\" tag" if not bin + macho[bin, code.length] = code + + return macho + end + # # Create a 64-bit Linux ELF containing the payload provided in +code+ # @@ -1700,7 +1720,13 @@ def self.to_executable_fmt(framework, arch, plat, code, fmt, exeopts) end when 'macho' - output = Msf::Util::EXE.to_osx_x86_macho(framework, code, exeopts) + if (not arch or (arch.index(ARCH_X86))) + output = Msf::Util::EXE.to_osx_x86_macho(framework, code, exeopts) + end + + if (arch and (arch.index(ARCH_X86_64) or arch.index(ARCH_X64))) + output = Msf::Util::EXE.to_osx_x64_macho(framework, code, exeopts) + end when 'vba' output = Msf::Util::EXE.to_vba(framework, code, exeopts)