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 = "2024/10/28"
6min_stack_version = "8.14.0"
7min_stack_comments = "Breaking change at 8.14.0 for the Windows Integration."
8
9[rule]
10author = ["Elastic"]
11description = """
12Identifies the use of Cmdlets and methods related to encryption/decryption of files in PowerShell scripts, which malware
13and offensive security tools can abuse to encrypt data or decrypt payloads to bypass security solutions.
14"""
15false_positives = ["Legitimate PowerShell Scripts which makes use of encryption."]
16from = "now-9m"
17index = ["winlogbeat-*", "logs-windows.powershell*"]
18language = "kuery"
19license = "Elastic License v2"
20name = "PowerShell Script with Encryption/Decryption Capabilities"
21note = """## Triage and analysis
22
23### Investigating PowerShell Script with Encryption/Decryption Capabilities
24
25PowerShell 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.
26
27PowerShell 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.
28
29#### Possible investigation steps
30
31- 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.
32- 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.
33- Examine file or network events from the involved PowerShell process for suspicious behavior.
34- Investigate other alerts associated with the user/host during the past 48 hours.
35- Evaluate whether the user needs to use PowerShell to complete tasks.
36
37### False positive analysis
38
39- 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.
40
41### Response and remediation
42
43- Initiate the incident response process based on the outcome of the triage.
44- Isolate the involved hosts to prevent further post-compromise behavior.
45- Restrict PowerShell usage outside of IT and engineering business units using GPOs, AppLocker, Intune, or similar software.
46- 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.
47- Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
48- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
49- 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).
50"""
51risk_score = 47
52rule_id = "1d9aeb0b-9549-46f6-a32d-05e2a001b7fd"
53severity = "medium"
54tags = [
55 "Domain: Endpoint",
56 "OS: Windows",
57 "Use Case: Threat Detection",
58 "Tactic: Defense Evasion",
59 "Data Source: PowerShell Logs",
60 "Resources: Investigation Guide",
61]
62timestamp_override = "event.ingested"
63type = "query"
64
65query = '''
66event.category:process and host.os.type:windows and
67 powershell.file.script_block_text : (
68 (
69 "Cryptography.AESManaged" or
70 "Cryptography.RijndaelManaged" or
71 "Cryptography.SHA1Managed" or
72 "Cryptography.SHA256Managed" or
73 "Cryptography.SHA384Managed" or
74 "Cryptography.SHA512Managed" or
75 "Cryptography.SymmetricAlgorithm" or
76 "PasswordDeriveBytes" or
77 "Rfc2898DeriveBytes"
78 ) and
79 (
80 CipherMode and PaddingMode
81 ) and
82 (
83 ".CreateEncryptor" or
84 ".CreateDecryptor"
85 )
86 ) and
87 not user.id : "S-1-5-18" and
88 not (
89 file.name : "Bootstrap.Octopus.FunctionAppenderContext.ps1" and
90 powershell.file.script_block_text : ("function Decrypt-Variables" or "github.com/OctopusDeploy")
91 )
92'''
93
94
95[[rule.threat]]
96framework = "MITRE ATT&CK"
97[[rule.threat.technique]]
98id = "T1027"
99name = "Obfuscated Files or Information"
100reference = "https://attack.mitre.org/techniques/T1027/"
101
102[[rule.threat.technique]]
103id = "T1140"
104name = "Deobfuscate/Decode Files or Information"
105reference = "https://attack.mitre.org/techniques/T1140/"
106
107
108[rule.threat.tactic]
109id = "TA0005"
110name = "Defense Evasion"
111reference = "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 Process Injection via PowerShell
- PowerShell Suspicious Payload Encoded and Compressed
- Suspicious .NET Reflection via PowerShell
- Suspicious Portable Executable Encoded in Powershell Script