Authors: | Hector Marco & Ismael Ripoll -- Cybersecurity Group |
CVE: | CVE-2016-4484 |
Comment: | CWE-636: Not failing securely. |
Dates: |
November 11th, 2016 - Disclosed at DeepSec 2016, Viena. November 14th, 2016 - Published in the web. |
![]() |
Enter 93 times to shell |
A vulnerability in Cryptsetup, concretely in the scripts that unlock the system partition when the partition is ciphered using LUKS (Linux Unified Key Setup). The disclosure of this vulnerability was presented as part of our talk "Abusing LUKS to Hack the System" in the DeepSec 2016 security conference, Vienna.
This vulnerability allows to obtain a root initramfs shell on affected systems. The vulnerability is very reliable because it doesn't depend on specific systems or configurations. Attackers can copy, modify or destroy the hard disc as well as set up the network to exflitrate data. This vulnerability is specially serious in environments like libraries, ATMs, airport machines, labs, etc, where the whole boot process is protect (password in BIOS and GRUB) and we only have a keyboard or/and a mouse.
Note that in cloud environments it is also possible to remotely exploit this vulnerability without having "physical access."
The bug is in the initrd scripts used for decrypting a system volume. Initrd contains stripts from multiple services, and the affected one is an script file from the cryptsetup Debian package.
The CVSS v3 standard (an admirable normalization effort) defines 4 coarse-grain levels of attack vectors: Network, Adjacent, Local and Physical. But as far as we know, there are some cloud environments that provide full console access over the network. We tried to reflect that cloud environments are not 100% safe, and they should not ignore this vulnerability. Depending on the service offered by some cloud providers they could be vulnerable, and so, it is not clear in which attack vector fits better.
Security is still a young field which tries to adapt to the continuous changes of the technology. Cloud computing is redefining many computing concepts.
Please, read the "Discussion: About physical access" at the end of this blog.If you use Debian or Ubuntu/ (probably many derived distributions are also vulnerable, but we have not tested), and you have encrypted the system partition, then your systems is vulnerable.
During the installation of Ubuntu, one of the first steps is to prepare the target partition (make partitions if needed, and/or format them). At this stage, the user is asked to "Encrypt the new (LXK)ubuntu installation for security". Nowadays, there is very little performance penalty working with an encrypted disk and it is an effective solution to protect data when the computer is not running. It is advisable to enable this feature.
If you didn't installed the system, the you can figure out the organization by running the blkid command.
This is the classic structure where the partition "/dev/sda5" is encrypted and then used as a physical_volume in the "lubuntu-vg" volume_group which contains two logical_volumes: lubuntu--vg-root and lubuntu--vg-swap_1. As a result, the system and the swap partitions are encrypted by LUKS and protected by a single password. This system is vulnerable.
An attacker with access to the console of the computer and with the ability to reboot the computer can launch a shell (with root permissions) when he/she is prompted for the password to unlock the system partition. The shell is executed in the initrd environment. Obviously, the system partition is encrypted and it is not possible to decrypt it (AFAWK). But other partitions may be not encrypted, and so accessible. Just to mention some exploitation strategies:
The fault is caused by an incorrect handling of the password check in the script file /scripts/local-top/cryptroot. When the user exceeds the maximum number of password tries (by default 3), then boot sequence continues normally.
The calling script, /scripts/local, handles the error as if it were caused by a slow device that needs more time to warm-up.
The booting scripts then tries to recover/mount the "failing" device, in the function local_deveice_setup(), multiple times (up to 30 times on an x86 system, and 150 on a powerpc machine). Every time the top level script tries to mount the encrypted partition (line 99 in /script/local), the user is allowed to try 3 more LUKS passwords. This gives a total of 93 password trials (on x86).
But the real problem happens when the maximum number of trials for transient hardware faults is reached (30 times for non ppc systems), line 114 at function local_device_setup(). In this case, the top level script is not aware of the root cause of the fault and drops a shell (busybox) to the user, line 124. The panic() function (see below) tries to insert additional drivers and runs a shell.
The attacker just have to press and keep pressing the [Enter] key at the LUKS password prompt until a shell appears, which occurs after 70 seconds approx.
The issue can be easily fixed by stopping the boot sequence when the number of password guesses has been exhausted. The following patch suspends the execution forever. The only way to exit is by rebooting the computer.
The panic function, which is the one that launches the shell, can prevent console access if the kernel is booted with the "panic" parameter.
Therefore, adding the "panic" parameter to the kernel entry in the grub configuration will prevent a shell.
The direct cause of this vulnerability is the improper checking of the maximum number of passwords, but the bug was (probably) introduced by the addition of new features (in this case security features). It is well known that "Complexity is the worst enemy of security". A system with more features requires more code and has more interactions between sub-systems, which results in harder to test systems and so more bugs.
Security is a non-functional requirement which must be analyzed globally. In this case, the "recovery" actions taken in the case of system errors should be revised and updated to match the security requirements.
There are many "levels" of physical access. Just to mention a few:
These are some of the scenarios where we can find a Linux system, but the IoT will increase the diversity further.
In order to protect the computer in these scenarios: the BIOS/UEFI has one or two passwords to protect the booting or the configuration menu; the GRUB also has the possibility to use multiple passwords to protect unauthorized operations.
And in the case of an encrypted system, the initrd shall block the maximum number of password trials and prevent the access to the computer in that case.In general, the GNU/Linux ecosystem (kernel, system apps, distros, ...) has been designed by developers for developers. Therefore, in the case of a fault, the recovery action is very "developer friendly", which is very convenient while developing or in controlled environments. But then Linux is used in more hostile environments, this helpful (but naive) recovery services shall not be the default option.
UEFI and GRUB contain two complete and very powerful shell facilities. Initrd system has powerful busybox with complete access to the network.
May be all this "just in case" functionality shall be remove, or seriously reconsidered, for the sake of security.