The Qualys security researchers have identified a critical vulnerability (CVE-2021-3156) in sudo utility, which is designed to organize command execution on behalf of other users.
Vulnerability allows unauthenticated access with root privileges. The problem can be used by any user, regardless of the presence in the system groups and the presence of an entry in the / etc / sudoers file.
The attack does not require entering the user's password, that is, the vulnerability can be used by an external person to elevate privileges on the system after the vulnerability has been compromised in a non-privileged process (including those started with the user "nobody").
To search for a vulnerability on your system, simply run the command "sudoedit -s /" and the vulnerability is present if an error message starting with "sudoedit:" is displayed.
The vulnerability has appeared since July 2011 and is caused by a buffer overflow in handling line escape characters in parameters intended to execute commands in shell mode. The shell mode is enabled by specifying the "-i" or "-s" arguments and causes the command to be executed not directly, but through an additional shell call with the "-c" flag ("sh -c command »).
The bottom line is that when the sudo utility is run normally, it escapes the special characters by specifying the "-i" and "-s" options, but when the sudoedit utility is started, the parameters are not escaped, since parse_args ( ) The function sets the environment variable MODE_EDIT instead of MODE_SHELL and does not reset the value of "valid_flags".
At the same time, unescaped character transmission creates conditions for another error to appear in the controller, which removes the escape characters before checking the sudoer rules.
The handler incorrectly parses the presence of a backslash character without escaping at the end of the line, it considers that this backslash escapes one more character and continues to read data beyond the line boundary, copying it to the "user_args" buffer and overwriting memory areas outside the buffer.
And it is mentioned that when trying to manipulate the values in the sudoedit command line, the attacker can achieve the superposition of a rewritable queue in the data that affects the subsequent course of the work.
In addition to creating an exploit it simplifies the fact that the attacker has complete control over the size of the user_args buffer, which corresponds to the size of all arguments passed, and also controls the size and content of data written outside of the buffer using environment variables.
Qualys security researchers managed to prepare three exploits, whose work is based on rewriting the content of the sudo_hook_entry, service_user and def_timestampdir structures:
- By aborting sudo_hook_entry a binary named "SYSTEMD_BYPASS_USERDB" could be run as root.
- Overriding service_user managed to run arbitrary code as root.
- By overriding def_timestampdir, it was possible to flush the contents of the sudo stack, including environment variables, into the / etc / passwd file, and achieve the replacement of the user with root privileges.
Los investigadores have shown that exploits work to get full root privileges on Ubuntu 20.04, Debian 10 and Fedora 33.
Vulnerability can be exploited on other operating systems and distributions, but the researchers' verification was limited to Ubuntu, Debian, and Fedora, plus it is mentioned that all sudo versions 1.8.2 to 1.8.31p2 and 1.9.0 to 1.9.5p1 in default settings are affected. Suggested solution in sudo 1.9.5p2.
Los investigadores have notified developers in advance distributors that have already released package updates in a coordinated way: Debian, RHEL, Fedor, Ubuntu, SUSE / openSUSE, Arch Linux, Slackware, Gentoo and FreeBSD.
Finally if you are interested in knowing more about it about the vulnerability, you can check the details In the following link.