Potential Chroot Container Escape via Mount
Monitors for the execution of a file system mount followed by a chroot execution. Given enough permissions, a user within a container is capable of mounting the root file system of the host, and leveraging chroot to escape its containarized environment. This behavior pattern is very uncommon and should be investigated.
Elastic rule (View on GitHub)
1[metadata]
2creation_date = "2024/01/15"
3integration = ["endpoint"]
4maturity = "production"
5updated_date = "2024/05/21"
6
7[rule]
8author = ["Elastic"]
9description = """
10Monitors for the execution of a file system mount followed by a chroot execution. Given enough permissions, a user
11within a container is capable of mounting the root file system of the host, and leveraging chroot to escape its
12containarized environment. This behavior pattern is very uncommon and should be investigated.
13"""
14from = "now-9m"
15index = ["logs-endpoint.events.*"]
16language = "eql"
17license = "Elastic License v2"
18name = "Potential Chroot Container Escape via Mount"
19references = [
20 "https://book.hacktricks.xyz/v/portugues-ht/linux-hardening/privilege-escalation/escaping-from-limited-bash",
21]
22risk_score = 47
23rule_id = "5ae02ebc-a5de-4eac-afe6-c88de696477d"
24setup = """## Setup
25
26
27This rule requires data coming in from Elastic Defend.
28
29### Elastic Defend Integration Setup
30Elastic 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.
31
32#### Prerequisite Requirements:
33- Fleet is required for Elastic Defend.
34- To configure Fleet Server refer to the [documentation](https://www.elastic.co/guide/en/fleet/current/fleet-server.html).
35
36#### The following steps should be executed in order to add the Elastic Defend integration on a Linux System:
37- Go to the Kibana home page and click "Add integrations".
38- In the query bar, search for "Elastic Defend" and select the integration to see more details about it.
39- Click "Add Elastic Defend".
40- Configure the integration name and optionally add a description.
41- Select the type of environment you want to protect, either "Traditional Endpoints" or "Cloud Workloads".
42- 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).
43- We suggest selecting "Complete EDR (Endpoint Detection and Response)" as a configuration setting, that provides "All events; all preventions"
44- 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.
45For more details on Elastic Agent configuration settings, refer to the [helper guide](https://www.elastic.co/guide/en/fleet/8.10/agent-policy.html).
46- Click "Save and Continue".
47- 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.
48For more details on Elastic Defend refer to the [helper guide](https://www.elastic.co/guide/en/security/current/install-endpoint.html).
49
50Session 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.
51#### To confirm that Session View data is enabled:
52- Go to “Manage → Policies”, and edit one or more of your Elastic Defend integration policies.
53- Select the” Policy settings” tab, then scroll down to the “Linux event collection” section near the bottom.
54- Check the box for “Process events”, and turn on the “Include session data” toggle.
55- If you want to include file and network alerts in Session View, check the boxes for “Network and File events”.
56- If you want to enable terminal output capture, turn on the “Capture terminal output” toggle.
57For 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).
58"""
59severity = "medium"
60tags = [
61 "Domain: Endpoint",
62 "OS: Linux",
63 "Use Case: Threat Detection",
64 "Tactic: Privilege Escalation",
65 "Domain: Container",
66 "Data Source: Elastic Defend",
67]
68type = "eql"
69
70query = '''
71sequence by host.id, process.parent.entity_id with maxspan=5m
72 [process where host.os.type == "linux" and event.type == "start" and event.action == "exec" and
73 process.name == "mount" and process.args : "/dev/sd*" and process.args_count >= 3 and
74 process.parent.name in ("bash", "dash", "sh", "tcsh", "csh", "zsh", "ksh", "fish")]
75 [process where host.os.type == "linux" and event.type == "start" and event.action == "exec" and
76 process.name == "chroot"]
77'''
78
79
80[[rule.threat]]
81framework = "MITRE ATT&CK"
82[[rule.threat.technique]]
83id = "T1611"
84name = "Escape to Host"
85reference = "https://attack.mitre.org/techniques/T1611/"
86
87
88[rule.threat.tactic]
89id = "TA0004"
90name = "Privilege Escalation"
91reference = "https://attack.mitre.org/tactics/TA0004/"
References
Related rules
- Potential Privilege Escalation through Writable Docker Socket
- Potential Privilege Escalation via Container Misconfiguration
- Modification of Dynamic Linker Preload Shared Object
- Namespace Manipulation Using Unshare
- Potential Privilege Escalation via CVE-2023-4911