Kubernetes Pod Created With HostPID
This rule detects an attempt to create or modify a pod attached to the host PID namespace. HostPID allows a pod to access all the processes running on the host and could allow an attacker to take malicious action. When paired with ptrace this can be used to escalate privileges outside of the container. When paired with a privileged container, the pod can see all of the processes on the host. An attacker can enter the init system (PID 1) on the host. From there, they could execute a shell and continue to escalate privileges to root.
Elastic rule (View on GitHub)
1[metadata]
2creation_date = "2022/07/05"
3integration = ["kubernetes"]
4maturity = "production"
5updated_date = "2024/05/21"
6
7[rule]
8author = ["Elastic"]
9description = """
10This rule detects an attempt to create or modify a pod attached to the host PID namespace. HostPID allows a pod to
11access all the processes running on the host and could allow an attacker to take malicious action. When paired with
12ptrace this can be used to escalate privileges outside of the container. When paired with a privileged container, the
13pod can see all of the processes on the host. An attacker can enter the init system (PID 1) on the host. From there,
14they could execute a shell and continue to escalate privileges to root.
15"""
16false_positives = [
17 """
18 An administrator or developer may want to use a pod that runs as root and shares the hosts IPC, Network, and PID
19 namespaces for debugging purposes. If something is going wrong in the cluster and there is no easy way to SSH onto
20 the host nodes directly, a privileged pod of this nature can be useful for viewing things like iptable rules and
21 network namespaces from the host's perspective. Add exceptions for trusted container images using the query field
22 "kubernetes.audit.requestObject.spec.container.image"
23 """,
24]
25index = ["logs-kubernetes.*"]
26language = "kuery"
27license = "Elastic License v2"
28name = "Kubernetes Pod Created With HostPID"
29note = """## Setup
30
31The Kubernetes Fleet integration with Audit Logs enabled or similarly structured data is required to be compatible with this rule."""
32references = [
33 "https://research.nccgroup.com/2021/11/10/detection-engineering-for-kubernetes-clusters/#part3-kubernetes-detections",
34 "https://kubernetes.io/docs/concepts/security/pod-security-policy/#host-namespaces",
35 "https://bishopfox.com/blog/kubernetes-pod-privilege-escalation",
36]
37risk_score = 47
38rule_id = "df7fda76-c92b-4943-bc68-04460a5ea5ba"
39severity = "medium"
40tags = ["Data Source: Kubernetes", "Tactic: Execution", "Tactic: Privilege Escalation"]
41timestamp_override = "event.ingested"
42type = "query"
43
44query = '''
45event.dataset : "kubernetes.audit_logs"
46 and kubernetes.audit.annotations.authorization_k8s_io/decision:"allow"
47 and kubernetes.audit.objectRef.resource:"pods"
48 and kubernetes.audit.verb:("create" or "update" or "patch")
49 and kubernetes.audit.requestObject.spec.hostPID:true
50 and not kubernetes.audit.requestObject.spec.containers.image: ("docker.elastic.co/beats/elastic-agent:8.4.0")
51'''
52
53
54[[rule.threat]]
55framework = "MITRE ATT&CK"
56[[rule.threat.technique]]
57id = "T1611"
58name = "Escape to Host"
59reference = "https://attack.mitre.org/techniques/T1611/"
60
61
62[rule.threat.tactic]
63id = "TA0004"
64name = "Privilege Escalation"
65reference = "https://attack.mitre.org/tactics/TA0004/"
66[[rule.threat]]
67framework = "MITRE ATT&CK"
68[[rule.threat.technique]]
69id = "T1610"
70name = "Deploy Container"
71reference = "https://attack.mitre.org/techniques/T1610/"
72
73
74[rule.threat.tactic]
75id = "TA0002"
76name = "Execution"
77reference = "https://attack.mitre.org/tactics/TA0002/"
Setup
The Kubernetes Fleet integration with Audit Logs enabled or similarly structured data is required to be compatible with this rule.
References
Related rules
- Kubernetes Container Created with Excessive Linux Capabilities
- Kubernetes Pod Created With HostIPC
- Kubernetes Pod Created With HostNetwork
- Kubernetes Pod created with a Sensitive hostPath Volume
- Kubernetes Privileged Pod Created