Malicious File - Detected - Elastic Defend

Generates a detection alert each time an Elastic Defend alert for malicious files is received. Enabling this rule allows you to immediately begin investigating your Endpoint malicious file alerts. This rule identifies Elastic Defend malicious file detections only, and does not include prevention alerts.

Elastic rule (View on GitHub)

  1[metadata]
  2creation_date = "2024/03/24"
  3integration = ["endpoint"]
  4maturity = "production"
  5min_stack_comments = "Defend alerting adjustments patch to distinguish prevention and detection."
  6min_stack_version = "8.16.0"
  7promotion = true
  8updated_date = "2024/11/26"
  9
 10[rule]
 11author = ["Elastic"]
 12description = """
 13Generates a detection alert each time an Elastic Defend alert for malicious files is received. Enabling this rule allows
 14you to immediately begin investigating your Endpoint malicious file alerts. This rule identifies Elastic Defend
 15malicious file detections only, and does not include prevention alerts.
 16"""
 17enabled = false
 18from = "now-10m"
 19index = ["logs-endpoint.alerts-*"]
 20interval = "5m"
 21language = "kuery"
 22license = "Elastic License v2"
 23max_signals = 10000
 24name = "Malicious File - Detected - Elastic Defend"
 25note = """## Triage and analysis
 26
 27### Investigating Malware Alerts
 28
 29Elastic Endpoint malware protection leverages a combination of supervised machine learning (ML) models (PE, MachO) and yara signatures. Our ML models are trained on hundreds of millions of executables and model updates are released approximately monthly. Our yara signatures are created with automated signature creation technologies built in-house along with  hand-written rules by our threat researchers.
 30
 31Files are scanned on write or deletion, process executables are scanned on executions and libraries are scanned on load. You can differentiate these types by looking at the `event.action` field in the alert. It can be execution, `load`, `creation`, `modification`, or `deletion`. Scanning files written to disk is best effort, while execution or load scanning is done ‘in-line’ for true prevention.
 32
 33### Possible investigation steps
 34
 35- For machine learning (ML) malware alerts the `file.Ext.malware_classification.score` and `file.Ext.malware_classification.version` fields indicate which model version was used to classify the file and the classification score (0 to 1).
 36- For malware signature hits, `threat_name` is an important field which will guide the user on what malware family the sample belongs to.
 37- For Yara matches, Malware alerts do provide the specific binary content identified by the yara rule in the alert metadata (it is base64 encoded and stored in the `matches` field).
 38- A file can also hit on multiple Yara signatures. In the alert metadata, the `primary` signature (`malware_signature.primary`) will be whichever we determine to have the highest severity.
 39- Malicious file alerts for files in download directories or written by browsers, office applications, script interpreters or other lolbins are especially correlated with malicious activity.
 40- Particular attention should be paid to files located in suspicious directories like `Public` folder, `Downloads`, `Temp` and `ProgramData`.
 41- Verify if the file is signed or not using the `file.Ext.code_signature` field. Even if the file is signed with a valid certificate verify the global prevalance of that signed in your environment.
 42- Verify the malicious file timestamp metadata using `file.created`, `file.mtime` and `file.accessed` to asses exactly if it's an old or new infection.
 43- Investigate the activity of the process that created, modified or loaded the malicious file (parent process tree, process.command_line, child processes, network, registry and files events).
 44- Assess whether this file is prevalent in the environment by looking for similar occurrences across hosts by `file.hash.sha256` or by `file.name` patterns.
 45- Verify the activity of the `user.name` associated with Malware alert (local or remote actity, privileged or standard user).
 46- Verify if there are any other Alert types (Behavior or Memory Threat) associated with the same host or user or process within the same time.
 47### False positive analysis
 48
 49- Other endpoint security vendors especially with their quarantine folders.
 50- Dynamically generated or compiled executables such as from csc.exe or other compilers. Due to the dynamic nature, each instance will likely have a unique hash and no signer
 51
 52### Response and Remediation
 53
 54- Initiate the incident response process based on the outcome of the triage.
 55  - If malicious activity is confirmed, perform a broader investigation to identify the scope of the compromise and determine the appropriate remediation steps.
 56- Implement Elastic Endpoint Security to detect and prevent further post exploitation activities in the environment.
 57   - Contain the affected system by isolating it from the network to prevent further spread of the attack.
 58- If the triage identified malware, search the environment for additional compromised hosts.
 59  - Implement temporary network rules, procedures, and segmentation to contain the malware.
 60  - Stop suspicious processes.
 61  - Immediately block the identified indicators of compromise (IoCs).
 62  - Inspect the affected systems for additional malware backdoors like reverse shells, reverse proxies, or droppers that attackers could use to reinfect the system.
 63- Remove and block malicious artifacts identified during triage.
 64- Restore the affected system to its operational state by applying any necessary patches, updates, or configuration changes.
 65- 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.
 66- Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
 67- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
 68- 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).
 69"""
 70references = [
 71    "https://github.com/elastic/protections-artifacts/tree/main/yara",
 72    "https://docs.elastic.co/en/integrations/endpoint",
 73]
 74risk_score = 47
 75rule_id = "f2c3caa6-ea34-11ee-a417-f661ea17fbce"
 76rule_name_override = "message"
 77setup = """## Setup
 78
 79### Elastic Defend Alerts
 80This rule is designed to capture specific alerts generated by Elastic Defend.
 81
 82To capture all the Elastic Defend alerts, it is recommended to use all of the Elastic Defend feature-specific protection rules:
 83
 84Behavior - Detected - Elastic Defend (UUID: 0f615fe4-eaa2-11ee-ae33-f661ea17fbce)
 85Behavior - Prevented - Elastic Defend (UUID: eb804972-ea34-11ee-a417-f661ea17fbce)
 86Malicious File - Detected - Elastic Defend (UUID: f2c3caa6-ea34-11ee-a417-f661ea17fbce)
 87Malicious File - Prevented - Elastic Defend (UUID: f87e6122-ea34-11ee-a417-f661ea17fbce)
 88Memory Threat - Detected - Elastic Defend (UUID: 017de1e4-ea35-11ee-a417-f661ea17fbce)
 89Memory Threat - Prevented - Elastic Defend (UUID: 06f3a26c-ea35-11ee-a417-f661ea17fbce)
 90Ransomware - Detected - Elastic Defend (UUID: 0c74cd7e-ea35-11ee-a417-f661ea17fbce)
 91Ransomware - Prevented - Elastic Defend (UUID: 10f3d520-ea35-11ee-a417-f661ea17fbce)
 92
 93To avoid generating duplicate alerts, you should enable either all feature-specific protection rules or the Endpoint Security (Elastic Defend) rule (UUID: 9a1a2dae-0b5f-4c3d-8305-a268d404c306).
 94
 95### Additional notes
 96This rule is configured to generate more **Max alerts per run** than the default 1000 alerts per run set for all rules. This is to ensure that it captures as many alerts as possible.
 97
 98**IMPORTANT:** The rule's **Max alerts per run** setting can be superseded by the `xpack.alerting.rules.run.alerts.max` Kibana config setting, which determines the maximum alerts generated by _any_ rule in the Kibana alerting framework. For example, if `xpack.alerting.rules.run.alerts.max` is set to 1000, this rule will still generate no more than 1000 alerts even if its own **Max alerts per run** is set higher.
 99
100To make sure this rule can generate as many alerts as it's configured in its own **Max alerts per run** setting, increase the `xpack.alerting.rules.run.alerts.max` system setting accordingly.
101
102**NOTE:** Changing `xpack.alerting.rules.run.alerts.max` is not possible in Serverless projects.
103"""
104severity = "medium"
105tags = ["Data Source: Elastic Defend", "Tactic: Execution"]
106timestamp_override = "event.ingested"
107type = "query"
108
109query = '''
110event.kind : alert and event.code : malicious_file and (event.type : allowed or (event.type: denied and event.outcome: failure))
111'''
112
113
114[[rule.exceptions_list]]
115id = "endpoint_list"
116list_id = "endpoint_list"
117namespace_type = "agnostic"
118type = "endpoint"
119
120[[rule.risk_score_mapping]]
121field = "event.risk_score"
122operator = "equals"
123value = ""
124
125[[rule.severity_mapping]]
126field = "event.severity"
127operator = "equals"
128severity = "low"
129value = "21"
130
131[[rule.severity_mapping]]
132field = "event.severity"
133operator = "equals"
134severity = "medium"
135value = "47"
136
137[[rule.severity_mapping]]
138field = "event.severity"
139operator = "equals"
140severity = "high"
141value = "73"
142
143[[rule.severity_mapping]]
144field = "event.severity"
145operator = "equals"
146severity = "critical"
147value = "99"
148
149[[rule.threat]]
150framework = "MITRE ATT&CK"
151[[rule.threat.technique]]
152id = "T1204"
153name = "User Execution"
154reference = "https://attack.mitre.org/techniques/T1204/"
155[[rule.threat.technique.subtechnique]]
156id = "T1204.002"
157name = "Malicious File"
158reference = "https://attack.mitre.org/techniques/T1204/002/"
159
160
161
162[rule.threat.tactic]
163id = "TA0002"
164name = "Execution"
165reference = "https://attack.mitre.org/tactics/TA0002/"

Triage and analysis

Investigating Malware Alerts

Elastic Endpoint malware protection leverages a combination of supervised machine learning (ML) models (PE, MachO) and yara signatures. Our ML models are trained on hundreds of millions of executables and model updates are released approximately monthly. Our yara signatures are created with automated signature creation technologies built in-house along with hand-written rules by our threat researchers.

Files are scanned on write or deletion, process executables are scanned on executions and libraries are scanned on load. You can differentiate these types by looking at the event.action field in the alert. It can be execution, load, creation, modification, or deletion. Scanning files written to disk is best effort, while execution or load scanning is done ‘in-line’ for true prevention.

Possible investigation steps

  • For machine learning (ML) malware alerts the file.Ext.malware_classification.score and file.Ext.malware_classification.version fields indicate which model version was used to classify the file and the classification score (0 to 1).
  • For malware signature hits, threat_name is an important field which will guide the user on what malware family the sample belongs to.
  • For Yara matches, Malware alerts do provide the specific binary content identified by the yara rule in the alert metadata (it is base64 encoded and stored in the matches field).
  • A file can also hit on multiple Yara signatures. In the alert metadata, the primary signature (malware_signature.primary) will be whichever we determine to have the highest severity.
  • Malicious file alerts for files in download directories or written by browsers, office applications, script interpreters or other lolbins are especially correlated with malicious activity.
  • Particular attention should be paid to files located in suspicious directories like Public folder, Downloads, Temp and ProgramData.
  • Verify if the file is signed or not using the file.Ext.code_signature field. Even if the file is signed with a valid certificate verify the global prevalance of that signed in your environment.
  • Verify the malicious file timestamp metadata using file.created, file.mtime and file.accessed to asses exactly if it's an old or new infection.
  • Investigate the activity of the process that created, modified or loaded the malicious file (parent process tree, process.command_line, child processes, network, registry and files events).
  • Assess whether this file is prevalent in the environment by looking for similar occurrences across hosts by file.hash.sha256 or by file.name patterns.
  • Verify the activity of the user.name associated with Malware alert (local or remote actity, privileged or standard user).
  • Verify if there are any other Alert types (Behavior or Memory Threat) associated with the same host or user or process within the same time.

False positive analysis

  • Other endpoint security vendors especially with their quarantine folders.
  • Dynamically generated or compiled executables such as from csc.exe or other compilers. Due to the dynamic nature, each instance will likely have a unique hash and no signer

Response and Remediation

  • Initiate the incident response process based on the outcome of the triage.
    • If malicious activity is confirmed, perform a broader investigation to identify the scope of the compromise and determine the appropriate remediation steps.
  • Implement Elastic Endpoint Security to detect and prevent further post exploitation activities in the environment.
    • Contain the affected system by isolating it from the network to prevent further spread of the attack.
  • 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.
  • Restore the affected system to its operational state by applying any necessary patches, updates, or configuration changes.
  • 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.
  • Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
  • 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