Potential Privilege Escalation via Container Misconfiguration

This rule monitors for the execution of processes that interact with Linux containers through an interactive shell without root permissions. Utilities such as runc and ctr are universal command-line utilities leveraged to interact with containers via root permissions. On systems where the access to these utilities are misconfigured, attackers might be able to create and run a container that mounts the root folder or spawn a privileged container vulnerable to a container escape attack, which might allow them to escalate privileges and gain further access onto the host file system.

Elastic rule (View on GitHub)

 1[metadata]
 2creation_date = "2023/07/31"
 3integration = ["endpoint"]
 4maturity = "production"
 5min_stack_comments = "New fields added: required_fields, related_integrations, setup"
 6min_stack_version = "8.3.0"
 7updated_date = "2024/03/08"
 8
 9[rule]
10author = ["Elastic"]
11description = """
12This rule monitors for the execution of processes that interact with Linux containers through an interactive shell 
13without root permissions. Utilities such as runc and ctr are universal command-line utilities leveraged to interact 
14with containers via root permissions. On systems where the access to these utilities are misconfigured, attackers might 
15be able to create and run a container that mounts the root folder or spawn a privileged container vulnerable to a 
16container escape attack, which might allow them to escalate privileges and gain further access onto the host file system.
17"""
18from = "now-9m"
19index = ["logs-endpoint.events.*"]
20language = "eql"
21license = "Elastic License v2"
22name = "Potential Privilege Escalation via Container Misconfiguration"
23references = [
24    "https://book.hacktricks.xyz/linux-hardening/privilege-escalation/runc-privilege-escalation",
25    "https://book.hacktricks.xyz/linux-hardening/privilege-escalation/containerd-ctr-privilege-escalation"
26    ]
27risk_score = 47
28rule_id = "afe6b0eb-dd9d-4922-b08a-1910124d524d"
29setup = """## Setup
30
31This rule requires data coming in from Elastic Defend.
32
33### Elastic Defend Integration Setup
34Elastic 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.
35
36#### Prerequisite Requirements:
37- Fleet is required for Elastic Defend.
38- To configure Fleet Server refer to the [documentation](https://www.elastic.co/guide/en/fleet/current/fleet-server.html).
39
40#### The following steps should be executed in order to add the Elastic Defend integration on a Linux System:
41- Go to the Kibana home page and click "Add integrations".
42- In the query bar, search for "Elastic Defend" and select the integration to see more details about it.
43- Click "Add Elastic Defend".
44- Configure the integration name and optionally add a description.
45- Select the type of environment you want to protect, either "Traditional Endpoints" or "Cloud Workloads".
46- 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).
47- We suggest selecting "Complete EDR (Endpoint Detection and Response)" as a configuration setting, that provides "All events; all preventions"
48- 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.
49For more details on Elastic Agent configuration settings, refer to the [helper guide](https://www.elastic.co/guide/en/fleet/8.10/agent-policy.html).
50- Click "Save and Continue".
51- 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.
52For more details on Elastic Defend refer to the [helper guide](https://www.elastic.co/guide/en/security/current/install-endpoint.html).
53
54Session View uses process data collected by the Elastic Defend integration, but this data is not always collected by default. Session View is available on enterprise subscription for versions 8.3 and above.
55#### To confirm that Session View data is enabled:
56- Go to “Manage → Policies”, and edit one or more of your Elastic Defend integration policies.
57- Select the” Policy settings” tab, then scroll down to the “Linux event collection” section near the bottom.
58- Check the box for “Process events”, and turn on the “Include session data” toggle.
59- If you want to include file and network alerts in Session View, check the boxes for “Network and File events”.
60- If you want to enable terminal output capture, turn on the “Capture terminal output” toggle.
61For more information about the additional fields collected when this setting is enabled and the usage of Session View for Analysis refer to the [helper guide](https://www.elastic.co/guide/en/security/current/session-view.html).
62"""
63severity = "medium"
64tags = ["Domain: Endpoint", "OS: Linux", "Use Case: Threat Detection", "Tactic: Privilege Escalation", "Domain: Container", "Data Source: Elastic Defend"]
65timestamp_override = "event.ingested"
66type = "eql"
67query = '''
68process where host.os.type == "linux" and event.type == "start" and event.action == "exec" and (
69  (process.name == "runc" and process.args == "run") or
70  (process.name == "ctr" and process.args == "run" and process.args in ("--privileged", "--mount"))
71) and not user.Ext.real.id == "0" and not group.Ext.real.id == "0" and 
72process.interactive == true and process.parent.interactive == true
73'''
74
75[[rule.threat]]
76framework = "MITRE ATT&CK"
77
78[[rule.threat.technique]]
79id = "T1611"
80name = "Escape to Host"
81reference = "https://attack.mitre.org/techniques/T1611/"
82
83[rule.threat.tactic]
84id = "TA0004"
85name = "Privilege Escalation"
86reference = "https://attack.mitre.org/tactics/TA0004/"

References

Related rules

to-top