Potential Kubectl Masquerading via Unexpected Process
This rule detects potential kubectl masquerading activity by monitoring for process events where the process name is not "kubectl" but the command line arguments include kubectl-related commands. This could indicate an adversary attempting to masquerade as legitimate kubectl activity to evade detection. This rule covers evasion gaps introduced by renaming the kubectl binary, or placing it in an unusual directory.
Elastic rule (View on GitHub)
1[metadata]
2creation_date = "2025/06/19"
3integration = ["endpoint", "crowdstrike", "sentinel_one_cloud_funnel"]
4maturity = "production"
5updated_date = "2025/07/07"
6
7[rule]
8author = ["Elastic"]
9description = """
10This rule detects potential kubectl masquerading activity by monitoring for process events where the process name
11is not "kubectl" but the command line arguments include kubectl-related commands. This could indicate an adversary
12attempting to masquerade as legitimate kubectl activity to evade detection. This rule covers evasion gaps
13introduced by renaming the kubectl binary, or placing it in an unusual directory.
14"""
15from = "now-9m"
16index = [
17 "endgame-*",
18 "logs-crowdstrike.fdr*",
19 "logs-endpoint.events.process*",
20 "logs-sentinel_one_cloud_funnel.*",
21]
22language = "eql"
23license = "Elastic License v2"
24name = "Potential Kubectl Masquerading via Unexpected Process"
25note = """ ## Triage and analysis
26
27> **Disclaimer**:
28> This investigation guide was created using generative AI technology and has been reviewed to improve its accuracy and relevance. While every effort has been made to ensure its quality, we recommend validating the content and adapting it to suit your specific environment and operational needs.
29
30### Investigating Potential Kubectl Masquerading via Unexpected Process
31
32Kubectl is a command-line tool for interacting with Kubernetes clusters, crucial for managing containerized applications. Adversaries may exploit this by renaming the kubectl binary or placing it in unusual directories to mimic legitimate activity and evade detection. The detection rule identifies such masquerading by monitoring for non-standard process names executing kubectl-related commands, thus highlighting potential evasion attempts.
33
34### Possible investigation steps
35
36- Review the process executable path to determine if it is located in a non-standard directory such as /tmp, /var/tmp, /dev/shm, or other specified paths in the query.
37- Examine the process name to check if it deviates from the expected "kubectl" name, which could indicate an attempt to masquerade the process.
38- Analyze the command line arguments used in the process to identify any kubectl-related commands, such as "get", "describe", "exec", "port-forward", or authentication commands, which may suggest unauthorized access or activity.
39- Investigate the user account associated with the process to determine if it has legitimate access to execute kubectl commands or if it might be compromised.
40- Check for any recent changes or anomalies in the Kubernetes cluster that could correlate with the suspicious process activity, such as unauthorized deployments or configuration changes.
41- Review system logs and other security alerts around the time of the event to identify any additional indicators of compromise or related suspicious activities.
42- If possible, capture and analyze network traffic associated with the process to detect any unusual or unauthorized communication with the Kubernetes API server or other cluster components.
43
44### False positive analysis
45
46- Processes running in development or testing environments may trigger alerts if kubectl is executed from non-standard directories. To manage this, create exceptions for known development paths where kubectl is legitimately used.
47- Automated scripts or CI/CD pipelines that use kubectl from custom directories might be flagged. Identify these scripts and exclude their specific paths or process names from the rule.
48- Some legitimate applications might wrap kubectl commands for functionality, leading to unexpected process names. Review these applications and add their process names to the exclusion list if they are verified as non-threatening.
49- Users with custom kubectl installations in home directories could cause false positives. Verify these installations and exclude the specific user paths if they are deemed safe.
50- Temporary or experimental setups where kubectl is renamed for testing purposes might be mistakenly flagged. Document these setups and apply temporary exclusions during the testing phase.
51
52### Response and remediation
53
54- Immediately isolate the affected host to prevent further unauthorized access or lateral movement within the network.
55- Terminate any suspicious processes identified by the detection rule that are masquerading as kubectl to halt potential malicious activity.
56- Conduct a thorough review of the affected system's logs and command history to identify any unauthorized kubectl commands executed and assess the scope of the compromise.
57- Revoke any potentially compromised credentials or access tokens associated with the Kubernetes cluster to prevent further unauthorized access.
58- Restore any altered or deleted Kubernetes resources from backups, ensuring the integrity and availability of the cluster's services.
59- Implement stricter access controls and monitoring on the Kubernetes cluster, such as enforcing the principle of least privilege and enabling audit logging for kubectl commands.
60- Escalate the incident to the security operations team for further investigation and to determine if additional systems or data have been affected.
61"""
62references = ["https://kubernetes.io/docs/reference/kubectl/"]
63risk_score = 21
64rule_id = "2388c687-cb2c-4b7b-be8f-6864a2385048"
65setup = """## Setup
66
67This rule requires data coming in from Elastic Defend.
68
69### Elastic Defend Integration Setup
70Elastic Defend is integrated into the Elastic Agent using Fleet. Upon configuration, the integration allows the Elastic Agent to monitor events on your host and send data to the Elastic Security app.
71
72#### Prerequisite Requirements:
73- Fleet is required for Elastic Defend.
74- To configure Fleet Server refer to the [documentation](https://www.elastic.co/guide/en/fleet/current/fleet-server.html).
75
76#### The following steps should be executed in order to add the Elastic Defend integration on a Linux System:
77- Go to the Kibana home page and click "Add integrations".
78- In the query bar, search for "Elastic Defend" and select the integration to see more details about it.
79- Click "Add Elastic Defend".
80- Configure the integration name and optionally add a description.
81- Select the type of environment you want to protect, either "Traditional Endpoints" or "Cloud Workloads".
82- Select a configuration preset. Each preset comes with different default settings for Elastic Agent, you can further customize these later by configuring the Elastic Defend integration policy. [Helper guide](https://www.elastic.co/guide/en/security/current/configure-endpoint-integration-policy.html).
83- We suggest selecting "Complete EDR (Endpoint Detection and Response)" as a configuration setting, that provides "All events; all preventions"
84- Enter a name for the agent policy in "New agent policy name". If other agent policies already exist, you can click the "Existing hosts" tab and select an existing policy instead.
85For more details on Elastic Agent configuration settings, refer to the [helper guide](https://www.elastic.co/guide/en/fleet/8.10/agent-policy.html).
86- Click "Save and Continue".
87- To complete the integration, select "Add Elastic Agent to your hosts" and continue to the next section to install the Elastic Agent on your hosts.
88For more details on Elastic Defend refer to the [helper guide](https://www.elastic.co/guide/en/security/current/install-endpoint.html).
89"""
90severity = "low"
91tags = [
92 "Domain: Endpoint",
93 "Domain: Container",
94 "Domain: Kubernetes",
95 "OS: Linux",
96 "Use Case: Threat Detection",
97 "Tactic: Defense Evasion",
98 "Data Source: Elastic Defend",
99 "Data Source: Elastic Endgame",
100 "Data Source: Crowdstrike",
101 "Data Source: SentinelOne",
102 "Resources: Investigation Guide",
103]
104timestamp_override = "event.ingested"
105type = "eql"
106query = '''
107process where host.os.type == "linux" and event.type == "start" and
108event.action in ("exec", "exec_event", "start", "executed", "process_started") and
109(
110 process.executable like~ ("/tmp/*", "/var/tmp/*", "/dev/shm/*", "/root/*", "/var/www/*", "./kubectl", "/home/*/kubectl") or
111 process.name like ".*"
112) and
113process.command_line like~ (
114
115 // get and describe commands
116 "*get po*", "*get deploy*", "*get node*", "*get svc*", "*get service*", "*get secret*", "*get clusterrole*", "*get ingress*",
117 "*get configmap*", "*describe po*", "*describe deploy*", "*describe node*", "*describe svc*", "*describe service*",
118 "*describe secret*", "*describe configmap*", "*describe clusterrole*", "*describe ingress*",
119
120 // exec commands
121 "*exec -it*", "*exec --stdin*", "*exec --tty*",
122
123 // networking commands
124 "*port-forward* ", "*proxy --port*", "*run --image=*", "*expose*",
125
126 // authentication/impersonation commands
127 "*auth can-i*", "*--kubeconfig*", "*--as *", "*--as=*", "*--as-group*", "*--as-uid*"
128) and not (
129 process.executable like "/tmp/newroot/*" or
130 process.name == ".flatpak-wrapped"
131)
132'''
133
134[[rule.threat]]
135framework = "MITRE ATT&CK"
136
137[[rule.threat.technique]]
138id = "T1036"
139name = "Masquerading"
140reference = "https://attack.mitre.org/techniques/T1036/"
141
142[[rule.threat.technique.subtechnique]]
143id = "T1036.003"
144name = "Rename Legitimate Utilities"
145reference = "https://attack.mitre.org/techniques/T1036/003/"
146
147[[rule.threat.technique]]
148id = "T1564"
149name = "Hide Artifacts"
150reference = "https://attack.mitre.org/techniques/T1564/"
151
152[rule.threat.tactic]
153id = "TA0005"
154name = "Defense Evasion"
155reference = "https://attack.mitre.org/tactics/TA0005/"
Triage and analysis
Disclaimer: This investigation guide was created using generative AI technology and has been reviewed to improve its accuracy and relevance. While every effort has been made to ensure its quality, we recommend validating the content and adapting it to suit your specific environment and operational needs.
Investigating Potential Kubectl Masquerading via Unexpected Process
Kubectl is a command-line tool for interacting with Kubernetes clusters, crucial for managing containerized applications. Adversaries may exploit this by renaming the kubectl binary or placing it in unusual directories to mimic legitimate activity and evade detection. The detection rule identifies such masquerading by monitoring for non-standard process names executing kubectl-related commands, thus highlighting potential evasion attempts.
Possible investigation steps
- Review the process executable path to determine if it is located in a non-standard directory such as /tmp, /var/tmp, /dev/shm, or other specified paths in the query.
- Examine the process name to check if it deviates from the expected "kubectl" name, which could indicate an attempt to masquerade the process.
- Analyze the command line arguments used in the process to identify any kubectl-related commands, such as "get", "describe", "exec", "port-forward", or authentication commands, which may suggest unauthorized access or activity.
- Investigate the user account associated with the process to determine if it has legitimate access to execute kubectl commands or if it might be compromised.
- Check for any recent changes or anomalies in the Kubernetes cluster that could correlate with the suspicious process activity, such as unauthorized deployments or configuration changes.
- Review system logs and other security alerts around the time of the event to identify any additional indicators of compromise or related suspicious activities.
- If possible, capture and analyze network traffic associated with the process to detect any unusual or unauthorized communication with the Kubernetes API server or other cluster components.
False positive analysis
- Processes running in development or testing environments may trigger alerts if kubectl is executed from non-standard directories. To manage this, create exceptions for known development paths where kubectl is legitimately used.
- Automated scripts or CI/CD pipelines that use kubectl from custom directories might be flagged. Identify these scripts and exclude their specific paths or process names from the rule.
- Some legitimate applications might wrap kubectl commands for functionality, leading to unexpected process names. Review these applications and add their process names to the exclusion list if they are verified as non-threatening.
- Users with custom kubectl installations in home directories could cause false positives. Verify these installations and exclude the specific user paths if they are deemed safe.
- Temporary or experimental setups where kubectl is renamed for testing purposes might be mistakenly flagged. Document these setups and apply temporary exclusions during the testing phase.
Response and remediation
- Immediately isolate the affected host to prevent further unauthorized access or lateral movement within the network.
- Terminate any suspicious processes identified by the detection rule that are masquerading as kubectl to halt potential malicious activity.
- Conduct a thorough review of the affected system's logs and command history to identify any unauthorized kubectl commands executed and assess the scope of the compromise.
- Revoke any potentially compromised credentials or access tokens associated with the Kubernetes cluster to prevent further unauthorized access.
- Restore any altered or deleted Kubernetes resources from backups, ensuring the integrity and availability of the cluster's services.
- Implement stricter access controls and monitoring on the Kubernetes cluster, such as enforcing the principle of least privilege and enabling audit logging for kubectl commands.
- Escalate the incident to the security operations team for further investigation and to determine if additional systems or data have been affected.
References
Related rules
- Kubectl Network Configuration Modification
- Kubernetes Direct API Request via Curl or Wget
- Kubectl Apply Pod from URL
- Potential Hex Payload Execution via Common Utility
- Docker Socket Enumeration