PowerShell Script with Encryption/Decryption Capabilities
Identifies the use of Cmdlets and methods related to encryption/decryption of files in PowerShell scripts, which malware and offensive security tools can abuse to encrypt data or decrypt payloads to bypass security solutions.
Elastic rule (View on GitHub)
1[metadata]
2creation_date = "2023/01/23"
3integration = ["windows"]
4maturity = "production"
5updated_date = "2025/03/20"
6
7[rule]
8author = ["Elastic"]
9description = """
10Identifies the use of Cmdlets and methods related to encryption/decryption of files in PowerShell scripts, which malware
11and offensive security tools can abuse to encrypt data or decrypt payloads to bypass security solutions.
12"""
13false_positives = ["Legitimate PowerShell Scripts which makes use of encryption."]
14from = "now-9m"
15index = ["winlogbeat-*", "logs-windows.powershell*"]
16language = "kuery"
17license = "Elastic License v2"
18name = "PowerShell Script with Encryption/Decryption Capabilities"
19note = """## Triage and analysis
20
21### Investigating PowerShell Script with Encryption/Decryption Capabilities
22
23PowerShell is one of the main tools system administrators use for automation, report routines, and other tasks, making it available for use in various environments, creating an attractive way for attackers to execute code.
24
25PowerShell offers encryption and decryption functionalities that attackers can abuse for various purposes, such as concealing payloads, C2 communications, and encrypting data as part of ransomware operations.
26
27#### Possible investigation steps
28
29- Examine the script content that triggered the detection; look for suspicious DLL imports, collection or exfiltration capabilities, suspicious functions, encoded or compressed data, and other potentially malicious characteristics.
30- Investigate the script execution chain (parent process tree) for unknown processes. Examine their executable files for prevalence, whether they are located in expected locations, and if they are signed with valid digital signatures.
31- Examine file or network events from the involved PowerShell process for suspicious behavior.
32- Investigate other alerts associated with the user/host during the past 48 hours.
33- Evaluate whether the user needs to use PowerShell to complete tasks.
34
35### False positive analysis
36
37- This is a dual-use mechanism, meaning its usage is not inherently malicious. Analysts can dismiss the alert if the script doesn't contain malicious functions or potential for abuse, no other suspicious activity was identified, and there are justifications for the execution.
38
39### Response and remediation
40
41- Initiate the incident response process based on the outcome of the triage.
42- Isolate the involved hosts to prevent further post-compromise behavior.
43- Restrict PowerShell usage outside of IT and engineering business units using GPOs, AppLocker, Intune, or similar software.
44- 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.
45- Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
46- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
47- 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).
48"""
49risk_score = 47
50rule_id = "1d9aeb0b-9549-46f6-a32d-05e2a001b7fd"
51severity = "medium"
52tags = [
53 "Domain: Endpoint",
54 "OS: Windows",
55 "Use Case: Threat Detection",
56 "Tactic: Defense Evasion",
57 "Data Source: PowerShell Logs",
58 "Resources: Investigation Guide",
59]
60timestamp_override = "event.ingested"
61type = "query"
62
63query = '''
64event.category:process and host.os.type:windows and
65 powershell.file.script_block_text : (
66 (
67 "Cryptography.AESManaged" or
68 "Cryptography.RijndaelManaged" or
69 "Cryptography.SHA1Managed" or
70 "Cryptography.SHA256Managed" or
71 "Cryptography.SHA384Managed" or
72 "Cryptography.SHA512Managed" or
73 "Cryptography.SymmetricAlgorithm" or
74 "PasswordDeriveBytes" or
75 "Rfc2898DeriveBytes"
76 ) and
77 (
78 CipherMode and PaddingMode
79 ) and
80 (
81 ".CreateEncryptor" or
82 ".CreateDecryptor"
83 )
84 ) and
85 not user.id : "S-1-5-18" and
86 not (
87 file.name : "Bootstrap.Octopus.FunctionAppenderContext.ps1" and
88 powershell.file.script_block_text : ("function Decrypt-Variables" or "github.com/OctopusDeploy")
89 )
90'''
91
92
93[[rule.threat]]
94framework = "MITRE ATT&CK"
95[[rule.threat.technique]]
96id = "T1027"
97name = "Obfuscated Files or Information"
98reference = "https://attack.mitre.org/techniques/T1027/"
99
100[[rule.threat.technique]]
101id = "T1140"
102name = "Deobfuscate/Decode Files or Information"
103reference = "https://attack.mitre.org/techniques/T1140/"
104
105
106[rule.threat.tactic]
107id = "TA0005"
108name = "Defense Evasion"
109reference = "https://attack.mitre.org/tactics/TA0005/"
Triage and analysis
Investigating PowerShell Script with Encryption/Decryption Capabilities
PowerShell is one of the main tools system administrators use for automation, report routines, and other tasks, making it available for use in various environments, creating an attractive way for attackers to execute code.
PowerShell offers encryption and decryption functionalities that attackers can abuse for various purposes, such as concealing payloads, C2 communications, and encrypting data as part of ransomware operations.
Possible investigation steps
- Examine the script content that triggered the detection; look for suspicious DLL imports, collection or exfiltration capabilities, suspicious functions, encoded or compressed data, and other potentially malicious characteristics.
- Investigate the script execution chain (parent process tree) for unknown processes. Examine their executable files for prevalence, whether they are located in expected locations, and if they are signed with valid digital signatures.
- Examine file or network events from the involved PowerShell process for suspicious behavior.
- Investigate other alerts associated with the user/host during the past 48 hours.
- Evaluate whether the user needs to use PowerShell to complete tasks.
False positive analysis
- This is a dual-use mechanism, meaning its usage is not inherently malicious. Analysts can dismiss the alert if the script doesn't contain malicious functions or potential for abuse, no other suspicious activity was identified, and there are justifications for the execution.
Response and remediation
- Initiate the incident response process based on the outcome of the triage.
- Isolate the involved hosts to prevent further post-compromise behavior.
- Restrict PowerShell usage outside of IT and engineering business units using GPOs, AppLocker, Intune, or similar software.
- 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).
Related rules
- Potential Antimalware Scan Interface Bypass via PowerShell
- Potential PowerShell Obfuscated Script
- Potential Process Injection via PowerShell
- PowerShell Suspicious Payload Encoded and Compressed
- Suspicious .NET Reflection via PowerShell