Skip to content

Commit

Permalink
Mac OS X x64 binary template support
Browse files Browse the repository at this point in the history
  • Loading branch information
argp committed Feb 6, 2012
1 parent 2d35cf4 commit f3345eb
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion lib/msf/util/exe.rb
Expand Up @@ -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))
Expand Down Expand Up @@ -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+
#
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit f3345eb

Please sign in to comment.