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", "cloud_defend"]
  4maturity = "production"
  5min_stack_comments = "Defend for Containers integration was re-introduced in 9.3.0"
  6min_stack_version = "9.3.0"
  7updated_date = "2026/02/05"
  8
  9[rule]
 10author = ["Elastic"]
 11description = """
 12This rule detects potential kubectl masquerading activity by monitoring for process events where the process name
 13is not "kubectl" but the command line arguments include kubectl-related commands. This could indicate an adversary
 14attempting to masquerade as legitimate kubectl activity to evade detection. This rule covers evasion gaps
 15introduced by renaming the kubectl binary, or placing it in an unusual directory.
 16"""
 17from = "now-9m"
 18index = [
 19    "endgame-*",
 20    "logs-crowdstrike.fdr*",
 21    "logs-endpoint.events.process*",
 22    "logs-sentinel_one_cloud_funnel.*",
 23    "logs-cloud_defend.process*",
 24]
 25language = "eql"
 26license = "Elastic License v2"
 27name = "Potential Kubectl Masquerading via Unexpected Process"
 28note = """ ## Triage and analysis
 29
 30> **Disclaimer**:
 31> 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.
 32
 33### Investigating Potential Kubectl Masquerading via Unexpected Process
 34
 35Kubectl 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.
 36
 37### Possible investigation steps
 38
 39- 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.
 40- Examine the process name to check if it deviates from the expected "kubectl" name, which could indicate an attempt to masquerade the process.
 41- 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.
 42- 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.
 43- 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.
 44- Review system logs and other security alerts around the time of the event to identify any additional indicators of compromise or related suspicious activities.
 45- 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.
 46
 47### False positive analysis
 48
 49- 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.
 50- 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.
 51- 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.
 52- 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.
 53- 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.
 54
 55### Response and remediation
 56
 57- Immediately isolate the affected host to prevent further unauthorized access or lateral movement within the network.
 58- Terminate any suspicious processes identified by the detection rule that are masquerading as kubectl to halt potential malicious activity.
 59- 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.
 60- Revoke any potentially compromised credentials or access tokens associated with the Kubernetes cluster to prevent further unauthorized access.
 61- Restore any altered or deleted Kubernetes resources from backups, ensuring the integrity and availability of the cluster's services.
 62- 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.
 63- Escalate the incident to the security operations team for further investigation and to determine if additional systems or data have been affected.
 64"""
 65references = ["https://kubernetes.io/docs/reference/kubectl/"]
 66risk_score = 47
 67rule_id = "2388c687-cb2c-4b7b-be8f-6864a2385048"
 68setup = """## Setup
 69
 70This rule requires data coming in from Elastic Defend.
 71
 72### Elastic Defend Integration Setup
 73Elastic 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.
 74
 75#### Prerequisite Requirements:
 76- Fleet is required for Elastic Defend.
 77- To configure Fleet Server refer to the [documentation](https://www.elastic.co/guide/en/fleet/current/fleet-server.html).
 78
 79#### The following steps should be executed in order to add the Elastic Defend integration on a Linux System:
 80- Go to the Kibana home page and click "Add integrations".
 81- In the query bar, search for "Elastic Defend" and select the integration to see more details about it.
 82- Click "Add Elastic Defend".
 83- Configure the integration name and optionally add a description.
 84- Select the type of environment you want to protect, either "Traditional Endpoints" or "Cloud Workloads".
 85- 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).
 86- We suggest selecting "Complete EDR (Endpoint Detection and Response)" as a configuration setting, that provides "All events; all preventions"
 87- 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.
 88For more details on Elastic Agent configuration settings, refer to the [helper guide](https://www.elastic.co/guide/en/fleet/8.10/agent-policy.html).
 89- Click "Save and Continue".
 90- 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.
 91For more details on Elastic Defend refer to the [helper guide](https://www.elastic.co/guide/en/security/current/install-endpoint.html).
 92"""
 93severity = "medium"
 94tags = [
 95    "Domain: Endpoint",
 96    "Domain: Container",
 97    "Domain: Kubernetes",
 98    "OS: Linux",
 99    "Use Case: Threat Detection",
100    "Tactic: Defense Evasion",
101    "Data Source: Elastic Defend",
102    "Data Source: Elastic Endgame",
103    "Data Source: Crowdstrike",
104    "Data Source: SentinelOne",
105    "Data Source: Elastic Defend for Containers",
106    "Resources: Investigation Guide",
107]
108timestamp_override = "event.ingested"
109type = "eql"
110query = '''
111process where host.os.type == "linux" and event.type == "start" and
112event.action in ("exec", "exec_event", "start", "executed", "process_started") and
113(
114  process.executable like~ ("/tmp/*", "/var/tmp/*", "/dev/shm/*", "/root/*", "/var/www/*", "./kubectl") or
115  process.name like ".*"
116) and
117process.args like~ (
118
119  // get and describe commands
120  "*get po*", "*get deploy*", "*get node*", "*get svc*", "*get service*", "*get secret*", "*get clusterrole*", "*get ingress*",
121  "*get configmap*", "*describe po*", "*describe deploy*", "*describe node*", "*describe svc*", "*describe service*",
122  "*describe secret*", "*describe configmap*", "*describe clusterrole*", "*describe ingress*",
123  
124  // exec commands
125  "*exec -it*", "*exec --stdin*", "*exec --tty*",
126  
127  // networking commands
128  "*port-forward* ", "*proxy --port*", "*run --image=*", "*expose*",
129
130  // authentication/impersonation commands
131  "*auth can-i*", "*--kubeconfig*", "*--as *", "*--as=*", "*--as-group*", "*--as-uid*"
132) and not (
133  process.executable like "/tmp/newroot/*" or
134  process.name == ".flatpak-wrapped"
135)
136'''
137
138[[rule.threat]]
139framework = "MITRE ATT&CK"
140
141[[rule.threat.technique]]
142id = "T1036"
143name = "Masquerading"
144reference = "https://attack.mitre.org/techniques/T1036/"
145
146[[rule.threat.technique.subtechnique]]
147id = "T1036.003"
148name = "Rename Legitimate Utilities"
149reference = "https://attack.mitre.org/techniques/T1036/003/"
150
151[[rule.threat.technique]]
152id = "T1564"
153name = "Hide Artifacts"
154reference = "https://attack.mitre.org/techniques/T1564/"
155
156[rule.threat.tactic]
157id = "TA0005"
158name = "Defense Evasion"
159reference = "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

to-top