Huntbook by Predefender

part-5

PowerShell Hunting

Author: Roger C.B. Johnsen

PowerShell is legitimate administration infrastructure and a frequent attack surface. A flag or cmdlet alone is weak evidence. Hunt the full chain: parent process, host, identity, script content, network activity, and follow-on execution.

Telemetry to collect

SourceEvent/dataUse
PowerShell Operational4103Module/pipeline execution when Module Logging is enabled.
PowerShell Operational4104Script block content; reconstruct multipart messages using message number and total.
Windows PowerShell400/403/600Engine and provider lifecycle context.
Security4688Process creation and command line when policy permits.
Sysmon1, 3, 7, 11, 22Process, network, module, file, and DNS context.
Defender XDRDeviceProcessEvents, DeviceNetworkEvents, DeviceFileEventsCross-device correlation and pivots.
TranscriptionText transcriptsCommands and output; secure access because secrets may be recorded.

PowerShell 7 writes to PowerShellCore/Operational; Windows PowerShell uses Microsoft-Windows-PowerShell/Operational. Script Block Logging can expose sensitive data, so protect collected logs.

High-signal patterns

PatternWhy it mattersValidate
-EncodedCommand, -encObscures command text, but is also used by automation.Decode as UTF-16LE for Windows PowerShell and inspect content.
-WindowStyle HiddenSuppresses the console.Parent, user interaction, scheduled task, and child processes.
-NoProfileProduces predictable execution; common in both admin and attack tooling.Baseline the invoking product and account.
Invoke-Expression / iexExecutes generated strings.Trace string construction and source.
Invoke-WebRequest, Invoke-RestMethod, DownloadStringRetrieves or submits content.Destination, response type, file writes, and follow-on execution.
FromBase64String, compression, XORCan unpack staged content.Decode safely and hash extracted material.
Reflection, Add-Type, unmanaged API callsMay execute in memory or bypass normal tooling.Script block, loaded modules, memory alerts, child activity.
AMSI or logging modification stringsMay indicate Defense Evasion.Registry/config changes, errors, and security product telemetry.
PowerShell from Office, browser, archive tool, or serviceUnusual parent-child relationship.User action, file origin, signer, and adjacent events.

Execution policy is not a security boundary. -ExecutionPolicy Bypass is context, not proof of compromise.

Triage workflow

  1. Preserve the original command line and script block events.
  2. Normalise aliases and decode layers without executing content.
  3. Build the process tree and identify logon session and parent.
  4. Correlate DNS, network, file, registry, task, service, and WMI activity.
  5. Compare the host, user, script path, signer, and destination with baseline.
  6. Search for the same script hash, command fragment, URL, or infrastructure fleet-wide.

References

Revision

Revised DateComment
2025-03-21Article added
2026-07-22Added telemetry, caveats, signals, and triage workflow