PowerShell Script with Encryption/Decryption Capabilities

Last updated a month ago on 2026-02-09
Created 3 years ago on 2023-01-23

About

Identifies PowerShell script block content that uses .NET cryptography APIs for file encryption or decryption. Attackers abuse these routines to encrypt data for impact or decrypt staged payloads to evade defenses.
Tags
Domain: EndpointOS: WindowsUse Case: Threat DetectionTactic: Defense EvasionData Source: PowerShell LogsLanguage: kuery
Severity
medium
Risk Score
47
MITRE ATT&CK™

Defense Evasion (TA0005)(external, opens in a new tab or window)

False Positive Examples
Legitimate PowerShell Scripts which makes use of encryption.
License
Elastic License v2(external, opens in a new tab or window)

Definition

Rule Type
Query (Kibana Query Language)
Integration Pack
Prebuilt Security Detection Rules
Index Patterns
winlogbeat-*logs-windows.powershell*
Related Integrations

windows(external, opens in a new tab or window)

Query
text code block:
event.category:process and host.os.type:windows and powershell.file.script_block_text : ( ( "Cryptography.AESManaged" or "Cryptography.RijndaelManaged" or "Cryptography.SHA1Managed" or "Cryptography.SHA256Managed" or "Cryptography.SHA384Managed" or "Cryptography.SHA512Managed" or "Cryptography.SymmetricAlgorithm" or "PasswordDeriveBytes" or "Rfc2898DeriveBytes" ) and ( CipherMode and PaddingMode ) and ( ".CreateEncryptor" or ".CreateDecryptor" ) ) and not user.id : "S-1-5-18" and not ( file.name : "Bootstrap.Octopus.FunctionAppenderContext.ps1" and powershell.file.script_block_text : ("function Decrypt-Variables" or "github.com/OctopusDeploy") )

Install detection rules in Elastic Security

Detect PowerShell Script with Encryption/Decryption Capabilities in the Elastic Security detection engine by installing this rule into your Elastic Stack.

To setup this rule, check out the installation guide for Prebuilt Security Detection Rules(external, opens in a new tab or window).