Potential PowerShell Obfuscated Script

Last updated a month ago on 2025-12-01
Created 2 years ago on 2024-07-03

About

Identifies scripts that contain patterns and known methods that obfuscate PowerShell code. Attackers can use obfuscation techniques to bypass PowerShell security protections such as Antimalware Scan Interface (AMSI).
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)

Execution (TA0002)(external, opens in a new tab or window)

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 : ( "[string]::join" or "-Join" or "[convert]::toint16" or "[char][int]$_" or ("ConvertTo-SecureString" and "PtrToStringAuto") or "-BXor" or ("replace" and "char") or "[array]::reverse" or "-replace" ) and powershell.file.script_block_text : ( ("$pSHoMe[" and "+$pSHoMe[") or ("$ShellId[" and "+$ShellId[") or ("$env:ComSpec[4" and "25]-Join") or (("Set-Variable" or "SV" or "Set-Item") and "OFS") or ("*MDR*" and "Name[3,11,2]") or ("$VerbosePreference" and "[1,3]+'X'-Join''") or ("rahc" or "ekovin" or "gnirts" or "ecnereferpesobrev" or "ecalper" or "cepsmoc" or "dillehs") or ("System.Management.Automation.$([cHAr]" or "System.$([cHAr]" or ")+[cHAR]([byte]") ) and not powershell.file.script_block_text : ( ("Copyright (c) 2018 Ansible Project" or "Export-ModuleMember -Function Add-CSharpType") and ("[Object]$AnsibleModule" or "$AnsibleModule.Tmpdir") )

Install detection rules in Elastic Security

Detect Potential PowerShell Obfuscated Script 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).