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"]
  4maturity = "production"
  5updated_date = "2024/10/24"
  6
  7[transform]
  8[[transform.osquery]]
  9label = "Osquery - Retrieve Information for a Specific User"
 10query = "SELECT * FROM users WHERE username = {{user.name}}"
 11
 12[[transform.osquery]]
 13label = "Osquery - Investigate the Account Authentication Status"
 14query = "SELECT * FROM logged_in_users WHERE user = {{user.name}}"
 15
 16[[transform.osquery]]
 17label = "Osquery - Retrieve Information for a Specific Group"
 18query = "SELECT * FROM groups WHERE groupname = {{group.name}}"
 19
 20[[transform.osquery]]
 21label = "Osquery - Retrieve Running Processes by User"
 22query = "SELECT pid, username, name FROM processes p JOIN users u ON u.uid = p.uid ORDER BY username"
 23
 24
 25[rule]
 26author = ["Elastic"]
 27description = """
 28Identifies attempts to add a user to a privileged group. Attackers may add users to a privileged group in order to
 29establish persistence on a system.
 30"""
 31from = "now-9m"
 32index = ["logs-endpoint.events.*", "endgame-*", "auditbeat-*", "logs-auditd_manager.auditd-*"]
 33language = "eql"
 34license = "Elastic License v2"
 35name = "Linux User Added to Privileged Group"
 36note = """## Triage and analysis
 37
 38### Investigating Linux User User Added to Privileged Group
 39
 40The `usermod`, `adduser`, and `gpasswd` commands can be used to assign user accounts to new groups in Linux-based operating systems.
 41
 42Attackers may add users to a privileged group in order to escalate privileges or establish persistence on a system or domain.
 43
 44This rule identifies the usages of `usermod`, `adduser` and `gpasswd` to assign user accounts to a privileged group.
 45
 46> **Note**:
 47> 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.
 48> 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.
 49
 50#### Possible investigation steps
 51
 52- Investigate whether the user was succesfully added to the privileged group.
 53  - $osquery_0
 54- Investigate whether the user is currently logged in and active.
 55  - $osquery_1
 56- Retrieve information about the privileged group to which the user was added.
 57  - $osquery_2
 58- 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.
 59  - $osquery_3
 60- Identify the user account that performed the action and whether it should perform this kind of action.
 61- Investigate other alerts associated with the user/host during the past 48 hours.
 62
 63### False positive analysis
 64
 65- 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.
 66
 67### Response and remediation
 68
 69- Initiate the incident response process based on the outcome of the triage.
 70- Isolate the involved host to prevent further post-compromise behavior.
 71- If the triage identified malware, search the environment for additional compromised hosts.
 72  - Implement temporary network rules, procedures, and segmentation to contain the malware.
 73  - Stop suspicious processes.
 74  - Immediately block the identified indicators of compromise (IoCs).
 75  - Inspect the affected systems for additional malware backdoors like reverse shells, reverse proxies, or droppers that attackers could use to reinfect the system.
 76- Review the privileges assigned to the involved users to ensure that the least privilege principle is being followed.
 77- Delete the account that seems to be involved in malicious activity.
 78- 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.
 79- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
 80- 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).
 81"""
 82references = ["https://www.elastic.co/security-labs/primer-on-persistence-mechanisms"]
 83risk_score = 21
 84rule_id = "43d6ec12-2b1c-47b5-8f35-e9de65551d3b"
 85setup = """## Setup
 86
 87This rule requires data coming in from Elastic Defend.
 88
 89### Elastic Defend Integration Setup
 90Elastic 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.
 91
 92#### Prerequisite Requirements:
 93- Fleet is required for Elastic Defend.
 94- To configure Fleet Server refer to the [documentation](https://www.elastic.co/guide/en/fleet/current/fleet-server.html).
 95
 96#### The following steps should be executed in order to add the Elastic Defend integration on a Linux System:
 97- Go to the Kibana home page and click "Add integrations".
 98- In the query bar, search for "Elastic Defend" and select the integration to see more details about it.
 99- Click "Add Elastic Defend".
100- Configure the integration name and optionally add a description.
101- Select the type of environment you want to protect, either "Traditional Endpoints" or "Cloud Workloads".
102- 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).
103- We suggest selecting "Complete EDR (Endpoint Detection and Response)" as a configuration setting, that provides "All events; all preventions"
104- 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.
105For more details on Elastic Agent configuration settings, refer to the [helper guide](https://www.elastic.co/guide/en/fleet/8.10/agent-policy.html).
106- Click "Save and Continue".
107- 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.
108For more details on Elastic Defend refer to the [helper guide](https://www.elastic.co/guide/en/security/current/install-endpoint.html).
109"""
110severity = "low"
111tags = [
112    "Domain: Endpoint",
113    "OS: Linux",
114    "Use Case: Threat Detection",
115    "Tactic: Persistence",
116    "Data Source: Elastic Endgame",
117    "Resources: Investigation Guide",
118    "Data Source: Elastic Defend",
119    "Data Source: Auditd Manager",
120]
121timestamp_override = "event.ingested"
122type = "eql"
123query = '''
124process where host.os.type == "linux" and event.type == "start" and event.action in ("exec", "exec_event", "executed", "process_started")
125 and process.args in (
126  "root", "admin", "wheel", "staff", "sudo","disk", "video", "shadow", "lxc", "lxd"
127) and
128(
129  process.name in ("usermod", "adduser") or
130  (process.name == "gpasswd" and process.args in ("-a", "--add", "-M", "--members")) 
131)
132'''
133
134[[rule.threat]]
135framework = "MITRE ATT&CK"
136
137[[rule.threat.technique]]
138id = "T1136"
139name = "Create Account"
140reference = "https://attack.mitre.org/techniques/T1136/"
141
142[[rule.threat.technique.subtechnique]]
143id = "T1136.001"
144name = "Local Account"
145reference = "https://attack.mitre.org/techniques/T1136/001/"
146
147[rule.threat.tactic]
148id = "TA0003"
149name = "Persistence"
150reference = "https://attack.mitre.org/tactics/TA0003/"

Triage and analysis

Investigating Linux User 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

to-top