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

to-top