Linux User Added to Privileged Group
Identifies attempts to add a user to a privileged group. Attackers may add users to a privileged group in order to establish persistence on a system.
Elastic rule (View on GitHub)
1[metadata]
2creation_date = "2023/02/13"
3integration = ["endpoint", "auditd_manager", "crowdstrike", "sentinel_one_cloud_funnel"]
4maturity = "production"
5min_stack_version = "8.13.0"
6min_stack_comments = "Breaking change at 8.13.0 for SentinelOne Integration."
7updated_date = "2025/01/17"
8
9[transform]
10[[transform.osquery]]
11label = "Osquery - Retrieve Information for a Specific User"
12query = "SELECT * FROM users WHERE username = {{user.name}}"
13
14[[transform.osquery]]
15label = "Osquery - Investigate the Account Authentication Status"
16query = "SELECT * FROM logged_in_users WHERE user = {{user.name}}"
17
18[[transform.osquery]]
19label = "Osquery - Retrieve Information for a Specific Group"
20query = "SELECT * FROM groups WHERE groupname = {{group.name}}"
21
22[[transform.osquery]]
23label = "Osquery - Retrieve Running Processes by User"
24query = "SELECT pid, username, name FROM processes p JOIN users u ON u.uid = p.uid ORDER BY username"
25
26
27[rule]
28author = ["Elastic"]
29description = """
30Identifies attempts to add a user to a privileged group. Attackers may add users to a privileged group in order to
31establish persistence on a system.
32"""
33from = "now-9m"
34index = ["logs-endpoint.events.*", "endgame-*", "auditbeat-*", "logs-auditd_manager.auditd-*", "logs-crowdstrike.fdr*", "logs-sentinel_one_cloud_funnel.*"]
35language = "eql"
36license = "Elastic License v2"
37name = "Linux User Added to Privileged Group"
38note = """## Triage and analysis
39
40### Investigating Linux User Added to Privileged Group
41
42The `usermod`, `adduser`, and `gpasswd` commands can be used to assign user accounts to new groups in Linux-based operating systems.
43
44Attackers may add users to a privileged group in order to escalate privileges or establish persistence on a system or domain.
45
46This rule identifies the usages of `usermod`, `adduser` and `gpasswd` to assign user accounts to a privileged group.
47
48> **Note**:
49> This investigation guide uses the [Osquery Markdown Plugin](https://www.elastic.co/guide/en/security/master/invest-guide-run-osquery.html) introduced in Elastic Stack version 8.5.0. Older Elastic Stack versions will display unrendered Markdown in this guide.
50> This investigation guide uses [placeholder fields](https://www.elastic.co/guide/en/security/current/osquery-placeholder-fields.html) to dynamically pass alert data into Osquery queries. Placeholder fields were introduced in Elastic Stack version 8.7.0. If you're using Elastic Stack version 8.6.0 or earlier, you'll need to manually adjust this investigation guide's queries to ensure they properly run.
51
52#### Possible investigation steps
53
54- Investigate whether the user was succesfully added to the privileged group.
55 - $osquery_0
56- Investigate whether the user is currently logged in and active.
57 - $osquery_1
58- Retrieve information about the privileged group to which the user was added.
59 - $osquery_2
60- Investigate the process execution chain (parent process tree) for unknown processes. Examine their executable files for prevalence and whether they are located in expected locations.
61 - $osquery_3
62- Identify the user account that performed the action and whether it should perform this kind of action.
63- Investigate other alerts associated with the user/host during the past 48 hours.
64
65### False positive analysis
66
67- Adding accounts to a group is a common administrative task, so there is a high chance of the activity being legitimate. Before investigating further, verify that this activity is not benign.
68
69### Response and remediation
70
71- Initiate the incident response process based on the outcome of the triage.
72- Isolate the involved host to prevent further post-compromise behavior.
73- If the triage identified malware, search the environment for additional compromised hosts.
74 - Implement temporary network rules, procedures, and segmentation to contain the malware.
75 - Stop suspicious processes.
76 - Immediately block the identified indicators of compromise (IoCs).
77 - Inspect the affected systems for additional malware backdoors like reverse shells, reverse proxies, or droppers that attackers could use to reinfect the system.
78- Review the privileges assigned to the involved users to ensure that the least privilege principle is being followed.
79- Delete the account that seems to be involved in malicious activity.
80- Investigate credential exposure on systems compromised or used by the attacker to ensure all compromised accounts are identified. Reset passwords for these accounts and other potentially compromised credentials, such as email, business systems, and web services.
81- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
82- Using the incident response data, update logging and audit policies to improve the mean time to detect (MTTD) and the mean time to respond (MTTR).
83"""
84references = ["https://www.elastic.co/security-labs/primer-on-persistence-mechanisms"]
85risk_score = 21
86rule_id = "43d6ec12-2b1c-47b5-8f35-e9de65551d3b"
87setup = """## Setup
88
89This rule requires data coming in from Elastic Defend.
90
91### Elastic Defend Integration Setup
92Elastic 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.
93
94#### Prerequisite Requirements:
95- Fleet is required for Elastic Defend.
96- To configure Fleet Server refer to the [documentation](https://www.elastic.co/guide/en/fleet/current/fleet-server.html).
97
98#### The following steps should be executed in order to add the Elastic Defend integration on a Linux System:
99- Go to the Kibana home page and click "Add integrations".
100- In the query bar, search for "Elastic Defend" and select the integration to see more details about it.
101- Click "Add Elastic Defend".
102- Configure the integration name and optionally add a description.
103- Select the type of environment you want to protect, either "Traditional Endpoints" or "Cloud Workloads".
104- 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).
105- We suggest selecting "Complete EDR (Endpoint Detection and Response)" as a configuration setting, that provides "All events; all preventions"
106- 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.
107For more details on Elastic Agent configuration settings, refer to the [helper guide](https://www.elastic.co/guide/en/fleet/8.10/agent-policy.html).
108- Click "Save and Continue".
109- 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.
110For more details on Elastic Defend refer to the [helper guide](https://www.elastic.co/guide/en/security/current/install-endpoint.html).
111"""
112severity = "low"
113tags = [
114 "Domain: Endpoint",
115 "OS: Linux",
116 "Use Case: Threat Detection",
117 "Tactic: Persistence",
118 "Data Source: Elastic Endgame",
119 "Resources: Investigation Guide",
120 "Data Source: Elastic Defend",
121 "Data Source: Auditd Manager",
122 "Data Source: Crowdstrike",
123 "Data Source: SentinelOne",
124]
125timestamp_override = "event.ingested"
126type = "eql"
127query = '''
128process where host.os.type == "linux" and event.type == "start" and
129 event.action in ("exec", "exec_event", "start", "ProcessRollup2", "executed", "process_started") and
130 process.args in (
131 "root", "admin", "wheel", "staff", "sudo","disk", "video", "shadow", "lxc", "lxd"
132 ) and
133 (
134 process.name in ("usermod", "adduser") or
135 (process.name == "gpasswd" and process.args in ("-a", "--add", "-M", "--members"))
136 )
137'''
138
139[[rule.threat]]
140framework = "MITRE ATT&CK"
141
142[[rule.threat.technique]]
143id = "T1136"
144name = "Create Account"
145reference = "https://attack.mitre.org/techniques/T1136/"
146
147[[rule.threat.technique.subtechnique]]
148id = "T1136.001"
149name = "Local Account"
150reference = "https://attack.mitre.org/techniques/T1136/001/"
151
152[rule.threat.tactic]
153id = "TA0003"
154name = "Persistence"
155reference = "https://attack.mitre.org/tactics/TA0003/"
Triage and analysis
Investigating Linux User Added to Privileged Group
The usermod
, adduser
, and gpasswd
commands can be used to assign user accounts to new groups in Linux-based operating systems.
Attackers may add users to a privileged group in order to escalate privileges or establish persistence on a system or domain.
This rule identifies the usages of usermod
, adduser
and gpasswd
to assign user accounts to a privileged group.
Note: This investigation guide uses the Osquery Markdown Plugin introduced in Elastic Stack version 8.5.0. Older Elastic Stack versions will display unrendered Markdown in this guide. This investigation guide uses placeholder fields to dynamically pass alert data into Osquery queries. Placeholder fields were introduced in Elastic Stack version 8.7.0. If you're using Elastic Stack version 8.6.0 or earlier, you'll need to manually adjust this investigation guide's queries to ensure they properly run.
Possible investigation steps
- Investigate whether the user was succesfully added to the privileged group.
- $osquery_0
- Investigate whether the user is currently logged in and active.
- $osquery_1
- Retrieve information about the privileged group to which the user was added.
- $osquery_2
- Investigate the process execution chain (parent process tree) for unknown processes. Examine their executable files for prevalence and whether they are located in expected locations.
- $osquery_3
- Identify the user account that performed the action and whether it should perform this kind of action.
- Investigate other alerts associated with the user/host during the past 48 hours.
False positive analysis
- Adding accounts to a group is a common administrative task, so there is a high chance of the activity being legitimate. Before investigating further, verify that this activity is not benign.
Response and remediation
- Initiate the incident response process based on the outcome of the triage.
- Isolate the involved host to prevent further post-compromise behavior.
- If the triage identified malware, search the environment for additional compromised hosts.
- Implement temporary network rules, procedures, and segmentation to contain the malware.
- Stop suspicious processes.
- Immediately block the identified indicators of compromise (IoCs).
- Inspect the affected systems for additional malware backdoors like reverse shells, reverse proxies, or droppers that attackers could use to reinfect the system.
- Review the privileges assigned to the involved users to ensure that the least privilege principle is being followed.
- Delete the account that seems to be involved in malicious activity.
- Investigate credential exposure on systems compromised or used by the attacker to ensure all compromised accounts are identified. Reset passwords for these accounts and other potentially compromised credentials, such as email, business systems, and web services.
- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
- Using the incident response data, update logging and audit policies to improve the mean time to detect (MTTD) and the mean time to respond (MTTR).
References
Related rules
- Kernel Load or Unload via Kexec Detected
- Potential Linux Backdoor User Account Creation
- Base16 or Base32 Encoding/Decoding Activity
- Directory Creation in /bin directory
- ESXI Timestomping using Touch Command