Namespace Manipulation Using Unshare
Identifies suspicious usage of unshare to manipulate system namespaces. Unshare can be utilized to escalate privileges or escape container security boundaries. Threat actors have utilized this binary to allow themselves to escape to the host and access other resources or escalate privileges.
Elastic rule (View on GitHub)
1[metadata]
2creation_date = "2022/08/30"
3integration = ["endpoint", "sentinel_one_cloud_funnel"]
4maturity = "production"
5updated_date = "2025/03/20"
6
7[rule]
8author = ["Elastic"]
9description = """
10Identifies suspicious usage of unshare to manipulate system namespaces. Unshare can be utilized to escalate privileges
11or escape container security boundaries. Threat actors have utilized this binary to allow themselves to escape to the
12host and access other resources or escalate privileges.
13"""
14from = "now-9m"
15index = ["auditbeat-*", "endgame-*", "logs-endpoint.events.process*", "logs-sentinel_one_cloud_funnel.*"]
16language = "eql"
17license = "Elastic License v2"
18name = "Namespace Manipulation Using Unshare"
19note = """## Triage and analysis
20
21> **Disclaimer**:
22> This investigation guide was created using generative AI technology and has been reviewed to improve its accuracy and relevance. While every effort has been made to ensure its quality, we recommend validating the content and adapting it to suit your specific environment and operational needs.
23
24### Investigating Namespace Manipulation Using Unshare
25
26The `unshare` command in Linux is used to create new namespaces, isolating processes from the rest of the system. This isolation is crucial for containerization and security. However, attackers can exploit `unshare` to break out of containers or elevate privileges by creating namespaces that bypass security controls. The detection rule identifies suspicious `unshare` executions by monitoring process starts, filtering out benign parent processes, and focusing on unusual usage patterns, thus highlighting potential misuse.
27
28### Possible investigation steps
29
30- Review the process tree to understand the context of the unshare execution, focusing on the parent process and any child processes spawned by unshare.
31- Investigate the user account associated with the unshare execution to determine if it is a legitimate user or potentially compromised.
32- Examine the command-line arguments used with unshare to identify any unusual or suspicious options that may indicate an attempt to bypass security controls.
33- Check for any recent changes or anomalies in the system logs around the time of the unshare execution to identify potential indicators of compromise or privilege escalation attempts.
34- Correlate the unshare event with other security alerts or logs to determine if it is part of a larger attack pattern or campaign.
35
36### False positive analysis
37
38- System management tools like udevadm and systemd-udevd may invoke unshare as part of their normal operations. These should be excluded by ensuring the rule filters out processes with these as parent executables.
39- Snap package management can trigger unshare during its operations. Exclude processes where the arguments include /usr/bin/snap to prevent unnecessary alerts.
40- Java applications might occasionally use unshare for legitimate purposes. Exclude processes with java as the parent name to reduce false positives.
41- Custom scripts or administrative tasks that use unshare for legitimate namespace management should be reviewed and, if deemed safe, added to the exclusion list to prevent repeated alerts.
42
43### Response and remediation
44
45- Immediately isolate the affected system to prevent further unauthorized access or lateral movement within the network.
46- Terminate any suspicious processes associated with the `unshare` command that do not have legitimate parent processes or arguments, as identified in the detection query.
47- Conduct a thorough review of system logs and process trees to identify any additional unauthorized or suspicious activities that may have occurred in conjunction with the `unshare` execution.
48- Revoke any unauthorized access or privileges that may have been granted as a result of the namespace manipulation, ensuring that all user and process permissions are appropriately restricted.
49- Restore the affected system from a known good backup if any unauthorized changes or damage to the system integrity are detected.
50- Implement additional monitoring and alerting for unusual `unshare` usage patterns to enhance detection capabilities and prevent future occurrences.
51- Escalate the incident to the security operations team for further investigation and to determine if additional systems or data have been compromised."""
52references = [
53 "https://man7.org/linux/man-pages/man1/unshare.1.html",
54 "https://www.crowdstrike.com/blog/cve-2022-0185-kubernetes-container-escape-using-linux-kernel-exploit/",
55]
56risk_score = 47
57rule_id = "d00f33e7-b57d-4023-9952-2db91b1767c4"
58setup = """## Setup
59
60This rule requires data coming in from one of the following integrations:
61- Elastic Defend
62- Auditbeat
63
64### Elastic Defend Integration Setup
65Elastic 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.
66
67#### Prerequisite Requirements:
68- Fleet is required for Elastic Defend.
69- To configure Fleet Server refer to the [documentation](https://www.elastic.co/guide/en/fleet/current/fleet-server.html).
70
71#### The following steps should be executed in order to add the Elastic Defend integration on a Linux System:
72- Go to the Kibana home page and click "Add integrations".
73- In the query bar, search for "Elastic Defend" and select the integration to see more details about it.
74- Click "Add Elastic Defend".
75- Configure the integration name and optionally add a description.
76- Select the type of environment you want to protect, either "Traditional Endpoints" or "Cloud Workloads".
77- 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).
78- We suggest selecting "Complete EDR (Endpoint Detection and Response)" as a configuration setting, that provides "All events; all preventions"
79- 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.
80For more details on Elastic Agent configuration settings, refer to the [helper guide](https://www.elastic.co/guide/en/fleet/8.10/agent-policy.html).
81- Click "Save and Continue".
82- 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.
83For more details on Elastic Defend refer to the [helper guide](https://www.elastic.co/guide/en/security/current/install-endpoint.html).
84
85### Auditbeat Setup
86Auditbeat is a lightweight shipper that you can install on your servers to audit the activities of users and processes on your systems. For example, you can use Auditbeat to collect and centralize audit events from the Linux Audit Framework. You can also use Auditbeat to detect changes to critical files, like binaries and configuration files, and identify potential security policy violations.
87
88#### The following steps should be executed in order to add the Auditbeat on a Linux System:
89- Elastic provides repositories available for APT and YUM-based distributions. Note that we provide binary packages, but no source packages.
90- To install the APT and YUM repositories follow the setup instructions in this [helper guide](https://www.elastic.co/guide/en/beats/auditbeat/current/setup-repositories.html).
91- To run Auditbeat on Docker follow the setup instructions in the [helper guide](https://www.elastic.co/guide/en/beats/auditbeat/current/running-on-docker.html).
92- To run Auditbeat on Kubernetes follow the setup instructions in the [helper guide](https://www.elastic.co/guide/en/beats/auditbeat/current/running-on-kubernetes.html).
93- For complete “Setup and Run Auditbeat” information refer to the [helper guide](https://www.elastic.co/guide/en/beats/auditbeat/current/setting-up-and-running.html).
94"""
95severity = "medium"
96tags = [
97 "Domain: Endpoint",
98 "OS: Linux",
99 "Use Case: Threat Detection",
100 "Tactic: Privilege Escalation",
101 "Data Source: Elastic Endgame",
102 "Data Source: Elastic Defend",
103 "Data Source: SentinelOne",
104 "Resources: Investigation Guide",
105]
106timestamp_override = "event.ingested"
107type = "eql"
108
109query = '''
110process where host.os.type == "linux" and event.type == "start" and event.action : ("exec", "exec_event", "start") and
111process.executable: "/usr/bin/unshare" and
112not process.parent.executable: ("/usr/bin/udevadm", "*/lib/systemd/systemd-udevd", "/usr/bin/unshare") and
113not process.args == "/usr/bin/snap" and not process.parent.name in ("zz-proxmox-boot", "java")
114'''
115
116
117[[rule.threat]]
118framework = "MITRE ATT&CK"
119[[rule.threat.technique]]
120id = "T1543"
121name = "Create or Modify System Process"
122reference = "https://attack.mitre.org/techniques/T1543/"
123
124
125[rule.threat.tactic]
126id = "TA0004"
127name = "Privilege Escalation"
128reference = "https://attack.mitre.org/tactics/TA0004/"
Triage and analysis
Disclaimer: This investigation guide was created using generative AI technology and has been reviewed to improve its accuracy and relevance. While every effort has been made to ensure its quality, we recommend validating the content and adapting it to suit your specific environment and operational needs.
Investigating Namespace Manipulation Using Unshare
The unshare
command in Linux is used to create new namespaces, isolating processes from the rest of the system. This isolation is crucial for containerization and security. However, attackers can exploit unshare
to break out of containers or elevate privileges by creating namespaces that bypass security controls. The detection rule identifies suspicious unshare
executions by monitoring process starts, filtering out benign parent processes, and focusing on unusual usage patterns, thus highlighting potential misuse.
Possible investigation steps
- Review the process tree to understand the context of the unshare execution, focusing on the parent process and any child processes spawned by unshare.
- Investigate the user account associated with the unshare execution to determine if it is a legitimate user or potentially compromised.
- Examine the command-line arguments used with unshare to identify any unusual or suspicious options that may indicate an attempt to bypass security controls.
- Check for any recent changes or anomalies in the system logs around the time of the unshare execution to identify potential indicators of compromise or privilege escalation attempts.
- Correlate the unshare event with other security alerts or logs to determine if it is part of a larger attack pattern or campaign.
False positive analysis
- System management tools like udevadm and systemd-udevd may invoke unshare as part of their normal operations. These should be excluded by ensuring the rule filters out processes with these as parent executables.
- Snap package management can trigger unshare during its operations. Exclude processes where the arguments include /usr/bin/snap to prevent unnecessary alerts.
- Java applications might occasionally use unshare for legitimate purposes. Exclude processes with java as the parent name to reduce false positives.
- Custom scripts or administrative tasks that use unshare for legitimate namespace management should be reviewed and, if deemed safe, added to the exclusion list to prevent repeated alerts.
Response and remediation
- Immediately isolate the affected system to prevent further unauthorized access or lateral movement within the network.
- Terminate any suspicious processes associated with the
unshare
command that do not have legitimate parent processes or arguments, as identified in the detection query. - Conduct a thorough review of system logs and process trees to identify any additional unauthorized or suspicious activities that may have occurred in conjunction with the
unshare
execution. - Revoke any unauthorized access or privileges that may have been granted as a result of the namespace manipulation, ensuring that all user and process permissions are appropriately restricted.
- Restore the affected system from a known good backup if any unauthorized changes or damage to the system integrity are detected.
- Implement additional monitoring and alerting for unusual
unshare
usage patterns to enhance detection capabilities and prevent future occurrences. - Escalate the incident to the security operations team for further investigation and to determine if additional systems or data have been compromised.
References
Related rules
- D-Bus Service Created
- Kernel Load or Unload via Kexec Detected
- Potential Privilege Escalation via PKEXEC
- Potential Sudo Privilege Escalation via CVE-2019-14287
- Potential Suspicious File Edit