Playbook: Suspicious encoded PowerShell

Query status: untested in production. The Sigma rules and KQL were syntax-checked only. The pseudo-SPL has not been run in Splunk. Test and tune everything in your own environment before you rely on it.
ATT&CK
T1059.001 Command and Scripting Interpreter: PowerShell; related T1027.010 Obfuscated Files or Information: Command Obfuscation (ATT&CK v20.1)
Tactic
Execution (T1059.001); Stealth (T1027.010)
Level
Beginner
Best time window
Last 7 to 30 days, then compare against your baseline

Hypothesis

If someone is running scripts on a Windows host without leaving files on disk, some of them will show up as powershell.exe or pwsh.exe started with an encoded command, from a parent process that does not normally launch PowerShell.

PowerShell accepts a base64 string through -EncodedCommand, and also its shortened forms such as -e, -ec and -enc. The string is the script encoded as UTF-16LE. Admin tools use this too, which is why this is a hunt and not a blocking rule.

Data sources

Data sources
SourceEventWhy it helps
Windows Security log4688 process creationNeeds "Include command line in process creation events" turned on
SysmonEvent ID 1Command line, parent process, hashes, user
EDR process telemetryProcess-start eventsSame fields, often searchable across all hosts at once
PowerShell Operational log4104 script block loggingRecords the decoded script, so you can read what actually ran
PowerShell Operational log4103 module loggingOptional: pipeline and parameter detail
Defender XDR or SentinelDeviceProcessEvents tableProcess, parent and command line from the endpoint sensor. The Sentinel copy has TimeGenerated, not Timestamp

Sample Sigma rules

Sigma: broad hunt rule (level low)
title: PowerShell Encoded Command With Long Base64 Argument (Hunt)
id: 6f1c0f9e-411a-4d3b-9a52-0b7e5c1d2a41
status: experimental
description: >-
    Windows PowerShell or PowerShell 7 started with -EncodedCommand, or one of its
    abbreviations (-e, -ec, -en, -enc ...), followed by a long base64 string.
    Broad hunting rule: admin and deployment tooling does this too, so tune the filter.
references:
    - https://attack.mitre.org/techniques/T1059/001/
    - https://attack.mitre.org/techniques/T1027/010/
    - https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_powershell_exe
author: 411 Threat Hunting
date: 2026-12-01
tags:
    - attack.execution
    - attack.stealth
    - attack.t1059.001
    - attack.t1027.010
logsource:
    category: process_creation
    product: windows
detection:
    selection_img:
        - Image|endswith:
              - '\powershell.exe'
              - '\pwsh.exe'
        - OriginalFileName:
              - 'PowerShell.EXE'
              - 'pwsh.dll'
    selection_enc:
        # -e, -ec, -en, -enc, -enco ... -encodedcommand (hyphen, slash or Unicode dash),
        # then 40+ base64 characters, optionally quoted. Does not match -EncodedArguments.
        CommandLine|re: '(?i)\s[-/–—―](e|ec|en|enc|enco|encod|encode|encoded|encodedc|encodedco|encodedcom|encodedcomm|encodedcomma|encodedcomman|encodedcommand)\s+[\x22\x27]?[A-Za-z0-9+/]{40,}'
    filter_known_benign:
        # Example only: replace with parent + account (+ command hash) pairs you have verified.
        ParentImage|endswith: '\CcmExec.exe'
    condition: selection_img and selection_enc and not filter_known_benign
falsepositives:
    - Software deployment and monitoring agents
    - Admin scripts that pass complex arguments as encoded commands
level: low
Sigma: narrower companion rule (level medium)
title: PowerShell Encoded Command From Suspicious Parent Or With Evasion Flags
id: 8d2b7c64-411b-4e0a-8f3d-5a9c1e6b7f12
status: experimental
description: >-
    Narrower companion to the hunt rule. PowerShell started with an encoded command and
    either a parent process that does not normally launch PowerShell (Office, script
    hosts, browsers, web server workers) or the hidden-window plus no-profile flag pair.
references:
    - https://attack.mitre.org/techniques/T1059/001/
    - https://attack.mitre.org/techniques/T1027/010/
author: 411 Threat Hunting
date: 2026-12-01
tags:
    - attack.execution
    - attack.t1059.001
    - attack.t1027.010
logsource:
    category: process_creation
    product: windows
detection:
    selection_img:
        - Image|endswith:
              - '\powershell.exe'
              - '\pwsh.exe'
        - OriginalFileName:
              - 'PowerShell.EXE'
              - 'pwsh.dll'
    selection_enc:
        CommandLine|re: '(?i)\s[-/–—―](e|ec|en|enc|enco|encod|encode|encoded|encodedc|encodedco|encodedcom|encodedcomm|encodedcomma|encodedcomman|encodedcommand)\s+[\x22\x27]?[A-Za-z0-9+/]{40,}'
    selection_parent:
        ParentImage|endswith:
            - '\winword.exe'
            - '\excel.exe'
            - '\powerpnt.exe'
            - '\outlook.exe'
            - '\mshta.exe'
            - '\wscript.exe'
            - '\cscript.exe'
            - '\w3wp.exe'
            - '\chrome.exe'
            - '\msedge.exe'
            - '\firefox.exe'
    selection_hidden:
        CommandLine|re: '(?i)\s[-/–—―]w[a-z]*\s+(h[a-z]*|1)\b'
    selection_noprofile:
        CommandLine|re: '(?i)\s[-/–—―]nop[a-z]*\b'
    filter_known_benign:
        ParentImage|endswith: '\CcmExec.exe'
    condition: selection_img and selection_enc and (selection_parent or (selection_hidden and selection_noprofile)) and not filter_known_benign
falsepositives:
    - Web-based admin consoles or installers that launch PowerShell from a browser or web server worker
    - Legitimate macros or add-ins that shell out to PowerShell
level: medium

Two original starter rules written for this site, untested in production. The first is a broad hunt rule (level: low) that matches the encoded-command flag and every prefix of -EncodedCommand with a hyphen, slash or Unicode dash, followed by 40 or more base64 characters. The companion (level: medium) keeps only hits with a parent process that rarely starts PowerShell, or the hidden-window plus no-profile pair. Replace filter_known_benign with parent, account and script pairs you have verified.

Sample KQL (Defender XDR and Sentinel)

KQL: list hits with score and decoded preview
// UNTESTED IN PRODUCTION. Syntax-checked only; tune before you rely on it.
// Microsoft Defender XDR Advanced Hunting, table DeviceProcessEvents.
// Sentinel: the table has TimeGenerated, not Timestamp. Swap the column name.
let lookback = 7d;
let SuspiciousParents = dynamic(["winword.exe", "excel.exe", "powerpnt.exe", "outlook.exe",
    "mshta.exe", "wscript.exe", "cscript.exe", "w3wp.exe", "chrome.exe", "msedge.exe", "firefox.exe"]);
// Example only. Prefer verified parent + account pairs over a parent name alone.
let KnownBenignParents = dynamic(["ccmexec.exe"]);
DeviceProcessEvents
| where Timestamp > ago(lookback)
| where FileName in~ ("powershell.exe", "pwsh.exe")
    or ProcessVersionInfoOriginalFileName in~ ("PowerShell.EXE", "pwsh.dll")
// Flag token after a hyphen, slash or Unicode dash, then 40+ base64 characters
| extend EncFlag = tolower(extract(@"(?i)\s[-/\x{2013}\x{2014}\x{2015}](e|ec|en[a-z]*)\s+[""']?[A-Za-z0-9+/]{40,}", 1, ProcessCommandLine))
// Keep -e, -ec, and any prefix of -encodedcommand (this drops -EncodedArguments)
| where isnotempty(EncFlag) and (EncFlag == "ec" or "encodedcommand" startswith EncFlag)
| where InitiatingProcessFileName !in~ (KnownBenignParents)
| extend B64 = extract(@"(?i)\s[-/\x{2013}\x{2014}\x{2015}](?:e|ec|en[a-z]*)\s+[""']?([A-Za-z0-9+/]{40,}={0,2})", 1, ProcessCommandLine)
// PowerShell encodes as UTF-16LE: dropping the NUL bytes makes ASCII scripts readable
| extend Decoded = replace_regex(base64_decode_tostring(B64), @"[^\x20-\x7E]", "")
| extend SuspiciousParent = InitiatingProcessFileName in~ (SuspiciousParents)
| extend HiddenWindow = ProcessCommandLine matches regex @"(?i)\s[-/]w[a-z]*\s+(h[a-z]*|1)\b"
| extend NoProfile = ProcessCommandLine matches regex @"(?i)\s[-/]nop[a-z]*\b"
| extend Score = iff(SuspiciousParent, 2, 0) + iff(HiddenWindow, 1, 0) + iff(NoProfile, 1, 0)
        + iff(Decoded matches regex @"(?i)(iex|invoke-expression|downloadstring|frombase64string|net\.webclient|-nop|bypass)", 2, 0)
| project Timestamp, DeviceName, AccountName, FileName, Parent = InitiatingProcessFileName,
    GrandParent = InitiatingProcessParentFileName, ParentCmd = InitiatingProcessCommandLine,
    Score, SuspiciousParent, HiddenWindow, NoProfile, Decoded, ProcessCommandLine
| order by Score desc, Timestamp desc
KQL: 30-day rarity view
// UNTESTED IN PRODUCTION. Rarity view: run after the query above, or paste the same filters first.
// Rare parent, account and script combinations first.
let lookback = 30d;
DeviceProcessEvents
| where Timestamp > ago(lookback)
| where FileName in~ ("powershell.exe", "pwsh.exe")
| where ProcessCommandLine matches regex @"(?i)\s[-/\x{2013}\x{2014}\x{2015}](e|ec|en[a-z]*)\s+[""']?[A-Za-z0-9+/]{40,}"
| extend B64 = extract(@"(?i)\s[-/\x{2013}\x{2014}\x{2015}](?:e|ec|en[a-z]*)\s+[""']?([A-Za-z0-9+/]{40,}={0,2})", 1, ProcessCommandLine)
| summarize Hits = count(), Devices = dcount(DeviceName), FirstSeen = min(Timestamp), LastSeen = max(Timestamp),
    SampleCmd = take_any(ProcessCommandLine)
    by Parent = InitiatingProcessFileName, AccountName, ScriptHash = hash_sha256(B64)
| order by Devices asc, Hits asc

Untested in production. The first query lists each hit with parent, grandparent, decoded preview and a simple score, highest first. The second summarises 30 days by parent, account and script hash so rare combinations surface first. The decode step is a quick preview for ASCII scripts; for anything else, decode the string in a safe analysis setting or read the matching 4104 event.

Sample pseudo-SPL

Pseudo-SPL, untested in Splunk. Adjust index, sourcetype and field names. It needs Sysmon event 1 (or equivalent) with CommandLine and ParentImage.

Pseudo-SPL (untested)
index=windows source="XmlWinEventLog:Microsoft-Windows-Sysmon/Operational" EventCode=1
    (Image="*\\powershell.exe" OR Image="*\\pwsh.exe" OR OriginalFileName="PowerShell.EXE" OR OriginalFileName="pwsh.dll")
| rex field=CommandLine "(?i)\s[-/–—―](?<enc_flag>e|ec|en[a-z]*)\s+[\"']?(?<b64>[A-Za-z0-9+/]{40,})"
| eval enc_flag=lower(enc_flag)
| where isnotnull(enc_flag) AND (enc_flag="ec" OR match("encodedcommand", "^".enc_flag))
| search NOT ParentImage="*\\CcmExec.exe"
| eval susp_parent=if(match(lower(ParentImage), "(winword|excel|powerpnt|outlook|mshta|wscript|cscript|w3wp|chrome|msedge|firefox)\.exe$"), 1, 0)
| eval hidden=if(match(CommandLine, "(?i)\s[-/]w[a-z]*\s+(h[a-z]*|1)\b"), 1, 0)
| eval noprofile=if(match(CommandLine, "(?i)\s[-/]nop[a-z]*\b"), 1, 0)
| eval score=susp_parent*2 + hidden + noprofile
| stats count AS hits dc(host) AS hosts min(_time) AS first_seen max(_time) AS last_seen max(score) AS score first(CommandLine) AS sample_cmd BY ParentImage, User
| convert ctime(first_seen) ctime(last_seen)
| sort 0 -score +hosts +hits

Splunk cannot decode base64 on its own, so decode the b64 value off-box with the steps below.

Decoding a string safely

Decode only; never executes the content
# Analyst workstation or isolated lab only. These lines only DECODE text; they never run it.
# PowerShell (Windows PowerShell 5.1 or PowerShell 7):
$b64 = '<paste the base64 string from the command line>'
[Text.Encoding]::Unicode.GetString([Convert]::FromBase64String($b64))

# Linux or macOS shell:
echo '<paste the base64 string>' | base64 -d | iconv -f UTF-16LE -t UTF-8

# Browser-free alternative: CyberChef recipe "From Base64" then "Decode text" (UTF-16LE, 1200)

This converts base64 into readable text and prints it. It does not execute the content. Do it on an analyst machine or lab, never on the affected host. The Linux line was tested; the PowerShell line was not run.

Good versus suspicious

Good versus suspicious
SignalUsually expectedWorth a closer look
Parent processSoftware-deployment or monitoring agent, scheduled task from known softwareOffice apps, browsers, mshta.exe, wscript.exe, a web server worker, or an unexpected service
Other flagsFew or noneCombined -NoProfile, -WindowStyle Hidden, -NonInteractive or -ExecutionPolicy Bypass
Decoded contentShort, readable, matches a documented admin taskDownload-and-run patterns, Invoke-Expression, FromBase64String, in-memory assembly loading
SpreadSame command on many hosts on a scheduleA single host, first time seen, or after-hours activity
AccountService or admin account that normally does thisOrdinary user account, or an account that never ran PowerShell before
What followsNothing unusualRare outbound connection, new scheduled task, new service, or file written to a user-writable path

Triage steps

  1. Decode the string and read it. If a 4104 event exists on that host, compare it with your decode.
  2. Check the parent chain: what started PowerShell, and what started that.
  3. Check the account and host: is this normal for them? Compare against 30 days of history.
  4. Look at what happened in the next few minutes: network connections, files written, tasks or services created.
  5. Search for the same command pattern, hash or destination on other hosts.
  6. Decide: benign and documented (add it to the baseline or tune the filter), unclear (watch and collect more), or suspicious (escalate to your incident process).
  7. Record the finding. If the hunt exposed a gap, turn it into a detection or a logging fix.

Limits and tuning

What was and was not tested

References