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

References

Related rules

to-top