Kubeconfig File Discovery

The kubeconfig file is a critical component in Kubernetes environments, containing configuration details for accessing and managing Kubernetes clusters. Attackers may attempt to get access to, create, or modify kubeconfig files to gain unauthorized initial access to Kubernetes clusters or move laterally within the cluster. This rule detects process discovery executions that involve kubeconfig files, particularly those executed from common shell environments or world-writeable directories.

Elastic rule (View on GitHub)

  1[metadata]
  2creation_date = "2025/06/17"
  3integration = ["endpoint"]
  4maturity = "production"
  5updated_date = "2025/06/17"
  6
  7[rule]
  8author = ["Elastic"]
  9description = """
 10The kubeconfig file is a critical component in Kubernetes environments, containing configuration
 11details for accessing and managing Kubernetes clusters. Attackers may attempt to get access to,
 12create, or modify kubeconfig files to gain unauthorized initial access to Kubernetes clusters or
 13move laterally within the cluster. This rule detects process discovery executions that involve
 14kubeconfig files, particularly those executed from common shell environments or world-writeable
 15directories.
 16"""
 17from = "now-9m"
 18index = [
 19    "logs-endpoint.events.process*",
 20]
 21language = "eql"
 22license = "Elastic License v2"
 23name = "Kubeconfig File Discovery"
 24references = [
 25    "https://kubernetes-threat-matrix.redguard.ch/initial-access/kubeconfig-file/",
 26    "https://kubenomicon.com/Initial_access/Kubeconfig_file.html",
 27    ]
 28risk_score = 21
 29rule_id = "9a6f5d74-c7e7-4a8b-945e-462c102daee4"
 30setup = """## Setup
 31
 32This rule requires data coming in from Elastic Defend.
 33
 34### Elastic Defend Integration Setup
 35Elastic 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.
 36
 37#### Prerequisite Requirements:
 38- Fleet is required for Elastic Defend.
 39- To configure Fleet Server refer to the [documentation](https://www.elastic.co/guide/en/fleet/current/fleet-server.html).
 40
 41#### The following steps should be executed in order to add the Elastic Defend integration on a Linux System:
 42- Go to the Kibana home page and click "Add integrations".
 43- In the query bar, search for "Elastic Defend" and select the integration to see more details about it.
 44- Click "Add Elastic Defend".
 45- Configure the integration name and optionally add a description.
 46- Select the type of environment you want to protect, either "Traditional Endpoints" or "Cloud Workloads".
 47- 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).
 48- We suggest selecting "Complete EDR (Endpoint Detection and Response)" as a configuration setting, that provides "All events; all preventions"
 49- 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.
 50For more details on Elastic Agent configuration settings, refer to the [helper guide](https://www.elastic.co/guide/en/fleet/8.10/agent-policy.html).
 51- Click "Save and Continue".
 52- 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.
 53For more details on Elastic Defend refer to the [helper guide](https://www.elastic.co/guide/en/security/current/install-endpoint.html).
 54"""
 55severity = "low"
 56tags = [
 57    "Domain: Endpoint",
 58    "Domain: Container",
 59    "OS: Linux",
 60    "Use Case: Threat Detection",
 61    "Tactic: Discovery",
 62    "Data Source: Elastic Defend",
 63]
 64timestamp_override = "event.ingested"
 65type = "eql"
 66query = '''
 67process where host.os.type == "linux" and event.type == "start" and event.action == "exec" and (
 68  process.parent.name in ("bash", "dash", "sh", "tcsh", "csh", "zsh", "ksh", "fish") or
 69  (
 70    process.parent.executable like ("/tmp/*", "/var/tmp/*", "/dev/shm/*", "/root/*", "/home/*") or
 71    process.parent.name like (".*", "*.sh")
 72  )
 73) and
 74(
 75  (
 76    process.working_directory like ("/etc/kubernetes", "/root/.kube", "/home/*/.kube") and
 77    process.args in ("kubeconfig", "admin.conf", "super-admin.conf", "kubelet.conf", "controller-manager.conf", "scheduler.conf")
 78  ) or
 79  process.args like (
 80    "/etc/kubernetes/admin.conf",
 81    "/etc/kubernetes/super-admin.conf",
 82    "/etc/kubernetes/kubelet.conf",
 83    "/etc/kubernetes/controller-manager.conf",
 84    "/etc/kubernetes/scheduler.conf",
 85    "/home/*/.kube/config",
 86    "/root/.kube/config",
 87    "/var/lib/*/kubeconfig"
 88  )
 89) and not process.name in ("stat", "md5sum", "dirname")
 90'''
 91
 92[[rule.threat]]
 93framework = "MITRE ATT&CK"
 94
 95[[rule.threat.technique]]
 96id = "T1613"
 97name = "Container and Resource Discovery"
 98reference = "https://attack.mitre.org/techniques/T1613/"
 99
100[rule.threat.tactic]
101id = "TA0007"
102name = "Discovery"
103reference = "https://attack.mitre.org/tactics/TA0007/"

References

Related rules

to-top