ByteRay CQL Hub
← All queries

Encoded PowerShell Command Execution

This query identifies PowerShell and pwsh executions that pass a Base64-encoded command via -EncodedCommand (or any of its accepted prefixes such as -e, -ec, -enc), decodes the payload inline and enriches the result with the executing user. Encoded commands are a common obfuscation technique used by malware loaders, offensive frameworks and living-off-the-land attacks.

CQL · Falcon Next-Gen SIEMCopy query
#event_simpleName=ProcessRollup2 ImageFileName=/\\(powershell|pwsh)\.exe$/i
| replace("\\^", with="", field=CommandLine, as=cmd)
| cmd=/\s[-\/]e(c|nc?[a-z]*)?\s+(?<b64>[A-Za-z0-9+\/=]{16,})/i
| decoded := base64Decode(b64, charset="UTF-16LE")
| join({#event_simpleName=UserIdentity}, field=[aid, AuthenticationId], include=[UserName], mode=left)
| table([aid, UserName, ParentImageFileName, ImageFileName, CommandLine, decoded])

This query uses CrowdStrike Query Language (CQL) to detect and decode encoded PowerShell commands:

  1. Event Filtering: #event_simpleName=ProcessRollup2 ImageFileName=/\\(powershell|pwsh)\.exe$/i - Searches ProcessRollup2 events for Windows PowerShell (powershell.exe) and PowerShell 7 (pwsh.exe), case-insensitive

  2. Caret Normalisation: replace("\\^", with="", field=CommandLine, as=cmd) - Removes cmd.exe caret escapes (e.g. -e^n^c) into a working copy cmd, so obfuscated parameter names are matched without listing every caret position in the regex. The original CommandLine is kept untouched for the output.

  3. Parameter Matching: cmd=/\s[-\/]e(c|nc?[a-z]*)?\s+(?<b64>[A-Za-z0-9+\/=]{16,})/i - PowerShell accepts any unambiguous prefix of -EncodedCommand. The pattern matches -e, -ec, -enc, -encoded, -encodedcommand and the / parameter prefix, while excluding -ex/-ep (ExecutionPolicy) - Captures the following Base64 argument into the field b64

  4. Payload Decoding: decoded := base64Decode(b64, charset="UTF-16LE") - PowerShell encodes commands as UTF-16LE. Decoding inline saves the round trip to an external tool during triage

  5. User Context: join({#event_simpleName=UserIdentity}, field=[aid, AuthenticationId], include=[UserName], mode=left) - Enriches results with the executing user. The key is [aid, AuthenticationId] because logon IDs are only unique per host. mode=left keeps hits even when no matching UserIdentity event exists in the search window

  6. Output: table([aid, UserName, ParentImageFileName, ImageFileName, CommandLine, decoded]) - Displays the parent process, the original command line and the decoded payload for analysis

Encoded_Powershell_Executions.yml
T1059.001, T1027.010
ByteRay GmbH
Hunting
Endpoint
Insight
2026-09-14
2026-09-14

Get this query running in your SIEM, with someone on call.

Our Managed SIEM team operates CrowdStrike Falcon Next-Gen SIEM in production, with over 350 battle-tested use cases and 24/7 incident response behind them.

Talk to the SIEM team