Privilege Escalation: Lets know the Hidden Danger.
Ayush Ganatra
DevOps Engineer @ The Good Glamm Group | AWS Solutions Architect Professional | CKS | CKA | Azure Administrator
Introduction:
Containers have revolutionized the way we build, ship, and run applications. They provide a lightweight and efficient way to package an application along with its dependencies, ensuring consistency and portability. Every technology comes with its set of best practices, but understanding and incorporating them is key. It's not just information; it's the foundation of secure and efficient architects. In this article, we delve into the one of the most crucial best practice in the context of containerization technologies(Kubernetes and Docker), PRIVILEGE CONTAINERS.
In this article we will also see how a privilege container's exploitation can cascade into a full-blown infrastructure breach.
The Problem with Privilege Containers:
Containers are designed to be isolated environments. A privileged container has elevated permissions, essentially granting it root-level access to the host system. While this might be convenient for certain tasks, it can also open the door to serious security vulnerabilities.
Root Filesystem Access: One of the most significant dangers of privileged containers is their ability to access the host system's root filesystem. This means that a compromised privileged container can potentially damage critical system files, leading to system instability or even complete compromise.
Demo: Highlighting the Difference
Scenario: You have a privileged container and a non-privileged container running on the same host.
Non-privileged Container
Privileged Container
In the images, the contrast between privileged and non-privileged containers becomes evident. The privileged container's ability to mount the host's root filesystem to a directory within the container, essentially mirroring the host's root filesystem, highlights the potential risks associated with such elevated privileges. Any alterations made within this directory from the container have a direct impact on the actual host's root filesystem.
领英推荐
Exploitation Scenario
In the exploitation scenario, we leverage the privileged container's access to the host's root filesystem to execute a series of potentially devastating actions. First, we generate an SSH key pair within the container, keeping the private key secure within the container environment. Then, we copy the public key into the host's root user's authorized_keys file, granting us SSH access. By extracting the host's hostname from the hostRootFilesystem/etc/hostname, we gain the all the information needed to connect to the host VM. This exploitation not only compromises the host VM but extends its reach to the entire infrastructure to which the host VM is connected.
This is one of the way of exploiting privileged container.
Solutions and Recommendations:
Now that the gravity of privilege escalation in containers is clear, let's discuss some practical solutions for such exploits