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"
  5min_stack_comments = "New fields added: required_fields, related_integrations, setup"
  6min_stack_version = "8.3.0"
  7updated_date = "2023/11/02"
  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 create new users. Attackers may add new users to establish persistence on a system.
 30"""
 31from = "now-9m"
 32index = ["filebeat-*", "logs-system.auth-*"]
 33language = "eql"
 34license = "Elastic License v2"
 35name = "Linux User Account Creation"
 36note = """## Triage and analysis
 37
 38### Investigating Linux User Account Creation
 39
 40The `useradd` and `adduser` commands are used to create new user accounts in Linux-based operating systems.
 41
 42Attackers may create new accounts (both local and domain) to maintain access to victim systems.
 43
 44This rule identifies the usage of `useradd` and `adduser` to create new accounts.
 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 created succesfully.
 53  - $osquery_0
 54- Investigate whether the user is currently logged in and active.
 55  - $osquery_1
 56- Identify if the account was added to privileged groups or assigned special privileges after creation.
 57  - $osquery_2
 58- Identify the user account that performed the action and whether it should perform this kind of action.
 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- Investigate other alerts associated with the user/host during the past 48 hours.
 62
 63### False positive analysis
 64
 65- 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.
 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 created account.
 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"""
 82risk_score = 21
 83rule_id = "edfd5ca9-9d6c-44d9-b615-1e56b920219c"
 84setup = """## Setup
 85
 86This rule requires data coming in from Filebeat.
 87
 88### Filebeat Setup
 89Filebeat 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.
 90
 91#### The following steps should be executed in order to add the Filebeat on a Linux System:
 92- Elastic provides repositories available for APT and YUM-based distributions. Note that we provide binary packages, but no source packages.
 93- 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).
 94- 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).
 95- 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).
 96- 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).
 97- 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).
 98
 99#### Rule Specific Setup Note
100- This rule requires the “Filebeat System Module” to be enabled.
101- The system module collects and parses logs created by the system logging service of common Unix/Linux based distributions.
102- 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).
103"""
104severity = "low"
105tags = ["Domain: Endpoint", "OS: Linux", "Use Case: Threat Detection", "Tactic: Persistence", "Resources: Investigation Guide"]
106timestamp_override = "event.ingested"
107type = "eql"
108query = '''
109iam where host.os.type == "linux" and (event.type == "user" and event.type == "creation") and
110process.name in ("useradd", "adduser") and user.name != null
111'''
112
113[[rule.threat]]
114framework = "MITRE ATT&CK"
115
116[[rule.threat.technique]]
117id = "T1136"
118name = "Create Account"
119reference = "https://attack.mitre.org/techniques/T1136/"
120
121[[rule.threat.technique.subtechnique]]
122id = "T1136.001"
123name = "Local Account"
124reference = "https://attack.mitre.org/techniques/T1136/001/"
125
126[rule.threat.tactic]
127id = "TA0003"
128name = "Persistence"
129reference = "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).

Related rules

to-top