Suspicious Powershell Script

A machine learning job detected a PowerShell script with unusual data characteristics, such as obfuscation, that may be a characteristic of malicious PowerShell script text blocks.

Elastic rule (View on GitHub)

  1[metadata]
  2creation_date = "2020/03/25"
  3integration = ["windows"]
  4maturity = "production"
  5min_stack_version = "9.4.0"
  6min_stack_comments = "Use EA (Entity Analytics) fields"
  7updated_date = "2026/07/27"
  8
  9[rule]
 10anomaly_threshold = 50
 11author = ["Elastic"]
 12description = """
 13A machine learning job detected a PowerShell script with unusual data characteristics, such as obfuscation, that may be
 14a characteristic of malicious PowerShell script text blocks.
 15"""
 16false_positives = [
 17    """
 18    Certain kinds of security testing may trigger this alert. PowerShell scripts that use high levels of obfuscation or
 19    have unusual script block payloads may trigger this alert.
 20    """,
 21]
 22from = "now-45m"
 23interval = "15m"
 24license = "Elastic License v2"
 25machine_learning_job_id = ["v3_windows_anomalous_script_ea"]
 26name = "Suspicious Powershell Script"
 27note = """## Triage and analysis
 28
 29> **Disclaimer**:
 30> This investigation guide was created using generative AI technology and has been reviewed to improve its accuracy and relevance. While every effort has been made to ensure its quality, we recommend validating the content and adapting it to suit your specific environment and operational needs.
 31
 32### Investigating Suspicious Powershell Script
 33
 34PowerShell is a powerful scripting language used for task automation and configuration management in Windows environments. Adversaries often exploit its capabilities to execute malicious scripts, leveraging obfuscation to evade detection. The 'Suspicious Powershell Script' detection rule employs machine learning to identify unusual script characteristics, such as obfuscation, indicating potential threats. By analyzing these anomalies, the rule aids in early threat detection and mitigation.
 35
 36### Possible investigation steps
 37
 38- Review the alert details to identify the specific PowerShell script or command that triggered the detection, focusing on any obfuscated elements.
 39- Examine the source endpoint and user account associated with the alert to determine if the activity aligns with expected behavior or if it appears suspicious.
 40- Check the execution history on the affected endpoint for any other unusual or unauthorized PowerShell commands or scripts executed around the same time.
 41- Investigate the network activity from the source endpoint to identify any connections to known malicious IP addresses or domains.
 42- Correlate the alert with other security events or logs, such as antivirus alerts or firewall logs, to gather additional context and assess the potential impact.
 43- Consult threat intelligence sources to determine if the detected script or its components are associated with known malware or attack campaigns.
 44
 45### False positive analysis
 46
 47- Legitimate administrative scripts may trigger the rule due to obfuscation techniques used for efficiency or security. Review the script's purpose and source to determine its legitimacy.
 48- Automated deployment tools often use PowerShell scripts that appear obfuscated. Identify and whitelist these tools to prevent unnecessary alerts.
 49- Security software updates might use obfuscated scripts for protection against tampering. Verify the update source and add exceptions for known trusted vendors.
 50- Custom scripts developed in-house for specific tasks may use obfuscation for intellectual property protection. Document and exclude these scripts after confirming their safety.
 51- Regularly review and update the list of exceptions to ensure that only verified non-threatening scripts are excluded, maintaining the effectiveness of the detection rule.
 52
 53### Response and remediation
 54
 55- Isolate the affected system from the network to prevent further spread of the potential threat and to contain any malicious activity.
 56- Terminate any suspicious PowerShell processes identified on the affected system to halt the execution of potentially harmful scripts.
 57- Conduct a thorough review of the PowerShell script logs and execution history on the affected system to identify any unauthorized or malicious commands executed.
 58- Restore the affected system from a known good backup if any malicious activity is confirmed, ensuring that the backup is free from compromise.
 59- Update and patch the affected system to the latest security standards to close any vulnerabilities that may have been exploited.
 60- Implement enhanced monitoring for PowerShell activity across the network, focusing on detecting obfuscation and unusual script characteristics.
 61- Escalate the incident to the security operations center (SOC) or incident response team for further investigation and to determine if additional systems are affected."""
 62references = [
 63    "https://www.elastic.co/guide/en/security/current/prebuilt-ml-jobs.html",
 64    "https://www.elastic.co/security-labs/detecting-living-off-the-land-attacks-with-new-elastic-integration",
 65]
 66risk_score = 21
 67rule_id = "1781d055-5c66-4adf-9d60-fc0fa58337b6"
 68setup = """## Setup
 69
 70This rule requires the installation of associated Machine Learning jobs, as well as data coming in from one of the following integrations:
 71- Windows
 72
 73### Anomaly Detection Setup
 74
 75Once the rule is enabled, the associated Machine Learning job will start automatically. You can view the Machine Learning job linked under the "Definition" panel of the detection rule. If the job does not start due to an error, the issue must be resolved for the job to commence successfully. For more details on setting up anomaly detection jobs, refer to the [helper guide](https://www.elastic.co/guide/en/kibana/current/xpack-ml-anomalies.html).
 76
 77### Windows Integration Setup
 78The Windows integration allows you to monitor the Windows OS, services, applications, and more.
 79
 80#### The following steps should be executed in order to add the Elastic Agent System integration "windows" to your system:
 81- Go to the Kibana home page and click “Add integrations”.
 82- In the query bar, search for “Windows” and select the integration to see more details about it.
 83- Click “Add Windows”.
 84- Configure the integration name and optionally add a description.
 85- Review optional and advanced settings accordingly.
 86- Add the newly installed “windows” to an existing or a new agent policy, and deploy the agent on your system from which windows log files are desirable.
 87- Click “Save and Continue”.
 88- For more details on the integration refer to the [helper guide](https://docs.elastic.co/integrations/windows).
 89"""
 90severity = "low"
 91tags = [
 92    "Domain: Endpoint",
 93    "OS: Windows",
 94    "Data Source: PowerShell Logs",
 95    "Use Case: Threat Detection",
 96    "Rule Type: ML",
 97    "Rule Type: Machine Learning",
 98    "Tactic: Execution",
 99    "Resources: Investigation Guide",
100]
101type = "machine_learning"
102[[rule.threat]]
103framework = "MITRE ATT&CK"
104
105[[rule.threat.technique]]
106id = "T1059"
107name = "Command and Scripting Interpreter"
108reference = "https://attack.mitre.org/techniques/T1059/"
109
110[[rule.threat.technique.subtechnique]]
111id = "T1059.001"
112name = "PowerShell"
113reference = "https://attack.mitre.org/techniques/T1059/001/"
114
115[rule.threat.tactic]
116id = "TA0002"
117name = "Execution"
118reference = "https://attack.mitre.org/tactics/TA0002/"
119
120[[rule.threat]]
121framework = "MITRE ATT&CK"
122
123[[rule.threat.technique]]
124id = "T1027"
125name = "Obfuscated Files or Information"
126reference = "https://attack.mitre.org/techniques/T1027/"
127
128[[rule.threat.technique.subtechnique]]
129id = "T1027.010"
130name = "Command Obfuscation"
131reference = "https://attack.mitre.org/techniques/T1027/010/"
132
133[rule.threat.tactic]
134id = "TA0005"
135name = "Defense Evasion"
136reference = "https://attack.mitre.org/tactics/TA0005/"

Triage and analysis

Disclaimer: This investigation guide was created using generative AI technology and has been reviewed to improve its accuracy and relevance. While every effort has been made to ensure its quality, we recommend validating the content and adapting it to suit your specific environment and operational needs.

Investigating Suspicious Powershell Script

PowerShell is a powerful scripting language used for task automation and configuration management in Windows environments. Adversaries often exploit its capabilities to execute malicious scripts, leveraging obfuscation to evade detection. The 'Suspicious Powershell Script' detection rule employs machine learning to identify unusual script characteristics, such as obfuscation, indicating potential threats. By analyzing these anomalies, the rule aids in early threat detection and mitigation.

Possible investigation steps

  • Review the alert details to identify the specific PowerShell script or command that triggered the detection, focusing on any obfuscated elements.
  • Examine the source endpoint and user account associated with the alert to determine if the activity aligns with expected behavior or if it appears suspicious.
  • Check the execution history on the affected endpoint for any other unusual or unauthorized PowerShell commands or scripts executed around the same time.
  • Investigate the network activity from the source endpoint to identify any connections to known malicious IP addresses or domains.
  • Correlate the alert with other security events or logs, such as antivirus alerts or firewall logs, to gather additional context and assess the potential impact.
  • Consult threat intelligence sources to determine if the detected script or its components are associated with known malware or attack campaigns.

False positive analysis

  • Legitimate administrative scripts may trigger the rule due to obfuscation techniques used for efficiency or security. Review the script's purpose and source to determine its legitimacy.
  • Automated deployment tools often use PowerShell scripts that appear obfuscated. Identify and whitelist these tools to prevent unnecessary alerts.
  • Security software updates might use obfuscated scripts for protection against tampering. Verify the update source and add exceptions for known trusted vendors.
  • Custom scripts developed in-house for specific tasks may use obfuscation for intellectual property protection. Document and exclude these scripts after confirming their safety.
  • Regularly review and update the list of exceptions to ensure that only verified non-threatening scripts are excluded, maintaining the effectiveness of the detection rule.

Response and remediation

  • Isolate the affected system from the network to prevent further spread of the potential threat and to contain any malicious activity.
  • Terminate any suspicious PowerShell processes identified on the affected system to halt the execution of potentially harmful scripts.
  • Conduct a thorough review of the PowerShell script logs and execution history on the affected system to identify any unauthorized or malicious commands executed.
  • Restore the affected system from a known good backup if any malicious activity is confirmed, ensuring that the backup is free from compromise.
  • Update and patch the affected system to the latest security standards to close any vulnerabilities that may have been exploited.
  • Implement enhanced monitoring for PowerShell activity across the network, focusing on detecting obfuscation and unusual script characteristics.
  • Escalate the incident to the security operations center (SOC) or incident response team for further investigation and to determine if additional systems are affected.

References

Related rules

to-top