Detecting Malicious Kubectl Network Configuration Manipulation
This brief documents techniques used to abuse the Kubernetes kubectl CLI for command and control or data exfiltration by manipulating network configurations through port-forwarding and proxying.
Adversaries targeting containerized environments may abuse the Kubernetes command-line interface (kubectl) to facilitate unauthorized access and data exfiltration. By leveraging legitimate administrative subcommands such as 'port-forward', 'proxy', and 'expose', attackers can establish persistent command and control channels or bypass network segmentation. This activity becomes particularly suspicious when executed from non-standard locations - such as '/tmp/', '/var/tmp/', or '/dev/shm/' - or when initiated by shell interpreters (e.g., bash, zsh) or scripts in atypical environments. Defenders should monitor for these kubectl executions to detect potential container breakout or cluster-level persistence, balancing the need to catch malicious activity against legitimate administrative and CI/CD pipeline operations.
Impact
Successful abuse of kubectl network commands allows attackers to create covert tunnels into a Kubernetes cluster, bypass internal network policies, or reach sensitive services that are not exposed to the public internet. This can lead to unauthorized access to containerized databases, service APIs, and administrative interfaces, potentially resulting in large-scale data exfiltration or cluster-wide compromise.
Recommendation
- Implement the provided detection logic to monitor kubectl process executions originating from suspicious parent processes or file paths.
- Establish an allowlist for known administrative service accounts, CI/CD pipeline runners, and authorized management scripts to reduce noise.
- Audit Kubernetes network policies and cluster configurations periodically to identify and remove unauthorized 'expose' or 'proxy' configurations.
- Enable process-level command-line auditing on all nodes capable of running kubectl to ensure visibility into the specific arguments passed during cluster interactions.
Immediate actions
Deploy provided detection rule to monitor for suspicious kubectl usage
Mitigations
Restrict kubectl access to specific CI/CD runners and authorized administrator identities via RBAC
Unauthorized access via kubectl
Detection coverage 1
Detect Kubectl Network Configuration Manipulation
lowDetects the use of kubectl commands like port-forward, proxy, or expose when initiated from suspicious parent processes or non-standard directories, which may indicate malicious C2 activity.
Detection queries are available on the platform. Get full rules →