Linux User Account Creation

Identifies attempts to create new users. Attackers may add new users to establish persistence on a system.

Elastic rule (View on GitHub)

  1[metadata]
  2creation_date = "2023/02/13"
  3integration = ["system"]
  4maturity = "production"
  5updated_date = "2024/09/23"
  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 = "Identifies attempts to create new users. Attackers may add new users to establish persistence on a system.\n"
 28from = "now-9m"
 29index = ["filebeat-*", "logs-system.auth-*"]
 30language = "eql"
 31license = "Elastic License v2"
 32name = "Linux User Account Creation"
 33note = """## Triage and analysis
 34
 35### Investigating Linux User Account Creation
 36
 37The `useradd` and `adduser` commands are used to create new user accounts in Linux-based operating systems.
 38
 39Attackers may create new accounts (both local and domain) to maintain access to victim systems.
 40
 41This rule identifies the usage of `useradd` and `adduser` to create new accounts.
 42
 43> **Note**:
 44> 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.
 45> 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.
 46
 47#### Possible investigation steps
 48
 49- Investigate whether the user was created succesfully.
 50  - $osquery_0
 51- Investigate whether the user is currently logged in and active.
 52  - $osquery_1
 53- Identify if the account was added to privileged groups or assigned special privileges after creation.
 54  - $osquery_2
 55- Identify the user account that performed the action and whether it should perform this kind of action.
 56- 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.
 57  - $osquery_3
 58- Investigate other alerts associated with the user/host during the past 48 hours.
 59
 60### False positive analysis
 61
 62- Account creation 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.
 63
 64### Response and remediation
 65
 66- Initiate the incident response process based on the outcome of the triage.
 67- Isolate the involved host to prevent further post-compromise behavior.
 68- If the triage identified malware, search the environment for additional compromised hosts.
 69  - Implement temporary network rules, procedures, and segmentation to contain the malware.
 70  - Stop suspicious processes.
 71  - Immediately block the identified indicators of compromise (IoCs).
 72  - Inspect the affected systems for additional malware backdoors like reverse shells, reverse proxies, or droppers that attackers could use to reinfect the system.
 73- Review the privileges assigned to the involved users to ensure that the least privilege principle is being followed.
 74- Delete the created account.
 75- 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.
 76- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
 77- 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).
 78"""
 79references = ["https://www.elastic.co/security-labs/primer-on-persistence-mechanisms"]
 80risk_score = 21
 81rule_id = "edfd5ca9-9d6c-44d9-b615-1e56b920219c"
 82setup = """## Setup
 83
 84This rule requires data coming in from Filebeat.
 85
 86### Filebeat Setup
 87Filebeat is a lightweight shipper for forwarding and centralizing log data. Installed as an agent on your servers, Filebeat monitors the log files or locations that you specify, collects log events, and forwards them either to Elasticsearch or Logstash for indexing.
 88
 89#### The following steps should be executed in order to add the Filebeat on a Linux System:
 90- Elastic provides repositories available for APT and YUM-based distributions. Note that we provide binary packages, but no source packages.
 91- To install the APT and YUM repositories follow the setup instructions in this [helper guide](https://www.elastic.co/guide/en/beats/filebeat/current/setup-repositories.html).
 92- To run Filebeat on Docker follow the setup instructions in the [helper guide](https://www.elastic.co/guide/en/beats/filebeat/current/running-on-docker.html).
 93- To run Filebeat on Kubernetes follow the setup instructions in the [helper guide](https://www.elastic.co/guide/en/beats/filebeat/current/running-on-kubernetes.html).
 94- For quick start information for Filebeat refer to the [helper guide](https://www.elastic.co/guide/en/beats/filebeat/8.11/filebeat-installation-configuration.html).
 95- For complete “Setup and Run Filebeat” information refer to the [helper guide](https://www.elastic.co/guide/en/beats/filebeat/current/setting-up-and-running.html).
 96
 97#### Rule Specific Setup Note
 98- This rule requires the “Filebeat System Module” to be enabled.
 99- The system module collects and parses logs created by the system logging service of common Unix/Linux based distributions.
100- To run the system module of Filebeat on Linux follow the setup instructions in the [helper guide](https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-module-system.html).
101"""
102severity = "low"
103tags = [
104    "Domain: Endpoint",
105    "OS: Linux",
106    "Use Case: Threat Detection",
107    "Tactic: Persistence",
108    "Resources: Investigation Guide",
109]
110timestamp_override = "event.ingested"
111type = "eql"
112
113query = '''
114iam where host.os.type == "linux" and (event.type == "user" and event.type == "creation") and
115process.name in ("useradd", "adduser") and user.name != null
116'''
117
118
119[[rule.threat]]
120framework = "MITRE ATT&CK"
121[[rule.threat.technique]]
122id = "T1136"
123name = "Create Account"
124reference = "https://attack.mitre.org/techniques/T1136/"
125[[rule.threat.technique.subtechnique]]
126id = "T1136.001"
127name = "Local Account"
128reference = "https://attack.mitre.org/techniques/T1136/001/"
129
130
131
132[rule.threat.tactic]
133id = "TA0003"
134name = "Persistence"
135reference = "https://attack.mitre.org/tactics/TA0003/"

Triage and analysis

Investigating Linux User Account Creation

The useradd and adduser commands are used to create new user accounts in Linux-based operating systems.

Attackers may create new accounts (both local and domain) to maintain access to victim systems.

This rule identifies the usage of useradd and adduser to create new accounts.

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 created succesfully.
    • $osquery_0
  • Investigate whether the user is currently logged in and active.
    • $osquery_1
  • Identify if the account was added to privileged groups or assigned special privileges after creation.
    • $osquery_2
  • Identify the user account that performed the action and whether it should perform this kind of action.
  • 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
  • Investigate other alerts associated with the user/host during the past 48 hours.

False positive analysis

  • Account creation 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 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.
  • 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