k8s Runtime Attack Scenarios 2
The article demonstrates how to read sensitive files inside a Kubernetes container using two web vulnerabilities (Remote Code Execution and Local File Inclusion) in a deliberately vulnerable .NET Core application, and also by using kubectl exec to access the pod's service account files. An attacker could read files such as /etc/passwd, /etc/shadow, and application configuration files, and potentially obtain credentials to communicate with the Kubernetes API server.
In this article, I will show you to read the sensitive files in the container running in the K8s environment, both by using the application that has the vulnerability and by connecting pod with kubectl.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the vulnerable application intentionally includes Remote Code Execution and Local File Inclusion flaws, and the Kubernetes pod mounts service account tokens that are readable by the container user.
What the attacker needed
Access to the vulnerable application; ability to send requests to the application; kubectl access to the cluster (for Attack 3)
How it was found
- Set up the Kubernetes environment using the provided environment.yml file.
- Access the vulnerable application's Swagger interface.
- Send a Remote Code Execution request to read /etc/passwd and /etc/shadow.
- Send a Local File Inclusion request to read /etc/passwd and /etc/shadow.
- Use kubectl exec to get a shell in the pod and navigate to the service account directory.
- Read the service account files to obtain information for communicating with the API server.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
This article shows how a security tester can read files that should be private inside a container running in Kubernetes. The tester uses two common web bugs: one lets them run commands on the server, the other lets them include local files in the response. They also show that if you already have access to the cluster, you can use a command-line tool to enter the container and read files directly.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.