Detection of Kubectl Binary Masquerading and Evasion
Adversaries may attempt to evade detection by renaming the kubectl binary or executing it from non-standard directories while retaining command-line functionality to perform unauthorized Kubernetes operations.
Adversaries targeting Kubernetes environments often seek to evade detection by disguising the use of legitimate administration tools. A common technique involves renaming the 'kubectl' binary or executing it from non-standard, often transient directories such as '/tmp', '/var/tmp', or '/dev/shm'. By mimicking legitimate administrative activity, attackers attempt to blend in with baseline operations while performing reconnaissance, discovery, or unauthorized control over containerized workloads. This activity typically manifests as processes with unexpected names or locations that invoke standard kubectl commands, such as 'get', 'describe', 'exec', or cluster authentication flags. Monitoring for these patterns is critical for identifying potential persistence, lateral movement, or unauthorized cluster administration.
Attack Chain
- Attacker gains initial access to a node or container within a Kubernetes cluster.
- Attacker retrieves the 'kubectl' binary or a secondary version of it.
- Attacker renames the binary or moves it to a directory with loose permissions (e.g., /tmp).
- Attacker sets execution permissions on the renamed binary if necessary.
- Attacker executes the renamed binary with arguments to discover cluster resources (e.g., 'get pods', 'get services').
- Attacker utilizes the binary to execute commands within pods or escalate privileges via service account token misuse.
- Attacker cleans up the binary or moves it to another location to maintain stealth during operations.
Impact
Successful masquerading of kubectl activity allows attackers to perform undetected reconnaissance and management of Kubernetes clusters. This can lead to unauthorized data exfiltration from pods, container escape attempts, or the deployment of malicious containers. In large-scale production environments, this can result in total cluster compromise, impacting the integrity and availability of hosted containerized applications.
Recommendation
Prioritize the identification of non-standard process executions that mimic kubectl behavior.
- Deploy the provided Sigma rule to monitor for suspicious process naming conventions or execution paths.
- Regularly audit processes executing from temporary directories like '/tmp', '/var/tmp', and '/dev/shm'.
- Enforce restrictive filesystem permissions to prevent unauthorized binaries from being placed in or executed from world-writable directories.
- Integrate Kubernetes API server audit logs with process-level telemetry to correlate kubectl usage with authenticated cluster requests.
Immediate actions
Deploy the provided Sigma rule to detect masqueraded kubectl execution
Threat Hunt
Search for processes executing from /tmp, /var/tmp, or /dev/shm that accept kubectl-like arguments
Data: process_creation
Detection coverage 1
Potential Kubectl Masquerading via Unexpected Process
mediumDetects potential kubectl masquerading by monitoring for process events where the process name is not 'kubectl' but the command line arguments include kubectl-related commands.
Detection queries are available on the platform. Get full rules →