Eskalacja uprawnień w sudo przez błąd w get_process_ttyname()
Napisał: Patryk Krawaczyński
31/05/2017 w Bezpieczeństwo Brak komentarzy. (artykuł nr 613, ilość słów: 310)
W
programie sudo wykryto poważną lukę w kodzie, która umożliwia uzyskanie uprawnień administratora przez każdego użytkownika posiadającego dostęp do powłoki shell. Działa ona również na systemach z włączoną obsługą SELinux (CentOS / RHEL). Wystarczy, że lokalny użytkownik posiada w systemie uprawnienia do uruchomienia dowolnego polecenia za pośrednictwem sudo
. Daje mu to możliwość eskalacji swoich uprawnienia do poziomu administratora.
Podatność występuje w funkcji get_process_ttyname()
, która może niepoprawnie parsować zawartość otwieranego pliku /proc/[pid]/stat
w celu określenia numeru terminala:
We discovered a vulnerability in Sudo’s get_process_ttyname() for Linux:
this function opens “/proc/[pid]/stat” (man proc) and reads the device
number of the tty from field 7 (tty_nr). Unfortunately, these fields are
space-separated and field 2 (comm, the filename of the command) can
contain spaces (CVE-2017-1000367).For example, if we execute Sudo through the symlink “./ 1 “,
get_process_ttyname() calls sudo_ttyname_dev() to search for the
non-existent tty device number “1” in the built-in search_devs[].Next, sudo_ttyname_dev() calls the function sudo_ttyname_scan() to
search for this non-existent tty device number “1” in a breadth-first
traversal of “/dev”.Last, we exploit this function during its traversal of the
world-writable “/dev/shm”: through this vulnerability, a local user can
pretend that his tty is any character device on the filesystem, and
after two race conditions, he can pretend that his tty is any file on
the filesystem.On an SELinux-enabled system, if a user is Sudoer for a command that
does not grant him full root privileges, he can overwrite any file on
the filesystem (including root-owned files) with his command’s output,
because relabel_tty() (in src/selinux.c) calls open(O_RDWR|O_NONBLOCK)
on his tty and dup2()s it to the command’s stdin, stdout, and stderr.
This allows any Sudoer user to obtain full root privileges.
Podatne są wersje od 1.8.6p7 do 1.8.20 włącznie.
Więcej informacji: Qualys Security Advisory, Potential overwrite of arbitrary files on Linux