Sudo Security Bypass
CVE-2019-14287 is a flaw in the Unix sudo program that lets a user run a command as root even when the sudoers config is meant to block exactly that. It was fixed long ago but can still turn up on older installs (versions < 1.8.28), so it is worth watching for.
sudo -u#-1 <command>
Example: sudo -u#-1 /bin/bash /etc/shadow
Background
CVE-2019-14287 was found in Sudo by Joe Vennix, a researcher working for Apple. Coincidentally, he also found the vulnerability covered in the next room of this series.
sudo is a Unix command that runs programs as other users. It usually defaults to the superuser (root), but you can also run a program as another user by giving their username or UID. The normal form is sudo <command>, and you can pick a different user with sudo -u#<id> <command>. Running a command this way means pretending to be another user, which can hand you higher permissions than you would otherwise have. For example:
Here my account could not read /root/root.txt, so I used sudo to give myself root privileges temporarily and read the file.
The Vulnerable Configuration
Like many Unix commands, sudo is configured in a file, in this case /etc/sudoers. Editing that file directly is risky given how important it is to the OS, so edit it with sudo visudo, which checks for misconfigurations when you save.
The vulnerability shows up in one specific scenario. Say you want to grant a user extra permissions: they may run a program as any other user, but not as root. You might add this line to the sudoers file:
<user> ALL=(ALL:!root) NOPASSWD: ALL
In theory this lets the user run any command as another user while preventing them from running it as the superuser/admin/root. You can pretend to be any user, except the admin.
Theoretically.
In practice, on vulnerable versions of Sudo you can get around this restriction and run the program as root anyway, which is obviously great for privilege escalation.
The Exploit
With the config above, sudo -u#0 <command> (root's UID is always 0) would not work, since we are not allowed to run commands as root. Trying to run as user 0 returns an error. Enter CVE-2019-14287.
Joe Vennix found that specifying a UID of -1 (or its unsigned equivalent, 4294967295) makes Sudo incorrectly read it as 0, that is, root. So by passing a UID of -1 or 4294967295 you can run a command as root despite being explicitly prevented from doing so. This only works if you have been granted non-root sudo permissions for the command, as in the config above.
In practice it looks like this: sudo -u#-1 <command>