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"
  5min_stack_comments = "New fields added: required_fields, related_integrations, setup"
  6min_stack_version = "8.3.0"
  7updated_date = "2024/03/08"
  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[rule]
 27author = ["Elastic"]
 28description = """
 29Identifies attempts to add a user to a privileged group. Attackers may add users to a privileged group in order to 
 30establish persistence on a system.
 31"""
 32from = "now-9m"
 33index = ["logs-endpoint.events.*", "endgame-*", "auditbeat-*", "logs-auditd_manager.auditd-*"]
 34language = "eql"
 35license = "Elastic License v2"
 36name = "Linux User Added to Privileged Group"
 37note = """## Triage and analysis
 38
 39### Investigating Linux User User Added to Privileged Group
 40
 41The `usermod`, `adduser`, and `gpasswd` commands can be used to assign user accounts to new groups in Linux-based operating systems.
 42
 43Attackers may add users to a privileged group in order to escalate privileges or establish persistence on a system or domain.
 44
 45This rule identifies the usages of `usermod`, `adduser` and `gpasswd` to assign user accounts to a privileged group.
 46
 47> **Note**:
 48> 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.
 49> 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.
 50
 51#### Possible investigation steps
 52
 53- Investigate whether the user was succesfully added to the privileged group.
 54  - $osquery_0
 55- Investigate whether the user is currently logged in and active.
 56  - $osquery_1
 57- Retrieve information about the privileged group to which the user was added.
 58  - $osquery_2
 59- 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.
 60  - $osquery_3
 61- Identify the user account that performed the action and whether it should perform this kind of action.
 62- Investigate other alerts associated with the user/host during the past 48 hours.
 63
 64### False positive analysis
 65
 66- 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.
 67
 68### Response and remediation
 69
 70- Initiate the incident response process based on the outcome of the triage.
 71- Isolate the involved host to prevent further post-compromise behavior.
 72- If the triage identified malware, search the environment for additional compromised hosts.
 73  - Implement temporary network rules, procedures, and segmentation to contain the malware.
 74  - Stop suspicious processes.
 75  - Immediately block the identified indicators of compromise (IoCs).
 76  - Inspect the affected systems for additional malware backdoors like reverse shells, reverse proxies, or droppers that attackers could use to reinfect the system.
 77- Review the privileges assigned to the involved users to ensure that the least privilege principle is being followed.
 78- Delete the account that seems to be involved in malicious activity.
 79- 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.
 80- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
 81- 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).
 82"""
 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 
131  process.args in ("-a", "--add", "-M", "--members") 
132)
133'''
134
135[[rule.threat]]
136framework = "MITRE ATT&CK"
137
138[[rule.threat.technique]]
139id = "T1136"
140name = "Create Account"
141reference = "https://attack.mitre.org/techniques/T1136/"
142
143[[rule.threat.technique.subtechnique]]
144id = "T1136.001"
145name = "Local Account"
146reference = "https://attack.mitre.org/techniques/T1136/001/"
147
148[rule.threat.tactic]
149id = "TA0003"
150name = "Persistence"
151reference = "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).

Related rules

to-top