PowerShell Script with Encryption/Decryption Capabilities
PowerShell scripts employing .NET cryptography APIs are used to encrypt data for impact or decrypt payloads for defense evasion.
This threat brief focuses on the detection of PowerShell scripts utilizing .NET cryptography APIs for file encryption or decryption. Attackers often leverage these capabilities to encrypt data for impact, potentially leading to data exfiltration or ransomware deployment, or to decrypt staged payloads, circumventing traditional security measures. Defenders should be aware of PowerShell scripts employing symmetric cryptography classes (AES/Rijndael, SymmetricAlgorithm), key derivation helpers (PasswordDeriveBytes, Rfc2898DeriveBytes), explicit cipher configurations (CipherMode, PaddingMode), and functions that generate encryptors/decryptors. Identifying such scripts is crucial for preventing both data compromise and the execution of malicious payloads. This detection specifically targets Windows systems where PowerShell is commonly used for both legitimate administration and malicious activities.
Attack Chain
- Attacker gains initial access to the target system (e.g., via compromised credentials or a phishing attack).
- Attacker uploads or stages a PowerShell script containing encryption/decryption capabilities.
- The PowerShell script utilizes .NET cryptography APIs (e.g.,
AESManaged,RijndaelManaged,PasswordDeriveBytes,Rfc2898DeriveBytes). - The script configures the cipher using
CipherModeandPaddingMode. - The script invokes
.CreateEncryptor()or.CreateDecryptor()methods to initialize the cryptographic operation. - If encrypting, the script iterates through target files, encrypting their content and potentially renaming or deleting originals.
- If decrypting, the script processes an encrypted payload, converting it to executable form or writing it to a new artifact.
- The attacker executes the decrypted payload or exfiltrates the encrypted data, completing their objective.
Impact
Successful exploitation can lead to significant data loss, system downtime, and financial damage. Data encryption for impact can render systems unusable, while the decryption of staged payloads can introduce malware into the environment. The number of victims can vary widely depending on the scope of the attack, ranging from individual workstations to entire networks. Targeted sectors may include any organization reliant on Windows-based systems, with potential consequences including operational disruption, reputational damage, and regulatory fines.
Recommendation
- Enable PowerShell Script Block Logging to capture the events required for detection, specifically event ID 4104, as detailed in the Elastic PowerShell logging setup guide.
- Deploy the Sigma rule
PowerShell Script with Encryption/Decryption Capabilitiesto your SIEM to detect suspicious PowerShell scripts utilizing .NET cryptography APIs. - Investigate alerts triggered by the Sigma rule, focusing on
powershell.file.script_block_textto understand the cryptographic intent and data flow. - Tune the Sigma rule by adding exceptions for legitimate PowerShell scripts that use encryption, referencing the “False positive analysis” section in this brief.
Detection coverage 2
PowerShell Encryption API Usage
mediumDetects PowerShell scripts using .NET encryption APIs
PowerShell Script Block Logging - Encryption Routines
mediumDetects PowerShell script blocks that contain encryption or decryption routines.
Detection queries are kept inside the platform. Get full rules →