Potential Linux Backdoor User Account Creation

Identifies the attempt to create a new backdoor user by setting the user's UID to 0. Attackers may alter a user's UID to 0 to establish persistence on a system.

Elastic rule (View on GitHub)

  1[metadata]
  2creation_date = "2023/03/07"
  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 User Accounts with a UID of 0"
 12query = "SELECT description, gid, gid_signed, shell, uid, uid_signed, username FROM users WHERE username != 'root' AND uid LIKE '0'"
 13
 14[[transform.osquery]]
 15label = "Osquery - Retrieve Running Processes by User"
 16query = "SELECT pid, username, name FROM processes p JOIN users u ON u.uid = p.uid ORDER BY username"
 17
 18[[transform.osquery]]
 19label = "Osquery - Retrieve Information for a Specific User"
 20query = "SELECT * FROM users WHERE username = {{user.name}}"
 21
 22[[transform.osquery]]
 23label = "Osquery - Investigate the Account Authentication Status"
 24query = "SELECT * FROM logged_in_users WHERE user = {{user.name}}"
 25
 26[[transform.osquery]]
 27label = "Osquery - Retrieve Information for a Specific Group"
 28query = "SELECT * FROM groups WHERE groupname = {{group.name}}"
 29
 30[rule]
 31author = ["Elastic"]
 32description = """
 33Identifies the attempt to create a new backdoor user by setting the user's UID to 0. Attackers may alter a user's UID to 
 340 to establish persistence on a system.
 35"""
 36from = "now-9m"
 37index = ["logs-endpoint.events.*", "endgame-*", "auditbeat-*", "logs-auditd_manager.auditd-*"]
 38language = "eql"
 39license = "Elastic License v2"
 40name = "Potential Linux Backdoor User Account Creation"
 41note = """## Triage and analysis
 42
 43### Investigating Potential Linux Backdoor User Account Creation
 44
 45The `usermod` command is used to modify user account attributes and settings in Linux-based operating systems.
 46
 47Attackers may create new accounts with a UID of 0 to maintain root access to target systems without leveraging the root user account.
 48
 49This rule identifies the usage of the `usermod` command to set a user's UID to 0, indicating that the user becomes a root account. 
 50
 51> **Note**:
 52> 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.
 53> 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.
 54
 55#### Possible investigation steps
 56- Investigate the user account that got assigned a uid of 0, and analyze its corresponding attributes.
 57  - $osquery_0
 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_1
 60- Identify the user account that performed the action, analyze it, and check whether it should perform this kind of action.
 61  - $osquery_2
 62- Investigate whether the user is currently logged in and active.
 63  - $osquery_3
 64- Identify if the account was added to privileged groups or assigned special privileges after creation.
 65  - $osquery_4
 66- Investigate other alerts associated with the user/host during the past 48 hours.
 67
 68### False positive analysis
 69
 70- This activity is unlikely to happen legitimately. Any activity that triggered the alert and is not inherently malicious must be monitored by the security team.
 71
 72### Response and remediation
 73
 74- Initiate the incident response process based on the outcome of the triage.
 75- Isolate the involved host to prevent further post-compromise behavior.
 76- If the triage identified malware, search the environment for additional compromised hosts.
 77  - Implement temporary network rules, procedures, and segmentation to contain the malware.
 78  - Stop suspicious processes.
 79  - Immediately block the identified indicators of compromise (IoCs).
 80  - Inspect the affected systems for additional malware backdoors like reverse shells, reverse proxies, or droppers that attackers could use to reinfect the system.
 81- Remove and block malicious artifacts identified during triage.
 82- Review the privileges assigned to the involved users to ensure that the least privilege principle is being followed.
 83- Delete the created account.
 84- 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.
 85- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
 86- Leverage the incident response data and logging to improve the mean time to detect (MTTD) and the mean time to respond (MTTR).
 87"""
 88risk_score = 47
 89rule_id = "494ebba4-ecb7-4be4-8c6f-654c686549ad"
 90setup = """## Setup
 91
 92This rule requires data coming in from Elastic Defend.
 93
 94### Elastic Defend Integration Setup
 95Elastic 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.
 96
 97#### Prerequisite Requirements:
 98- Fleet is required for Elastic Defend.
 99- To configure Fleet Server refer to the [documentation](https://www.elastic.co/guide/en/fleet/current/fleet-server.html).
100
101#### The following steps should be executed in order to add the Elastic Defend integration on a Linux System:
102- Go to the Kibana home page and click "Add integrations".
103- In the query bar, search for "Elastic Defend" and select the integration to see more details about it.
104- Click "Add Elastic Defend".
105- Configure the integration name and optionally add a description.
106- Select the type of environment you want to protect, either "Traditional Endpoints" or "Cloud Workloads".
107- 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).
108- We suggest selecting "Complete EDR (Endpoint Detection and Response)" as a configuration setting, that provides "All events; all preventions"
109- 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.
110For more details on Elastic Agent configuration settings, refer to the [helper guide](https://www.elastic.co/guide/en/fleet/8.10/agent-policy.html).
111- Click "Save and Continue".
112- 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.
113For more details on Elastic Defend refer to the [helper guide](https://www.elastic.co/guide/en/security/current/install-endpoint.html).
114"""
115severity = "medium"
116tags = [
117        "Domain: Endpoint",
118        "OS: Linux",
119        "Use Case: Threat Detection",
120        "Tactic: Persistence",
121        "Data Source: Elastic Endgame",
122        "Resources: Investigation Guide",
123        "Data Source: Elastic Defend",
124        "Data Source: Auditd Manager"
125        ]
126timestamp_override = "event.ingested"
127type = "eql"
128query = '''
129process where host.os.type == "linux" and event.type == "start" and event.action in ("exec", "exec_event", "executed", "process_started")
130 and process.name == "usermod" and process.args : "-u" and process.args : "0" and process.args : "-o"
131'''
132
133[[rule.threat]]
134framework = "MITRE ATT&CK"
135
136[[rule.threat.technique]]
137id = "T1136"
138name = "Create Account"
139reference = "https://attack.mitre.org/techniques/T1136/"
140
141[[rule.threat.technique.subtechnique]]
142id = "T1136.001"
143name = "Local Account"
144reference = "https://attack.mitre.org/techniques/T1136/001/"
145
146[rule.threat.tactic]
147id = "TA0003"
148name = "Persistence"
149reference = "https://attack.mitre.org/tactics/TA0003/"

Triage and analysis

Investigating Potential Linux Backdoor User Account Creation

The usermod command is used to modify user account attributes and settings in Linux-based operating systems.

Attackers may create new accounts with a UID of 0 to maintain root access to target systems without leveraging the root user account.

This rule identifies the usage of the usermod command to set a user's UID to 0, indicating that the user becomes a root account.

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 the user account that got assigned a uid of 0, and analyze its corresponding attributes.
    • $osquery_0
  • 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_1
  • Identify the user account that performed the action, analyze it, and check whether it should perform this kind of action.
    • $osquery_2
  • Investigate whether the user is currently logged in and active.
    • $osquery_3
  • Identify if the account was added to privileged groups or assigned special privileges after creation.
    • $osquery_4
  • Investigate other alerts associated with the user/host during the past 48 hours.

False positive analysis

  • This activity is unlikely to happen legitimately. Any activity that triggered the alert and is not inherently malicious must be monitored by the security team.

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.
  • Remove and block malicious artifacts identified during triage.
  • Review the privileges assigned to the involved users to ensure that the least privilege principle is being followed.
  • Delete the created account.
  • 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.
  • Leverage the incident response data and logging to improve the mean time to detect (MTTD) and the mean time to respond (MTTR).

Related rules

to-top