nuclei-templates/cloud/kubernetes/deployments/k8s-privileged-container.yaml

52 lines
2.2 KiB
YAML
Raw Normal View History

2024-05-26 04:52:23 +00:00
id: k8s-privileged-containers
info:
name: Privileged Containers Found in Deployments
author: princechaddha
severity: critical
2024-06-14 05:57:21 +00:00
description: Checks for containers running in privileged mode within Kubernetes Deployments, and now also checks for user privileges and privilege escalation settings.
2024-05-26 04:52:23 +00:00
impact: |
2024-06-14 05:57:21 +00:00
Running containers in privileged mode, as the root user, or with privilege escalation enabled can grant them access to host resources and could lead to security breaches if the container is compromised.
2024-05-26 04:52:23 +00:00
remediation: |
2024-06-14 05:57:21 +00:00
Ensure that no container in Kubernetes Deployments runs in privileged mode, as the root user, or with privilege escalation enabled. Modify the security context for each container to set `privileged: false`, `runAsUser` appropriately, and `allowPrivilegeEscalation: false`.
2024-05-26 04:52:23 +00:00
reference:
- https://kubernetes.io/docs/concepts/policy/pod-security-policy/#privileged
tags: cloud,devops,kubernetes,k8s,devsecops,deployments
flow: |
code(1);
for (let deployment of template.items) {
set("deployment", deployment)
javascript(1);
}
self-contained: true
code:
- engine:
- sh
- bash
source: kubectl get deployments --all-namespaces --output=json
extractors:
- type: json
name: items
internal: true
json:
- '.items[]'
javascript:
- code: |
deployment = JSON.parse(template.deployment);
2024-06-14 05:57:21 +00:00
for (let container of deployment.spec.template.spec.containers) {
let sc = container.securityContext || {};
if (sc.privileged || sc.runAsUser < 1000 || sc.allowPrivilegeEscalation) {
let result = (`Deployment '${deployment.metadata.name}' in namespace '${deployment.metadata.namespace}' is running container '${container.name}' with insecure settings: Privileged=${sc.privileged}, runAsUser=${sc.runAsUser}, allowPrivilegeEscalation=${sc.allowPrivilegeEscalation}.`);
Export(result);
break;
}
2024-05-26 04:52:23 +00:00
}
extractors:
- type: dsl
dsl:
- response
2024-06-14 05:57:21 +00:00
# digest: 490a00463044022038295a725d25b77f920cfd32a5a407220f8f9c5faa37544670696f4cea356434022027fd56a2feae1101fe03c0d2e6e2452a2a89947f5c14e9711b8a744d11368b1e:366f2a24c8eb519f6968bd8801c08ebe