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/05/21"
  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"""
 79risk_score = 21
 80rule_id = "edfd5ca9-9d6c-44d9-b615-1e56b920219c"
 81setup = """## Setup
 82
 83This rule requires data coming in from Filebeat.
 84
 85### Filebeat Setup
 86Filebeat 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.
 87
 88#### The following steps should be executed in order to add the Filebeat on a Linux System:
 89- Elastic provides repositories available for APT and YUM-based distributions. Note that we provide binary packages, but no source packages.
 90- 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).
 91- 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).
 92- 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).
 93- 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).
 94- 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).
 95
 96#### Rule Specific Setup Note
 97- This rule requires the “Filebeat System Module” to be enabled.
 98- The system module collects and parses logs created by the system logging service of common Unix/Linux based distributions.
 99- 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).
100"""
101severity = "low"
102tags = [
103    "Domain: Endpoint",
104    "OS: Linux",
105    "Use Case: Threat Detection",
106    "Tactic: Persistence",
107    "Resources: Investigation Guide",
108]
109timestamp_override = "event.ingested"
110type = "eql"
111
112query = '''
113iam where host.os.type == "linux" and (event.type == "user" and event.type == "creation") and
114process.name in ("useradd", "adduser") and user.name != null
115'''
116
117
118[[rule.threat]]
119framework = "MITRE ATT&CK"
120[[rule.threat.technique]]
121id = "T1136"
122name = "Create Account"
123reference = "https://attack.mitre.org/techniques/T1136/"
124[[rule.threat.technique.subtechnique]]
125id = "T1136.001"
126name = "Local Account"
127reference = "https://attack.mitre.org/techniques/T1136/001/"
128
129
130
131[rule.threat.tactic]
132id = "TA0003"
133name = "Persistence"
134reference = "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