diff --git a/data/templates/template_x64_darwin.bin b/data/templates/template_x64_darwin.bin new file mode 100755 index 0000000000..4bb259a205 Binary files /dev/null and b/data/templates/template_x64_darwin.bin differ diff --git a/lib/msf/util/exe.rb b/lib/msf/util/exe.rb index 1aa796f17d..d6b7da8b12 100755 --- a/lib/msf/util/exe.rb +++ b/lib/msf/util/exe.rb @@ -95,6 +95,10 @@ require 'digest/sha1' 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 @@ require 'digest/sha1' return mo end + def self.to_osx_x64_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 @@ End Sub 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)